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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    employee: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shift: '',
    
    
    
    
    
    
    
    
    
    workDate: '',
    
    
    
    
    
    
    
    
    
    
    scheduledTimeIn: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    scheduledTimeOut: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actualTimeIn: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    actualTimeOut: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    tardinessMinutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    undertimeMinutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    overtimeMinutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    nightDiffHours: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    workType: 'REGULAR',
    
    
    
    
    
    
    
    
    
    
    
    
    
    isAbsent: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    isHalfDay: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    halfDayType: 'AM',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source: 'BIOMETRIC',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    modifiedByUser: '',
    
    
    
    
    
    modificationReason: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    approvedByUser: '',
    
    
    
    
    
    
    
    
    
    approvedAt: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payrollRun: '',
    
    
    
}


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





















  <FormField label="Employee" labelFor="employee">
      <Field name="employee" id="employee" component={SelectField} options={[]} itemRef={'employees'}></Field>
  </FormField>



























  <FormField label="Shift" labelFor="shift">
      <Field name="shift" id="shift" component={SelectField} options={[]} itemRef={'shifts'}></Field>
  </FormField>



















  <FormField
      label="WorkDate"
  >
      <Field
          type="datetime-local"
          name="workDate"
          placeholder="WorkDate"
      />
  </FormField>

















  <FormField
      label="ScheduledTimeIn"
  >
      <Field
          name="scheduledTimeIn"
          placeholder="ScheduledTimeIn"
      />
  </FormField>



























  <FormField
      label="ScheduledTimeOut"
  >
      <Field
          name="scheduledTimeOut"
          placeholder="ScheduledTimeOut"
      />
  </FormField>





































  <FormField
      label="ActualTimeIn"
  >
      <Field
          type="datetime-local"
          name="actualTimeIn"
          placeholder="ActualTimeIn"
      />
  </FormField>



























  <FormField
      label="ActualTimeOut"
  >
      <Field
          type="datetime-local"
          name="actualTimeOut"
          placeholder="ActualTimeOut"
      />
  </FormField>























    <FormField
        label="TardinessMinutes"
    >
        <Field
            type="number"
            name="tardinessMinutes"
            placeholder="TardinessMinutes"
        />
    </FormField>



























    <FormField
        label="UndertimeMinutes"
    >
        <Field
            type="number"
            name="undertimeMinutes"
            placeholder="UndertimeMinutes"
        />
    </FormField>



























    <FormField
        label="OvertimeMinutes"
    >
        <Field
            type="number"
            name="overtimeMinutes"
            placeholder="OvertimeMinutes"
        />
    </FormField>



























    <FormField
        label="NightDiffHours"
    >
        <Field
            type="number"
            name="nightDiffHours"
            placeholder="NightDiffHours"
        />
    </FormField>



































  <FormField label="WorkType" labelFor="workType">
      <Field name="workType" id="workType" component="select">
      
        <option value="REGULAR">REGULAR</option>
      
        <option value="REST_DAY">REST_DAY</option>
      
        <option value="REGULAR_HOLIDAY">REGULAR_HOLIDAY</option>
      
        <option value="SPECIAL_HOLIDAY">SPECIAL_HOLIDAY</option>
      
      </Field>
  </FormField>





























  <FormField label='IsAbsent' labelFor='isAbsent'>
      <Field
          name='isAbsent'
          id='isAbsent'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='IsHalfDay' labelFor='isHalfDay'>
      <Field
          name='isHalfDay'
          id='isHalfDay'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="HalfDayType" labelFor="halfDayType">
      <Field name="halfDayType" id="halfDayType" component="select">
      
        <option value="AM">AM</option>
      
        <option value="PM">PM</option>
      
      </Field>
  </FormField>



























  <FormField label="Source" labelFor="source">
      <Field name="source" id="source" component="select">
      
        <option value="BIOMETRIC">BIOMETRIC</option>
      
        <option value="MANUAL">MANUAL</option>
      
        <option value="SYSTEM">SYSTEM</option>
      
      </Field>
  </FormField>































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











    <FormField label="ModificationReason" hasTextareaHeight>
        <Field name="modificationReason" as="textarea" placeholder="ModificationReason" />
    </FormField>











































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



















  <FormField
      label="ApprovedAt"
  >
      <Field
          type="datetime-local"
          name="approvedAt"
          placeholder="ApprovedAt"
      />
  </FormField>



































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

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

export default Time_recordsNew
