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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    trading_account: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    broker: 'alpaca',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'connected',
    
    
    
    
    
    
    
    connection_label: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sync_enabled: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    last_sync_at: '',
    
    
    
    
    
    
    
    
    
    
    
    last_error: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/broker_connections/broker_connections-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="TradingAccount" labelFor="trading_account">
      <Field name="trading_account" id="trading_account" component={SelectField} options={[]} itemRef={'trading_accounts'}></Field>
  </FormField>























  <FormField label="Broker" labelFor="broker">
      <Field name="broker" id="broker" component="select">
      
        <option value="alpaca">alpaca</option>
      
        <option value="interactive_brokers">interactive_brokers</option>
      
        <option value="tradingview">tradingview</option>
      
        <option value="metatrader4">metatrader4</option>
      
        <option value="metatrader5">metatrader5</option>
      
        <option value="binance">binance</option>
      
        <option value="coinbase">coinbase</option>
      
        <option value="kraken">kraken</option>
      
        <option value="other">other</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="connected">connected</option>
      
        <option value="disconnected">disconnected</option>
      
        <option value="error">error</option>
      
        <option value="pending">pending</option>
      
      </Field>
  </FormField>













  <FormField
      label="ConnectionLabel"
  >
      <Field
          name="connection_label"
          placeholder="ConnectionLabel"
      />
  </FormField>











































  <FormField label='SyncEnabled' labelFor='sync_enabled'>
      <Field
          name='sync_enabled'
          id='sync_enabled'
          component={SwitchField}
      ></Field>
  </FormField>





















  <FormField
      label="LastSyncAt"
  >
      <Field
          type="datetime-local"
          name="last_sync_at"
          placeholder="LastSyncAt"
      />
  </FormField>



















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

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

export default Broker_connectionsNew
