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/tests/testsSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValues = {
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    subject: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    grade_level: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    textbook: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    chapter: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    build_mode: 'manual',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    target_question_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    target_total_points: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    target_average_difficulty: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shuffle_questions: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shuffle_answers: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    assigned_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    due_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    instructions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    skills: [],
    
    
}


const TestsNew = () => {
  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('/tests/tests-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    assigned_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    due_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



  <FormField
      label="TestTitle"
  >
      <Field
          name="title"
          placeholder="TestTitle"
      />
  </FormField>













































  <FormField label="Owner" labelFor="owner_user">
      <Field name="owner_user" id="owner_user" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>



























  <FormField label="Subject" labelFor="subject">
      <Field name="subject" id="subject" component={SelectField} options={[]} itemRef={'subjects'}></Field>
  </FormField>



























  <FormField label="GradeLevel" labelFor="grade_level">
      <Field name="grade_level" id="grade_level" component={SelectField} options={[]} itemRef={'grade_levels'}></Field>
  </FormField>



























  <FormField label="Textbook" labelFor="textbook">
      <Field name="textbook" id="textbook" component={SelectField} options={[]} itemRef={'textbooks'}></Field>
  </FormField>



























  <FormField label="Chapter" labelFor="chapter">
      <Field name="chapter" id="chapter" component={SelectField} options={[]} itemRef={'chapters'}></Field>
  </FormField>























  <FormField label="BuildMode" labelFor="build_mode">
      <Field name="build_mode" id="build_mode" component="select">
      
        <option value="manual">manual</option>
      
        <option value="automatic">automatic</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="ready">ready</option>
      
        <option value="exported">exported</option>
      
        <option value="archived">archived</option>
      
      </Field>
  </FormField>



















    <FormField
        label="TargetQuestionCount"
    >
        <Field
            type="number"
            name="target_question_count"
            placeholder="TargetQuestionCount"
        />
    </FormField>



























    <FormField
        label="TargetTotalPoints"
    >
        <Field
            type="number"
            name="target_total_points"
            placeholder="TargetTotalPoints"
        />
    </FormField>



























    <FormField
        label="TargetAverageDifficulty"
    >
        <Field
            type="number"
            name="target_average_difficulty"
            placeholder="TargetAverageDifficulty"
        />
    </FormField>





































  <FormField label='ShuffleQuestions' labelFor='shuffle_questions'>
      <Field
          name='shuffle_questions'
          id='shuffle_questions'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='ShuffleAnswers' labelFor='shuffle_answers'>
      <Field
          name='shuffle_answers'
          id='shuffle_answers'
          component={SwitchField}
      ></Field>
  </FormField>





















  <FormField
      label="AssignedAt"
  >
      <Field
          type="datetime-local"
          name="assigned_at"
          placeholder="AssignedAt"
      />
  </FormField>



























  <FormField
      label="DueAt"
  >
      <Field
          type="datetime-local"
          name="due_at"
          placeholder="DueAt"
      />
  </FormField>





















      <FormField label='Instructions' hasTextareaHeight>
          <Field
              name='instructions'
              id='instructions'
              component={RichTextField}
          ></Field>
      </FormField>











































    <FormField label='SkillsCovered' labelFor='skills'>
        <Field
            name='skills'
            id='skills'
            itemRef={'skills'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </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('/tests/tests-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default TestsNew
