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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    lab: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    initiated_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    scenario_type: 'phishing',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'queued',
    
    
    
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ended_at: '',
    
    
    
    
    
    
    
    
    
    
    success_score: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    findings: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    affected_assets: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


const Simulation_runsNew = () => {
  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('/simulation_runs/simulation_runs-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'),
                    ended_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="SimulationLab" labelFor="lab">
      <Field name="lab" id="lab" component={SelectField} options={[]} itemRef={'simulation_labs'}></Field>
  </FormField>



























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























  <FormField label="ScenarioType" labelFor="scenario_type">
      <Field name="scenario_type" id="scenario_type" component="select">
      
        <option value="phishing">phishing</option>
      
        <option value="ransomware">ransomware</option>
      
        <option value="malware_outbreak">malware_outbreak</option>
      
        <option value="insider_threat">insider_threat</option>
      
        <option value="cloud_misconfig">cloud_misconfig</option>
      
        <option value="lateral_movement">lateral_movement</option>
      
        <option value="ddos">ddos</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="completed">completed</option>
      
        <option value="failed">failed</option>
      
        <option value="canceled">canceled</option>
      
      </Field>
  </FormField>























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



























  <FormField
      label="EndedAt"
  >
      <Field
          type="datetime-local"
          name="ended_at"
          placeholder="EndedAt"
      />
  </FormField>























    <FormField
        label="SuccessScore"
    >
        <Field
            type="number"
            name="success_score"
            placeholder="SuccessScore"
        />
    </FormField>

























      <FormField label='Findings' hasTextareaHeight>
          <Field
              name='findings'
              id='findings'
              component={RichTextField}
          ></Field>
      </FormField>











































    <FormField label='AffectedAssets' labelFor='affected_assets'>
        <Field
            name='affected_assets'
            id='affected_assets'
            itemRef={'assets'}
            options={[]}
            component={SelectFieldMany}>
        </Field>
    </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('/simulation_runs/simulation_runs-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Simulation_runsNew
