import { mdiAccount, mdiChartTimelineVariant, mdiMail, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement, useEffect, useState } 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/verification_submissions/verification_submissionsSlice'
import { useAppDispatch } from '../../stores/hooks'
import { useRouter } from 'next/router'
import moment from 'moment';

const initialValuesDefault = {
    business: '',
    badge_type: 'VERIFIED_BUSINESS',
    status: 'PENDING',
    notes: '',
    admin_notes: '',
    created_at_ts: '',
    updated_at_ts: '',
}


const Verification_submissionsNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const { businessId } = router.query
  const [initialValues, setInitialValues] = useState(initialValuesDefault)

  useEffect(() => {
    if (businessId) {
      setInitialValues({
        ...initialValuesDefault,
        business: businessId as string,
        badge_type: 'VERIFIED_BUSINESS'
      })
    }
  }, [businessId])

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    if (businessId) {
        router.push('/my-listing')
    } else {
        await router.push('/verification_submissions/verification_submissions-list')
    }
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('Verification Submission')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="Verification Submission" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            enableReinitialize
            initialValues={initialValues}
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>

  <FormField label="Business" labelFor="business">
      <Field name="business" id="business" component={SelectField} options={[]} itemRef={'businesses'}></Field>
  </FormField>

  <FormField label="Badge Type" labelFor="badge_type">
      <Field name="badge_type" id="badge_type" component="select">
      
        <option value="VERIFIED_BUSINESS">VERIFIED_BUSINESS (Ownership Claim)</option>
      
        <option value="VERIFIED_LICENSE">VERIFIED_LICENSE</option>
      
        <option value="VERIFIED_INSURANCE">VERIFIED_INSURANCE</option>
      
        <option value="VERIFIED_PRICING">VERIFIED_PRICING</option>
      
        <option value="FAST_RESPONDER">FAST_RESPONDER</option>
      
        <option value="VERIFIED_JOBS">VERIFIED_JOBS</option>
      
      </Field>
  </FormField>

  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="PENDING">PENDING</option>
      
        <option value="APPROVED">APPROVED</option>
      
        <option value="REJECTED">REJECTED</option>
      
      </Field>
  </FormField>

    <FormField label="Notes / Verification Proof Description" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Enter details about your verification proof..." />
    </FormField>

    <FormField label="Admin Notes" hasTextareaHeight>
        <Field name="admin_notes" as="textarea" placeholder="Admin notes..." />
    </FormField>

  <FormField
      label="Created At"
  >
      <Field
          type="datetime-local"
          name="created_at_ts"
          placeholder="CreatedAt"
      />
  </FormField>

              <BaseDivider />
              <BaseButtons>
                <BaseButton type="submit" color="info" label="Submit Verification" />
                <BaseButton type="reset" color="info" outline label="Reset" />
                <BaseButton type='reset' color='danger' outline label='Cancel' onClick={() => router.back()}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Verification_submissionsNew