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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    trading_account: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    instrument: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    setup: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    direction: 'long',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'planned',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    timeframe: '1m',
    
    
    
    
    
    
    
    
    
    
    
    
    entry_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    exit_at: '',
    
    
    
    
    
    
    
    
    
    
    entry_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    exit_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    stop_loss_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    take_profit_price: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    position_size: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    position_size_unit: 'shares',
    
    
    
    
    
    
    
    fees: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    slippage: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pnl_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pnl_percent: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    risk_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    rr_ratio: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    mae_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    mfe_amount: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    duration_minutes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_win: false,
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tags: [],
    
    
}


const TradesNew = () => {
  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('/trades/trades-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    entry_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    exit_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : 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="Instrument" labelFor="instrument">
      <Field name="instrument" id="instrument" component={SelectField} options={[]} itemRef={'instruments'}></Field>
  </FormField>



























  <FormField label="Setup" labelFor="setup">
      <Field name="setup" id="setup" component={SelectField} options={[]} itemRef={'setups'}></Field>
  </FormField>























  <FormField label="Direction" labelFor="direction">
      <Field name="direction" id="direction" component="select">
      
        <option value="long">long</option>
      
        <option value="short">short</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="planned">planned</option>
      
        <option value="open">open</option>
      
        <option value="closed">closed</option>
      
        <option value="canceled">canceled</option>
      
      </Field>
  </FormField>



























  <FormField label="Timeframe" labelFor="timeframe">
      <Field name="timeframe" id="timeframe" component="select">
      
        <option value="1m">1m</option>
      
        <option value="5m">5m</option>
      
        <option value="15m">15m</option>
      
        <option value="30m">30m</option>
      
        <option value="1h">1h</option>
      
        <option value="4h">4h</option>
      
        <option value="1d">1d</option>
      
        <option value="1w">1w</option>
      
        <option value="1mo">1mo</option>
      
        <option value="custom">custom</option>
      
      </Field>
  </FormField>























  <FormField
      label="EntryAt"
  >
      <Field
          type="datetime-local"
          name="entry_at"
          placeholder="EntryAt"
      />
  </FormField>



























  <FormField
      label="ExitAt"
  >
      <Field
          type="datetime-local"
          name="exit_at"
          placeholder="ExitAt"
      />
  </FormField>























    <FormField
        label="EntryPrice"
    >
        <Field
            type="number"
            name="entry_price"
            placeholder="EntryPrice"
        />
    </FormField>



























    <FormField
        label="ExitPrice"
    >
        <Field
            type="number"
            name="exit_price"
            placeholder="ExitPrice"
        />
    </FormField>



























    <FormField
        label="StopLossPrice"
    >
        <Field
            type="number"
            name="stop_loss_price"
            placeholder="StopLossPrice"
        />
    </FormField>



























    <FormField
        label="TakeProfitPrice"
    >
        <Field
            type="number"
            name="take_profit_price"
            placeholder="TakeProfitPrice"
        />
    </FormField>



























    <FormField
        label="PositionSize"
    >
        <Field
            type="number"
            name="position_size"
            placeholder="PositionSize"
        />
    </FormField>



































  <FormField label="PositionSizeUnit" labelFor="position_size_unit">
      <Field name="position_size_unit" id="position_size_unit" component="select">
      
        <option value="shares">shares</option>
      
        <option value="contracts">contracts</option>
      
        <option value="lots">lots</option>
      
        <option value="units">units</option>
      
      </Field>
  </FormField>



















    <FormField
        label="Fees"
    >
        <Field
            type="number"
            name="fees"
            placeholder="Fees"
        />
    </FormField>



























    <FormField
        label="Slippage"
    >
        <Field
            type="number"
            name="slippage"
            placeholder="Slippage"
        />
    </FormField>



























    <FormField
        label="PnLAmount"
    >
        <Field
            type="number"
            name="pnl_amount"
            placeholder="PnLAmount"
        />
    </FormField>



























    <FormField
        label="PnLPercent"
    >
        <Field
            type="number"
            name="pnl_percent"
            placeholder="PnLPercent"
        />
    </FormField>



























    <FormField
        label="RiskAmount"
    >
        <Field
            type="number"
            name="risk_amount"
            placeholder="RiskAmount"
        />
    </FormField>



























    <FormField
        label="RiskRewardRatio"
    >
        <Field
            type="number"
            name="rr_ratio"
            placeholder="RiskRewardRatio"
        />
    </FormField>



























    <FormField
        label="MaxAdverseExcursion"
    >
        <Field
            type="number"
            name="mae_amount"
            placeholder="MaxAdverseExcursion"
        />
    </FormField>



























    <FormField
        label="MaxFavorableExcursion"
    >
        <Field
            type="number"
            name="mfe_amount"
            placeholder="MaxFavorableExcursion"
        />
    </FormField>



























    <FormField
        label="DurationMinutes"
    >
        <Field
            type="number"
            name="duration_minutes"
            placeholder="DurationMinutes"
        />
    </FormField>





































  <FormField label='IsWin' labelFor='is_win'>
      <Field
          name='is_win'
          id='is_win'
          component={SwitchField}
      ></Field>
  </FormField>













    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </FormField>













































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

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

export default TradesNew
