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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    creator: '',
    
    
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: 'gaming',
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_live: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_adult: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    thumbnail_images: [],
    
    
    
    
    
    
    
    
    
    
    scheduled_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ended_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    viewer_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    stream_key_hint: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    overlay_profile: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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





















  <FormField label="Creator" labelFor="creator">
      <Field name="creator" id="creator" component={SelectField} options={[]} itemRef={'creator_profiles'}></Field>
  </FormField>









  <FormField
      label="Title"
  >
      <Field
          name="title"
          placeholder="Title"
      />
  </FormField>































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





































  <FormField label="Category" labelFor="category">
      <Field name="category" id="category" component="select">
      
        <option value="gaming">gaming</option>
      
        <option value="just_chatting">just_chatting</option>
      
        <option value="music">music</option>
      
        <option value="art">art</option>
      
        <option value="dev">dev</option>
      
        <option value="watch_party">watch_party</option>
      
        <option value="adult">adult</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>





























  <FormField label='IsLive' labelFor='is_live'>
      <Field
          name='is_live'
          id='is_live'
          component={SwitchField}
      ></Field>
  </FormField>



























  <FormField label='IsAdult' labelFor='is_adult'>
      <Field
          name='is_adult'
          id='is_adult'
          component={SwitchField}
      ></Field>
  </FormField>

































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















  <FormField
      label="ScheduledStartAt"
  >
      <Field
          type="datetime-local"
          name="scheduled_start_at"
          placeholder="ScheduledStartAt"
      />
  </FormField>



























  <FormField
      label="StartedAt"
  >
      <Field
          type="datetime-local"
          name="started_at"
          placeholder="StartedAt"
      />
  </FormField>



























  <FormField
      label="EndedAt"
  >
      <Field
          type="datetime-local"
          name="ended_at"
          placeholder="EndedAt"
      />
  </FormField>























    <FormField
        label="ViewerCount"
    >
        <Field
            type="number"
            name="viewer_count"
            placeholder="ViewerCount"
        />
    </FormField>





















  <FormField
      label="StreamKeyHint"
  >
      <Field
          name="stream_key_hint"
          placeholder="StreamKeyHint"
      />
  </FormField>













































  <FormField label="OverlayProfile" labelFor="overlay_profile">
      <Field name="overlay_profile" id="overlay_profile" component={SelectField} options={[]} itemRef={'overlay_profiles'}></Field>
  </FormField>



























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

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

export default StreamsNew
