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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    placement: '',
    
    
    
    
    ad_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    enabled: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ad_type: 'image',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    creative_image: [],
    
    
    
    
    
    
    
    creative_text: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    custom_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    destination_url: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    starts_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ends_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    impressions_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    clicks_count: '',
    
    
    
    
    
    
    
    
    
    
    
}


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





















  <FormField label="Placement" labelFor="placement">
      <Field name="placement" id="placement" component={SelectField} options={[]} itemRef={'ad_placements'}></Field>
  </FormField>









  <FormField
      label="AdName"
  >
      <Field
          name="ad_name"
          placeholder="AdName"
      />
  </FormField>











































  <FormField label='Enabled' labelFor='enabled'>
      <Field
          name='enabled'
          id='enabled'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="AdType" labelFor="ad_type">
      <Field name="ad_type" id="ad_type" component="select">
      
        <option value="image">image</option>
      
        <option value="custom_code">custom_code</option>
      
      </Field>
  </FormField>



































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









      <FormField label='CreativeText' hasTextareaHeight>
          <Field
              name='creative_text'
              id='creative_text'
              component={RichTextField}
          ></Field>
      </FormField>

























    <FormField label="CustomCode" hasTextareaHeight>
        <Field name="custom_code" as="textarea" placeholder="CustomCode" />
    </FormField>

























  <FormField
      label="DestinationURL"
  >
      <Field
          name="destination_url"
          placeholder="DestinationURL"
      />
  </FormField>





































  <FormField
      label="StartsAt"
  >
      <Field
          type="datetime-local"
          name="starts_at"
          placeholder="StartsAt"
      />
  </FormField>



























  <FormField
      label="EndsAt"
  >
      <Field
          type="datetime-local"
          name="ends_at"
          placeholder="EndsAt"
      />
  </FormField>























    <FormField
        label="ImpressionsCount"
    >
        <Field
            type="number"
            name="impressions_count"
            placeholder="ImpressionsCount"
        />
    </FormField>



























    <FormField
        label="ClicksCount"
    >
        <Field
            type="number"
            name="clicks_count"
            placeholder="ClicksCount"
        />
    </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('/ads/ads-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default AdsNew
