import { aj as useGetWorkflowsQuery, ak as useCreateWorkflowMutation, al as useUpdateWorkflowMutation, am as useDeleteWorkflowMutation, an as STAGE_ATTRIBUTE_NAME, g as getTranslation, ao as ASSIGNEE_ATTRIBUTE_NAME, a5 as useAdminUsers, a as useField, a0 as getDisplayName, d as useDoc, ap as getStageColorByHex } from "./index--h1ljeG8-PYl4iNtw.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Combobox, ComboboxOption, SingleSelect, Flex, Typography, Loader, SingleSelectOption } from "@strapi/design-system";
import { useIntl } from "react-intl";
function useReviewWorkflows(params = {}) {
  const { id = "", ...queryParams } = params;
  const { data, isLoading } = useGetWorkflowsQuery({
    id,
    populate: "stages",
    ...queryParams
  });
  const [createWorkflow] = useCreateWorkflowMutation();
  const [updateWorkflow] = useUpdateWorkflowMutation();
  const [deleteWorkflow] = 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.useState(1);
  const { formatMessage } = useIntl();
  const { data, isLoading } = useAdminUsers({
    page
  });
  const users = data?.users || [];
  const field = useField(name);
  const handleChange = (value) => {
    setPage(1);
    field.onChange(name, value);
  };
  return /* @__PURE__ */ jsx(
    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__ */ jsx(ComboboxOption, { value: user.id.toString(), children: getDisplayName(user, formatMessage) }, user.id);
      })
    }
  );
};
const StageFilter = (props) => {
  const { model } = useDoc();
  const { formatMessage } = useIntl();
  const { workflows, isLoading } = useReviewWorkflows({ filters: { contentTypes: model } });
  const field = useField(props.name);
  const [workflow] = workflows ?? [];
  return /* @__PURE__ */ jsx(
    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__ */ jsxs(Flex, { as: "span", justifyContent: "space-between", alignItems: "center", width: "100%", children: [
        /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", ellipsis: true, children: field.value }),
        isLoading ? /* @__PURE__ */ jsx(Loader, { small: true, style: { display: "flex" } }) : null
      ] }),
      children: (workflow?.stages ?? []).map(({ id, color, name }) => {
        const { themeColorName } = getStageColorByHex(color) ?? {};
        return /* @__PURE__ */ jsx(
          SingleSelectOption,
          {
            startIcon: /* @__PURE__ */ jsx(
              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: STAGE_ATTRIBUTE_NAME,
    attribute: {
      type: "relation",
      relation: "oneToMany",
      target: "admin::review-workflow-stage"
    },
    label: {
      id: getTranslation(`containers.list.table-headers.reviewWorkflows.stage`),
      defaultMessage: "Review stage"
    },
    searchable: false,
    sortable: true,
    mainField: {
      name: "name",
      type: "string"
    }
  },
  {
    name: ASSIGNEE_ATTRIBUTE_NAME,
    attribute: {
      type: "relation",
      target: "admin::user",
      relation: "oneToMany"
    },
    label: {
      id: 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: 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: getTranslation(`containers.list.table-headers.reviewWorkflows.assignee.label`),
      defaultMessage: "Assignee"
    },
    name: "strapi_assignee"
  }
];
export {
  REVIEW_WORKFLOW_COLUMNS_EE,
  REVIEW_WORKFLOW_FILTERS
};
//# sourceMappingURL=constants-VMWcn5Dg-z8ZNCCYd.mjs.map
