import { Collapse, Form, InputNumber, Switch } from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectJobReadOnly } from "../../redux/application/application.selectors";
import LayoutFormRow from "../layout-form-row/layout-form-row.component";

const mapStateToProps = createStructuredSelector({
  jobRO: selectJobReadOnly,
});

export function JobsDetailRatesParts({ jobRO, expanded, required = true }) {
  const { t } = useTranslation();

  return (
    <Collapse defaultActiveKey={expanded && "rates"}>
      <Collapse.Panel header={t("jobs.labels.parts_tax_rates")} key="rates">
        <LayoutFormRow header={t("joblines.fields.part_types.PAA")}>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_discp")}
            name={["parts_tax_rates", "PAA", "prt_discp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
            name={["parts_tax_rates", "PAA", "prt_mktyp"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
            name={["parts_tax_rates", "PAA", "prt_mkupp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
            name={["parts_tax_rates", "PAA", "prt_tax_in"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
            name={["parts_tax_rates", "PAA", "prt_tax_rt"]}
            rules={[
              {
                required: required,
                message: t("general.validation.required"),
              },
            ]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
        </LayoutFormRow>
        <LayoutFormRow header={t("joblines.fields.part_types.PAC")}>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_discp")}
            name={["parts_tax_rates", "PAC", "prt_discp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
            name={["parts_tax_rates", "PAC", "prt_mktyp"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
            name={["parts_tax_rates", "PAC", "prt_mkupp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
            name={["parts_tax_rates", "PAC", "prt_tax_in"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
            name={["parts_tax_rates", "PAC", "prt_tax_rt"]}
            rules={[
              {
                required: required,
                message: t("general.validation.required"),
              },
            ]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
        </LayoutFormRow>
        <LayoutFormRow header={t("joblines.fields.part_types.PAL")}>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_discp")}
            name={["parts_tax_rates", "PAL", "prt_discp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
            name={["parts_tax_rates", "PAL", "prt_mktyp"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
            name={["parts_tax_rates", "PAL", "prt_mkupp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
            name={["parts_tax_rates", "PAL", "prt_tax_in"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
            name={["parts_tax_rates", "PAL", "prt_tax_rt"]}
            rules={[
              {
                required: required,
                message: t("general.validation.required"),
              },
            ]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
        </LayoutFormRow>
        <LayoutFormRow header={t("joblines.fields.part_types.PAM")}>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_discp")}
            name={["parts_tax_rates", "PAM", "prt_discp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
            name={["parts_tax_rates", "PAM", "prt_mktyp"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
            name={["parts_tax_rates", "PAM", "prt_mkupp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
            name={["parts_tax_rates", "PAM", "prt_tax_in"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
            name={["parts_tax_rates", "PAM", "prt_tax_rt"]}
            rules={[
              {
                required: required,
                message: t("general.validation.required"),
              },
            ]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
        </LayoutFormRow>
        <LayoutFormRow header={t("joblines.fields.part_types.PAN")}>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_discp")}
            name={["parts_tax_rates", "PAN", "prt_discp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
            name={["parts_tax_rates", "PAN", "prt_mktyp"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
            name={["parts_tax_rates", "PAN", "prt_mkupp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
            name={["parts_tax_rates", "PAN", "prt_tax_in"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
            name={["parts_tax_rates", "PAN", "prt_tax_rt"]}
            rules={[
              {
                required: required,
                message: t("general.validation.required"),
              },
            ]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
        </LayoutFormRow>
        <LayoutFormRow header={t("joblines.fields.part_types.PAR")}>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_discp")}
            name={["parts_tax_rates", "PAR", "prt_discp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
            name={["parts_tax_rates", "PAR", "prt_mktyp"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
            name={["parts_tax_rates", "PAR", "prt_mkupp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
            name={["parts_tax_rates", "PAR", "prt_tax_in"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
            name={["parts_tax_rates", "PAR", "prt_tax_rt"]}
            rules={[
              {
                required: required,
                message: t("general.validation.required"),
              },
            ]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
        </LayoutFormRow>
        <LayoutFormRow header={t("joblines.fields.part_types.PAS")}>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_discp")}
            name={["parts_tax_rates", "PAS", "prt_discp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mktyp")}
            name={["parts_tax_rates", "PAS", "prt_mktyp"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_mkupp")}
            name={["parts_tax_rates", "PAS", "prt_mkupp"]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_in")}
            name={["parts_tax_rates", "PAS", "prt_tax_in"]}
            valuePropName="checked"
          >
            <Switch />
          </Form.Item>
          <Form.Item
            label={t("jobs.fields.parts_tax_rates.prt_tax_rt")}
            name={["parts_tax_rates", "PAS", "prt_tax_rt"]}
            rules={[
              {
                required: required,
                message: t("general.validation.required"),
              },
            ]}
          >
            <InputNumber min={0} max={1} precision={2} disabled={jobRO} />
          </Form.Item>
        </LayoutFormRow>
      </Collapse.Panel>
    </Collapse>
  );
}
export default connect(mapStateToProps, null)(JobsDetailRatesParts);
