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

const initialValues = {
    
    
    title: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    scope: 'global',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organization: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    course: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    metric: 'score',
    
    
    
    
    
    
    
    
    
    
    
    
    period_start: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    period_end: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_active: false,
    
    
    
    
    
    
    
    
}


const LeaderboardsNew = () => {
  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('/leaderboards/leaderboards-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    period_start: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    period_end: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



  <FormField
      label="Title"
  >
      <Field
          name="title"
          placeholder="Title"
      />
  </FormField>









































  <FormField label="Scope" labelFor="scope">
      <Field name="scope" id="scope" component="select">
      
        <option value="global">global</option>
      
        <option value="country">country</option>
      
        <option value="organization">organization</option>
      
        <option value="course">course</option>
      
        <option value="weekly">weekly</option>
      
        <option value="monthly">monthly</option>
      
      </Field>
  </FormField>































  <FormField label="Organization" labelFor="organization">
      <Field name="organization" id="organization" component={SelectField} options={[]} itemRef={'organizations'}></Field>
  </FormField>



























  <FormField label="Course" labelFor="course">
      <Field name="course" id="course" component={SelectField} options={[]} itemRef={'courses'}></Field>
  </FormField>























  <FormField label="Metric" labelFor="metric">
      <Field name="metric" id="metric" component="select">
      
        <option value="score">score</option>
      
        <option value="streak_days">streak_days</option>
      
        <option value="completed_items">completed_items</option>
      
        <option value="accuracy">accuracy</option>
      
      </Field>
  </FormField>























  <FormField
      label="PeriodStart"
  >
      <Field
          type="datetime-local"
          name="period_start"
          placeholder="PeriodStart"
      />
  </FormField>



























  <FormField
      label="PeriodEnd"
  >
      <Field
          type="datetime-local"
          name="period_end"
          placeholder="PeriodEnd"
      />
  </FormField>

































  <FormField label='IsActive' labelFor='is_active'>
      <Field
          name='is_active'
          id='is_active'
          component={SwitchField}
      ></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('/leaderboards/leaderboards-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default LeaderboardsNew
