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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    conversation: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sender_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sender_agent: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    sender_type: 'user',
    
    
    
    
    
    
    
    
    
    content: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    format: 'markdown',
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_streaming: false,
    
    
    
    
    
    
    
    
    
    
    
    
    token_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sent_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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

    
    

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



























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



























  <FormField label="SenderAgent" labelFor="sender_agent">
      <Field name="sender_agent" id="sender_agent" component={SelectField} options={[]} itemRef={'ai_agents'}></Field>
  </FormField>























  <FormField label="SenderType" labelFor="sender_type">
      <Field name="sender_type" id="sender_type" component="select">
      
        <option value="user">user</option>
      
        <option value="agent">agent</option>
      
        <option value="system">system</option>
      
        <option value="tool">tool</option>
      
      </Field>
  </FormField>

















      <FormField label='Content' hasTextareaHeight>
          <Field
              name='content'
              id='content'
              component={RichTextField}
          ></Field>
      </FormField>





































  <FormField label="Format" labelFor="format">
      <Field name="format" id="format" component="select">
      
        <option value="markdown">markdown</option>
      
        <option value="plain_text">plain_text</option>
      
        <option value="html">html</option>
      
      </Field>
  </FormField>





























  <FormField label='IsStreaming' labelFor='is_streaming'>
      <Field
          name='is_streaming'
          id='is_streaming'
          component={SwitchField}
      ></Field>
  </FormField>

















    <FormField
        label="TokenCount"
    >
        <Field
            type="number"
            name="token_count"
            placeholder="TokenCount"
        />
    </FormField>































  <FormField
      label="SentAt"
  >
      <Field
          type="datetime-local"
          name="sent_at"
          placeholder="SentAt"
      />
  </FormField>





































    <FormField label='Attachments' labelFor='attachments'>
        <Field
            name='attachments'
            id='attachments'
            itemRef={'message_attachments'}
            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('/messages/messages-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default MessagesNew
