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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    document_type: '',
    
    
    
    
    template_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    template_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    template_family: 'sop',
    
    
    
    
    
    
    
    
    purpose: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    template_body: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    template_files: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    format: 'html',
    
    
    
    
    
    
    
    
    
    
    
    
    
    active: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    mapped_clauses: [],
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/document_templates/document_templates-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="DocumentType" labelFor="document_type">
      <Field name="document_type" id="document_type" component={SelectField} options={[]} itemRef={'document_types'}></Field>
  </FormField>









  <FormField
      label="TemplateName"
  >
      <Field
          name="template_name"
          placeholder="TemplateName"
      />
  </FormField>



























  <FormField
      label="TemplateCode"
  >
      <Field
          name="template_code"
          placeholder="TemplateCode"
      />
  </FormField>









































  <FormField label="TemplateFamily" labelFor="template_family">
      <Field name="template_family" id="template_family" component="select">
      
        <option value="sop">sop</option>
      
        <option value="bmr">bmr</option>
      
        <option value="coa">coa</option>
      
        <option value="doc">doc</option>
      
        <option value="risk_file">risk_file</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>















    <FormField label="Purpose" hasTextareaHeight>
        <Field name="purpose" as="textarea" placeholder="Purpose" />
    </FormField>





























      <FormField label='TemplateBody' hasTextareaHeight>
          <Field
              name='template_body'
              id='template_body'
              component={RichTextField}
          ></Field>
      </FormField>














































  <FormField>
      <Field
          label='TemplateFiles'
          color='info'
          icon={mdiUpload}
          path={'document_templates/template_files'}
          name='template_files'
          id='template_files'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>


















  <FormField label="Format" labelFor="format">
      <Field name="format" id="format" component="select">
      
        <option value="html">html</option>
      
        <option value="docx">docx</option>
      
        <option value="xlsx">xlsx</option>
      
        <option value="pdf">pdf</option>
      
        <option value="mixed">mixed</option>
      
      </Field>
  </FormField>





























  <FormField label='Active' labelFor='active'>
      <Field
          name='active'
          id='active'
          component={SwitchField}
      ></Field>
  </FormField>































    <FormField label='MappedClauses' labelFor='mapped_clauses'>
        <Field
            name='mapped_clauses'
            id='mapped_clauses'
            itemRef={'clauses'}
            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('/document_templates/document_templates-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Document_templatesNew
