import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports, L as Link } from "./vendor-react-DYNCg6N5.js";
import { S as Search } from "./index-CcqTjOWY.js";
import { H as HEADER_HEIGHT, bi as useDeleteQuotaRelationMutation, b as useActions, c as useAppSelector, t as extractErrorCode, v as generateErrorMessage, O as themeColors, V as PanelsEnum, bj as canEditRole, bk as EditProfileIcon, bl as useGetDefaultQuotaRelationFiltersQuery, I as IFiltersEnumType, N as getFilterAttributeByKey, bm as listSizes, bn as useGetQuotasRelationsQuery, y as SearchIcon, bo as useGetUsersActionsFilterQuery } from "./index-DfebxkL9.js";
import { c as createStyles, s as showNotification, a5 as openContextModal, b as Box, h as ActionIcon, G as Group, M as Menu, O as Badge, U as UnstyledButton, V as LoadingOverlay, F as Flex, B as Button, T as Text, K as Divider, a8 as Pagination } from "./vendor-mantine-h0WlM2Mj.js";
import { v as zKe, b as gq, W as Ws, X as XMe } from "./vendor-icons-xWhXK_Ui.js";
import { T as TableHeader, P as PaginatedTable } from "./index-DXVFB9sp.js";
import { E as EntityTypeDictionary } from "./utiils-DzEu0_6s.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { a as formatDataSizeUnits } from "./format-CMT-x-V3.js";
import { N as NoDataText } from "./index-C_Fw_IUU.js";
import { S as SearchFilter } from "./index-C6QQOvbB.js";
import { u as useDebounce } from "./useDebounce-DTubzIUC.js";
import { A as AssignQuotaModal } from "./index-DeLPTh4Q.js";
import "./styles-BC5VOxAU.js";
import "./index-Zaude47i.js";
import "./index-lR9_AURi.js";
import "./index.es-BTZFX8B-.js";
import "./index-DqcA8P_y.js";
import "./styles-3NoIlzov.js";
import "./index-BvQfhnV_.js";
import "./styles-C9HVNQJ0.js";
import "./index-BoQKW1g7.js";
import "./errorIcon-PZO0f1IY.js";
import "./validation-Ds00Zghx.js";
import "./validate-CA6bwF22.js";
import "./types-espwwxTQ.js";
const useStyles$1 = createStyles((theme, _, utils) => ({
  paginateWrapper: {
    overflow: "auto"
  },
  wrapper: {
    flexGrow: 1,
    overflow: "auto",
    marginBottom: theme.spacing.md,
    [utils.smallerThan("lg")]: {
      paddingRight: theme.spacing.md
    },
    [utils.smallerThan("md")]: {
      padding: `0 ${theme.spacing.md}`
    }
  },
  container: {
    position: "relative",
    overflowX: "hidden"
  },
  searchContainer: {
    backgroundColor: theme.colors.backgroundGray[0],
    ".mantine-Input-wrapper": {
      // width: '100%'
    }
  },
  search: {
    "& input": {
      backgroundColor: theme.colors.backgroundGray[6],
      paddingLeft: "56px",
      height: "45px",
      fontSize: "16px"
    },
    "& .mantine-Input-section": {
      marginLeft: "15px"
    }
  },
  contentContainer: {
    backgroundColor: theme.white,
    borderRadius: "8px"
  },
  divider: {
    borderColor: theme.colors.backgroundGray[2]
  },
  listWrapper: {
    display: "flex",
    justifyContent: "space-between",
    width: "100%",
    overflowX: "auto",
    msOverflowStyle: "none",
    scrollbarWidth: "none",
    backgroundColor: "white",
    [utils.smallerThan("md")]: {
      flexWrap: "wrap"
    }
  },
  paginateControl: {
    border: "none",
    borderRadius: "0px",
    padding: "23px 28px",
    [utils.smallerThan("md")]: {
      padding: "10px 15px"
    },
    "&[data-active]": {
      borderBottom: "2px solid #101828",
      backgroundColor: theme.white,
      color: theme.black,
      "&:hover": {
        backgroundColor: theme.white
      }
    },
    "&[data-active]:not([data-disabled]):hover": {
      backgroundColor: theme.white
    }
  },
  paginateRoot: {
    backgroundColor: theme.white,
    justifyContent: "center",
    width: "100%",
    flexWrap: "nowrap",
    padding: "23px 28px",
    "& .mantine-Group-root": {
      justifyContent: "center"
    }
  },
  simpleNavbar: {
    backgroundColor: theme.colors.backgroundGray[0],
    position: "fixed",
    [utils.smallerThan("md")]: {
      alignItems: "flex-start",
      marginRight: theme.spacing.xs,
      marginLeft: theme.spacing.xs,
      backgroundColor: "white",
      padding: "0"
    }
  },
  headerMenu: {
    flexGrow: 1,
    overflow: "auto",
    [utils.smallerThan("md")]: {
      maxWidth: "850px",
      backgroundColor: "white",
      borderRadius: "8px",
      margin: "20px 15px"
    },
    [utils.largerThan("md")]: {
      marginLeft: 300
    }
  },
  headerMenuBurger: {
    padding: "20px 0 0 10px",
    button: {
      div: {
        height: "2px"
      }
    },
    [utils.largerThan("md")]: {
      display: "none"
    }
  },
  section: {
    height: `calc(100vh - ${HEADER_HEIGHT}px)`
  },
  link: {
    color: theme.colors.blue[5],
    textDecoration: "none",
    "&:hover": {
      textDecoration: "underline"
    }
  }
}));
const useDeleteQuotas = () => {
  const $ = compilerRuntimeExports.c(15);
  const {
    t
  } = useTranslation();
  const [deleteQuota, t0] = useDeleteQuotaRelationMutation();
  const {
    isSuccess
  } = t0;
  const {
    setSelectedPanel
  } = useActions();
  const {
    quotasFilters
  } = useAppSelector(_temp$2);
  const {
    setQuotasFilters
  } = useActions();
  let t1;
  if ($[0] !== deleteQuota) {
    t1 = async (selection) => {
      try {
        const res = await deleteQuota(selection);
        if ("error" in res) {
          const codeError = extractErrorCode(res.error);
          showNotification({
            title: generateErrorMessage(codeError),
            message: "",
            autoClose: true,
            color: "red"
          });
        }
      } catch (t22) {
      }
    };
    $[0] = deleteQuota;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const handleConfirm = t1;
  let t2;
  if ($[2] !== handleConfirm || $[3] !== t) {
    t2 = (selection_0) => {
      openContextModal({
        modal: "context",
        centered: true,
        innerProps: {
          title: t("warning"),
          modalBody: /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { mb: 24, children: t("quota.deleteWarningText") }),
          confirmProps: {
            color: "brandRed.1",
            sx: {
              backgroundColor: themeColors.brandRed[1],
              color: "white",
              width: "49%"
            }
          },
          cancelProps: {
            sx: {
              backgroundColor: themeColors.brandGray[1],
              color: "black",
              width: "49%",
              "& .mantine-Button-label": {
                color: "black"
              }
            }
          },
          labels: {
            confirm: t("continue"),
            cancel: t("cancel")
          },
          onConfirm: () => handleConfirm(selection_0)
        }
      });
    };
    $[2] = handleConfirm;
    $[3] = t;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  const openDeleteQuotas = t2;
  let t3;
  if ($[5] !== isSuccess || $[6] !== quotasFilters || $[7] !== setQuotasFilters || $[8] !== setSelectedPanel || $[9] !== t) {
    t3 = () => {
      if (isSuccess) {
        setQuotasFilters({
          ...quotasFilters,
          Offset: 0
        });
        showNotification({
          title: t("quota.deleteSuccess"),
          message: "",
          autoClose: true,
          color: "green"
        });
        setSelectedPanel(PanelsEnum.generalInformation);
      }
    };
    $[5] = isSuccess;
    $[6] = quotasFilters;
    $[7] = setQuotasFilters;
    $[8] = setSelectedPanel;
    $[9] = t;
    $[10] = t3;
  } else {
    t3 = $[10];
  }
  let t4;
  if ($[11] !== isSuccess) {
    t4 = [isSuccess];
    $[11] = isSuccess;
    $[12] = t4;
  } else {
    t4 = $[12];
  }
  reactExports.useEffect(t3, t4);
  let t5;
  if ($[13] !== openDeleteQuotas) {
    t5 = {
      openDeleteQuotas
    };
    $[13] = openDeleteQuotas;
    $[14] = t5;
  } else {
    t5 = $[14];
  }
  return t5;
};
function _temp$2(state) {
  return state.quotas;
}
const Action = (t0) => {
  const $ = compilerRuntimeExports.c(17);
  const {
    item
  } = t0;
  const {
    selectedRolesId
  } = useAppSelector(_temp$1);
  const {
    openDeleteQuotas
  } = useDeleteQuotas();
  const {
    setSelectedQuotaRelation
  } = useActions();
  let t1;
  if ($[0] !== (item == null ? void 0 : item.Entity.Id) || $[1] !== (item == null ? void 0 : item.Entity.Type) || $[2] !== openDeleteQuotas) {
    t1 = (event) => {
      event.preventDefault();
      event.stopPropagation();
      openDeleteQuotas({
        entityId: item == null ? void 0 : item.Entity.Id,
        entityType: item == null ? void 0 : item.Entity.Type
      });
    };
    $[0] = item == null ? void 0 : item.Entity.Id;
    $[1] = item == null ? void 0 : item.Entity.Type;
    $[2] = openDeleteQuotas;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  const handleClickModal = t1;
  let t2;
  if ($[4] !== item || $[5] !== setSelectedQuotaRelation) {
    t2 = () => {
      setSelectedQuotaRelation(item);
    };
    $[4] = item;
    $[5] = setSelectedQuotaRelation;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  const editRole = t2;
  let t3;
  if ($[7] !== editRole || $[8] !== (item == null ? void 0 : item.Type) || $[9] !== selectedRolesId) {
    t3 = !selectedRolesId && (canEditRole(item == null ? void 0 : item.Type) ? /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { "data-cy": "editRole", className: "action-icon", "data-action": "action", onClick: editRole, children: /* @__PURE__ */ jsxRuntimeExports.jsx(EditProfileIcon, { size: 24 }) }) : null);
    $[7] = editRole;
    $[8] = item == null ? void 0 : item.Type;
    $[9] = selectedRolesId;
    $[10] = t3;
  } else {
    t3 = $[10];
  }
  let t4;
  if ($[11] !== handleClickModal || $[12] !== (item == null ? void 0 : item.Type)) {
    t4 = canEditRole(item == null ? void 0 : item.Type) ? /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { "data-cy": "roleActions", className: "action-icon", onClick: handleClickModal, "data-action": "action", children: /* @__PURE__ */ jsxRuntimeExports.jsx(zKe, { size: "1.5rem", color: "#667085", stroke: 1.5, style: {
      pointerEvents: "none"
    } }) }) : null;
    $[11] = handleClickModal;
    $[12] = item == null ? void 0 : item.Type;
    $[13] = t4;
  } else {
    t4 = $[13];
  }
  let t5;
  if ($[14] !== t3 || $[15] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { gap: 4, justify: "flex-end", wrap: "nowrap", children: [
      t3,
      t4
    ] });
    $[14] = t3;
    $[15] = t4;
    $[16] = t5;
  } else {
    t5 = $[16];
  }
  return t5;
};
function _temp$1(state) {
  return state.roles;
}
const useGetColumns = () => {
  const $ = compilerRuntimeExports.c(35);
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles$1();
  let t0;
  if ($[0] !== t) {
    t0 = t("filials.diskSpace.quotasSetup.table.quota");
    $[0] = t;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  let t1;
  if ($[2] !== t0) {
    t1 = {
      width: "200px",
      dataIndex: "Quota.Name",
      title: t0,
      hasSort: true,
      sortField: "QuotaName",
      render: _temp
    };
    $[2] = t0;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  let t2;
  if ($[4] !== t) {
    t2 = t("filials.diskSpace.quotasSetup.table.size");
    $[4] = t;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  let t3;
  if ($[6] !== t2) {
    t3 = {
      width: "120px",
      dataIndex: "Size",
      title: t2,
      hasSort: true,
      sortField: "QuotaSize",
      render: _temp2
    };
    $[6] = t2;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  let t4;
  if ($[8] !== t) {
    t4 = t("filials.diskSpace.quotasSetup.table.objectType");
    $[8] = t;
    $[9] = t4;
  } else {
    t4 = $[9];
  }
  let t5;
  if ($[10] !== t4) {
    t5 = {
      width: "180px",
      dataIndex: "ObjectType",
      title: t4,
      hasSort: true,
      sortField: "EntityType",
      render: _temp3
    };
    $[10] = t4;
    $[11] = t5;
  } else {
    t5 = $[11];
  }
  let t6;
  if ($[12] !== t) {
    t6 = t("filials.diskSpace.quotasSetup.table.object");
    $[12] = t;
    $[13] = t6;
  } else {
    t6 = $[13];
  }
  let t7;
  if ($[14] !== classes) {
    t7 = (item_2) => {
      var _a;
      return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { to: item_2.Url, target: "_blank", className: classes.link, children: (_a = item_2.Entity) == null ? void 0 : _a.Name });
    };
    $[14] = classes;
    $[15] = t7;
  } else {
    t7 = $[15];
  }
  let t8;
  if ($[16] !== t6 || $[17] !== t7) {
    t8 = {
      width: "200px",
      dataIndex: "Object",
      title: t6,
      hasSort: true,
      sortField: "Entity",
      render: t7
    };
    $[16] = t6;
    $[17] = t7;
    $[18] = t8;
  } else {
    t8 = $[18];
  }
  let t9;
  if ($[19] !== t) {
    t9 = t("filials.diskSpace.quotasSetup.table.owner");
    $[19] = t;
    $[20] = t9;
  } else {
    t9 = $[20];
  }
  let t10;
  if ($[21] !== classes) {
    t10 = (item_3) => {
      var _a;
      return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { to: item_3.Url, target: "_blank", className: classes.link, children: (_a = item_3.Owner) == null ? void 0 : _a.Name });
    };
    $[21] = classes;
    $[22] = t10;
  } else {
    t10 = $[22];
  }
  let t11;
  if ($[23] !== t10 || $[24] !== t9) {
    t11 = {
      width: "210px",
      dataIndex: "Owner",
      title: t9,
      hasSort: true,
      sortField: "Owner",
      render: t10
    };
    $[23] = t10;
    $[24] = t9;
    $[25] = t11;
  } else {
    t11 = $[25];
  }
  let t12;
  if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
    t12 = {
      width: "80px",
      dataIndex: "Action",
      title: "",
      hideColumn: false,
      render: _temp4
    };
    $[26] = t12;
  } else {
    t12 = $[26];
  }
  let t13;
  if ($[27] !== t1 || $[28] !== t11 || $[29] !== t3 || $[30] !== t5 || $[31] !== t8) {
    t13 = [t1, t3, t5, t8, t11, t12];
    $[27] = t1;
    $[28] = t11;
    $[29] = t3;
    $[30] = t5;
    $[31] = t8;
    $[32] = t13;
  } else {
    t13 = $[32];
  }
  const columnsData = t13;
  const [columns, setColumns] = reactExports.useState(columnsData);
  let t14;
  if ($[33] !== columns) {
    t14 = {
      columns,
      setColumns
    };
    $[33] = columns;
    $[34] = t14;
  } else {
    t14 = $[34];
  }
  return t14;
};
function _temp(item) {
  var _a;
  return (_a = item.Quota) == null ? void 0 : _a.Name;
}
function _temp2(item_0) {
  return formatDataSizeUnits(item_0.QuotaSize);
}
function _temp3(item_1) {
  var _a;
  return (_a = EntityTypeDictionary[item_1.Entity.Type]) == null ? void 0 : _a.label;
}
function _temp4(item_4) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Action, { item: item_4 });
}
const transformFilters = (data, t) => {
  return data == null ? void 0 : data.map((item) => {
    var _a;
    return {
      ...item,
      label: item.Type === IFiltersEnumType.QuotaFilter ? t("filials.diskSpace.quotasSetup.filters.quota") : item.Type === IFiltersEnumType.UserFilter ? t("filials.diskSpace.quotasSetup.filters.owner") : item.Type === IFiltersEnumType.ObjectRoleFilter ? t("filials.diskSpace.quotasSetup.filters.objectType") : t("filters.title"),
      Items: (_a = item.Items) == null ? void 0 : _a.map((filterItem) => ({
        ...filterItem,
        Count: void 0,
        checked: false
      })),
      hideSearch: false
    };
  }).sort((a, b) => a.Type - b.Type);
};
const useGetFilters = (t0) => {
  const $ = compilerRuntimeExports.c(11);
  const {
    customerId
  } = t0;
  const {
    t
  } = useTranslation();
  let t1;
  if ($[0] !== customerId) {
    t1 = {
      count: 20,
      customerId
    };
    $[0] = customerId;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const t2 = !customerId;
  let t3;
  if ($[2] !== t2) {
    t3 = {
      skip: t2
    };
    $[2] = t2;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  const {
    data,
    isFetching,
    isSuccess
  } = useGetDefaultQuotaRelationFiltersQuery(t1, t3);
  let t4;
  if ($[4] !== data || $[5] !== isSuccess || $[6] !== t) {
    t4 = isSuccess ? transformFilters(data || [], t) : [];
    $[4] = data;
    $[5] = isSuccess;
    $[6] = t;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  const filters = t4;
  let t5;
  if ($[8] !== filters || $[9] !== isFetching) {
    t5 = {
      filters,
      isFetching
    };
    $[8] = filters;
    $[9] = isFetching;
    $[10] = t5;
  } else {
    t5 = $[10];
  }
  return t5;
};
const useStyles = createStyles((theme) => ({
  filtersListWrapper: {
    padding: `${theme.spacing.sm} ${theme.spacing.md} ${theme.spacing.sm} 0`,
    display: "flex",
    justifyContent: "flex-start",
    backgroundColor: "white",
    gap: 20
  },
  filterHeader: {
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: "#F2F4F7",
    padding: "4px, 20px, 4px, 20px",
    height: "32px",
    gap: 0,
    borderRadius: "54px",
    fontWeight: 400,
    color: "var(--mantine-colors-black)"
  },
  menuButton: {
    display: "flex",
    alignItems: "center",
    justifyContent: "center"
  },
  badgeContainer: {
    flexDirection: "row",
    display: "flex",
    justifyContent: "center",
    alignItems: "center",
    marginLeft: "12px"
  },
  scroll: {
    overflow: "scroll",
    height: "100%",
    width: "100%",
    position: "absolute",
    top: "0",
    left: "0",
    visibility: "hidden"
  },
  checkbox: {
    display: "flex",
    marginRight: theme.spacing.md,
    "& input": {
      cursor: "pointer"
    }
  },
  badge: {
    textTransform: "none",
    fontSize: "12px",
    fontWeight: 400,
    lineHeight: "18px",
    marginRight: theme.spacing.xs,
    borderRadius: "16px",
    padding: `0px 6px`
  },
  leftSection: {
    display: "flex",
    alignItems: "flex-start"
  },
  rightSection: {
    display: "flex",
    alignItems: "flex-end"
  },
  menu: {
    height: "180px",
    marginBottom: "10px"
  },
  dropdownContainer: {
    padding: theme.spacing.sm
  }
}));
const FilterList = (t0) => {
  const $ = compilerRuntimeExports.c(19);
  const {
    activeFilters,
    handleFilterReset,
    filtersMenuList,
    handleFilterChange,
    onLoadData
  } = t0;
  const {
    classes
  } = useStyles();
  let t1;
  if ($[0] !== filtersMenuList) {
    t1 = [...filtersMenuList.slice(0, 4)];
    $[0] = filtersMenuList;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const slicedFilters = t1;
  if (!filtersMenuList) {
    return null;
  }
  let t2;
  if ($[2] !== handleFilterReset) {
    t2 = (e, type) => {
      e.stopPropagation();
      handleFilterReset(type);
    };
    $[2] = handleFilterReset;
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  const onFilterResetClick = t2;
  const t3 = classes.filtersListWrapper;
  let t4;
  if ($[4] !== activeFilters || $[5] !== classes.badge || $[6] !== classes.badgeContainer || $[7] !== classes.dropdownContainer || $[8] !== classes.filterHeader || $[9] !== classes.menuButton || $[10] !== handleFilterChange || $[11] !== handleFilterReset || $[12] !== onFilterResetClick || $[13] !== onLoadData || $[14] !== slicedFilters) {
    t4 = slicedFilters.map((filterMenu, index) => {
      const activeIds = activeFilters[filterMenu == null ? void 0 : filterMenu.Type];
      return /* @__PURE__ */ jsxRuntimeExports.jsxs(Menu, { width: "auto", zIndex: 400, position: "bottom-start", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Menu.Target, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Badge, { variant: "transparent", color: "gray", className: classes.filterHeader, rightSection: (activeIds == null ? void 0 : activeIds.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.badgeContainer, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Badge, { className: classes.badge, variant: "filled", children: activeIds == null ? void 0 : activeIds.length }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { size: 24, onClick: (e_0) => onFilterResetClick(e_0, filterMenu.Type), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Ws, { size: 16, color: themeColors.brandGray[0] }) })
        ] }) : null, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(UnstyledButton, { className: classes.menuButton, "data-cy": getFilterAttributeByKey(filterMenu.Type), children: [
          (filterMenu == null ? void 0 : filterMenu.label) || "Статус",
          " ",
          /* @__PURE__ */ jsxRuntimeExports.jsx(gq, { size: 18 })
        ] }) }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Menu.Dropdown, { className: classes.dropdownContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchFilter, { handleFilterReset, activeIds, filterType: filterMenu == null ? void 0 : filterMenu.Type, label: filterMenu == null ? void 0 : filterMenu.label, list: filterMenu == null ? void 0 : filterMenu.Items, hideCollapse: true, handleFilterChange, handleLoadData: onLoadData, hideSearch: filterMenu == null ? void 0 : filterMenu.hideSearch }) })
      ] }, (filterMenu == null ? void 0 : filterMenu.label) + index);
    });
    $[4] = activeFilters;
    $[5] = classes.badge;
    $[6] = classes.badgeContainer;
    $[7] = classes.dropdownContainer;
    $[8] = classes.filterHeader;
    $[9] = classes.menuButton;
    $[10] = handleFilterChange;
    $[11] = handleFilterReset;
    $[12] = onFilterResetClick;
    $[13] = onLoadData;
    $[14] = slicedFilters;
    $[15] = t4;
  } else {
    t4 = $[15];
  }
  let t5;
  if ($[16] !== classes.filtersListWrapper || $[17] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: t3, children: t4 });
    $[16] = classes.filtersListWrapper;
    $[17] = t4;
    $[18] = t5;
  } else {
    t5 = $[18];
  }
  return t5;
};
const convertToFilterConditions = (activeFilters) => {
  const filterObjects = [];
  for (const [key, value] of Object.entries(activeFilters)) {
    const filterObject = {
      Type: Number(key)
    };
    if (key === "11" || key === "12" || key === "13") {
      const [from, to] = value;
      filterObject.DateRange = {
        From: from == null ? void 0 : from.toISOString(),
        To: to.toISOString()
      };
    } else if (key === "15") {
      const [from, to] = value;
      filterObject.NumRange = {
        From: from,
        To: to
      };
    } else {
      filterObject.NumValues = value;
    }
    filterObjects.push(filterObject);
  }
  return filterObjects;
};
const pageSizeOptions = listSizes.map((page) => ({
  value: page.toString(),
  label: page.toString()
}));
const SetupQuota = () => {
  var _a, _b;
  const {
    classes
  } = useStyles$1();
  const {
    t
  } = useTranslation();
  const {
    columns,
    setColumns
  } = useGetColumns();
  const [sort, setSort] = reactExports.useState(void 0);
  const handleSetSort = (sortParams) => {
    setSort(sortParams);
    const col = columns.find((c) => c.dataIndex === sortParams.SortField);
    const sortField = col == null ? void 0 : col.sortField;
    if (!sortField) return;
    setQuotaRelationFilters({
      ...filter,
      Offset: 0,
      SortBy: sortField,
      SortDirection: sortParams.SortOrder ? "desc" : "asc"
    });
    setActivePage(1);
  };
  const {
    setQuotaRelationFilters,
    setQuotaRelations
  } = useActions();
  const {
    filial
  } = useAppSelector((state) => state.filials);
  const {
    filters: filtersMenuList
  } = useGetFilters({
    customerId: filial == null ? void 0 : filial.Id
  });
  const [activeFilters, setActiveFilters] = reactExports.useState({});
  const {
    quotaRelationFilters: filter,
    totalQuotaRelations
  } = useAppSelector((state_0) => state_0.quotas);
  const handleFilterChange = ({
    Type,
    value
  }) => {
    const updatedData = {
      ...activeFilters
    };
    if (Array.isArray(value)) {
      updatedData[Type] = value;
    } else {
      if (typeof value === "number") {
        const array = updatedData[Type] || [];
        updatedData[Type] = array.includes(value) ? array.filter((val) => val !== value) : [...array, value];
      }
    }
    setQuotaRelationFilters({
      ...filter,
      FilterConditions: convertToFilterConditions(updatedData),
      Offset: 0
    });
    setActiveFilters(updatedData);
  };
  const resetActiveFilterByType = (type) => {
    setActiveFilters((prevNumbers) => {
      const updatedNumbers = {
        ...prevNumbers
      };
      delete updatedNumbers[type];
      setQuotaRelationFilters({
        ...filter,
        FilterConditions: convertToFilterConditions(updatedNumbers),
        Offset: 0
      });
      return updatedNumbers;
    });
  };
  const resetAllActiveFilters = () => {
    setActiveFilters({});
    setQuotaRelationFilters({
      ...filter,
      FilterConditions: [],
      Offset: 0,
      Query: ""
    });
  };
  const [search, setSearch] = reactExports.useState("");
  const debounced = useDebounce(search, 500);
  reactExports.useEffect(() => {
    setQuotaRelationFilters({
      ...filter,
      Query: debounced,
      Offset: 0
    });
  }, [debounced]);
  const [pageSize, setPageSize] = reactExports.useState(filter.Count || listSizes[0]);
  const [activePage, setActivePage] = reactExports.useState(1);
  const handleChangeActivePage = (value_0) => {
    setActivePage(value_0);
    setQuotaRelationFilters({
      ...filter,
      Offset: (value_0 >= 1 ? value_0 - 1 : 0) * pageSize
    });
  };
  const handleChangePageSize = (value_1) => {
    setPageSize(value_1);
    setQuotaRelationFilters({
      ...filter,
      Offset: 0,
      Count: value_1
    });
  };
  const {
    data,
    isLoading
  } = useGetQuotasRelationsQuery({
    CustomerId: filial == null ? void 0 : filial.Id,
    Count: pageSize,
    Offset: filter.Offset,
    Query: filter.Query,
    FilterConditions: filter.FilterConditions,
    SortBy: filter.SortBy,
    SortDirection: filter.SortDirection
  }, {
    skip: !filial
  });
  reactExports.useEffect(() => {
    if (data) {
      setQuotaRelations(data);
    }
  }, [data]);
  const {
    selectedQuotaRelation
  } = useAppSelector((state_1) => state_1.quotas);
  const {
    setSelectedQuotaRelation
  } = useActions();
  const [isAssignModalOpened, setIsAssignModalOpened] = reactExports.useState(false);
  reactExports.useEffect(() => {
    if (selectedQuotaRelation) {
      setIsAssignModalOpened(true);
    }
  }, [selectedQuotaRelation]);
  const handleAssignModalClose = () => {
    setSelectedQuotaRelation(null);
    setIsAssignModalOpened(false);
  };
  if (isLoading) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: true });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.wrapper, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { direction: "column", align: "stretch", className: classes.container, mb: "sm", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { gap: 22, className: classes.searchContainer, align: "center", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Search, { "data-cy": "auditSearch", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, {}), setSearch, className: classes.search, fullSize: true, value: search, placeholder: t("filials.diskSpace.quotasSetup.searchPlaceholder") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { leftSection: /* @__PURE__ */ jsxRuntimeExports.jsx(XMe, {}), h: 42, w: 290, onClick: () => {
        setIsAssignModalOpened(true);
      }, children: t("filials.diskSpace.quotasSetup.createAssignment") })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { direction: "column", align: "stretch", className: classes.container, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { direction: "column", className: classes.contentContainer, px: "md", py: "md", mt: "sm", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { c: "#101828", fw: "600", children: [
        t("filials.diskSpace.quotasSetup.sectionTitle"),
        " 2"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.listWrapper, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(FilterList, { filtersMenuList, activeFilters, handleFilterChange, handleFilterReset: resetActiveFilterByType, handleResetFilters: resetAllActiveFilters, onLoadData: useGetUsersActionsFilterQuery }),
        ((_a = data == null ? void 0 : data.Items) == null ? void 0 : _a.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx(
          TableHeader,
          {
            handleChangePageSize,
            pageSize,
            pageSizeOptions,
            isLoading,
            startOffset: filter.Offset + 1,
            endOffset: Math.min(filter.Offset + pageSize, data.TotalCount),
            totalCount: data.TotalCount,
            showButton: true,
            buttonComponent: /* @__PURE__ */ jsxRuntimeExports.jsx("div", {}),
            setColumnsData: setColumns,
            list: columns
          }
        ) : null
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Divider, { mb: "sm" }),
      ((_b = data == null ? void 0 : data.Items) == null ? void 0 : _b.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(PaginatedTable, { allDataLength: data == null ? void 0 : data.TotalCount, rowData: data == null ? void 0 : data.Items, columns, search, height: "100%", width: "100%", isLoading, sort, setSort: handleSetSort, layout: "fixed" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.paginateWrapper, children: totalQuotaRelations > pageSize && /* @__PURE__ */ jsxRuntimeExports.jsx(Pagination, { classNames: {
          root: classes.paginateRoot,
          control: classes.paginateControl
        }, value: activePage, onChange: handleChangeActivePage, total: Math.ceil(totalQuotaRelations / pageSize), withControls: false, withEdges: true, size: "sm" }) })
      ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { align: "center", justify: "center", h: "350px", children: /* @__PURE__ */ jsxRuntimeExports.jsx(NoDataText, {}) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: false }),
      " "
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(AssignQuotaModal, { opened: isAssignModalOpened, handleClose: handleAssignModalClose })
  ] });
};
export {
  SetupQuota as default
};
//# sourceMappingURL=index-wbXPwO45.js.map
