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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    learning_path: '',
    
    
    
    
    mission_title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    mission_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    mission_type: 'video',
    
    
    
    
    
    
    
    
    
    
    sequence_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    estimated_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    instructions: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    resource_files: [],
    
    
    
    
    
    
    video_url: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_required: false,
    
    
    
    
    
    
    
    
    
    points_awarded: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    coins_awarded: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/missions/missions-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="LearningPath" labelFor="learning_path">
      <Field name="learning_path" id="learning_path" component={SelectField} options={[]} itemRef={'learning_paths'}></Field>
  </FormField>









  <FormField
      label="MissionTitle"
  >
      <Field
          name="mission_title"
          placeholder="MissionTitle"
      />
  </FormField>



























  <FormField
      label="MissionCode"
  >
      <Field
          name="mission_code"
          placeholder="MissionCode"
      />
  </FormField>









































  <FormField label="MissionType" labelFor="mission_type">
      <Field name="mission_type" id="mission_type" component="select">
      
        <option value="video">video</option>
      
        <option value="document">document</option>
      
        <option value="quiz">quiz</option>
      
        <option value="simulation">simulation</option>
      
        <option value="task">task</option>
      
        <option value="checklist_item">checklist_item</option>
      
      </Field>
  </FormField>



















    <FormField
        label="SequenceOrder"
    >
        <Field
            type="number"
            name="sequence_order"
            placeholder="SequenceOrder"
        />
    </FormField>



























    <FormField
        label="EstimatedMinutes"
    >
        <Field
            type="number"
            name="estimated_minutes"
            placeholder="EstimatedMinutes"
        />
    </FormField>

























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














































  <FormField>
      <Field
          label='ResourceFiles'
          color='info'
          icon={mdiUpload}
          path={'missions/resource_files'}
          name='resource_files'
          id='resource_files'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>




  <FormField
      label="VideoURL"
  >
      <Field
          name="video_url"
          placeholder="VideoURL"
      />
  </FormField>











































  <FormField label='IsRequired' labelFor='is_required'>
      <Field
          name='is_required'
          id='is_required'
          component={SwitchField}
      ></Field>
  </FormField>

















    <FormField
        label="PointsAwarded"
    >
        <Field
            type="number"
            name="points_awarded"
            placeholder="PointsAwarded"
        />
    </FormField>



























    <FormField
        label="CoinsAwarded"
    >
        <Field
            type="number"
            name="coins_awarded"
            placeholder="CoinsAwarded"
        />
    </FormField>



































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































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

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

export default MissionsNew
