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/content_moderation_reports/content_moderation_reportsSlice'
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 EditContent_moderation_reports = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()
  const initVals = {
      
    

    

    

    

    

    

    

    

    

    

    

    
    reporter: null,
    

    
    
    

    

    

    

    

    

    

    

    
    target_type: '',
    

    

    

    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    post: null,
    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    comment: null,
    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    message: null,
    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    reported_user: null,
    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    live_stream: null,
    

    
    
    

    

    

    

    

    

    

    

    
    reason_code: '',
    

    

    

    

    
    
    

    
    details_text: '',
    

    

    

    

    

    

    

    

    

    

    

    
    
    

    

    

    

    

    

    

    

    
    status: '',
    

    

    

    

    
    
    

    

    

    

    

    

    

    

    

    

    

    
    assigned_moderator: null,
    

    
    
    

    

    

    

    

    
    reported_at: new Date(),
    

    

    

    

    

    

    

    
    
    

    

    

    

    

    
    resolved_at: new Date(),
    

    

    

    

    

    

    

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

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

  const { content_moderation_reportsId } = router.query

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

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

  useEffect(() => {
      if (typeof content_moderation_reports === 'object') {

          const newInitialVal = {...initVals};

          Object.keys(initVals).forEach(el => newInitialVal[el] = (content_moderation_reports)[el])

          setInitialValues(newInitialVal);
      }
  }, [content_moderation_reports])

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

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


  

  

  

  

  

  

  

  

  

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

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="TargetType" labelFor="target_type">
        <Field name="target_type" id="target_type" component="select">
          
            <option value="post">post</option>
          
            <option value="comment">comment</option>
          
            <option value="message">message</option>
          
            <option value="user">user</option>
          
            <option value="live_stream">live_stream</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  

  

  
  
    <FormField label='Post' labelFor='post'>
        <Field
            name='post'
            id='post'
            component={SelectField}
            options={initialValues.post}
            itemRef={'posts'}
      
        
      
        
      
        
      
        
            showField={'caption'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  

  

  

  

  

  

  

  

  
  
    <FormField label='Comment' labelFor='comment'>
        <Field
            name='comment'
            id='comment'
            component={SelectField}
            options={initialValues.comment}
            itemRef={'comments'}
      
        
      
        
      
        
      
        
      
        
            showField={'body'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  

  

  

  

  

  

  

  

  
  
    <FormField label='Message' labelFor='message'>
        <Field
            name='message'
            id='message'
            component={SelectField}
            options={initialValues.message}
            itemRef={'messages'}
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
            showField={'body'}
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  

  

  

  

  

  

  

  

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

  

  

    

  



  

  

  

  

  

  

  

  

  

  
  
    <FormField label='LiveStream' labelFor='live_stream'>
        <Field
            name='live_stream'
            id='live_stream'
            component={SelectField}
            options={initialValues.live_stream}
            itemRef={'live_streams'}
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
      
        
            showField={'title_text'}
        
      
        
      
        
      
        
      
        
      
        
      
        ></Field>
    </FormField>
    

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="Reason" labelFor="reason_code">
        <Field name="reason_code" id="reason_code" component="select">
          
            <option value="spam">spam</option>
          
            <option value="hate_speech">hate_speech</option>
          
            <option value="harassment">harassment</option>
          
            <option value="nudity">nudity</option>
          
            <option value="violence">violence</option>
          
            <option value="self_harm">self_harm</option>
          
            <option value="copyright">copyright</option>
          
            <option value="scam">scam</option>
          
            <option value="other">other</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  
    <FormField label="Details" hasTextareaHeight>
        <Field name="details_text" as="textarea" placeholder="Details" />
    </FormField>
  

  

  

  

  

  

  

  

  

  

    

  



  

  

  

  

  

  

  

  
    <FormField label="Status" labelFor="status">
        <Field name="status" id="status" component="select">
          
            <option value="open">open</option>
          
            <option value="under_review">under_review</option>
          
            <option value="action_taken">action_taken</option>
          
            <option value="dismissed">dismissed</option>
          
        </Field>
    </FormField>
  

  

  

  

    

  



  

  

  

  

  

  

  

  

  

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

  

  

    

  



  

  

  

  

  

  
      <FormField
          label="ReportedAt"
      >
          <DatePicker
              dateFormat="yyyy-MM-dd hh:mm"
              showTimeSelect
              selected={initialValues.reported_at ?
                  new Date(
                      dayjs(initialValues.reported_at).format('YYYY-MM-DD hh:mm'),
                  ) : null
              }
              onChange={(date) => setInitialValues({...initialValues, 'reported_at': date})}
          />
      </FormField>
  

  

  

  

  

  

    

  



  

  

  

  

  

  
      <FormField
          label="ResolvedAt"
      >
          <DatePicker
              dateFormat="yyyy-MM-dd hh:mm"
              showTimeSelect
              selected={initialValues.resolved_at ?
                  new Date(
                      dayjs(initialValues.resolved_at).format('YYYY-MM-DD hh:mm'),
                  ) : null
              }
              onChange={(date) => setInitialValues({...initialValues, 'resolved_at': date})}
          />
      </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('/content_moderation_reports/content_moderation_reports-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default EditContent_moderation_reports
