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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    workspace: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    snippet: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    requested_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    runtime: 'node',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'queued',
    
    
    
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    finished_at: '',
    
    
    
    
    
    
    
    
    
    
    
    stdout: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    stderr: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    exit_code: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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





















  <FormField label="Workspace" labelFor="workspace">
      <Field name="workspace" id="workspace" component={SelectField} options={[]} itemRef={'workspaces'}></Field>
  </FormField>



























  <FormField label="Snippet" labelFor="snippet">
      <Field name="snippet" id="snippet" component={SelectField} options={[]} itemRef={'code_snippets'}></Field>
  </FormField>



























  <FormField label="RequestedBy" labelFor="requested_by">
      <Field name="requested_by" id="requested_by" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>























  <FormField label="Runtime" labelFor="runtime">
      <Field name="runtime" id="runtime" component="select">
      
        <option value="node">node</option>
      
        <option value="python">python</option>
      
        <option value="java">java</option>
      
        <option value="dotnet">dotnet</option>
      
        <option value="go">go</option>
      
        <option value="rust">rust</option>
      
        <option value="php">php</option>
      
        <option value="ruby">ruby</option>
      
        <option value="bash">bash</option>
      
        <option value="browser">browser</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="queued">queued</option>
      
        <option value="running">running</option>
      
        <option value="succeeded">succeeded</option>
      
        <option value="failed">failed</option>
      
        <option value="canceled">canceled</option>
      
        <option value="timed_out">timed_out</option>
      
      </Field>
  </FormField>























  <FormField
      label="StartedAt"
  >
      <Field
          type="datetime-local"
          name="started_at"
          placeholder="StartedAt"
      />
  </FormField>



























  <FormField
      label="FinishedAt"
  >
      <Field
          type="datetime-local"
          name="finished_at"
          placeholder="FinishedAt"
      />
  </FormField>



















    <FormField label="Stdout" hasTextareaHeight>
        <Field name="stdout" as="textarea" placeholder="Stdout" />
    </FormField>



























    <FormField label="Stderr" hasTextareaHeight>
        <Field name="stderr" as="textarea" placeholder="Stderr" />
    </FormField>































    <FormField
        label="ExitCode"
    >
        <Field
            type="number"
            name="exit_code"
            placeholder="ExitCode"
        />
    </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('/executions/executions-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ExecutionsNew
