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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    restaurant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    client_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    table: '',
    
    
    
    
    
    
    
    
    
    start_time: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_time: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    party_size: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'en_attente',
    
    
    
    
    
    
    
    
    note: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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





















  <FormField label="Restaurant" labelFor="restaurant">
      <Field name="restaurant" id="restaurant" component={SelectField} options={[]} itemRef={'restaurants'}></Field>
  </FormField>



























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



























  <FormField label="Table" labelFor="table">
      <Field name="table" id="table" component={SelectField} options={[]} itemRef={'restaurant_tables'}></Field>
  </FormField>



















  <FormField
      label="Débutréservation"
  >
      <Field
          type="datetime-local"
          name="start_time"
          placeholder="Débutréservation"
      />
  </FormField>



























  <FormField
      label="Finréservation"
  >
      <Field
          type="datetime-local"
          name="end_time"
          placeholder="Finréservation"
      />
  </FormField>























    <FormField
        label="Nombredepersonnes"
    >
        <Field
            type="number"
            name="party_size"
            placeholder="Nombredepersonnes"
        />
    </FormField>



































  <FormField label="Statut" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="en_attente">en_attente</option>
      
        <option value="confirmee">confirmee</option>
      
        <option value="honoree">honoree</option>
      
        <option value="annulee">annulee</option>
      
        <option value="no_show">no_show</option>
      
      </Field>
  </FormField>















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

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

export default ReservationsNew
