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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    rule_set: '',
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    severity: 'error',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    rule_type: 'required',
    
    
    
    
    
    
    
    target_field: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    condition_expression: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    parameters: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    message_template: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_active: false,
    
    
    
    
    
    
    
    
    
    
    
    
    order_index: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

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









  <FormField
      label="RuleName"
  >
      <Field
          name="name"
          placeholder="RuleName"
      />
  </FormField>









































  <FormField label="Severity" labelFor="severity">
      <Field name="severity" id="severity" component="select">
      
        <option value="error">error</option>
      
        <option value="warning">warning</option>
      
      </Field>
  </FormField>



























  <FormField label="RuleType" labelFor="rule_type">
      <Field name="rule_type" id="rule_type" component="select">
      
        <option value="required">required</option>
      
        <option value="format">format</option>
      
        <option value="range">range</option>
      
        <option value="enum_in">enum_in</option>
      
        <option value="unique">unique</option>
      
        <option value="duplicate_in_file">duplicate_in_file</option>
      
        <option value="foreign_key">foreign_key</option>
      
        <option value="custom_expression">custom_expression</option>
      
      </Field>
  </FormField>













  <FormField
      label="TargetField"
  >
      <Field
          name="target_field"
          placeholder="TargetField"
      />
  </FormField>





























    <FormField label="ConditionExpression" hasTextareaHeight>
        <Field name="condition_expression" as="textarea" placeholder="ConditionExpression" />
    </FormField>



























    <FormField label="Parameters(JSON)" hasTextareaHeight>
        <Field name="parameters" as="textarea" placeholder="Parameters(JSON)" />
    </FormField>



























    <FormField label="MessageTemplate" hasTextareaHeight>
        <Field name="message_template" as="textarea" placeholder="MessageTemplate" />
    </FormField>









































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

















    <FormField
        label="OrderIndex"
    >
        <Field
            type="number"
            name="order_index"
            placeholder="OrderIndex"
        />
    </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('/validation_rules/validation_rules-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Validation_rulesNew
