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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    report_type: 'asset_occupancy',
    
    
    
    
    
    
    
    
    
    
    
    
    period_start: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    period_end: '',
    
    
    
    
    
    
    
    
    
    
    
    filters_json: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    export_files: [],
    
    
    
    
    
}


const ReportsNew = () => {
  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('/reports/reports-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    period_start: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    period_end: 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="ReportName"
  >
      <Field
          name="name"
          placeholder="ReportName"
      />
  </FormField>









































  <FormField label="ReportType" labelFor="report_type">
      <Field name="report_type" id="report_type" component="select">
      
        <option value="asset_occupancy">asset_occupancy</option>
      
        <option value="inventory_turnover">inventory_turnover</option>
      
        <option value="sales_summary">sales_summary</option>
      
        <option value="ar_aging">ar_aging</option>
      
        <option value="crm_pipeline">crm_pipeline</option>
      
        <option value="content_performance">content_performance</option>
      
        <option value="custom">custom</option>
      
      </Field>
  </FormField>























  <FormField
      label="PeriodStart"
  >
      <Field
          type="datetime-local"
          name="period_start"
          placeholder="PeriodStart"
      />
  </FormField>



























  <FormField
      label="PeriodEnd"
  >
      <Field
          type="datetime-local"
          name="period_end"
          placeholder="PeriodEnd"
      />
  </FormField>



















    <FormField label="FiltersJSON" hasTextareaHeight>
        <Field name="filters_json" as="textarea" placeholder="FiltersJSON" />
    </FormField>
















































  <FormField>
      <Field
          label='ExportFiles'
          color='info'
          icon={mdiUpload}
          path={'reports/export_files'}
          name='export_files'
          id='export_files'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></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('/reports/reports-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ReportsNew
