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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    challenge_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    challenge_type: 'individual',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    metric_type: 'mission_completions',
    
    
    
    
    
    
    
    
    
    description: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    target_value: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reward_points: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    reward_coins: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    starts_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ends_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'scheduled',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    created_by: '',
    
    
    
}


const ChallengesNew = () => {
  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('/challenges/challenges-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="Organization" labelFor="organization">
      <Field name="organization" id="organization" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </FormField>









  <FormField
      label="ChallengeName"
  >
      <Field
          name="challenge_name"
          placeholder="ChallengeName"
      />
  </FormField>









































  <FormField label="ChallengeType" labelFor="challenge_type">
      <Field name="challenge_type" id="challenge_type" component="select">
      
        <option value="individual">individual</option>
      
        <option value="team">team</option>
      
      </Field>
  </FormField>



























  <FormField label="MetricType" labelFor="metric_type">
      <Field name="metric_type" id="metric_type" component="select">
      
        <option value="mission_completions">mission_completions</option>
      
        <option value="points">points</option>
      
        <option value="coins">coins</option>
      
        <option value="kpi_value">kpi_value</option>
      
        <option value="quiz_score_average">quiz_score_average</option>
      
      </Field>
  </FormField>

















      <FormField label='Description' hasTextareaHeight>
          <Field
              name='description'
              id='description'
              component={RichTextField}
          ></Field>
      </FormField>





























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



























    <FormField
        label="RewardPoints"
    >
        <Field
            type="number"
            name="reward_points"
            placeholder="RewardPoints"
        />
    </FormField>



























    <FormField
        label="RewardCoins"
    >
        <Field
            type="number"
            name="reward_coins"
            placeholder="RewardCoins"
        />
    </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="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="scheduled">scheduled</option>
      
        <option value="active">active</option>
      
        <option value="completed">completed</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>































  <FormField label="CreatedBy" labelFor="created_by">
      <Field name="created_by" id="created_by" component={SelectField} options={[]} itemRef={'users'}></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('/challenges/challenges-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ChallengesNew
