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

const initialValues = {
    
    
    announcement_title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    announcement_body: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    audience_type: 'school',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    school: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    classroom: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    target_role: 'student',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    posted_by: '',
    
    
    
    
    
    
    
    
    
    posted_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    expires_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pinned: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
}


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

    
    

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































      <FormField label='AnnouncementBody' hasTextareaHeight>
          <Field
              name='announcement_body'
              id='announcement_body'
              component={RichTextField}
          ></Field>
      </FormField>





































  <FormField label="AudienceType" labelFor="audience_type">
      <Field name="audience_type" id="audience_type" component="select">
      
        <option value="school">school</option>
      
        <option value="classroom">classroom</option>
      
        <option value="role_based">role_based</option>
      
        <option value="global">global</option>
      
      </Field>
  </FormField>































  <FormField label="School" labelFor="school">
      <Field name="school" id="school" component={SelectField} options={[]} itemRef={'schools'}></Field>
  </FormField>



























  <FormField label="Classroom" labelFor="classroom">
      <Field name="classroom" id="classroom" component={SelectField} options={[]} itemRef={'classrooms'}></Field>
  </FormField>























  <FormField label="TargetRole" labelFor="target_role">
      <Field name="target_role" id="target_role" component="select">
      
        <option value="student">student</option>
      
        <option value="teacher">teacher</option>
      
        <option value="principal">principal</option>
      
        <option value="admin">admin</option>
      
      </Field>
  </FormField>































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



















  <FormField
      label="PostedAt"
  >
      <Field
          type="datetime-local"
          name="posted_at"
          placeholder="PostedAt"
      />
  </FormField>



























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

































  <FormField label='Pinned' labelFor='pinned'>
      <Field
          name='pinned'
          id='pinned'
          component={SwitchField}
      ></Field>
  </FormField>


































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

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

export default AnnouncementsNew
