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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    employee: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    outlet: '',
    
    
    
    
    
    
    
    
    
    work_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_in_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_out_at: '',
    
    
    
    
    
    
    
    
    
    
    check_in_lat: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_in_lng: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_out_lat: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_out_lng: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_in_photo: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_out_photo: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'hadir',
    
    
    
    
    
    
    
    
    
    
    late_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    gps_valid: false,
    
    
    
    
    
    
    
    
    
    
    remarks: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const Attendance_logsNew = () => {
  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('/attendance_logs/attendance_logs-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    check_in_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    check_out_at: 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="Outlet" labelFor="outlet">
      <Field name="outlet" id="outlet" component={SelectField} options={[]} itemRef={'outlets'}></Field>
  </FormField>



















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



























  <FormField
      label="CheckInTime"
  >
      <Field
          type="datetime-local"
          name="check_in_at"
          placeholder="CheckInTime"
      />
  </FormField>



























  <FormField
      label="CheckOutTime"
  >
      <Field
          type="datetime-local"
          name="check_out_at"
          placeholder="CheckOutTime"
      />
  </FormField>























    <FormField
        label="CheckInLatitude"
    >
        <Field
            type="number"
            name="check_in_lat"
            placeholder="CheckInLatitude"
        />
    </FormField>



























    <FormField
        label="CheckInLongitude"
    >
        <Field
            type="number"
            name="check_in_lng"
            placeholder="CheckInLongitude"
        />
    </FormField>



























    <FormField
        label="CheckOutLatitude"
    >
        <Field
            type="number"
            name="check_out_lat"
            placeholder="CheckOutLatitude"
        />
    </FormField>



























    <FormField
        label="CheckOutLongitude"
    >
        <Field
            type="number"
            name="check_out_lng"
            placeholder="CheckOutLongitude"
        />
    </FormField>











































  <FormField>
      <Field
          label='CheckInPhoto'
          color='info'
          icon={mdiUpload}
          path={'attendance_logs/check_in_photo'}
          name='check_in_photo'
          id='check_in_photo'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>



























  <FormField>
      <Field
          label='CheckOutPhoto'
          color='info'
          icon={mdiUpload}
          path={'attendance_logs/check_out_photo'}
          name='check_out_photo'
          id='check_out_photo'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>



















  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="hadir">hadir</option>
      
        <option value="telat">telat</option>
      
        <option value="tidak_hadir">tidak_hadir</option>
      
        <option value="sakit">sakit</option>
      
        <option value="izin">izin</option>
      
        <option value="dinas">dinas</option>
      
      </Field>
  </FormField>



















    <FormField
        label="LateMinutes"
    >
        <Field
            type="number"
            name="late_minutes"
            placeholder="LateMinutes"
        />
    </FormField>





































  <FormField label='GPSValid' labelFor='gps_valid'>
      <Field
          name='gps_valid'
          id='gps_valid'
          component={SwitchField}
      ></Field>
  </FormField>













    <FormField label="Remarks" hasTextareaHeight>
        <Field name="remarks" as="textarea" placeholder="Remarks" />
    </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('/attendance_logs/attendance_logs-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Attendance_logsNew
