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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    product_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sku: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    barcode: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    product_status: 'draft',
    
    
    
    
    
    
    
    brand: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    unit: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    weight_grams: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    length_cm: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    width_cm: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    height_cm: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cost_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    retail_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reseller_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    agent_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    distributor_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    low_stock_threshold: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    product_images: [],
    
    
    
    
    
    
    short_description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/products/products-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















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









  <FormField
      label="ProductName"
  >
      <Field
          name="product_name"
          placeholder="ProductName"
      />
  </FormField>



























  <FormField
      label="SKU"
  >
      <Field
          name="sku"
          placeholder="SKU"
      />
  </FormField>



























  <FormField
      label="Barcode"
  >
      <Field
          name="barcode"
          placeholder="Barcode"
      />
  </FormField>









































  <FormField label="ProductStatus" labelFor="product_status">
      <Field name="product_status" id="product_status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="active">active</option>
      
        <option value="archived">archived</option>
      
      </Field>
  </FormField>













  <FormField
      label="Brand"
  >
      <Field
          name="brand"
          placeholder="Brand"
      />
  </FormField>



























  <FormField
      label="Category"
  >
      <Field
          name="category"
          placeholder="Category"
      />
  </FormField>



























  <FormField
      label="Unit"
  >
      <Field
          name="unit"
          placeholder="Unit"
      />
  </FormField>

































    <FormField
        label="Weight(grams)"
    >
        <Field
            type="number"
            name="weight_grams"
            placeholder="Weight(grams)"
        />
    </FormField>



























    <FormField
        label="Length(cm)"
    >
        <Field
            type="number"
            name="length_cm"
            placeholder="Length(cm)"
        />
    </FormField>



























    <FormField
        label="Width(cm)"
    >
        <Field
            type="number"
            name="width_cm"
            placeholder="Width(cm)"
        />
    </FormField>



























    <FormField
        label="Height(cm)"
    >
        <Field
            type="number"
            name="height_cm"
            placeholder="Height(cm)"
        />
    </FormField>



























    <FormField
        label="CostPrice"
    >
        <Field
            type="number"
            name="cost_price"
            placeholder="CostPrice"
        />
    </FormField>



























    <FormField
        label="RetailPrice"
    >
        <Field
            type="number"
            name="retail_price"
            placeholder="RetailPrice"
        />
    </FormField>



























    <FormField
        label="ResellerPrice"
    >
        <Field
            type="number"
            name="reseller_price"
            placeholder="ResellerPrice"
        />
    </FormField>



























    <FormField
        label="AgentPrice"
    >
        <Field
            type="number"
            name="agent_price"
            placeholder="AgentPrice"
        />
    </FormField>



























    <FormField
        label="DistributorPrice"
    >
        <Field
            type="number"
            name="distributor_price"
            placeholder="DistributorPrice"
        />
    </FormField>



























    <FormField
        label="LowStockThreshold"
    >
        <Field
            type="number"
            name="low_stock_threshold"
            placeholder="LowStockThreshold"
        />
    </FormField>











































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







    <FormField label="ShortDescription" hasTextareaHeight>
        <Field name="short_description" as="textarea" placeholder="ShortDescription" />
    </FormField>





























      <FormField label='Description' hasTextareaHeight>
          <Field
              name='description'
              id='description'
              component={RichTextField}
          ></Field>
      </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('/products/products-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ProductsNew
