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

const initialValues = {
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    venue: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    owner: '',
    
    
    
    
    budget_total: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    budget_spent: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const EventsNew = () => {
  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('/events/events-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('Yeni Kayıt')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="Yeni Kayıt" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    start_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    end_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



  <FormField
      label="Etkinlik Adı"
  >
      <Field
          name="name"
          placeholder="Etkinlik Adı"
      />
  </FormField>









































  <FormField label="Durum" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="planning">planning</option>
      
        <option value="confirmed">confirmed</option>
      
        <option value="in_progress">in_progress</option>
      
        <option value="completed">completed</option>
      
        <option value="canceled">canceled</option>
      
      </Field>
  </FormField>























  <FormField
      label="Başlangıç Tarihi"
  >
      <Field
          type="datetime-local"
          name="start_at"
          placeholder="Başlangıç Tarihi"
      />
  </FormField>



























  <FormField
      label="Bitiş Tarihi"
  >
      <Field
          type="datetime-local"
          name="end_at"
          placeholder="Bitiş Tarihi"
      />
  </FormField>



































  <FormField label="Mekan" labelFor="venue">
      <Field name="venue" id="venue" component={SelectField} options={[]} itemRef={'venues'}></Field>
  </FormField>



























  <FormField label="Sorumlu Kişi" labelFor="owner">
      <Field name="owner" id="owner" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>















    <FormField
        label="Toplam Bütçe"
    >
        <Field
            type="number"
            name="budget_total"
            placeholder="Toplam Bütçe"
        />
    </FormField>



























    <FormField
        label="Harcanan Bütçe"
    >
        <Field
            type="number"
            name="budget_spent"
            placeholder="Harcanan Bütçe"
        />
    </FormField>

























      <FormField label='Açıklama' hasTextareaHeight>
          <Field
              name='description'
              id='description'
              component={RichTextField}
          ></Field>
      </FormField>














































  <FormField>
      <Field
          label='Ekler'
          color='info'
          icon={mdiUpload}
          path={'events/attachments'}
          name='attachments'
          id='attachments'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></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="Kaydet" />
                <BaseButton type="reset" color="info" outline label="Sıfırla" />
                <BaseButton type='reset' color='danger' outline label='İptal' onClick={() => router.push('/events/events-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EventsNew
