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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    workspace: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    property: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    service_catalog_item: '',
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    frequency: 'weekly',
    
    
    
    
    
    
    
    
    
    
    interval_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    day_of_week: 'mon',
    
    
    
    
    
    
    
    
    
    
    day_of_month: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_active: false,
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const Recurring_schedulesNew = () => {
  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('/recurring_schedules/recurring_schedules-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_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    end_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















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



























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



























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



























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









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









































  <FormField label="Frequency" labelFor="frequency">
      <Field name="frequency" id="frequency" component="select">
      
        <option value="weekly">weekly</option>
      
        <option value="biweekly">biweekly</option>
      
        <option value="monthly">monthly</option>
      
      </Field>
  </FormField>



















    <FormField
        label="IntervalCount"
    >
        <Field
            type="number"
            name="interval_count"
            placeholder="IntervalCount"
        />
    </FormField>



































  <FormField label="DayOfWeek" labelFor="day_of_week">
      <Field name="day_of_week" id="day_of_week" component="select">
      
        <option value="mon">mon</option>
      
        <option value="tue">tue</option>
      
        <option value="wed">wed</option>
      
        <option value="thu">thu</option>
      
        <option value="fri">fri</option>
      
        <option value="sat">sat</option>
      
        <option value="sun">sun</option>
      
      </Field>
  </FormField>



















    <FormField
        label="DayOfMonth"
    >
        <Field
            type="number"
            name="day_of_month"
            placeholder="DayOfMonth"
        />
    </FormField>































  <FormField
      label="StartAt"
  >
      <Field
          type="datetime-local"
          name="start_at"
          placeholder="StartAt"
      />
  </FormField>



























  <FormField
      label="EndAt"
  >
      <Field
          type="datetime-local"
          name="end_at"
          placeholder="EndAt"
      />
  </FormField>

































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













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

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

export default Recurring_schedulesNew
