import { useSplitTreatments } from "@splitsoftware/splitio-react";
import { Form, InputNumber } from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component";
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component";

const mapStateToProps = createStructuredSelector({
  bodyshop: selectBodyshop
});
const mapDispatchToProps = (dispatch) => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
});
export default connect(mapStateToProps, mapDispatchToProps)(ShopInfoRbacComponent);

export function ShopInfoRbacComponent({ form, bodyshop }) {
  const { t } = useTranslation();
  const {
    treatments: { Simple_Inventory }
  } = useSplitTreatments({
    attributes: {},
    names: ["Simple_Inventory"],
    splitKey: bodyshop && bodyshop.imexshopid
  });
  //TODO:AIO Ensure that there are no duplicates here, it seems like there may be.
  return (
    <RbacWrapper action="shop:rbac">
      <LayoutFormRow>
        {...HasFeatureAccess({ featureName: "export", bodyshop })
          ? [
              <Form.Item
                label={t("bodyshop.fields.rbac.accounting.exportlog")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "accounting:exportlog"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.accounting.payables")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "accounting:payables"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.accounting.payments")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "accounting:payments"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.accounting.receivables")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "accounting:receivables"]}
              >
                <InputNumber />
              </Form.Item>
            ]
          : []}
        {...HasFeatureAccess({ featureName: "bills", bodyshop })
          ? [
              <Form.Item
                label={t("bodyshop.fields.rbac.bills.delete")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "bills:delete"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.bills.enter")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "bills:enter"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.bills.list")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "bills:list"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.bills.reexport")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "bills:reexport"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.bills.view")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "bills:view"]}
              >
                <InputNumber />
              </Form.Item>
            ]
          : []}
        {...HasFeatureAccess({ featureName: "courtesycars", bodyshop })
          ? [
              <Form.Item
                label={t("bodyshop.fields.rbac.contracts.create")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "contracts:create"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.contracts.detail")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "contracts:detail"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.contracts.list")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "contracts:list"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.courtesycar.create")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "courtesycar:create"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.courtesycar.detail")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "courtesycar:detail"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.courtesycar.list")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "courtesycar:list"]}
              >
                <InputNumber />
              </Form.Item>
            ]
          : []}
        {...HasFeatureAccess({ featureName: "csi", bodyshop })
          ? [
              <Form.Item
                label={t("bodyshop.fields.rbac.csi.export")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "csi:export"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.csi.page")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "csi:page"]}
              >
                <InputNumber />
              </Form.Item>
            ]
          : []}
        <Form.Item
          label={t("bodyshop.fields.rbac.employees.page")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "employees:page"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.employee_teams.page")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "employee_teams:page"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.admin")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:admin"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.available-list")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:available-list"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.checklist-view")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:checklist-view"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.close")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:close"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.create")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:create"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.deliver")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:deliver"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.detail")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:detail"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.intake")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:intake"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.list-active")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:list-active"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.list-all")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:list-all"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.list-ready")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:list-ready"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.partsqueue")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:partsqueue"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.jobs.void")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "jobs:void"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.owners.detail")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "owners:detail"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.owners.list")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "owners:list"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.payments.enter")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "payments:enter"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.payments.list")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "payments:list"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.phonebook.edit")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "phonebook:edit"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.phonebook.view")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "phonebook:view"]}
        >
          <InputNumber />
        </Form.Item>
        {HasFeatureAccess({ featureName: "visualboard", bodyshop }) && (
          <Form.Item
            label={t("bodyshop.fields.rbac.production.board")}
            rules={[
              {
                required: true
                //message: t("general.validation.required"),
              }
            ]}
            name={["md_rbac", "production:board"]}
          >
            <InputNumber />
          </Form.Item>
        )}
        <Form.Item
          label={t("bodyshop.fields.rbac.production.list")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "production:list"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.schedule.view")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "schedule:view"]}
        >
          <InputNumber />
        </Form.Item>
        {HasFeatureAccess({ featureName: "scoreboard", bodyshop }) && (
          <Form.Item
            label={t("bodyshop.fields.rbac.scoreboard.view")}
            rules={[
              {
                required: true
                //message: t("general.validation.required"),
              }
            ]}
            name={["md_rbac", "scoreboard:view"]}
          >
            <InputNumber />
          </Form.Item>
        )}
        {...HasFeatureAccess({ featureName: "timetickets", bodyshop })
          ? [
              <Form.Item
                label={t("bodyshop.fields.rbac.shiftclock.view")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "shiftclock:view"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.shop.config")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "shop:config"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.timetickets.edit")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "timetickets:edit"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.timetickets.shiftedit")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "timetickets:shiftedit"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.timetickets.editcommitted")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "timetickets:editcommitted"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.ttapprovals.view")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "ttapprovals:view"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.ttapprovals.approve")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "ttapprovals:approve"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.timetickets.enter")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "timetickets:enter"]}
              >
                <InputNumber />
              </Form.Item>,
              <Form.Item
                label={t("bodyshop.fields.rbac.timetickets.list")}
                rules={[
                  {
                    required: true
                    //message: t("general.validation.required"),
                  }
                ]}
                name={["md_rbac", "timetickets:list"]}
              >
                <InputNumber />
              </Form.Item>
            ]
          : []}
        <Form.Item
          label={t("bodyshop.fields.rbac.shop.vendors")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "shop:vendors"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.shop.dashboard")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "shop:dashboard"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.shop.rbac")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "shop:rbac"]}
        >
          <InputNumber />
        </Form.Item>
        <Form.Item
          label={t("bodyshop.fields.rbac.shop.reportcenter")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "shop:reportcenter"]}
        >
          <InputNumber />
        </Form.Item>
        {/* <Form.Item
          label={t("bodyshop.fields.rbac.shop.templates")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "shop:templates"]}
        >
          <InputNumber />
        </Form.Item> */}
        {HasFeatureAccess({ featureName: "media", bodyshop }) && (
          <Form.Item
            label={t("bodyshop.fields.rbac.temporarydocs.view")}
            rules={[
              {
                required: true
                //message: t("general.validation.required"),
              }
            ]}
            name={["md_rbac", "temporarydocs:view"]}
          >
            <InputNumber />
          </Form.Item>
        )}
        <Form.Item
          label={t("bodyshop.fields.rbac.users.editaccess")}
          rules={[
            {
              required: true
              //message: t("general.validation.required"),
            }
          ]}
          name={["md_rbac", "users:editaccess"]}
        >
          <InputNumber />
        </Form.Item>
        {Simple_Inventory.treatment === "on" && (
          <>
            <Form.Item
              label={t("bodyshop.fields.rbac.inventory.list")}
              rules={[
                {
                  required: true
                  //message: t("general.validation.required"),
                }
              ]}
              name={["md_rbac", "inventory:list"]}
            >
              <InputNumber />
            </Form.Item>
            <Form.Item
              label={t("bodyshop.fields.rbac.inventory.delete")}
              rules={[
                {
                  required: true
                  //message: t("general.validation.required"),
                }
              ]}
              name={["md_rbac", "inventory:delete"]}
            >
              <InputNumber />
            </Form.Item>
          </>
        )}
      </LayoutFormRow>
    </RbacWrapper>
  );
}
