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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    hotel: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    primary_guest: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    room_type: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    rate_plan: '',
    
    
    
    
    booking_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_in_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_out_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    adults: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    children: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source: 'web',
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    city_tax_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    deposit_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    deposit_status: 'none',
    
    
    
    
    
    
    
    
    special_requests: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cancelled_at: '',
    
    
    
    
    
    
    
    
    
    
    
    cancellation_reason: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reserved_rooms: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    booking_guests: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    messages: [],
    
    
}


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,
                    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="Hotel" labelFor="hotel">
      <Field name="hotel" id="hotel" component={SelectField} options={[]} itemRef={'hotels'}></Field>
  </FormField>



























  <FormField label="PrimaryGuest" labelFor="primary_guest">
      <Field name="primary_guest" id="primary_guest" component={SelectField} options={[]} itemRef={'guests'}></Field>
  </FormField>



























  <FormField label="RoomType" labelFor="room_type">
      <Field name="room_type" id="room_type" component={SelectField} options={[]} itemRef={'room_types'}></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="BookingCode"
  >
      <Field
          name="booking_code"
          placeholder="BookingCode"
      />
  </FormField>





































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



























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























    <FormField
        label="Adults"
    >
        <Field
            type="number"
            name="adults"
            placeholder="Adults"
        />
    </FormField>



























    <FormField
        label="Children"
    >
        <Field
            type="number"
            name="children"
            placeholder="Children"
        />
    </FormField>



































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



























  <FormField label="Source" labelFor="source">
      <Field name="source" id="source" component="select">
      
        <option value="web">web</option>
      
        <option value="admin">admin</option>
      
        <option value="phone">phone</option>
      
        <option value="email">email</option>
      
        <option value="ota">ota</option>
      
      </Field>
  </FormField>



















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



























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



























    <FormField
        label="CityTaxAmount"
    >
        <Field
            type="number"
            name="city_tax_amount"
            placeholder="CityTaxAmount"
        />
    </FormField>





















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

































    <FormField
        label="DepositAmount"
    >
        <Field
            type="number"
            name="deposit_amount"
            placeholder="DepositAmount"
        />
    </FormField>



































  <FormField label="DepositStatus" labelFor="deposit_status">
      <Field name="deposit_status" id="deposit_status" component="select">
      
        <option value="none">none</option>
      
        <option value="requested">requested</option>
      
        <option value="paid">paid</option>
      
        <option value="refunded">refunded</option>
      
      </Field>
  </FormField>















    <FormField label="SpecialRequests" hasTextareaHeight>
        <Field name="special_requests" as="textarea" placeholder="SpecialRequests" />
    </FormField>



































  <FormField
      label="CancelledAt"
  >
      <Field
          type="datetime-local"
          name="cancelled_at"
          placeholder="CancelledAt"
      />
  </FormField>



















    <FormField label="CancellationReason" hasTextareaHeight>
        <Field name="cancellation_reason" as="textarea" placeholder="CancellationReason" />
    </FormField>













































    <FormField label='ReservedRooms' labelFor='reserved_rooms'>
        <Field
            name='reserved_rooms'
            id='reserved_rooms'
            itemRef={'rooms'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='BookingGuests' labelFor='booking_guests'>
        <Field
            name='booking_guests'
            id='booking_guests'
            itemRef={'booking_guests'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='Payments' labelFor='payments'>
        <Field
            name='payments'
            id='payments'
            itemRef={'payments'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='Messages' labelFor='messages'>
        <Field
            name='messages'
            id='messages'
            itemRef={'messages'}
            options={[]}
            component={SelectFieldMany}>
        </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
