import { Form, Input, InputNumber, Switch } from "antd";
import { useTranslation } from "react-i18next";
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
import InstanceRenderManager from "../../utils/instanceRenderMgr";

export default function ShopInfoRoGuard({ form }) {
  const { t } = useTranslation();

  return (
    <div>
      <LayoutFormRow header={t("bodyshop.labels.md_ro_guard")}>
        <Form.Item
          label={t("bodyshop.fields.md_ro_guard.enabled")}
          name={["md_ro_guard", "enabled"]}
          valuePropName="checked"
        >
          <Switch />
        </Form.Item>
      </LayoutFormRow>
      <Form.Item noStyle dependencies={[["md_ro_guard", "enabled"]]}>
        {() => {
          const disabled = !form.getFieldValue(["md_ro_guard", "enabled"]);
          return (
            <LayoutFormRow header={t("bodyshop.labels.md_ro_guard_options")}>
              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.totalgppercent_minimum")}
                name={["md_ro_guard", "totalgppercent_minimum"]}
                rules={[
                  {
                    required: !disabled
                    //message: t("general.validation.required"),
                  }
                ]}
              >
                <InputNumber min={0} max={100} precision={1} suffix="%" disabled={disabled} />
              </Form.Item>

              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.masterbypass")}
                name={["md_ro_guard", "masterbypass"]}
                rules={[
                  {
                    required: !disabled
                    //message: t("general.validation.required"),
                  }
                ]}
              >
                <Input type="password" allowClear disabled={disabled} />
              </Form.Item>

              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.enforce_bills")}
                name={["md_ro_guard", "enforce_bills"]}
                valuePropName="checked"
              >
                <Switch disabled={disabled} />
              </Form.Item>
              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.enforce_cm")}
                name={["md_ro_guard", "enforce_cm"]}
                valuePropName="checked"
              >
                <Switch disabled={disabled} />
              </Form.Item>

              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.enforce_profit")}
                name={["md_ro_guard", "enforce_profit"]}
                valuePropName="checked"
              >
                <Switch disabled={disabled} />
              </Form.Item>

              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.enforce_ar")}
                name={["md_ro_guard", "enforce_ar"]}
                valuePropName="checked"
              >
                <Switch disabled={disabled} />
              </Form.Item>

              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.enforce_sublet")}
                name={["md_ro_guard", "enforce_sublet"]}
                valuePropName="checked"
              >
                <Switch disabled={disabled} />
              </Form.Item>

              {InstanceRenderManager({
                rome: (
                  <Form.Item
                    label={t("bodyshop.fields.md_ro_guard.enforce_ppd")}
                    name={["md_ro_guard", "enforce_ppd"]}
                    valuePropName="checked"
                  >
                    <Switch disabled={disabled} />
                  </Form.Item>
                )
              })}

              <Form.Item
                label={t("bodyshop.fields.md_ro_guard.enforce_labor")}
                name={["md_ro_guard", "enforce_labor"]}
                valuePropName="checked"
              >
                <Switch disabled={disabled} />
              </Form.Item>
            </LayoutFormRow>
          );
        }}
      </Form.Item>
    </div>
  );
}
