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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    hotel: '',
    
    
    
    
    reservation_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    guest: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    room: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    room_type: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    rate_plan: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sales_channel: '',
    
    
    
    
    
    
    
    
    
    check_in_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    check_out_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    adults: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    children: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'pending',
    
    
    
    
    
    
    
    total_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tax_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    deposit_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    special_requests: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    internal_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cancelled_at: '',
    
    
    
    
    
    
    
    
    
    
    
    cancellation_reason: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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,
                    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="ReservationNumber"
  >
      <Field
          name="reservation_number"
          placeholder="ReservationNumber"
      />
  </FormField>













































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



























  <FormField label="Room" labelFor="room">
      <Field name="room" id="room" component={SelectField} options={[]} itemRef={'rooms'}></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="SourceChannel" labelFor="sales_channel">
      <Field name="sales_channel" id="sales_channel" component={SelectField} options={[]} itemRef={'sales_channels'}></Field>
  </FormField>



















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



























  <FormField
      label="CheckOut"
  >
      <Field
          type="datetime-local"
          name="check_out_at"
          placeholder="CheckOut"
      />
  </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="pending">pending</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="TotalAmount"
    >
        <Field
            type="number"
            name="total_amount"
            placeholder="TotalAmount"
        />
    </FormField>



























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



























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























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



























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

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

export default ReservationsNew
