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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    address: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    city: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    country: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    timezone: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    images: [],
    
    
    
    
    
    
    
    
    
    
    
    is_active: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    unit_types: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    units: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    amenities: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const PropertiesNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/properties/properties-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Property')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Property" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox className='mx-auto max-w-6xl'>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>
              <div className='grid gap-5 md:grid-cols-2'>





















  <FormField label="Tenant" labelFor="tenant">
      <Field name="tenant" id="tenant" component={SelectField} options={[]} itemRef={'tenants'}></Field>
  </FormField>









  <FormField
      label="Propertyname"
  >
      <Field
          name="name"
          placeholder="Propertyname"
      />
  </FormField>



























  <FormField
      label="Propertycode"
  >
      <Field
          name="code"
          placeholder="Propertycode"
      />
  </FormField>





























    <FormField label="Address" hasTextareaHeight>
        <Field name="address" as="textarea" placeholder="Address" />
    </FormField>

























  <FormField
      label="City"
  >
      <Field
          name="city"
          placeholder="City"
      />
  </FormField>



























  <FormField
      label="Country"
  >
      <Field
          name="country"
          placeholder="Country"
      />
  </FormField>



























  <FormField
      label="Timezone"
  >
      <Field
          name="timezone"
          placeholder="Timezone"
      />
  </FormField>































      <FormField label='Description' hasTextareaHeight>
          <Field
              name='description'
              id='description'
              component={RichTextField}
          ></Field>
      </FormField>













































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





















  <FormField label='Isactive' labelFor='is_active'>
      <Field
          name='is_active'
          id='is_active'
          component={SwitchField}
      ></Field>
  </FormField>































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



























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



























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

























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







              </div>

              <BaseDivider />
              <BaseButtons>
                <BaseButton type="submit" color="info" label="Save" />
                <BaseButton type="reset" color="info" outline label="Reset" />
                <BaseButton type='reset' color='danger' outline label='Cancel' onClick={() => router.push('/properties/properties-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default PropertiesNew
