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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    membership_plan: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'ACTIVE',
    
    
    
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    next_billing_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    cancelled_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ends_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    price_supercharged: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    perks_snapshot: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const User_membershipsNew = () => {
  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('/user_memberships/user_memberships-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    started_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="User" labelFor="user">
      <Field name="user" id="user" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>



























  <FormField label="MembershipPlan" labelFor="membership_plan">
      <Field name="membership_plan" id="membership_plan" component={SelectField} options={[]} itemRef={'membership_plans'}></Field>
  </FormField>























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="ACTIVE">ACTIVE</option>
      
        <option value="CANCELLED">CANCELLED</option>
      
        <option value="EXPIRED">EXPIRED</option>
      
      </Field>
  </FormField>























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



























  <FormField
      label="NextBillingAt"
  >
      <Field
          type="datetime-local"
          name="next_billing_at"
          placeholder="NextBillingAt"
      />
  </FormField>



























  <FormField
      label="CancelledAt"
  >
      <Field
          type="datetime-local"
          name="cancelled_at"
          placeholder="CancelledAt"
      />
  </FormField>



























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























    <FormField
        label="PriceSupercharged"
    >
        <Field
            type="number"
            name="price_supercharged"
            placeholder="PriceSupercharged"
        />
    </FormField>























    <FormField label="PerksSnapshot" hasTextareaHeight>
        <Field name="perks_snapshot" as="textarea" placeholder="PerksSnapshot" />
    </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('/user_memberships/user_memberships-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default User_membershipsNew
