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/theme_profiles/theme_profilesSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";



const EditTheme_profilesPage = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    owner_user: null,
    

    
    
    

    

    

    

    

    

    

    

    
    mode: '',
    

    

    

    

    
    
    
    'theme_name': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'primary_color_hex': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'accent_color_hex': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'neon_glow_color_hex': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    
    rgb_cycle_enabled: false,
    

    

    

    

    

    

    
    
    

    

    

    
    rgb_cycle_speed: '',
    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    holiday_palette: '',
    

    

    

    

    
    
    

    

    

    

    

    

    
    adult_palette_enabled: false,
    

    

    

    

    

    

    
    
    
    'adult_primary_color_hex': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    
    'adult_accent_color_hex': '',
    

    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    organizations: null,
    

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

  const { theme_profiles } = useAppSelector((state) => state.theme_profiles)
  
  const { currentUser } = useAppSelector((state) => state.auth);
  

  const { id } = router.query

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

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

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

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

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


  

  

  

  

  

  

  

  

  

  
  
    <FormField label='OwnerUser' labelFor='owner_user'>
        <Field
            name='owner_user'
            id='owner_user'
            component={SelectField}
            options={initialValues.owner_user}
            itemRef={'users'}
      
        
            showField={'firstName'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="Mode" labelFor="mode">
        <Field name="mode" id="mode" component="select">
          
            <option value="auto_time">auto_time</option>
          
            <option value="manual">manual</option>
          
            <option value="holiday">holiday</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  
    <FormField
        label="ThemeName"
    >
        <Field
            name="theme_name"
            placeholder="ThemeName"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="PrimaryColorHex"
    >
        <Field
            name="primary_color_hex"
            placeholder="PrimaryColorHex"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="AccentColorHex"
    >
        <Field
            name="accent_color_hex"
            placeholder="AccentColorHex"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="NeonGlowColorHex"
    >
        <Field
            name="neon_glow_color_hex"
            placeholder="NeonGlowColorHex"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='RGBCycleEnabled' labelFor='rgb_cycle_enabled'>
        <Field
            name='rgb_cycle_enabled'
            id='rgb_cycle_enabled'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  

  

  

  
    <FormField
        label="RGBCycleSpeed"
    >
        <Field
            type="number"
            name="rgb_cycle_speed"
            placeholder="RGBCycleSpeed"
        />
    </FormField>
  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="HolidayPalette" labelFor="holiday_palette">
        <Field name="holiday_palette" id="holiday_palette" component="select">
          
            <option value="none">none</option>
          
            <option value="new_year">new_year</option>
          
            <option value="valentines">valentines</option>
          
            <option value="st_patricks">st_patricks</option>
          
            <option value="easter">easter</option>
          
            <option value="ramadan">ramadan</option>
          
            <option value="eid">eid</option>
          
            <option value="pride">pride</option>
          
            <option value="halloween">halloween</option>
          
            <option value="thanksgiving">thanksgiving</option>
          
            <option value="hanukkah">hanukkah</option>
          
            <option value="christmas">christmas</option>
          
            <option value="lunar_new_year">lunar_new_year</option>
          
            <option value="diwali">diwali</option>
          
            <option value="other">other</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  

  
    <FormField label='AdultPaletteEnabled' labelFor='adult_palette_enabled'>
        <Field
            name='adult_palette_enabled'
            id='adult_palette_enabled'
            component={SwitchField}
        ></Field>
    </FormField>
  

  

  

    

  



  
    <FormField
        label="AdultPrimaryColorHex"
    >
        <Field
            name="adult_primary_color_hex"
            placeholder="AdultPrimaryColorHex"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  
    <FormField
        label="AdultAccentColorHex"
    >
        <Field
            name="adult_accent_color_hex"
            placeholder="AdultAccentColorHex"
        />
    </FormField>
  

  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  

  

  
  
    <FormField label='organizations' labelFor='organizations'>
        <Field
            name='organizations'
            id='organizations'
            component={SelectField}
            options={initialValues.organizations}
            itemRef={'organizations'}
      
        
      
        
      
        
      
        
            showField={'name'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></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('/theme_profiles/theme_profiles-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EditTheme_profilesPage
