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

const initialValues = {
    
    
    title_ar: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    slug: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    author: '',
    
    
    
    
    
    excerpt_ar: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    content_ar: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    featured_image: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_stones: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    related_projects: [],
    
    
    
    
    
    
    
    
    
    
    
    
    publish_status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    published_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_featured: false,
    
    
    
    
    
    
    
    
}


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

    
    

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



























  <FormField
      label="Slug"
  >
      <Field
          name="slug"
          placeholder="Slug"
      />
  </FormField>













































  <FormField label="Category" labelFor="category">
      <Field name="category" id="category" component={SelectField} options={[]} itemRef={'blog_categories'}></Field>
  </FormField>



























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











    <FormField label="ExcerptArabic" hasTextareaHeight>
        <Field name="excerpt_ar" as="textarea" placeholder="ExcerptArabic" />
    </FormField>





























      <FormField label='ContentArabic' hasTextareaHeight>
          <Field
              name='content_ar'
              id='content_ar'
              component={RichTextField}
          ></Field>
      </FormField>













































  <FormField>
      <Field
          label='FeaturedImage'
          color='info'
          icon={mdiUpload}
          path={'blog_posts/featured_image'}
          name='featured_image'
          id='featured_image'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>




























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
























    <FormField label='RelatedStones' labelFor='related_stones'>
        <Field
            name='related_stones'
            id='related_stones'
            itemRef={'stones'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='RelatedProjects' labelFor='related_projects'>
        <Field
            name='related_projects'
            id='related_projects'
            itemRef={'projects'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>





















  <FormField label="PublishStatus" labelFor="publish_status">
      <Field name="publish_status" id="publish_status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="scheduled">scheduled</option>
      
        <option value="published">published</option>
      
        <option value="archived">archived</option>
      
      </Field>
  </FormField>























  <FormField
      label="PublishedAt"
  >
      <Field
          type="datetime-local"
          name="published_at"
          placeholder="PublishedAt"
      />
  </FormField>

































  <FormField label='IsFeatured' labelFor='is_featured'>
      <Field
          name='is_featured'
          id='is_featured'
          component={SwitchField}
      ></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('/blog_posts/blog_posts-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Blog_postsNew
