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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    ir_company: '',
    
    
    
    
    
    
    
    
    
    declaration_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ex_dividend_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    record_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payable_at: '',
    
    
    
    
    
    
    
    
    
    
    amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    currency: 'USD',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    frequency: 'one_time',
    
    
    
    
    
    
}


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





















  <FormField label="IRCompany" labelFor="ir_company">
      <Field name="ir_company" id="ir_company" component={SelectField} options={[]} itemRef={'ir_companies'}></Field>
  </FormField>



















  <FormField
      label="DeclarationDate"
  >
      <Field
          type="datetime-local"
          name="declaration_at"
          placeholder="DeclarationDate"
      />
  </FormField>



























  <FormField
      label="Ex-DividendDate"
  >
      <Field
          type="datetime-local"
          name="ex_dividend_at"
          placeholder="Ex-DividendDate"
      />
  </FormField>



























  <FormField
      label="RecordDate"
  >
      <Field
          type="datetime-local"
          name="record_at"
          placeholder="RecordDate"
      />
  </FormField>



























  <FormField
      label="PayableDate"
  >
      <Field
          type="datetime-local"
          name="payable_at"
          placeholder="PayableDate"
      />
  </FormField>























    <FormField
        label="Amount"
    >
        <Field
            type="number"
            name="amount"
            placeholder="Amount"
        />
    </FormField>



































  <FormField label="Currency" labelFor="currency">
      <Field name="currency" id="currency" component="select">
      
        <option value="USD">USD</option>
      
        <option value="EUR">EUR</option>
      
        <option value="GBP">GBP</option>
      
        <option value="JPY">JPY</option>
      
      </Field>
  </FormField>



























  <FormField label="Frequency" labelFor="frequency">
      <Field name="frequency" id="frequency" component="select">
      
        <option value="one_time">one_time</option>
      
        <option value="quarterly">quarterly</option>
      
        <option value="semi_annual">semi_annual</option>
      
        <option value="annual">annual</option>
      
        <option value="monthly">monthly</option>
      
      </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('/ir_dividends/ir_dividends-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Ir_dividendsNew
