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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    artist_profile: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    platform: '',
    
    
    
    
    
    
    
    
    
    period_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    period_end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source_type: 'api',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    source_file: [],
    
    
    
    
    
    
    source_reference: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'imported',
    
    
    
    
    
    
    
    
    error_details: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const Royalty_reportsNew = () => {
  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('/royalty_reports/royalty_reports-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_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    period_end_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Artistprofile" labelFor="artist_profile">
      <Field name="artist_profile" id="artist_profile" component={SelectField} options={[]} itemRef={'artist_profiles'}></Field>
  </FormField>



























  <FormField label="Platform" labelFor="platform">
      <Field name="platform" id="platform" component={SelectField} options={[]} itemRef={'distribution_platforms'}></Field>
  </FormField>



















  <FormField
      label="Periodstartat"
  >
      <Field
          type="datetime-local"
          name="period_start_at"
          placeholder="Periodstartat"
      />
  </FormField>



























  <FormField
      label="Periodendat"
  >
      <Field
          type="datetime-local"
          name="period_end_at"
          placeholder="Periodendat"
      />
  </FormField>































  <FormField label="Sourcetype" labelFor="source_type">
      <Field name="source_type" id="source_type" component="select">
      
        <option value="api">api</option>
      
        <option value="csv">csv</option>
      
        <option value="xml">xml</option>
      
        <option value="manual">manual</option>
      
      </Field>
  </FormField>




































  <FormField>
      <Field
          label='Sourcefile'
          color='info'
          icon={mdiUpload}
          path={'royalty_reports/source_file'}
          name='source_file'
          id='source_file'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>




  <FormField
      label="Sourcereference"
  >
      <Field
          name="source_reference"
          placeholder="Sourcereference"
      />
  </FormField>









































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="imported">imported</option>
      
        <option value="processing">processing</option>
      
        <option value="completed">completed</option>
      
        <option value="failed">failed</option>
      
      </Field>
  </FormField>















    <FormField label="Errordetails" hasTextareaHeight>
        <Field name="error_details" as="textarea" placeholder="Errordetails" />
    </FormField>











































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

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

export default Royalty_reportsNew
