import { mdiAccount, mdiChartTimelineVariant, mdiMail, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement } from 'react'
import CardBox from '../../components/CardBox'
import LayoutAuthenticated from '../../layouts/Authenticated'
import SectionMain from '../../components/SectionMain'
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton'
import { getPageTitle } from '../../config'

import { Field, Form, Formik } from 'formik'
import FormField from '../../components/FormField'
import BaseDivider from '../../components/BaseDivider'
import BaseButtons from '../../components/BaseButtons'
import BaseButton from '../../components/BaseButton'
import FormCheckRadio from '../../components/FormCheckRadio'
import FormCheckRadioGroup from '../../components/FormCheckRadioGroup'
import FormFilePicker from '../../components/FormFilePicker'
import FormImagePicker from '../../components/FormImagePicker'
import { SwitchField } from '../../components/SwitchField'

import { SelectField } from '../../components/SelectField'
import { SelectFieldMany } from "../../components/SelectFieldMany";
import {RichTextField} from "../../components/RichTextField";

import { create } from '../../stores/timetable_entries/timetable_entriesSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    course_section: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    room: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    day_of_week: 'monday',
    
    
    
    
    
    
    
    
    
    
    
    
    start_time: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_time: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    effective_from: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    effective_to: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    repeat_pattern: 'weekly',
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const Timetable_entriesNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()

    
    
    // get from url params
    const { dateRangeStart, dateRangeEnd } = router.query
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/timetable_entries/timetable_entries-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    start_time: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    end_time: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="CourseSection" labelFor="course_section">
      <Field name="course_section" id="course_section" component={SelectField} options={[]} itemRef={'course_sections'}></Field>
  </FormField>



























  <FormField label="Room" labelFor="room">
      <Field name="room" id="room" component={SelectField} options={[]} itemRef={'rooms'}></Field>
  </FormField>























  <FormField label="DayofWeek" labelFor="day_of_week">
      <Field name="day_of_week" id="day_of_week" component="select">
      
        <option value="monday">monday</option>
      
        <option value="tuesday">tuesday</option>
      
        <option value="wednesday">wednesday</option>
      
        <option value="thursday">thursday</option>
      
        <option value="friday">friday</option>
      
        <option value="saturday">saturday</option>
      
        <option value="sunday">sunday</option>
      
      </Field>
  </FormField>























  <FormField
      label="StartTime"
  >
      <Field
          type="datetime-local"
          name="start_time"
          placeholder="StartTime"
      />
  </FormField>



























  <FormField
      label="EndTime"
  >
      <Field
          type="datetime-local"
          name="end_time"
          placeholder="EndTime"
      />
  </FormField>



























  <FormField
      label="EffectiveFrom"
  >
      <Field
          type="datetime-local"
          name="effective_from"
          placeholder="EffectiveFrom"
      />
  </FormField>



























  <FormField
      label="EffectiveTo"
  >
      <Field
          type="datetime-local"
          name="effective_to"
          placeholder="EffectiveTo"
      />
  </FormField>































  <FormField label="RepeatPattern" labelFor="repeat_pattern">
      <Field name="repeat_pattern" id="repeat_pattern" component="select">
      
        <option value="weekly">weekly</option>
      
        <option value="biweekly">biweekly</option>
      
        <option value="once">once</option>
      
      </Field>
  </FormField>















    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </FormField>























              <BaseDivider />
              <BaseButtons>
                <BaseButton type="submit" color="info" label="Submit" />
                <BaseButton type="reset" color="info" outline label="Reset" />
                <BaseButton type='reset' color='danger' outline label='Cancel' onClick={() => router.push('/timetable_entries/timetable_entries-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

Timetable_entriesNew.getLayout = function getLayout(page: ReactElement) {
  return (
      <LayoutAuthenticated
        
          permission={'CREATE_TIMETABLE_ENTRIES'}
        
      >
          {page}
      </LayoutAuthenticated>
  )
}

export default Timetable_entriesNew
