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 = {
    
    
    name_ar: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    name_en: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    slug: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    short_description_ar: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    short_description_en: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description_ar: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description_en: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    images: [],
    
    
    
    
    
    sku: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    barcode: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    price_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    compare_at_price_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cost_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    stock_on_hand: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    low_stock_threshold: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    track_inventory: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_active: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_featured: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    condition: 'new',
    
    
    
    
    
    
    
    
    
    
    
    
    published_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    brand: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    supplier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    variants: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reviews: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    collections: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fbt_items: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    seo_entries: [],
    
    
}


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="Name(Arabic)"
  >
      <Field
          name="name_ar"
          placeholder="Name(Arabic)"
      />
  </FormField>



























  <FormField
      label="Name(English)"
  >
      <Field
          name="name_en"
          placeholder="Name(English)"
      />
  </FormField>



























  <FormField
      label="Slug"
  >
      <Field
          name="slug"
          placeholder="Slug"
      />
  </FormField>































      <FormField label='ShortDescription(Arabic)' hasTextareaHeight>
          <Field
              name='short_description_ar'
              id='short_description_ar'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='ShortDescription(English)' hasTextareaHeight>
          <Field
              name='short_description_en'
              id='short_description_en'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='Description(Arabic)' hasTextareaHeight>
          <Field
              name='description_ar'
              id='description_ar'
              component={RichTextField}
          ></Field>
      </FormField>



























      <FormField label='Description(English)' hasTextareaHeight>
          <Field
              name='description_en'
              id='description_en'
              component={RichTextField}
          ></Field>
      </FormField>













































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





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



























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

































    <FormField
        label="Price(IQD)"
    >
        <Field
            type="number"
            name="price_iqd"
            placeholder="Price(IQD)"
        />
    </FormField>



























    <FormField
        label="CompareAtPrice(IQD)"
    >
        <Field
            type="number"
            name="compare_at_price_iqd"
            placeholder="CompareAtPrice(IQD)"
        />
    </FormField>



























    <FormField
        label="Cost(IQD)"
    >
        <Field
            type="number"
            name="cost_iqd"
            placeholder="Cost(IQD)"
        />
    </FormField>



























    <FormField
        label="StockOnHand"
    >
        <Field
            type="number"
            name="stock_on_hand"
            placeholder="StockOnHand"
        />
    </FormField>



























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





































  <FormField label='TrackInventory' labelFor='track_inventory'>
      <Field
          name='track_inventory'
          id='track_inventory'
          component={SwitchField}
      ></Field>
  </FormField>



























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



























  <FormField label='IsFeatured' labelFor='is_featured'>
      <Field
          name='is_featured'
          id='is_featured'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="Condition" labelFor="condition">
      <Field name="condition" id="condition" component="select">
      
        <option value="new">new</option>
      
        <option value="used">used</option>
      
        <option value="refurbished">refurbished</option>
      
      </Field>
  </FormField>























  <FormField
      label="PublishedAt"
  >
      <Field
          type="datetime-local"
          name="published_at"
          placeholder="PublishedAt"
      />
  </FormField>



































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



























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



























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





























    <FormField label='Variants' labelFor='variants'>
        <Field
            name='variants'
            id='variants'
            itemRef={'product_variants'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='Reviews' labelFor='reviews'>
        <Field
            name='reviews'
            id='reviews'
            itemRef={'product_reviews'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























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



























    <FormField label='FrequentlyBoughtTogetherItems' labelFor='fbt_items'>
        <Field
            name='fbt_items'
            id='fbt_items'
            itemRef={'frequently_bought_together_items'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='SEOEntries' labelFor='seo_entries'>
        <Field
            name='seo_entries'
            id='seo_entries'
            itemRef={'seo_entries'}
            options={[]}
            component={SelectFieldMany}>
        </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
