import { mdiChartTimelineVariant, mdiUpload } from '@mdi/js'
import Head from 'next/head'
import React, { ReactElement, useEffect, useState } from 'react'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";

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 { SelectField } from "../../components/SelectField";
import { SelectFieldMany } from "../../components/SelectFieldMany";
import { SwitchField } from '../../components/SwitchField'
import {RichTextField} from "../../components/RichTextField";

import { update, fetch } from '../../stores/premium_plans/premium_plansSlice'
import { useAppDispatch, useAppSelector } from '../../stores/hooks'
import { useRouter } from 'next/router'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";



const EditPremium_plansPage = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    
    'name': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    tier: '',
    

    

    

    

    
    
    
    'price_monthly': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'price_yearly': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    unlimited_likes: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    unlimited_chats: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    see_who_liked_me: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    advanced_filters: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    passport_mode: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    boost_profile: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    read_receipts: false,
    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    incognito_mode: false,
    

    

    

    

    

    

    
    
    

    
    description: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    
  }
  const [initialValues, setInitialValues] = useState(initVals)

  const { premium_plans } = useAppSelector((state) => state.premium_plans)
  

  const { id } = router.query

  useEffect(() => {
    dispatch(fetch({ id: id }))
  }, [id])

  useEffect(() => {
    if (typeof premium_plans === 'object') {
      setInitialValues(premium_plans)
    }
  }, [premium_plans])

  useEffect(() => {
      if (typeof premium_plans === 'object') {
          const newInitialVal = {...initVals};
          Object.keys(initVals).forEach(el => newInitialVal[el] = (premium_plans)[el])
          setInitialValues(newInitialVal);
      }
  }, [premium_plans])

  const handleSubmit = async (data) => {
    await dispatch(update({ id: id, data }))
    await router.push('/premium_plans/premium_plans-list')
  }

  return (
    <>
      <Head>
        <title>{getPageTitle('Edit premium_plans')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={'Edit premium_plans'} main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            enableReinitialize
            initialValues={initialValues}
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>


  
    <FormField
        label="PlanName"
    >
        <Field
            name="name"
            placeholder="PlanName"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="Tier" labelFor="tier">
        <Field name="tier" id="tier" component="select">
          
            <option value="premium">premium</option>
          
            <option value="premium_plus">premium_plus</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  
    <FormField
        label="PriceMonthly"
    >
        <Field
            type="number"
            name="price_monthly"
            placeholder="PriceMonthly"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  
    <FormField
        label="PriceYearly"
    >
        <Field
            type="number"
            name="price_yearly"
            placeholder="PriceYearly"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='UnlimitedLikes' labelFor='unlimited_likes'>
        <Field
            name='unlimited_likes'
            id='unlimited_likes'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='UnlimitedChats' labelFor='unlimited_chats'>
        <Field
            name='unlimited_chats'
            id='unlimited_chats'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='SeeWhoLikedMe' labelFor='see_who_liked_me'>
        <Field
            name='see_who_liked_me'
            id='see_who_liked_me'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='AdvancedFilters' labelFor='advanced_filters'>
        <Field
            name='advanced_filters'
            id='advanced_filters'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='PassportMode' labelFor='passport_mode'>
        <Field
            name='passport_mode'
            id='passport_mode'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='BoostProfile' labelFor='boost_profile'>
        <Field
            name='boost_profile'
            id='boost_profile'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='ReadReceipts' labelFor='read_receipts'>
        <Field
            name='read_receipts'
            id='read_receipts'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='IncognitoMode' labelFor='incognito_mode'>
        <Field
            name='incognito_mode'
            id='incognito_mode'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

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

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

export default EditPremium_plansPage
