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

const initialValues = {
    
    
    name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    base_url: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    provider_type: 'market_data',
    
    
    
    
    
    
    
    
    
    
    
    
    
    enabled: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    last_health_check_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    health_status: 'unknown',
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const Api_providersNew = () => {
  const router = useRouter()
  const dispatch = useAppDispatch()

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/api_providers/api_providers-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



  <FormField
      label="Name"
  >
      <Field
          name="name"
          placeholder="Name"
      />
  </FormField>



























  <FormField
      label="BaseURL"
  >
      <Field
          name="base_url"
          placeholder="BaseURL"
      />
  </FormField>









































  <FormField label="ProviderType" labelFor="provider_type">
      <Field name="provider_type" id="provider_type" component="select">
      
        <option value="market_data">market_data</option>
      
        <option value="news">news</option>
      
        <option value="ai">ai</option>
      
      </Field>
  </FormField>





























  <FormField label='Enabled' labelFor='enabled'>
      <Field
          name='enabled'
          id='enabled'
          component={SwitchField}
      ></Field>
  </FormField>





















  <FormField
      label="LastHealthCheckAt"
  >
      <Field
          type="datetime-local"
          name="last_health_check_at"
          placeholder="LastHealthCheckAt"
      />
  </FormField>































  <FormField label="HealthStatus" labelFor="health_status">
      <Field name="health_status" id="health_status" component="select">
      
        <option value="unknown">unknown</option>
      
        <option value="ok">ok</option>
      
        <option value="degraded">degraded</option>
      
        <option value="down">down</option>
      
      </Field>
  </FormField>















    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </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('/api_providers/api_providers-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default Api_providersNew
