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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    tenant: '',
    
    
    
    
    program_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    program_status: 'draft',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    target_metric: 'revenue',
    
    
    
    
    
    
    
    target_value: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reward_type: 'percentage',
    
    
    
    
    
    
    
    reward_rate: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reward_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    gift_description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    starts_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ends_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    terms: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const Bonus_programsNew = () => {
  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('/bonus_programs/bonus_programs-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="Tenant" labelFor="tenant">
      <Field name="tenant" id="tenant" component={SelectField} options={[]} itemRef={'tenants'}></Field>
  </FormField>









  <FormField
      label="ProgramName"
  >
      <Field
          name="program_name"
          placeholder="ProgramName"
      />
  </FormField>









































  <FormField label="ProgramStatus" labelFor="program_status">
      <Field name="program_status" id="program_status" component="select">
      
        <option value="draft">draft</option>
      
        <option value="active">active</option>
      
        <option value="inactive">inactive</option>
      
        <option value="ended">ended</option>
      
      </Field>
  </FormField>



























  <FormField label="TargetMetric" labelFor="target_metric">
      <Field name="target_metric" id="target_metric" component="select">
      
        <option value="revenue">revenue</option>
      
        <option value="profit_estimate">profit_estimate</option>
      
        <option value="orders_count">orders_count</option>
      
        <option value="units_sold">units_sold</option>
      
      </Field>
  </FormField>



















    <FormField
        label="TargetValue"
    >
        <Field
            type="number"
            name="target_value"
            placeholder="TargetValue"
        />
    </FormField>



































  <FormField label="RewardType" labelFor="reward_type">
      <Field name="reward_type" id="reward_type" component="select">
      
        <option value="percentage">percentage</option>
      
        <option value="fixed_amount">fixed_amount</option>
      
        <option value="gift">gift</option>
      
      </Field>
  </FormField>



















    <FormField
        label="RewardRate"
    >
        <Field
            type="number"
            name="reward_rate"
            placeholder="RewardRate"
        />
    </FormField>



























    <FormField
        label="RewardAmount"
    >
        <Field
            type="number"
            name="reward_amount"
            placeholder="RewardAmount"
        />
    </FormField>























    <FormField label="GiftDescription" hasTextareaHeight>
        <Field name="gift_description" as="textarea" placeholder="GiftDescription" />
    </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='Terms' hasTextareaHeight>
          <Field
              name='terms'
              id='terms'
              component={RichTextField}
          ></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('/bonus_programs/bonus_programs-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Bonus_programsNew
