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

const initialValues = {
    
    
    session_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    survey: '',
    
    
    
    
    
    
    
    
    
    started: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ended: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'queued',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ai_model: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    api_key: '',
    
    
    
    
    
    
    response_cache: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    progress_percent: '',
    
    
    
    
    
    
    
    
    
    
    
}


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



  <FormField
      label="SessionName"
  >
      <Field
          name="session_name"
          placeholder="SessionName"
      />
  </FormField>













































  <FormField label="Survey" labelFor="survey">
      <Field name="survey" id="survey" component={SelectField} options={[]} itemRef={'surveys'}></Field>
  </FormField>



















  <FormField
      label="Started"
  >
      <Field
          type="datetime-local"
          name="started"
          placeholder="Started"
      />
  </FormField>



























  <FormField
      label="Ended"
  >
      <Field
          type="datetime-local"
          name="ended"
          placeholder="Ended"
      />
  </FormField>































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="queued">queued</option>
      
        <option value="processing">processing</option>
      
        <option value="completed">completed</option>
      
        <option value="failed">failed</option>
      
      </Field>
  </FormField>































  <FormField label="AIModel" labelFor="ai_model">
      <Field name="ai_model" id="ai_model" component={SelectField} options={[]} itemRef={'ai_models'}></Field>
  </FormField>



























  <FormField label="APIKey" labelFor="api_key">
      <Field name="api_key" id="api_key" component={SelectField} options={[]} itemRef={'api_keys'}></Field>
  </FormField>













      <FormField label='CachedResponse' hasTextareaHeight>
          <Field
              name='response_cache'
              id='response_cache'
              component={RichTextField}
          ></Field>
      </FormField>





























    <FormField
        label="Progress(%)"
    >
        <Field
            type="number"
            name="progress_percent"
            placeholder="Progress(%)"
        />
    </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('/fill_sessions/fill_sessions-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Fill_sessionsNew
