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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    exception_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    exception_type: 'break_glass',
    
    
    
    
    
    
    
    subject: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    approver_user: '',
    
    
    
    
    
    reason: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    granted_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    expires_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    revoked_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    followup_review_required: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    linked_artifacts: [],
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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

    
    
    // get from url params
    const { dateRangeStart, dateRangeEnd } = router.query
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/exceptions/exceptions-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    granted_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    expires_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Organization" labelFor="organization">
      <Field name="organization" id="organization" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </FormField>









  <FormField
      label="ExceptionName"
  >
      <Field
          name="exception_name"
          placeholder="ExceptionName"
      />
  </FormField>









































  <FormField label="ExceptionType" labelFor="exception_type">
      <Field name="exception_type" id="exception_type" component="select">
      
        <option value="break_glass">break_glass</option>
      
        <option value="emergency_access">emergency_access</option>
      
        <option value="policy_exception">policy_exception</option>
      
        <option value="temporary_privilege">temporary_privilege</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>













  <FormField
      label="Subject"
  >
      <Field
          name="subject"
          placeholder="Subject"
      />
  </FormField>













































  <FormField label="Approver" labelFor="approver_user">
      <Field name="approver_user" id="approver_user" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>











    <FormField label="Reason" hasTextareaHeight>
        <Field name="reason" as="textarea" placeholder="Reason" />
    </FormField>



































  <FormField
      label="GrantedAt"
  >
      <Field
          type="datetime-local"
          name="granted_at"
          placeholder="GrantedAt"
      />
  </FormField>



























  <FormField
      label="ExpiresAt"
  >
      <Field
          type="datetime-local"
          name="expires_at"
          placeholder="ExpiresAt"
      />
  </FormField>



























  <FormField
      label="RevokedAt"
  >
      <Field
          type="datetime-local"
          name="revoked_at"
          placeholder="RevokedAt"
      />
  </FormField>

































  <FormField label='Follow-upReviewRequired' labelFor='followup_review_required'>
      <Field
          name='followup_review_required'
          id='followup_review_required'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="active">active</option>
      
        <option value="expired">expired</option>
      
        <option value="revoked">revoked</option>
      
        <option value="closed">closed</option>
      
      </Field>
  </FormField>

































    <FormField label='LinkedArtifacts' labelFor='linked_artifacts'>
        <Field
            name='linked_artifacts'
            id='linked_artifacts'
            itemRef={'artifacts'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>









    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </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('/exceptions/exceptions-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ExceptionsNew
