import { useTreatmentsWithConfig } from "@splitsoftware/splitio-react";
import { Form, InputNumber } from "antd";
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 = () => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
});
export default connect(mapStateToProps, mapDispatchToProps)(ShopInfoRbacComponent);

export function ShopInfoRbacComponent({ bodyshop }) {
  const { t } = useTranslation();
  const {
    treatments: { Simple_Inventory }
  } = useTreatmentsWithConfig({
    attributes: {},
    names: ["Simple_Inventory"],
    splitKey: bodyshop && bodyshop.imexshopid
  });
  return (
    <RbacWrapper action="shop:rbac">
      <LayoutFormRow header={t("bodyshop.labels.rbac_options")}>
        {[
          ...(HasFeatureAccess({ featureName: "export", bodyshop })
            ? [
                <Form.Item
                  key="accounting:exportlog"
                  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
                  key="accounting:payables"
                  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
                  key="accounting:payments"
                  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
                  key="accounting:receivables"
                  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
                  key="bills:delete"
                  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
                  key="bills:enter"
                  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
                  key="bills:list"
                  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
                  key="bills:reexport"
                  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
                  key="bills:view"
                  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
                  key="contracts:create"
                  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
                  key="contracts:detail"
                  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
                  key="contracts:list"
                  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
                  key="courtesycar:create"
                  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
                  key="courtesycar:detail"
                  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
                  key="courtesycar:list"
                  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
                  key="csi:export"
                  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
                  key="csi:page"
                  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
            key="employees:page"
            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
            key="employee_teams:page"
            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
            key="jobs:admin"
            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
            key="jobs:available-list"
            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
            key="jobs:checklist-view"
            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
            key="jobs:close"
            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
            key="jobs:create"
            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
            key="jobs:deliver"
            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
            key="jobs:detail"
            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
            key="jobs:intake"
            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
            key="jobs:list-active"
            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
            key="jobs:list-all"
            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
            key="jobs:list-ready"
            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
            key="jobs:manual-line"
            label={t("bodyshop.fields.rbac.jobs.manual-line")}
            rules={[
              {
                required: true
                //message: t("general.validation.required"),
              }
            ]}
            name={["md_rbac", "jobs:manual-line"]}
          >
            <InputNumber />
          </Form.Item>,
          <Form.Item
            key="jobs:partsqueue"
            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
            key="jobs:void"
            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
            key="owners:detail"
            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
            key="owners:list"
            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
            key="payments:enter"
            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
            key="payments:list"
            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
            key="phonebook:edit"
            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
            key="phonebook:view"
            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
                  key="production:board"
                  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
            key="production:list"
            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
            key="schedule:view"
            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
                  key="scoreboard:view"
                  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
                  key="shiftclock:view"
                  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
                  key="timetickets:edit"
                  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
                  key="timetickets:shiftedit"
                  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
                  key="timetickets:editcommitted"
                  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
                  key="ttapprovals:view"
                  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
                  key="ttapprovals:approve"
                  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
                  key="timetickets:enter"
                  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
                  key="timetickets:list"
                  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
            key="shop:config"
            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
            key="shop:dashboard"
            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
            key="shop:rbac"
            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
            key="shop:reportcenter"
            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
            key="shop:responsibilitycenter"
            label={t("bodyshop.fields.rbac.shop.responsibilitycenter")}
            rules={[
              {
                required: true
                //message: t("general.validation.required"),
              }
            ]}
            name={["md_rbac", "shop:responsibilitycenter"]}
          >
            <InputNumber />
          </Form.Item>,
          <Form.Item
            key="shop:vendors"
            label={t("bodyshop.fields.rbac.shop.vendors")}
            rules={[
              {
                required: true
                //message: t("general.validation.required"),
              }
            ]}
            name={["md_rbac", "shop:vendors"]}
          >
            <InputNumber />
          </Form.Item>,
          ...(HasFeatureAccess({ featureName: "media", bodyshop })
            ? [
                <Form.Item
                  key="temporarydocs:view"
                  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
            key="users:editaccess"
            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
                  key="inventory:list"
                  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
                  key="inventory:delete"
                  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>
  );
}
