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

const initialValues = {
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    item_type: 'product',
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    base_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    weight: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_stackable: false,
    
    
    
    
    
    
    
    
    
    
    
    
    max_stack_size: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_perishable: false,
    
    
    
    
    
    
    
    
    
    
    
    
    shelf_life_days: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    item_images: [],
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/items/items-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"
  >
      <Field
          name="name"
          placeholder="Name"
      />
  </FormField>













































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























  <FormField label="ItemType" labelFor="item_type">
      <Field name="item_type" id="item_type" component="select">
      
        <option value="product">product</option>
      
        <option value="ingredient">ingredient</option>
      
        <option value="seed">seed</option>
      
        <option value="fish">fish</option>
      
        <option value="crop">crop</option>
      
        <option value="resource">resource</option>
      
        <option value="tool">tool</option>
      
        <option value="furniture">furniture</option>
      
        <option value="decoration">decoration</option>
      
        <option value="consumable">consumable</option>
      
        <option value="quest">quest</option>
      
      </Field>
  </FormField>

















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





























    <FormField
        label="BasePrice"
    >
        <Field
            type="number"
            name="base_price"
            placeholder="BasePrice"
        />
    </FormField>



























    <FormField
        label="Weight"
    >
        <Field
            type="number"
            name="weight"
            placeholder="Weight"
        />
    </FormField>





































  <FormField label='IsStackable' labelFor='is_stackable'>
      <Field
          name='is_stackable'
          id='is_stackable'
          component={SwitchField}
      ></Field>
  </FormField>

















    <FormField
        label="MaxStackSize"
    >
        <Field
            type="number"
            name="max_stack_size"
            placeholder="MaxStackSize"
        />
    </FormField>





































  <FormField label='IsPerishable' labelFor='is_perishable'>
      <Field
          name='is_perishable'
          id='is_perishable'
          component={SwitchField}
      ></Field>
  </FormField>

















    <FormField
        label="ShelfLifeDays"
    >
        <Field
            type="number"
            name="shelf_life_days"
            placeholder="ShelfLifeDays"
        />
    </FormField>











































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

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

export default ItemsNew
