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

const initialValues = {
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    subtitle: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    isbn: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    language: 'uz',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    format: 'ebook',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cover_images: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    content_files: [],
    
    
    
    
    
    
    
    
    
    page_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    word_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    duration_seconds: '',
    
    
    
    
    
    
    
    
    
    
    
    
    difficulty_score: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    popularity_score: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    published_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    publisher: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    authors: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    genres: [],
    
    
}


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

    
    

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



























  <FormField
      label="Subtitle"
  >
      <Field
          name="subtitle"
          placeholder="Subtitle"
      />
  </FormField>



























  <FormField
      label="ISBN"
  >
      <Field
          name="isbn"
          placeholder="ISBN"
      />
  </FormField>









































  <FormField label="Language" labelFor="language">
      <Field name="language" id="language" component="select">
      
        <option value="uz">uz</option>
      
        <option value="ru">ru</option>
      
        <option value="en">en</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>



























  <FormField label="Format" labelFor="format">
      <Field name="format" id="format" component="select">
      
        <option value="ebook">ebook</option>
      
        <option value="audiobook">audiobook</option>
      
        <option value="videobook">videobook</option>
      
        <option value="physical_reference">physical_reference</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="published">published</option>
      
        <option value="archived">archived</option>
      
      </Field>
  </FormField>

















      <FormField label='Description' hasTextareaHeight>
          <Field
              name='description'
              id='description'
              component={RichTextField}
          ></Field>
      </FormField>













































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




























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










    <FormField
        label="Pagecount"
    >
        <Field
            type="number"
            name="page_count"
            placeholder="Pagecount"
        />
    </FormField>



























    <FormField
        label="Wordcount"
    >
        <Field
            type="number"
            name="word_count"
            placeholder="Wordcount"
        />
    </FormField>



























    <FormField
        label="Duration(seconds)"
    >
        <Field
            type="number"
            name="duration_seconds"
            placeholder="Duration(seconds)"
        />
    </FormField>



























    <FormField
        label="Difficultyscore"
    >
        <Field
            type="number"
            name="difficulty_score"
            placeholder="Difficultyscore"
        />
    </FormField>



























    <FormField
        label="Popularityscore"
    >
        <Field
            type="number"
            name="popularity_score"
            placeholder="Popularityscore"
        />
    </FormField>































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



































  <FormField label="Publisher" labelFor="publisher">
      <Field name="publisher" id="publisher" component={SelectField} options={[]} itemRef={'publishers'}></Field>
  </FormField>





























    <FormField label='Authors' labelFor='authors'>
        <Field
            name='authors'
            id='authors'
            itemRef={'authors'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </FormField>



























    <FormField label='Genres' labelFor='genres'>
        <Field
            name='genres'
            id='genres'
            itemRef={'genres'}
            options={[]}
            component={SelectFieldMany}>
        </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('/books/books-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default BooksNew
