import { DeleteFilled } from "@ant-design/icons";
import { Button, Form, Input, Space } from "antd";
import { useTranslation } from "react-i18next";
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
import FormListMoveArrows from "../form-list-move-arrows/form-list-move-arrows.component";
import ConfigListEmptyState from "../layout-form-row/config-list-empty-state.component.jsx";
import InlineValidatedFormRow from "../layout-form-row/inline-validated-form-row.component.jsx";
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
import {
  INLINE_TITLE_GROUP_STYLE,
  INLINE_TITLE_HANDLE_STYLE,
  INLINE_TITLE_INPUT_STYLE,
  INLINE_TITLE_LABEL_STYLE,
  INLINE_TITLE_ROW_STYLE,
  InlineTitleListIcon
} from "../layout-form-row/inline-form-row-title.utils.js";

export default function ShopInfoLaborRates() {
  const { t } = useTranslation();
  const form = Form.useFormInstance();

  return (
    <>
      <LayoutFormRow header={t("bodyshop.labels.shoprates")}>
        <Form.Item label={t("jobs.fields.rate_ats")} name={["shoprates", "rate_ats"]}>
          <CurrencyInput prefix="$" min={0} />
        </Form.Item>
        <Form.Item label={t("jobs.fields.rate_ats_flat")} name={["shoprates", "rate_ats_flat"]}>
          <CurrencyInput prefix="$" min={0} />
        </Form.Item>
      </LayoutFormRow>
      <Form.List name={["md_labor_rates"]}>
        {(fields, { add, remove, move }) => {
          return (
            <LayoutFormRow
              header={t("bodyshop.labels.laborrates")}
              actions={[
                <Button
                  key="add-labor-rate"
                  type="primary"
                  block
                  onClick={() => {
                    add();
                  }}
                >
                  {t("bodyshop.actions.newlaborrate")}
                </Button>
              ]}
            >
              <div>
                {fields.length === 0 ? (
                  <ConfigListEmptyState actionLabel={t("bodyshop.actions.newlaborrate")} />
                ) : (
                  fields.map((field, index) => {
                    return (
                      <Form.Item noStyle key={field.key}>
                        <InlineValidatedFormRow
                          form={form}
                          errorNames={[["md_labor_rates", field.name, "rate_label"]]}
                          noDivider={index === 0}
                          title={
                            <div style={INLINE_TITLE_ROW_STYLE}>
                              <InlineTitleListIcon style={INLINE_TITLE_HANDLE_STYLE} />
                              <div style={INLINE_TITLE_GROUP_STYLE}>
                                <div style={INLINE_TITLE_LABEL_STYLE}>{t("jobs.fields.labor_rate_desc")}</div>
                                <Form.Item
                                  noStyle
                                  name={[field.name, "rate_label"]}
                                  rules={[
                                    {
                                      required: true
                                    }
                                  ]}
                                >
                                  <Input
                                    size="small"
                                    placeholder={t("jobs.fields.labor_rate_desc")}
                                    style={{
                                      ...INLINE_TITLE_INPUT_STYLE,
                                      width: "100%"
                                    }}
                                  />
                                </Form.Item>
                              </div>
                            </div>
                          }
                          wrapTitle
                          extra={
                            <Space align="center" size="small">
                              <Button
                                type="text"
                                danger
                                icon={<DeleteFilled />}
                                onClick={() => {
                                  remove(field.name);
                                }}
                              />
                              <FormListMoveArrows
                                move={move}
                                index={index}
                                total={fields.length}
                                orientation="horizontal"
                              />
                            </Space>
                          }
                        >
                          <Form.Item
                            label={t("jobs.fields.rate_laa")}
                            key={`${index}rate_laa`}
                            name={[field.name, "rate_laa"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_lab")}
                            key={`${index}rate_lab`}
                            name={[field.name, "rate_lab"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_lad")}
                            key={`${index}rate_lad`}
                            name={[field.name, "rate_lad"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_lae")}
                            key={`${index}rate_lae`}
                            name={[field.name, "rate_lae"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_laf")}
                            key={`${index}rate_laf`}
                            name={[field.name, "rate_laf"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_lag")}
                            key={`${index}rate_lag`}
                            name={[field.name, "rate_lag"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_lam")}
                            key={`${index}rate_lam`}
                            name={[field.name, "rate_lam"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_lar")}
                            key={`${index}rate_lar`}
                            name={[field.name, "rate_lar"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_las")}
                            key={`${index}rate_las`}
                            name={[field.name, "rate_las"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_la1")}
                            key={`${index}rate_la1`}
                            name={[field.name, "rate_la1"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_la2")}
                            key={`${index}rate_la2`}
                            name={[field.name, "rate_la2"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_la3")}
                            key={`${index}rate_la3`}
                            name={[field.name, "rate_la3"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_la4")}
                            key={`${index}rate_la4`}
                            name={[field.name, "rate_la4"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_mash")}
                            key={`${index}rate_mash`}
                            name={[field.name, "rate_mash"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_mapa")}
                            key={`${index}rate_mapa`}
                            name={[field.name, "rate_mapa"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_ma2s")}
                            key={`${index}rate_ma2s`}
                            name={[field.name, "rate_ma2s"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_ma3s")}
                            key={`${index}rate_ma3s`}
                            name={[field.name, "rate_ma3s"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          {
                            // <Form.Item
                            //   label={t("jobs.fields.rate_mabl")}
                            //   key={`${index}rate_mabl`}
                            //   name={[field.name, "rate_mabl"]}
                            //   rules={[
                            //     {
                            //       required: true,
                            //       //message: t("general.validation.required"),
                            //     },
                            //   ]}
                            // >
                            //   <CurrencyInput min={0} />
                            // </Form.Item>
                            // <Form.Item
                            //   label={t("jobs.fields.rate_macs")}
                            //   key={`${index}rate_macs`}
                            //   name={[field.name, "rate_macs"]}
                            //   rules={[
                            //     {
                            //       required: true,
                            //       //message: t("general.validation.required"),
                            //     },
                            //   ]}
                            // >
                            //   <CurrencyInput min={0} />
                            // </Form.Item>
                          }
                          <Form.Item
                            label={t("jobs.fields.rate_matd")}
                            key={`${index}rate_matd`}
                            name={[field.name, "rate_matd"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                          <Form.Item
                            label={t("jobs.fields.rate_mahw")}
                            key={`${index}rate_mahw`}
                            name={[field.name, "rate_mahw"]}
                            rules={[
                              {
                                required: true
                                //message: t("general.validation.required"),
                              }
                            ]}
                          >
                            <CurrencyInput prefix="$" min={0} />
                          </Form.Item>
                        </InlineValidatedFormRow>
                      </Form.Item>
                    );
                  })
                )}
              </div>
            </LayoutFormRow>
          );
        }}
      </Form.List>
    </>
  );
}
