"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index_H1ljeG8 = require("./index--h1ljeG8-TLddt1Eo.js");
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const designSystem = require("@strapi/design-system");
const reactIntl = require("react-intl");
function _interopNamespace(e) {
  if (e && e.__esModule)
    return e;
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
function useReviewWorkflows(params = {}) {
  const { id = "", ...queryParams } = params;
  const { data, isLoading } = index_H1ljeG8.useGetWorkflowsQuery({
    id,
    populate: "stages",
    ...queryParams
  });
  const [createWorkflow] = index_H1ljeG8.useCreateWorkflowMutation();
  const [updateWorkflow] = index_H1ljeG8.useUpdateWorkflowMutation();
  const [deleteWorkflow] = index_H1ljeG8.useDeleteWorkflowMutation();
  const { workflows, meta } = data ?? {};
  return {
    // meta contains e.g. the total of all workflows. we can not use
    // the pagination object here, because the list is not paginated.
    meta,
    workflows,
    isLoading,
    createWorkflow,
    updateWorkflow,
    deleteWorkflow
  };
}
const AssigneeFilter = ({ name }) => {
  const [page, setPage] = React__namespace.useState(1);
  const { formatMessage } = reactIntl.useIntl();
  const { data, isLoading } = index_H1ljeG8.useAdminUsers({
    page
  });
  const users = data?.users || [];
  const field = index_H1ljeG8.useField(name);
  const handleChange = (value) => {
    setPage(1);
    field.onChange(name, value);
  };
  return /* @__PURE__ */ jsxRuntime.jsx(
    designSystem.Combobox,
    {
      value: field.value,
      "aria-label": formatMessage({
        id: "content-manager.components.Filters.usersSelect.label",
        defaultMessage: "Search and select an user to filter"
      }),
      onChange: handleChange,
      loading: isLoading,
      onLoadMore: () => setPage((prev) => prev + 1),
      children: users.map((user) => {
        return /* @__PURE__ */ jsxRuntime.jsx(designSystem.ComboboxOption, { value: user.id.toString(), children: index_H1ljeG8.getDisplayName(user, formatMessage) }, user.id);
      })
    }
  );
};
const StageFilter = (props) => {
  const { model } = index_H1ljeG8.useDoc();
  const { formatMessage } = reactIntl.useIntl();
  const { workflows, isLoading } = useReviewWorkflows({ filters: { contentTypes: model } });
  const field = index_H1ljeG8.useField(props.name);
  const [workflow] = workflows ?? [];
  return /* @__PURE__ */ jsxRuntime.jsx(
    designSystem.SingleSelect,
    {
      "aria-label": formatMessage({
        id: "content-manager.components.Filters.reviewWorkflows.label",
        defaultMessage: "Search and select an workflow stage to filter"
      }),
      value: field.value,
      onChange: (value) => {
        field.onChange(props.name, value);
      },
      loading: isLoading,
      customizeContent: () => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { as: "span", justifyContent: "space-between", alignItems: "center", width: "100%", children: [
        /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", ellipsis: true, children: field.value }),
        isLoading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, style: { display: "flex" } }) : null
      ] }),
      children: (workflow?.stages ?? []).map(({ id, color, name }) => {
        const { themeColorName } = index_H1ljeG8.getStageColorByHex(color) ?? {};
        return /* @__PURE__ */ jsxRuntime.jsx(
          designSystem.SingleSelectOption,
          {
            startIcon: /* @__PURE__ */ jsxRuntime.jsx(
              designSystem.Flex,
              {
                height: 2,
                background: color,
                borderColor: themeColorName === "neutral0" ? "neutral150" : void 0,
                hasRadius: true,
                shrink: 0,
                width: 2
              }
            ),
            value: name,
            children: name
          },
          id
        );
      })
    }
  );
};
const REVIEW_WORKFLOW_COLUMNS_EE = [
  {
    name: index_H1ljeG8.STAGE_ATTRIBUTE_NAME,
    attribute: {
      type: "relation",
      relation: "oneToMany",
      target: "admin::review-workflow-stage"
    },
    label: {
      id: index_H1ljeG8.getTranslation(`containers.list.table-headers.reviewWorkflows.stage`),
      defaultMessage: "Review stage"
    },
    searchable: false,
    sortable: true,
    mainField: {
      name: "name",
      type: "string"
    }
  },
  {
    name: index_H1ljeG8.ASSIGNEE_ATTRIBUTE_NAME,
    attribute: {
      type: "relation",
      target: "admin::user",
      relation: "oneToMany"
    },
    label: {
      id: index_H1ljeG8.getTranslation(`containers.list.table-headers.reviewWorkflows.assignee`),
      defaultMessage: "Assignee"
    },
    searchable: false,
    sortable: true,
    mainField: {
      name: "firstname",
      type: "string"
    }
  }
];
const REVIEW_WORKFLOW_FILTERS = [
  {
    mainField: {
      name: "name",
      type: "string"
    },
    input: StageFilter,
    label: {
      id: index_H1ljeG8.getTranslation(`containers.list.table-headers.reviewWorkflows.stage`),
      defaultMessage: "Review stage"
    },
    name: "strapi_stage",
    type: "relation"
  },
  {
    type: "relation",
    mainField: {
      name: "id",
      type: "integer"
    },
    input: AssigneeFilter,
    operators: [
      {
        label: {
          id: "components.FilterOptions.FILTER_TYPES.$eq",
          defaultMessage: "is"
        },
        value: "$eq"
      },
      {
        label: {
          id: "components.FilterOptions.FILTER_TYPES.$ne",
          defaultMessage: "is not"
        },
        value: "$ne"
      }
    ],
    label: {
      id: index_H1ljeG8.getTranslation(`containers.list.table-headers.reviewWorkflows.assignee.label`),
      defaultMessage: "Assignee"
    },
    name: "strapi_assignee"
  }
];
exports.REVIEW_WORKFLOW_COLUMNS_EE = REVIEW_WORKFLOW_COLUMNS_EE;
exports.REVIEW_WORKFLOW_FILTERS = REVIEW_WORKFLOW_FILTERS;
//# sourceMappingURL=constants-VMWcn5Dg-AljxaBIG.js.map
