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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    title_type: 'movie',
    
    
    
    
    
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    original_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tagline: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    overview: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    release_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    first_air_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    last_air_date: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    content_rating: 'g',
    
    
    
    
    
    
    
    original_language: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    runtime_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    number_of_seasons: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    number_of_episodes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    average_rating: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    rating_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    popularity_score: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    imdb_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    poster_images: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    backdrop_images: [],
    
    
    
    
    
    
    
    
    
    
    
    is_trending: false,
    
    
    
    
    
    
    
    
}


const TitlesNew = () => {
  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('/titles/titles-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    release_date: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    last_air_date: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>

















  <FormField label="Type" labelFor="title_type">
      <Field name="title_type" id="title_type" component="select">
      
        <option value="movie">movie</option>
      
        <option value="tv_show">tv_show</option>
      
      </Field>
  </FormField>













  <FormField
      label="Name"
  >
      <Field
          name="name"
          placeholder="Name"
      />
  </FormField>



























  <FormField
      label="OriginalName"
  >
      <Field
          name="original_name"
          placeholder="OriginalName"
      />
  </FormField>



























  <FormField
      label="Tagline"
  >
      <Field
          name="tagline"
          placeholder="Tagline"
      />
  </FormField>































      <FormField label='Overview' hasTextareaHeight>
          <Field
              name='overview'
              id='overview'
              component={RichTextField}
          ></Field>
      </FormField>

































  <FormField
      label="ReleaseDate"
  >
      <Field
          type="datetime-local"
          name="release_date"
          placeholder="ReleaseDate"
      />
  </FormField>



























  <FormField
      label="FirstAirDate"
  >
      <Field
          type="datetime-local"
          name="first_air_date"
          placeholder="FirstAirDate"
      />
  </FormField>



























  <FormField
      label="LastAirDate"
  >
      <Field
          type="datetime-local"
          name="last_air_date"
          placeholder="LastAirDate"
      />
  </FormField>































  <FormField label="ContentRating" labelFor="content_rating">
      <Field name="content_rating" id="content_rating" component="select">
      
        <option value="g">g</option>
      
        <option value="pg">pg</option>
      
        <option value="pg_13">pg_13</option>
      
        <option value="r">r</option>
      
        <option value="nc_17">nc_17</option>
      
        <option value="tv_y">tv_y</option>
      
        <option value="tv_y7">tv_y7</option>
      
        <option value="tv_g">tv_g</option>
      
        <option value="tv_pg">tv_pg</option>
      
        <option value="tv_14">tv_14</option>
      
        <option value="tv_ma">tv_ma</option>
      
        <option value="unrated">unrated</option>
      
      </Field>
  </FormField>













  <FormField
      label="OriginalLanguage"
  >
      <Field
          name="original_language"
          placeholder="OriginalLanguage"
      />
  </FormField>

































    <FormField
        label="RuntimeMinutes"
    >
        <Field
            type="number"
            name="runtime_minutes"
            placeholder="RuntimeMinutes"
        />
    </FormField>



























    <FormField
        label="NumberofSeasons"
    >
        <Field
            type="number"
            name="number_of_seasons"
            placeholder="NumberofSeasons"
        />
    </FormField>



























    <FormField
        label="NumberofEpisodes"
    >
        <Field
            type="number"
            name="number_of_episodes"
            placeholder="NumberofEpisodes"
        />
    </FormField>



























    <FormField
        label="AverageRating"
    >
        <Field
            type="number"
            name="average_rating"
            placeholder="AverageRating"
        />
    </FormField>



























    <FormField
        label="RatingCount"
    >
        <Field
            type="number"
            name="rating_count"
            placeholder="RatingCount"
        />
    </FormField>



























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





















  <FormField
      label="IMDBCode"
  >
      <Field
          name="imdb_code"
          placeholder="IMDBCode"
      />
  </FormField>

















































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



























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





















  <FormField label='Trending' labelFor='is_trending'>
      <Field
          name='is_trending'
          id='is_trending'
          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('/titles/titles-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default TitlesNew
