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

const initialValues = {
  modelo: '',

  fabricante: '',

  local_instalacao: '',

  coordenada_lat: '',

  coordenada_lon: '',

  altura_instalacao_m: '',

  angulo_focal: '',

  ip_acesso: '',

  status_operacional: '',

  data_instalacao: '',
  dateData_instalacao: '',

  observacoes: '',

  obra: '',

  clientes: '',
};

const Cameras_ptzNew = () => {
  const router = useRouter();
  const dispatch = useAppDispatch();

  const handleSubmit = async (data) => {
    await dispatch(create(data));
    await router.push('/cameras_ptz/cameras_ptz-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='Modelo'>
                <Field name='modelo' placeholder='Modelo' />
              </FormField>

              <FormField label='Fabricante'>
                <Field name='fabricante' placeholder='Fabricante' />
              </FormField>

              <FormField label='LocaldeInstalação' hasTextareaHeight>
                <Field
                  name='local_instalacao'
                  as='textarea'
                  placeholder='LocaldeInstalação'
                />
              </FormField>

              <FormField label='CoordenadaLatitude'>
                <Field
                  type='number'
                  name='coordenada_lat'
                  placeholder='CoordenadaLatitude'
                />
              </FormField>

              <FormField label='CoordenadaLongitude'>
                <Field
                  type='number'
                  name='coordenada_lon'
                  placeholder='CoordenadaLongitude'
                />
              </FormField>

              <FormField label='AlturadeInstalação(m)'>
                <Field
                  type='number'
                  name='altura_instalacao_m'
                  placeholder='AlturadeInstalação(m)'
                />
              </FormField>

              <FormField label='ÂnguloFocal'>
                <Field name='angulo_focal' placeholder='ÂnguloFocal' />
              </FormField>

              <FormField label='IPdeAcesso'>
                <Field name='ip_acesso' placeholder='IPdeAcesso' />
              </FormField>

              <FormField label='StatusOperacional'>
                <Field
                  name='status_operacional'
                  placeholder='StatusOperacional'
                />
              </FormField>

              <FormField label='DatadeInstalação'>
                <Field
                  type='date'
                  name='data_instalacao'
                  placeholder='DatadeInstalação'
                />
              </FormField>

              <FormField label='Observações' hasTextareaHeight>
                <Field
                  name='observacoes'
                  as='textarea'
                  placeholder='Observações'
                />
              </FormField>

              <FormField label='Obra' labelFor='obra'>
                <Field
                  name='obra'
                  id='obra'
                  component={SelectField}
                  options={[]}
                  itemRef={'obras'}
                ></Field>
              </FormField>

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

Cameras_ptzNew.getLayout = function getLayout(page: ReactElement) {
  return (
    <LayoutAuthenticated permission={'CREATE_CAMERAS_PTZ'}>
      {page}
    </LayoutAuthenticated>
  );
};

export default Cameras_ptzNew;
