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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vehicle: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pickup_branch: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dropoff_branch: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    rate_plan: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    insurance_plan: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    promo_code: '',
    
    
    
    
    
    
    
    
    
    pickup_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dropoff_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payment_status: 'unpaid',
    
    
    
    
    
    
    
    subtotal_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    extras_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    insurance_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    discount_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    internal_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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





















  <FormField label="Company" labelFor="company">
      <Field name="company" id="company" component={SelectField} options={[]} itemRef={'companies'}></Field>
  </FormField>



























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



























  <FormField label="Vehicle" labelFor="vehicle">
      <Field name="vehicle" id="vehicle" component={SelectField} options={[]} itemRef={'vehicles'}></Field>
  </FormField>



























  <FormField label="PickupBranch" labelFor="pickup_branch">
      <Field name="pickup_branch" id="pickup_branch" component={SelectField} options={[]} itemRef={'branches'}></Field>
  </FormField>



























  <FormField label="DropoffBranch" labelFor="dropoff_branch">
      <Field name="dropoff_branch" id="dropoff_branch" component={SelectField} options={[]} itemRef={'branches'}></Field>
  </FormField>



























  <FormField label="RatePlan" labelFor="rate_plan">
      <Field name="rate_plan" id="rate_plan" component={SelectField} options={[]} itemRef={'rate_plans'}></Field>
  </FormField>



























  <FormField label="InsurancePlan" labelFor="insurance_plan">
      <Field name="insurance_plan" id="insurance_plan" component={SelectField} options={[]} itemRef={'insurance_plans'}></Field>
  </FormField>



























  <FormField label="PromoCode" labelFor="promo_code">
      <Field name="promo_code" id="promo_code" component={SelectField} options={[]} itemRef={'promo_codes'}></Field>
  </FormField>



















  <FormField
      label="PickupAt"
  >
      <Field
          type="datetime-local"
          name="pickup_at"
          placeholder="PickupAt"
      />
  </FormField>



























  <FormField
      label="DropoffAt"
  >
      <Field
          type="datetime-local"
          name="dropoff_at"
          placeholder="DropoffAt"
      />
  </FormField>































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="pending_payment">pending_payment</option>
      
        <option value="confirmed">confirmed</option>
      
        <option value="checked_out">checked_out</option>
      
        <option value="checked_in">checked_in</option>
      
        <option value="cancelled">cancelled</option>
      
        <option value="no_show">no_show</option>
      
      </Field>
  </FormField>



























  <FormField label="PaymentStatus" labelFor="payment_status">
      <Field name="payment_status" id="payment_status" component="select">
      
        <option value="unpaid">unpaid</option>
      
        <option value="authorized">authorized</option>
      
        <option value="paid">paid</option>
      
        <option value="partially_refunded">partially_refunded</option>
      
        <option value="refunded">refunded</option>
      
        <option value="failed">failed</option>
      
      </Field>
  </FormField>



















    <FormField
        label="SubtotalAmount"
    >
        <Field
            type="number"
            name="subtotal_amount"
            placeholder="SubtotalAmount"
        />
    </FormField>



























    <FormField
        label="ExtrasAmount"
    >
        <Field
            type="number"
            name="extras_amount"
            placeholder="ExtrasAmount"
        />
    </FormField>



























    <FormField
        label="InsuranceAmount"
    >
        <Field
            type="number"
            name="insurance_amount"
            placeholder="InsuranceAmount"
        />
    </FormField>



























    <FormField
        label="DiscountAmount"
    >
        <Field
            type="number"
            name="discount_amount"
            placeholder="DiscountAmount"
        />
    </FormField>



























    <FormField
        label="TaxAmount"
    >
        <Field
            type="number"
            name="tax_amount"
            placeholder="TaxAmount"
        />
    </FormField>



























    <FormField
        label="TotalAmount"
    >
        <Field
            type="number"
            name="total_amount"
            placeholder="TotalAmount"
        />
    </FormField>





















  <FormField
      label="Currency"
  >
      <Field
          name="currency"
          placeholder="Currency"
      />
  </FormField>





























    <FormField label="CustomerNotes" hasTextareaHeight>
        <Field name="customer_notes" as="textarea" placeholder="CustomerNotes" />
    </FormField>



























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

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

export default BookingsNew
