import { Form, Input, InputNumber, Space } from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import ContractLicenseDecodeButton from "../contract-license-decode-button/contract-license-decode-button.component";
import ContractStatusSelector from "../contract-status-select/contract-status-select.component";
import CourtesyCarFuelSlider from "../courtesy-car-fuel-select/courtesy-car-fuel-select.component";
import FormDatePicker from "../form-date-picker/form-date-picker.component";
import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-alert.component";
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
import InputPhone, {
  PhoneItemFormatterValidation,
} from "../form-items-formatted/phone-form-item.component";
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
import ContractFormJobPrefill from "./contract-form-job-prefill.component";

export default function ContractFormComponent({
  form,
  create = false,
  selectedJobState,
}) {
  const { t } = useTranslation();
  return (
    <div>
      <FormFieldsChanged form={form} />
      <LayoutFormRow>
        {create ? null : (
          <Form.Item
            label={t("contracts.fields.status")}
            name="status"
            rules={[
              {
                required: true,
                message: t("general.validation.required"),
              },
            ]}
          >
            <ContractStatusSelector />
          </Form.Item>
        )}

        <Form.Item
          label={t("contracts.fields.start")}
          name="start"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <FormDatePicker />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.scheduledreturn")}
          name="scheduledreturn"
        >
          <FormDatePicker />
        </Form.Item>
        {create ? null : (
          <Form.Item
            label={t("contracts.fields.actualreturn")}
            name="actualreturn"
          >
            <FormDatePicker />
          </Form.Item>
        )}
      </LayoutFormRow>
      <LayoutFormRow>
        <Form.Item
          label={t("contracts.fields.kmstart")}
          name="kmstart"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <InputNumber />
        </Form.Item>
        {create ? null : (
          <Form.Item label={t("contracts.fields.kmend")} name="kmend">
            <InputNumber />
          </Form.Item>
        )}
      </LayoutFormRow>
      <LayoutFormRow>
        <Form.Item
          label={t("contracts.fields.fuelout")}
          name="fuelout"
          span={8}
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <CourtesyCarFuelSlider />
        </Form.Item>
        {create ? null : (
          <Form.Item
            label={t("contracts.fields.fuelin")}
            name="fuelin"
            span={8}
          >
            <CourtesyCarFuelSlider />
          </Form.Item>
        )}
      </LayoutFormRow>
      <div>
        <Space wrap>
          {selectedJobState && (
            <div>
              <ContractFormJobPrefill
                jobId={selectedJobState && selectedJobState[0]}
                form={form}
              />
            </div>
          )}
          <ContractLicenseDecodeButton form={form} />
        </Space>
      </div>
      <LayoutFormRow header={t("contracts.labels.driverinformation")}>
        <Form.Item
          label={t("contracts.fields.driver_dlnumber")}
          name="driver_dlnumber"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_dlexpiry")}
          name="driver_dlexpiry"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <FormDatePicker />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_dlst")}
          name="driver_dlst"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_fn")}
          name="driver_fn"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_ln")}
          name="driver_ln"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_addr1")}
          name="driver_addr1"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
          ]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_addr2")}
          name="driver_addr2"
        >
          <Input />
        </Form.Item>
        <Form.Item label={t("contracts.fields.driver_city")} name="driver_city">
          <Input />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_state")}
          name="driver_state"
        >
          <Input />
        </Form.Item>
        <Form.Item label={t("contracts.fields.driver_zip")} name="driver_zip">
          <Input />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.driver_ph1")}
          name="driver_ph1"
          rules={[
            {
              required: true,
              message: t("general.validation.required"),
            },
            ({ getFieldValue }) =>
              PhoneItemFormatterValidation(getFieldValue, "driver_ph1"),
          ]}
        >
          <InputPhone />
        </Form.Item>
        <Form.Item label={t("contracts.fields.driver_dob")} name="driver_dob">
          <FormDatePicker />
        </Form.Item>
      </LayoutFormRow>
      <LayoutFormRow header={t("contracts.labels.rates")}>
        <Form.Item label={t("contracts.fields.dailyrate")} name="dailyrate">
          <InputNumber precision={2} />
        </Form.Item>
        <Form.Item label={t("contracts.fields.actax")} name="actax">
          <InputNumber precision={2} />
        </Form.Item>
        <Form.Item label={t("contracts.fields.dailyfreekm")} name="dailyfreekm">
          <InputNumber precision={2} />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.refuelcharge")}
          name="refuelcharge"
        >
          <InputNumber precision={2} />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.excesskmrate")}
          name="excesskmrate"
        >
          <InputNumber precision={2} />
        </Form.Item>
        <Form.Item
          label={t("contracts.fields.cleanupcharge")}
          name="cleanupcharge"
        >
          <InputNumber precision={2} />
        </Form.Item>
      </LayoutFormRow>
      <LayoutFormRow>
        <Form.Item
          label={t("contracts.fields.damagewaiver")}
          name="damagewaiver"
        >
          <InputNumber precision={2} />
        </Form.Item>
        <Form.Item label={t("contracts.fields.federaltax")} name="federaltax">
          <InputNumberCalculator precision={2} />
        </Form.Item>
        <Form.Item label={t("contracts.fields.statetax")} name="statetax">
          <InputNumberCalculator precision={2} />
        </Form.Item>
        <Form.Item label={t("contracts.fields.localtax")} name="localtax">
          <InputNumberCalculator precision={2} />
        </Form.Item>
        <Form.Item label={t("contracts.fields.coverage")} name="coverage">
          <InputNumberCalculator precision={2} />
        </Form.Item>
      </LayoutFormRow>
    </div>
  );
}
