import { E as compilerRuntimeExports, j as jsxRuntimeExports, r as reactExports, T as useNavigate } from "./vendor-react-DYNCg6N5.js";
import { c as useAppSelector, b8 as useUpdateFilialQuotaMutation, t as extractErrorCode, v as generateErrorMessage, b as useActions, b9 as useGetFilialQuotaQuery, i as isSaaS, ba as useUpdateFilialSettingsMutation, aT as SettingsEnum, bb as useDeleteQuotaMutation, O as themeColors, bc as useCreateQuotaMutation, bd as useUpdateQuotaMutation, I as IFiltersEnumType, be as useGetQuotasQuery, R as ROUTES, bf as useSetQuotaByRoleMutation, m as universalNotification, a6 as clearApiCacheByTags, ae as usersApi, bg as QuotaRulesEnum, bh as isSuperAdmin, E as ErrorBoundary } from "./index-DfebxkL9.js";
import { D as DriveInfoPanelsEnum } from "./index-Rv8Lmn4U.js";
import { a as Th, T as Tr } from "./index-Zaude47i.js";
import { $ as Table, T as Text, W as useMediaQuery, n as useDisclosure, h as ActionIcon, b as Box, F as Flex, z as useForm, a0 as SimpleGrid, ad as NumberInput, B as Button, U as UnstyledButton, s as showNotification, V as LoadingOverlay, a4 as Select, a6 as notifications, a5 as openContextModal, k as Tooltip, g as Loader, ae as Input, d as Checkbox, R as Radio } from "./vendor-mantine-h0WlM2Mj.js";
import { a as formatDataSizeUnits, c as convertByteToGb, b as convertGbToByte } from "./format-CMT-x-V3.js";
import { T as CX, U as xte, J as IconChevronDown, V as IconAxisY, X as XMe } from "./vendor-icons-xWhXK_Ui.js";
import { a as PopoverMenu } from "./index-leRPH4yM.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { M as Modal } from "./index-DqcA8P_y.js";
import { T as TextFieldInput } from "./index-BvQfhnV_.js";
import { g as getValidateErrors } from "./validation-Ds00Zghx.js";
import { u as useStyles } from "./styles-rKP3r-bS.js";
import { o as objectType, n as numberType, s as stringType } from "./types-espwwxTQ.js";
import { s as storageConfigurationApiArea } from "./index-BVQ-Y7LP.js";
import { I as InfiniteScroll } from "./index.es-BTZFX8B-.js";
import { A as AddButton } from "./index-72JBTuLT.js";
import { A as AssignQuotaModal } from "./index-DeLPTh4Q.js";
import { S as SelectGroupSimpleModal } from "./index-BWhdniX1.js";
import { S as SelectQuotas } from "./index-BoQKW1g7.js";
import { B as Badges } from "./index-woYEqWvh.js";
import { u as useSaveSettings } from "./useSaveSettings-GkZlPEM1.js";
import "./index-D4BAIihc.js";
import "./useCopyToClipboard-C-S2RacD.js";
import "./index-C-CFogWu.js";
import "./useTerminateSessions-Cb3ukMTY.js";
import "./index-DMTgSMwy.js";
import "./index-DFEP7Sv_.js";
import "./index-CcqTjOWY.js";
import "./useDebounce-DTubzIUC.js";
import "./index-3c9En-DB.js";
import "./index-C_Fw_IUU.js";
import "./index-Ds4Bnwmy.js";
import "./styles-3NoIlzov.js";
import "./date-bOIw2uwV.js";
import "./styles-C9HVNQJ0.js";
import "./validate-CA6bwF22.js";
import "./utiils-DzEu0_6s.js";
import "./errorIcon-PZO0f1IY.js";
const TableHeadList = (t0) => {
  const $ = compilerRuntimeExports.c(11);
  const {
    columns,
    sort,
    onSort
  } = t0;
  let t1;
  if ($[0] !== columns || $[1] !== onSort || $[2] !== (sort == null ? void 0 : sort.SortField) || $[3] !== (sort == null ? void 0 : sort.SortOrder)) {
    let t22;
    if ($[5] !== onSort || $[6] !== (sort == null ? void 0 : sort.SortField) || $[7] !== (sort == null ? void 0 : sort.SortOrder)) {
      t22 = (t3) => {
        const {
          dataIndex,
          title,
          width,
          hasSort
        } = t3;
        if (hasSort && onSort) {
          return /* @__PURE__ */ jsxRuntimeExports.jsx(Th, { width, sorted: (sort == null ? void 0 : sort.SortField) === dataIndex, reversed: !!(sort == null ? void 0 : sort.SortOrder), onSort: () => onSort(String(dataIndex)), hideSort: false, children: title }, dataIndex + title);
        }
        return /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { style: {
          width,
          minWidth: width
        }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", c: "gray.6", children: title }) }, dataIndex + title);
      };
      $[5] = onSort;
      $[6] = sort == null ? void 0 : sort.SortField;
      $[7] = sort == null ? void 0 : sort.SortOrder;
      $[8] = t22;
    } else {
      t22 = $[8];
    }
    t1 = columns.map(t22);
    $[0] = columns;
    $[1] = onSort;
    $[2] = sort == null ? void 0 : sort.SortField;
    $[3] = sort == null ? void 0 : sort.SortOrder;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  let t2;
  if ($[9] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Tr, { children: t1 });
    $[9] = t1;
    $[10] = t2;
  } else {
    t2 = $[10];
  }
  return t2;
};
const TableRowList = (t0) => {
  const $ = compilerRuntimeExports.c(7);
  const {
    columns,
    rows
  } = t0;
  let t1;
  if ($[0] !== columns || $[1] !== rows) {
    let t22;
    if ($[3] !== columns) {
      t22 = (row, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(Tr, { columns, row }, `${(row == null ? void 0 : row.Id) ? row == null ? void 0 : row.Id : row == null ? void 0 : row.CustomerId}${index}`);
      $[3] = columns;
      $[4] = t22;
    } else {
      t22 = $[4];
    }
    t1 = rows.map(t22);
    $[0] = columns;
    $[1] = rows;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[5] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: t1 });
    $[5] = t1;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  return t2;
};
var ActionQuotaMenuEnum$1 = /* @__PURE__ */ ((ActionQuotaMenuEnum2) => {
  ActionQuotaMenuEnum2["edit"] = "edit";
  ActionQuotaMenuEnum2["delete"] = "delete";
  ActionQuotaMenuEnum2["changeTariff"] = "chaneTariff";
  return ActionQuotaMenuEnum2;
})(ActionQuotaMenuEnum$1 || {});
const FilialQuotaAction = ({
  quota,
  openFilialQuotaModal,
  isSaaS: isSaaS2
}) => {
  const {
    t
  } = useTranslation();
  const isMobile = useMediaQuery("(max-width: 600px)");
  const modules = useAppSelector((state) => {
    var _a, _b;
    return (_b = (_a = state.userInfo.Settings) == null ? void 0 : _a.ModuleSettings) == null ? void 0 : _b.ModuleUrls;
  });
  const paymentModule = modules.find((module) => module.Name === "Payments");
  const PaymentLink = (paymentModule == null ? void 0 : paymentModule.Url) || "/";
  if (!quota) {
    return null;
  }
  const [opened, {
    close,
    open
  }] = useDisclosure(false);
  const onClickItem = reactExports.useCallback(async (event) => {
    close();
    event.stopPropagation();
    const {
      value
    } = event.currentTarget.dataset;
    switch (value) {
      case ActionQuotaMenuEnum$1.edit:
        openFilialQuotaModal();
        break;
      case ActionQuotaMenuEnum$1.changeTariff:
        {
          window.location.href = PaymentLink;
        }
        break;
    }
  }, [quota]);
  const handleContextMenu = (event_0) => {
    event_0.preventDefault();
    close();
  };
  const handleClick = (event_1) => {
    event_1.preventDefault();
    event_1.nativeEvent.stopPropagation();
    open();
  };
  const listMenu = isSaaS2 ? [{
    label: t("filials.diskSpace.changeTariff"),
    value: ActionQuotaMenuEnum$1.changeTariff
  }] : [{
    label: t("filials.diskSpace.edit"),
    value: ActionQuotaMenuEnum$1.edit
  }];
  return /* @__PURE__ */ jsxRuntimeExports.jsx(PopoverMenu, { opened, onClickItem, width: 292, list: listMenu, position: isMobile ? "bottom-start" : "left-start", onClose: close, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { className: "action-icon", onClick: handleClick, onContextMenu: handleContextMenu, children: /* @__PURE__ */ jsxRuntimeExports.jsx(CX, { color: "#667085", "data-action": "action" }) }) });
};
const useGetFilialQuotaColumns = (t0) => {
  const $ = compilerRuntimeExports.c(28);
  const {
    openFilialQuotaModal,
    isSaaS: isSaaS2
  } = t0;
  const {
    t
  } = useTranslation();
  let t1;
  if ($[0] !== t) {
    t1 = t("filials.diskSpace.table.name");
    $[0] = t;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  let t2;
  if ($[2] !== t) {
    t2 = (item) => /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: (item == null ? void 0 : item.Name) || t("filials.diskSpace.commonQuota") });
    $[2] = t;
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  let t3;
  if ($[4] !== t1 || $[5] !== t2) {
    t3 = {
      width: "33%",
      dataIndex: "name",
      title: t1,
      render: t2
    };
    $[4] = t1;
    $[5] = t2;
    $[6] = t3;
  } else {
    t3 = $[6];
  }
  let t4;
  if ($[7] !== t) {
    t4 = t("filials.diskSpace.table.available");
    $[7] = t;
    $[8] = t4;
  } else {
    t4 = $[8];
  }
  let t5;
  if ($[9] !== isSaaS2) {
    t5 = (item_0) => /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { component: "div", children: !isSaaS2 && (item_0 == null ? void 0 : item_0.QuotaSize) === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { pt: "12px", children: /* @__PURE__ */ jsxRuntimeExports.jsx(xte, { size: 16, color: "#667085" }) }) : formatDataSizeUnits(item_0 == null ? void 0 : item_0.QuotaSize) });
    $[9] = isSaaS2;
    $[10] = t5;
  } else {
    t5 = $[10];
  }
  let t6;
  if ($[11] !== t4 || $[12] !== t5) {
    t6 = {
      width: "20%",
      dataIndex: "available",
      title: t4,
      render: t5
    };
    $[11] = t4;
    $[12] = t5;
    $[13] = t6;
  } else {
    t6 = $[13];
  }
  let t7;
  if ($[14] !== t) {
    t7 = t("filials.diskSpace.table.used");
    $[14] = t;
    $[15] = t7;
  } else {
    t7 = $[15];
  }
  let t8;
  if ($[16] !== t7) {
    t8 = {
      width: "10%",
      dataIndex: "used",
      title: t7,
      render: _temp$6
    };
    $[16] = t7;
    $[17] = t8;
  } else {
    t8 = $[17];
  }
  let t9;
  if ($[18] !== isSaaS2 || $[19] !== openFilialQuotaModal) {
    t9 = {
      width: "auto",
      dataIndex: "action",
      title: "",
      render: (item_2) => /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { justify: "flex-end", children: /* @__PURE__ */ jsxRuntimeExports.jsx(FilialQuotaAction, { quota: item_2, openFilialQuotaModal, isSaaS: isSaaS2 }) })
    };
    $[18] = isSaaS2;
    $[19] = openFilialQuotaModal;
    $[20] = t9;
  } else {
    t9 = $[20];
  }
  let t10;
  if ($[21] !== t3 || $[22] !== t6 || $[23] !== t8 || $[24] !== t9) {
    t10 = [t3, t6, t8, t9];
    $[21] = t3;
    $[22] = t6;
    $[23] = t8;
    $[24] = t9;
    $[25] = t10;
  } else {
    t10 = $[25];
  }
  const filialColumns = t10;
  const [filiaQuotaColumns, setFilialQuotaColumns] = reactExports.useState(filialColumns);
  let t11;
  if ($[26] !== filiaQuotaColumns) {
    t11 = {
      filiaQuotaColumns,
      setFilialQuotaColumns
    };
    $[26] = filiaQuotaColumns;
    $[27] = t11;
  } else {
    t11 = $[27];
  }
  return t11;
};
function _temp$6(item_1) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: formatDataSizeUnits(item_1 == null ? void 0 : item_1.UsedSize) || "" });
}
const FilialQuotaModal = ({
  onClose,
  quota,
  onEditQuota
}) => {
  const {
    classes
  } = useStyles();
  const {
    t
  } = useTranslation();
  const [updateFilialQuota] = useUpdateFilialQuotaMutation();
  const form = useForm({
    validateInputOnChange: true,
    validate: (values) => getValidateErrors(validateScheme, values)
  });
  const validateScheme = objectType({
    size: numberType({
      required_error: t("filials.diskSpace.errors.size"),
      invalid_type_error: t("filials.diskSpace.errors.type")
    }).max(2097151, {
      message: t("filials.diskSpace.errors.filialMax")
    }).nonnegative({
      message: t("filials.diskSpace.errors.positive")
    }).safe()
  });
  const handleSubmit = async (formValues) => {
    try {
      const res = await updateFilialQuota({
        QuotaSize: convertGbToByte(formValues.size),
        CustomerId: quota == null ? void 0 : quota.CustomerId
      });
      if ("error" in res) {
        const codeError = extractErrorCode(res.error);
        showNotification({
          title: generateErrorMessage(codeError),
          message: "",
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
      } else {
        showNotification({
          title: t("saved"),
          message: "",
          autoClose: true,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
        onClose();
        form.reset();
        onEditQuota();
      }
    } catch (error) {
      console.error(error);
    }
  };
  reactExports.useEffect(() => {
    if (quota) {
      const formValue = {
        name: (quota == null ? void 0 : quota.Name) || t("filials.diskSpace.commonQuota"),
        size: (quota == null ? void 0 : quota.QuotaSize) ? convertByteToGb(quota == null ? void 0 : quota.QuotaSize) : 0
      };
      form.setValues(formValue);
      form.resetDirty(formValue);
    }
  }, [quota]);
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: form.onSubmit(handleSubmit), children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { px: "md", py: "sm", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextFieldInput, { form, fieldName: "name", label: t("filials.diskSpace.quotaName"), disabled: true }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { radius: "8px", className: classes.textFieldInput, label: t("filials.diskSpace.quotaSizeInGb"), allowNegative: false, ...form.getInputProps("size") })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.modalFooter, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", size: "sm", radius: 8, w: "49%", disabled: !form.isValid(), children: t("save") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(UnstyledButton, { type: "button", ml: 8, className: classes.modalCancelBtn, w: "49%", onClick: onClose, children: t("cancel") })
    ] })
  ] });
};
const FilialQuota = (t0) => {
  const $ = compilerRuntimeExports.c(52);
  const {
    filial
  } = t0;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const {
    Settings
  } = useAppSelector(_temp$5);
  const [opened, t1] = useDisclosure(false);
  const {
    close,
    open
  } = t1;
  const {
    setFilialQuota,
    setQuotasFilters
  } = useActions();
  const {
    filialQuota
  } = useAppSelector(_temp2$2);
  const {
    data,
    isLoading
  } = useGetFilialQuotaQuery(filial == null ? void 0 : filial.Id);
  let t2;
  if ($[0] !== data || $[1] !== setFilialQuota) {
    t2 = () => {
      if (data) {
        setFilialQuota(data);
      }
    };
    $[0] = data;
    $[1] = setFilialQuota;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  let t3;
  if ($[3] !== data) {
    t3 = [data];
    $[3] = data;
    $[4] = t3;
  } else {
    t3 = $[4];
  }
  reactExports.useEffect(t2, t3);
  let t4;
  if ($[5] !== open) {
    t4 = () => {
      open();
    };
    $[5] = open;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  const openFilialQuotaModal = t4;
  let t5;
  if ($[7] !== setQuotasFilters) {
    t5 = async () => {
      setQuotasFilters({
        Count: 10,
        Offset: 0
      });
    };
    $[7] = setQuotasFilters;
    $[8] = t5;
  } else {
    t5 = $[8];
  }
  const onEditQuota = t5;
  let t6;
  if ($[9] !== Settings) {
    t6 = isSaaS(Settings);
    $[9] = Settings;
    $[10] = t6;
  } else {
    t6 = $[10];
  }
  let t7;
  if ($[11] !== openFilialQuotaModal || $[12] !== t6) {
    t7 = {
      isSaaS: t6,
      openFilialQuotaModal
    };
    $[11] = openFilialQuotaModal;
    $[12] = t6;
    $[13] = t7;
  } else {
    t7 = $[13];
  }
  const {
    filiaQuotaColumns
  } = useGetFilialQuotaColumns(t7);
  const t8 = classes.section;
  const t9 = classes.title;
  let t10;
  if ($[14] !== t) {
    t10 = t("filials.diskSpace.filialQuota");
    $[14] = t;
    $[15] = t10;
  } else {
    t10 = $[15];
  }
  let t11;
  if ($[16] !== classes.title || $[17] !== t10) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t9, children: t10 });
    $[16] = classes.title;
    $[17] = t10;
    $[18] = t11;
  } else {
    t11 = $[18];
  }
  let t12;
  if ($[19] !== filiaQuotaColumns) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Thead, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(TableHeadList, { columns: filiaQuotaColumns }) });
    $[19] = filiaQuotaColumns;
    $[20] = t12;
  } else {
    t12 = $[20];
  }
  const t13 = filialQuota;
  let t14;
  if ($[21] !== t13) {
    t14 = [t13];
    $[21] = t13;
    $[22] = t14;
  } else {
    t14 = $[22];
  }
  let t15;
  if ($[23] !== filiaQuotaColumns || $[24] !== t14) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Tbody, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(TableRowList, { rows: t14, columns: filiaQuotaColumns }) });
    $[23] = filiaQuotaColumns;
    $[24] = t14;
    $[25] = t15;
  } else {
    t15 = $[25];
  }
  let t16;
  if ($[26] !== t12 || $[27] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Table, { horizontalSpacing: "md", verticalSpacing: "xs", mt: "sm", children: [
      t12,
      t15
    ] });
    $[26] = t12;
    $[27] = t15;
    $[28] = t16;
  } else {
    t16 = $[28];
  }
  let t17;
  if ($[29] !== classes.container || $[30] !== t16) {
    t17 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.container, "data-section": DriveInfoPanelsEnum.filialQuota, children: t16 });
    $[29] = classes.container;
    $[30] = t16;
    $[31] = t17;
  } else {
    t17 = $[31];
  }
  let t18;
  if ($[32] !== isLoading) {
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isLoading });
    $[32] = isLoading;
    $[33] = t18;
  } else {
    t18 = $[33];
  }
  let t19;
  if ($[34] !== t) {
    t19 = t("filials.diskSpace.filialQuotaEdit");
    $[34] = t;
    $[35] = t19;
  } else {
    t19 = $[35];
  }
  let t20;
  if ($[36] !== close || $[37] !== filialQuota || $[38] !== onEditQuota || $[39] !== opened) {
    t20 = /* @__PURE__ */ jsxRuntimeExports.jsx(FilialQuotaModal, { onEditQuota, isOpened: opened, onClose: close, quota: filialQuota });
    $[36] = close;
    $[37] = filialQuota;
    $[38] = onEditQuota;
    $[39] = opened;
    $[40] = t20;
  } else {
    t20 = $[40];
  }
  let t21;
  if ($[41] !== close || $[42] !== opened || $[43] !== t19 || $[44] !== t20) {
    t21 = /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { size: "450px", opened, title: t19, onClose: close, children: t20 });
    $[41] = close;
    $[42] = opened;
    $[43] = t19;
    $[44] = t20;
    $[45] = t21;
  } else {
    t21 = $[45];
  }
  let t22;
  if ($[46] !== classes.section || $[47] !== t11 || $[48] !== t17 || $[49] !== t18 || $[50] !== t21) {
    t22 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t8, "data-section": DriveInfoPanelsEnum.filialQuota, children: [
      t11,
      t17,
      t18,
      t21
    ] });
    $[46] = classes.section;
    $[47] = t11;
    $[48] = t17;
    $[49] = t18;
    $[50] = t21;
    $[51] = t22;
  } else {
    t22 = $[51];
  }
  return t22;
};
function _temp$5(state) {
  return state.userInfo;
}
function _temp2$2(state_0) {
  return state_0.quotas;
}
const FilialStorage = ({
  filial
}) => {
  var _a, _b, _c, _d;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const [storages, setStorages] = reactExports.useState([]);
  const [isLoadingStorages, setIsLoadingStorages] = reactExports.useState(false);
  const [updateFilialSettings, {
    isLoading: isSaving
  }] = useUpdateFilialSettingsMutation();
  const storageForm = useForm({
    initialValues: {
      Id: ((_b = (_a = filial.Settings) == null ? void 0 : _a.StorageId) == null ? void 0 : _b.toString()) ?? null
    },
    validateInputOnChange: true
  });
  reactExports.useEffect(() => {
    const fetchStorages = async () => {
      try {
        setIsLoadingStorages(true);
        const data = await storageConfigurationApiArea().GetStorageConfigurations();
        setStorages(data);
      } catch (error) {
        console.error("Error fetching storages:", error);
      } finally {
        setIsLoadingStorages(false);
      }
    };
    fetchStorages();
  }, []);
  reactExports.useEffect(() => {
    var _a2, _b2;
    const newId = ((_b2 = (_a2 = filial.Settings) == null ? void 0 : _a2.StorageId) == null ? void 0 : _b2.toString()) ?? null;
    if (storageForm.values.Id !== newId) {
      const storageData = {
        Id: newId
      };
      storageForm.setValues(storageData);
      storageForm.resetDirty(storageData);
    }
  }, [(_c = filial.Storage) == null ? void 0 : _c.Id]);
  const storageOptions = storages.filter((s) => s.IsEnabled).map((storage) => ({
    value: storage.Id.toString(),
    label: storage.Name
  }));
  const handleStorageChange = (value) => {
    if (value === null) {
      return;
    }
    const selectedStorage = storages.find((s_0) => s_0.Id.toString() === value);
    if (selectedStorage) {
      storageForm.setFieldValue("Id", selectedStorage.Id.toString());
    }
  };
  const handleSubmit = async () => {
    try {
      await updateFilialSettings({
        id: filial.Id,
        type: SettingsEnum.StorageConfigurationSettings,
        StorageId: storageForm.values.Id
      }).unwrap();
      storageForm.resetDirty();
      notifications.show({
        message: t("filials.diskSpace.storageUpdated"),
        color: "green"
      });
    } catch (error_0) {
      console.error("Error saving storage:", error_0);
      notifications.show({
        message: t("filials.diskSpace.storageUpdateError"),
        color: "red"
      });
    }
  };
  const isDisabled = !storageForm.isDirty() || isSaving || isLoadingStorages;
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.section, "data-section": DriveInfoPanelsEnum.filialQuota, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.title, children: t("profile.storageBinding") }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.container, "data-section": DriveInfoPanelsEnum.filialQuota, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", c: "dimmed", mb: "md", children: t("profile.storageBindingDescription") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { label: t("profile.selectStorage"), placeholder: storageForm.values.Id === null ? t("profile.noStorage") : t("profile.selectStorage"), data: storageOptions, value: ((_d = storageForm.values.Id) == null ? void 0 : _d.toString()) || null, onChange: handleStorageChange, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconChevronDown, { size: "1rem", color: "#98A2B3" }), disabled: isLoadingStorages, clearable: false, comboboxProps: {
        zIndex: 1e4
      }, mb: "md", style: {
        maxWidth: "400px"
      } }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: handleSubmit, size: "sm", radius: 8, disabled: isDisabled, style: {
        padding: "0 20px"
      }, children: t("profile.save") })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isSaving || isLoadingStorages })
  ] });
};
var ActionQuotaMenuEnum = /* @__PURE__ */ ((ActionQuotaMenuEnum2) => {
  ActionQuotaMenuEnum2["edit"] = "edit";
  ActionQuotaMenuEnum2["delete"] = "delete";
  return ActionQuotaMenuEnum2;
})(ActionQuotaMenuEnum || {});
const isDefaultQuota = (quotaId) => quotaId === 1;
const actionMenu = (quotaId, t) => {
  const list = [{
    label: t("filials.diskSpace.edit"),
    value: "edit"
    /* edit */
  }];
  if (!isDefaultQuota(quotaId)) {
    list.push({
      label: t("filials.diskSpace.delete"),
      value: "delete",
      color: "brandRed.0"
    });
  }
  return list;
};
const useDeleteQuotaModal = (quota) => {
  const $ = compilerRuntimeExports.c(8);
  const [deleteQuota] = useDeleteQuotaMutation();
  const {
    setQuotasFilters
  } = useActions();
  const {
    t
  } = useTranslation();
  let t0;
  if ($[0] !== deleteQuota || $[1] !== setQuotasFilters || $[2] !== t) {
    t0 = async (id) => {
      try {
        const res = await deleteQuota(id);
        if ("error" in res) {
          const codeError = extractErrorCode(res.error);
          showNotification({
            title: generateErrorMessage(codeError),
            message: "",
            autoClose: true,
            color: "red",
            style: {
              zIndex: 1003
            }
          });
        } else {
          showNotification({
            title: t("deleted"),
            message: "",
            autoClose: true,
            color: "green",
            style: {
              zIndex: 1003
            }
          });
          setQuotasFilters({
            Count: 10,
            Offset: 0
          });
        }
      } catch (t12) {
        const error = t12;
        console.error(error);
      }
    };
    $[0] = deleteQuota;
    $[1] = setQuotasFilters;
    $[2] = t;
    $[3] = t0;
  } else {
    t0 = $[3];
  }
  const handleDeleteQuota = t0;
  let t1;
  if ($[4] !== handleDeleteQuota || $[5] !== quota || $[6] !== t) {
    const openDeleteQuotaModal = () => {
      const {
        id: id_0,
        name,
        users
      } = quota;
      if (!users) {
        handleDeleteQuota(id_0);
        return;
      }
      const usersText = users % 10 === 1 && users % 100 !== 11 ? "пользователь останется" : "пользователей останутся";
      openContextModal({
        modal: "context",
        centered: true,
        innerProps: {
          title: t("warning"),
          modalBody: /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { mb: 24, children: t("filials.diskSpace.deleteUsersQuotaDescription", {
            name,
            users,
            usersText
          }) }),
          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("delete"),
            cancel: t("cancel")
          },
          onConfirm: () => handleDeleteQuota(quota.id)
        }
      });
    };
    t1 = {
      openDeleteQuotaModal
    };
    $[4] = handleDeleteQuota;
    $[5] = quota;
    $[6] = t;
    $[7] = t1;
  } else {
    t1 = $[7];
  }
  return t1;
};
const Action = ({
  quota,
  onEdit
}) => {
  const {
    t
  } = useTranslation();
  const isMobile = useMediaQuery("(max-width: 600px)");
  if (!quota) {
    return null;
  }
  const [opened, {
    close,
    open
  }] = useDisclosure(false);
  const {
    openDeleteQuotaModal
  } = useDeleteQuotaModal(quota);
  const onClickItem = reactExports.useCallback(async (event) => {
    close();
    event.stopPropagation();
    const {
      value
    } = event.currentTarget.dataset;
    switch (value) {
      case ActionQuotaMenuEnum.edit:
        onEdit(quota);
        break;
      case ActionQuotaMenuEnum.delete:
        openDeleteQuotaModal();
        break;
    }
  }, [quota]);
  const handleContextMenu = (event_0) => {
    event_0.preventDefault();
    close();
  };
  const handleClick = (event_1) => {
    event_1.preventDefault();
    event_1.nativeEvent.stopPropagation();
    open();
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(PopoverMenu, { opened, onClickItem, width: 200, list: actionMenu(quota == null ? void 0 : quota.id, t), position: isMobile ? "bottom-start" : "left-start", onClose: close, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { className: "action-icon", onClick: handleClick, onContextMenu: handleContextMenu, children: /* @__PURE__ */ jsxRuntimeExports.jsx(CX, { color: "#667085", "data-action": "action" }) }) });
};
const useGetColumns = (t0) => {
  const $ = compilerRuntimeExports.c(21);
  const {
    onEdit
  } = t0;
  const {
    t
  } = useTranslation();
  let t1;
  if ($[0] !== t) {
    t1 = t("filials.diskSpace.table.name");
    $[0] = t;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  let t2;
  if ($[2] !== t1) {
    t2 = {
      width: "33%",
      dataIndex: "name",
      title: t1,
      hasSort: true,
      sortField: "Name",
      render: _temp$4
    };
    $[2] = t1;
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  let t3;
  if ($[4] !== t) {
    t3 = t("filials.diskSpace.table.size");
    $[4] = t;
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  let t4;
  if ($[6] !== t3) {
    t4 = {
      width: "20%",
      dataIndex: "size",
      title: t3,
      hasSort: true,
      sortField: "Size",
      render: _temp2$1
    };
    $[6] = t3;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  let t5;
  if ($[8] !== t) {
    t5 = t("filials.diskSpace.table.appointments");
    $[8] = t;
    $[9] = t5;
  } else {
    t5 = $[9];
  }
  let t6;
  if ($[10] !== t5) {
    t6 = {
      width: "25%",
      dataIndex: "appointments",
      title: t5,
      render: _temp3
    };
    $[10] = t5;
    $[11] = t6;
  } else {
    t6 = $[11];
  }
  let t7;
  if ($[12] !== onEdit) {
    t7 = {
      width: "auto",
      dataIndex: "action",
      title: "",
      render: (item_2) => /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { justify: "flex-end", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Action, { quota: item_2, onEdit }) })
    };
    $[12] = onEdit;
    $[13] = t7;
  } else {
    t7 = $[13];
  }
  let t8;
  if ($[14] !== t2 || $[15] !== t4 || $[16] !== t6 || $[17] !== t7) {
    t8 = [t2, t4, t6, t7];
    $[14] = t2;
    $[15] = t4;
    $[16] = t6;
    $[17] = t7;
    $[18] = t8;
  } else {
    t8 = $[18];
  }
  const columnsData = t8;
  const [columns, setColumns] = reactExports.useState(columnsData);
  let t9;
  if ($[19] !== columns) {
    t9 = {
      columns,
      setColumns
    };
    $[19] = columns;
    $[20] = t9;
  } else {
    t9 = $[20];
  }
  return t9;
};
function _temp$4(item) {
  return item.name;
}
function _temp2$1(item_0) {
  return formatDataSizeUnits(item_0.size);
}
function _temp3(item_1) {
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: item_1.users });
}
const UsersQuotaModal = ({
  onClose,
  quota,
  CustomerId
}) => {
  const {
    classes
  } = useStyles();
  const {
    t
  } = useTranslation();
  const [createQuota] = useCreateQuotaMutation();
  const [updateQuota] = useUpdateQuotaMutation();
  const form = useForm({
    validateInputOnChange: true,
    validate: (values) => getValidateErrors(validateScheme, values)
  });
  const validateScheme = objectType({
    name: stringType().trim().min(1, {
      message: t("validation.required")
    }).max(64, {
      message: t("validation.maxLengthSymbolsWithCount.symbols", {
        count: 64
      })
    }),
    size: numberType({
      required_error: t("filials.diskSpace.errors.size"),
      invalid_type_error: t("filials.diskSpace.errors.type")
    }).max(9e7, {
      message: t("filials.diskSpace.errors.max")
    }).positive({
      message: t("filials.diskSpace.errors.positive")
    }).safe()
  });
  const handleSubmit = async (formValues) => {
    var _a, _b;
    try {
      let res;
      if (quota == null ? void 0 : quota.id) {
        res = await updateQuota({
          Id: quota.id,
          Name: (_a = formValues == null ? void 0 : formValues.name) == null ? void 0 : _a.trim(),
          Size: convertGbToByte(formValues.size),
          CustomerId
        });
      } else {
        res = await createQuota({
          Name: (_b = formValues == null ? void 0 : formValues.name) == null ? void 0 : _b.trim(),
          Size: convertGbToByte(formValues.size),
          CustomerId
        });
      }
      if ("error" in res) {
        const codeError = extractErrorCode(res.error);
        showNotification({
          title: generateErrorMessage(codeError),
          message: "",
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
      } else {
        showNotification({
          title: t("saved"),
          message: "",
          autoClose: true,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
        form.reset();
        onClose();
      }
    } catch (error) {
      console.error(error);
    }
  };
  reactExports.useEffect(() => {
    if (quota) {
      const formValue = {
        name: (quota == null ? void 0 : quota.name) || "",
        size: convertByteToGb((quota == null ? void 0 : quota.size) ?? 0)
      };
      form.setValues(formValue);
      form.resetDirty(formValue);
    }
  }, [quota]);
  const handleSetMaxValue = () => {
    form.setFieldValue("size", 9e7);
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: form.onSubmit(handleSubmit), children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { px: "md", py: "sm", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextFieldInput, { form, fieldName: "name", label: t("filials.diskSpace.quotaName") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { autoComplete: "off", hideControls: true, withAsterisk: true, clampBehavior: "strict", min: 1, max: 9e7, className: classes.textFieldInput, label: t("filials.diskSpace.quotaSizeInGb"), allowNegative: false, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { color: "gray", label: t("filials.diskSpace.maxTextTooltip"), zIndex: "3000", children: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { size: 16, variant: "transparent", onClick: handleSetMaxValue, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconAxisY, { size: 16, color: themeColors.brandGray[0] }) }) }), ...form.getInputProps("size") })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.modalFooter, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", size: "sm", radius: 8, w: "49%", disabled: Object.keys(form.errors).length !== 0 || !form.isDirty(), children: quota ? t("save") : t("create") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(UnstyledButton, { type: "button", ml: 8, className: classes.modalCancelBtn, w: "49%", onClick: onClose, children: t("cancel") })
    ] })
  ] });
};
const UsersQuotaList = (t0) => {
  const $ = compilerRuntimeExports.c(120);
  const {
    filial
  } = t0;
  const {
    t
  } = useTranslation();
  const {
    classes,
    cx
  } = useStyles();
  const scrollRef = reactExports.useRef(null);
  const [isModalOpened, setIsModalOpened] = reactExports.useState(false);
  const [isAssignModalOpened, setIsAssignModalOpened] = reactExports.useState(false);
  const [scrolled, setScrolled] = reactExports.useState(false);
  const [sort, setSort] = reactExports.useState(void 0);
  const [sortBy, setSortBy] = reactExports.useState("");
  const [sortDirection, setSortDirection] = reactExports.useState("");
  const {
    setQuotas,
    setQuotasFilters,
    setSelectedQuota
  } = useActions();
  const {
    quotas,
    totalQuotas,
    quotasFilters,
    selectedQuota
  } = useAppSelector(_temp$3);
  const navigate = useNavigate();
  let t1;
  if ($[0] !== filial) {
    t1 = filial ? [{
      Type: IFiltersEnumType.FilialFilter,
      NumValues: [filial == null ? void 0 : filial.Id]
    }] : [];
    $[0] = filial;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  let t2;
  if ($[2] !== sortBy || $[3] !== sortDirection) {
    t2 = sortBy ? {
      SortBy: sortBy,
      SortDirection: sortDirection
    } : {};
    $[2] = sortBy;
    $[3] = sortDirection;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  let t3;
  if ($[5] !== quotasFilters.Count || $[6] !== quotasFilters.Offset || $[7] !== t1 || $[8] !== t2) {
    t3 = {
      Count: quotasFilters.Count,
      Offset: quotasFilters.Offset,
      LoadUseCount: true,
      FilterConditions: t1,
      ...t2
    };
    $[5] = quotasFilters.Count;
    $[6] = quotasFilters.Offset;
    $[7] = t1;
    $[8] = t2;
    $[9] = t3;
  } else {
    t3 = $[9];
  }
  const {
    data,
    isLoading
  } = useGetQuotasQuery(t3);
  let t4;
  if ($[10] !== setSelectedQuota) {
    t4 = (quota) => {
      setSelectedQuota(quota);
      setIsModalOpened(true);
    };
    $[10] = setSelectedQuota;
    $[11] = t4;
  } else {
    t4 = $[11];
  }
  const onEdit = t4;
  let t5;
  if ($[12] !== onEdit) {
    t5 = {
      onEdit
    };
    $[12] = onEdit;
    $[13] = t5;
  } else {
    t5 = $[13];
  }
  const {
    columns
  } = useGetColumns(t5);
  let t6;
  if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
    t6 = {
      name: "Name",
      size: "Size"
    };
    $[14] = t6;
  } else {
    t6 = $[14];
  }
  const sortFieldMap = t6;
  let t7;
  if ($[15] !== quotasFilters.Count || $[16] !== setQuotasFilters || $[17] !== sort) {
    t7 = (field) => {
      const newSort = {
        SortField: field,
        SortOrder: field === (sort == null ? void 0 : sort.SortField) ? !sort.SortOrder : false
      };
      setSort(newSort);
      const newSortBy = sortFieldMap[field] || "";
      setSortBy(newSortBy);
      if (newSortBy) {
        setSortDirection(newSort.SortOrder ? "desc" : "asc");
      }
      setQuotasFilters({
        Count: quotasFilters.Count,
        Offset: 0
      });
    };
    $[15] = quotasFilters.Count;
    $[16] = setQuotasFilters;
    $[17] = sort;
    $[18] = t7;
  } else {
    t7 = $[18];
  }
  const handleSort = t7;
  let t8;
  if ($[19] !== data || $[20] !== quotas || $[21] !== quotasFilters.Offset || $[22] !== setQuotas) {
    t8 = () => {
      if (!data) {
        return;
      }
      const quotasData = quotasFilters.Offset > 0 ? [...quotas, ...data.Quotas] : data.Quotas;
      setQuotas({
        ...data,
        Quotas: quotasData
      });
    };
    $[19] = data;
    $[20] = quotas;
    $[21] = quotasFilters.Offset;
    $[22] = setQuotas;
    $[23] = t8;
  } else {
    t8 = $[23];
  }
  let t9;
  if ($[24] !== data) {
    t9 = [data];
    $[24] = data;
    $[25] = t9;
  } else {
    t9 = $[25];
  }
  reactExports.useEffect(t8, t9);
  let t10;
  if ($[26] !== quotasFilters || $[27] !== setQuotasFilters) {
    t10 = () => {
      setQuotasFilters({
        ...quotasFilters,
        Offset: quotasFilters.Offset + quotasFilters.Count
      });
    };
    $[26] = quotasFilters;
    $[27] = setQuotasFilters;
    $[28] = t10;
  } else {
    t10 = $[28];
  }
  const handleLoadMore = t10;
  let t11;
  if ($[29] !== setQuotasFilters) {
    t11 = () => {
      scrollRef.current.el.scrollTo(0, 0);
      setQuotasFilters({
        Count: 10,
        Offset: 0
      });
    };
    $[29] = setQuotasFilters;
    $[30] = t11;
  } else {
    t11 = $[30];
  }
  const resetQuotaFilters = t11;
  let t12;
  if ($[31] !== quotasFilters.Offset) {
    t12 = () => {
      if (quotasFilters.Offset === 0) {
        scrollRef.current.el.scrollTo(0, 0);
      }
    };
    $[31] = quotasFilters.Offset;
    $[32] = t12;
  } else {
    t12 = $[32];
  }
  let t13;
  if ($[33] !== quotasFilters) {
    t13 = [quotasFilters];
    $[33] = quotasFilters;
    $[34] = t13;
  } else {
    t13 = $[34];
  }
  reactExports.useEffect(t12, t13);
  let t14;
  if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
    t14 = () => {
      setScrolled(true);
    };
    $[35] = t14;
  } else {
    t14 = $[35];
  }
  const handleScroll = t14;
  const t15 = classes.section;
  const t16 = classes.title;
  let t17;
  if ($[36] !== t) {
    t17 = t("filials.diskSpace.quotas");
    $[36] = t;
    $[37] = t17;
  } else {
    t17 = $[37];
  }
  let t18;
  if ($[38] !== classes.title || $[39] !== t17) {
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t16, children: t17 });
    $[38] = classes.title;
    $[39] = t17;
    $[40] = t18;
  } else {
    t18 = $[40];
  }
  const t19 = quotas == null ? void 0 : quotas.length;
  const t20 = totalQuotas > (quotas == null ? void 0 : quotas.length);
  let t21;
  if ($[41] !== classes.infiniteScrollMoreData || $[42] !== (quotas == null ? void 0 : quotas.length)) {
    t21 = (quotas == null ? void 0 : quotas.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.infiniteScrollMoreData, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "sm" }) }) : null;
    $[41] = classes.infiniteScrollMoreData;
    $[42] = quotas == null ? void 0 : quotas.length;
    $[43] = t21;
  } else {
    t21 = $[43];
  }
  const t22 = (quotas == null ? void 0 : quotas.length) < 5 ? "auto" : "400px";
  let t23;
  if ($[44] !== classes.scrolled || $[45] !== classes.tableHeader || $[46] !== columns || $[47] !== cx || $[48] !== handleSort || $[49] !== quotas || $[50] !== scrolled || $[51] !== sort) {
    t23 = quotas && (quotas == null ? void 0 : quotas.length) > 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Table, { horizontalSpacing: "md", verticalSpacing: "xs", mt: "sm", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("thead", { className: cx(classes.tableHeader, {
        [classes.scrolled]: scrolled
      }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(TableHeadList, { columns, sort, onSort: handleSort }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("tbody", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(TableRowList, { rows: quotas, columns }) })
    ] }) : null;
    $[44] = classes.scrolled;
    $[45] = classes.tableHeader;
    $[46] = columns;
    $[47] = cx;
    $[48] = handleSort;
    $[49] = quotas;
    $[50] = scrolled;
    $[51] = sort;
    $[52] = t23;
  } else {
    t23 = $[52];
  }
  let t24;
  if ($[53] !== classes.infiniteScroll || $[54] !== handleLoadMore || $[55] !== t19 || $[56] !== t20 || $[57] !== t21 || $[58] !== t22 || $[59] !== t23) {
    t24 = /* @__PURE__ */ jsxRuntimeExports.jsx(InfiniteScroll, { ref: scrollRef, dataLength: t19, next: handleLoadMore, hasMore: t20, loader: t21, className: classes.infiniteScroll, height: t22, onScroll: handleScroll, children: t23 });
    $[53] = classes.infiniteScroll;
    $[54] = handleLoadMore;
    $[55] = t19;
    $[56] = t20;
    $[57] = t21;
    $[58] = t22;
    $[59] = t23;
    $[60] = t24;
  } else {
    t24 = $[60];
  }
  let t25;
  if ($[61] === Symbol.for("react.memo_cache_sentinel")) {
    t25 = {
      base: 1,
      sm: 2
    };
    $[61] = t25;
  } else {
    t25 = $[61];
  }
  const t26 = classes.addButton;
  let t27;
  if ($[62] === Symbol.for("react.memo_cache_sentinel")) {
    t27 = () => {
      setIsModalOpened(true);
    };
    $[62] = t27;
  } else {
    t27 = $[62];
  }
  let t28;
  if ($[63] !== t) {
    t28 = t("filials.diskSpace.quotaCreate");
    $[63] = t;
    $[64] = t28;
  } else {
    t28 = $[64];
  }
  let t29;
  if ($[65] !== classes.addButton || $[66] !== t28) {
    t29 = /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { cols: t25, w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { className: t26, mt: "sm", onClick: t27, children: t28 }) });
    $[65] = classes.addButton;
    $[66] = t28;
    $[67] = t29;
  } else {
    t29 = $[67];
  }
  let t30;
  if ($[68] === Symbol.for("react.memo_cache_sentinel")) {
    t30 = {
      base: 1,
      sm: 2
    };
    $[68] = t30;
  } else {
    t30 = $[68];
  }
  const t31 = classes.addButton;
  let t32;
  if ($[69] === Symbol.for("react.memo_cache_sentinel")) {
    t32 = () => {
      setIsAssignModalOpened(true);
    };
    $[69] = t32;
  } else {
    t32 = $[69];
  }
  let t33;
  if ($[70] !== t) {
    t33 = t("filials.diskSpace.addQuotaAppointment");
    $[70] = t;
    $[71] = t33;
  } else {
    t33 = $[71];
  }
  let t34;
  if ($[72] !== classes.addButton || $[73] !== t33) {
    t34 = /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { cols: t30, w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { className: t31, mt: "sm", onClick: t32, children: t33 }) });
    $[72] = classes.addButton;
    $[73] = t33;
    $[74] = t34;
  } else {
    t34 = $[74];
  }
  let t35;
  if ($[75] !== t) {
    t35 = t("filials.diskSpace.quotasDescription");
    $[75] = t;
    $[76] = t35;
  } else {
    t35 = $[76];
  }
  let t36;
  if ($[77] !== t35) {
    t36 = /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { my: "22px", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", c: "#667085", children: t35 }) });
    $[77] = t35;
    $[78] = t36;
  } else {
    t36 = $[78];
  }
  let t37;
  if ($[79] !== navigate) {
    t37 = () => navigate(ROUTES.filials.edit.pages.subRoutes.quotas.path);
    $[79] = navigate;
    $[80] = t37;
  } else {
    t37 = $[80];
  }
  let t38;
  if ($[81] !== t) {
    t38 = t("filials.diskSpace.quotasTable");
    $[81] = t;
    $[82] = t38;
  } else {
    t38 = $[82];
  }
  let t39;
  if ($[83] !== t37 || $[84] !== t38) {
    t39 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "sm", px: "lg", onClick: t37, children: t38 });
    $[83] = t37;
    $[84] = t38;
    $[85] = t39;
  } else {
    t39 = $[85];
  }
  let t40;
  if ($[86] !== isLoading) {
    t40 = /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isLoading });
    $[86] = isLoading;
    $[87] = t40;
  } else {
    t40 = $[87];
  }
  let t41;
  if ($[88] === Symbol.for("react.memo_cache_sentinel")) {
    t41 = () => setIsAssignModalOpened(false);
    $[88] = t41;
  } else {
    t41 = $[88];
  }
  let t42;
  if ($[89] !== isAssignModalOpened) {
    t42 = /* @__PURE__ */ jsxRuntimeExports.jsx(AssignQuotaModal, { opened: isAssignModalOpened, handleClose: t41 });
    $[89] = isAssignModalOpened;
    $[90] = t42;
  } else {
    t42 = $[90];
  }
  const t43 = `filials.diskSpace.${selectedQuota ? "editUsersQuota" : "createUsersQuota"}`;
  let t44;
  if ($[91] !== t || $[92] !== t43) {
    t44 = t(t43);
    $[91] = t;
    $[92] = t43;
    $[93] = t44;
  } else {
    t44 = $[93];
  }
  let t45;
  if ($[94] !== resetQuotaFilters || $[95] !== setSelectedQuota) {
    t45 = () => {
      setSelectedQuota(null);
      setIsModalOpened(false);
      resetQuotaFilters();
    };
    $[94] = resetQuotaFilters;
    $[95] = setSelectedQuota;
    $[96] = t45;
  } else {
    t45 = $[96];
  }
  let t46;
  if ($[97] !== resetQuotaFilters || $[98] !== setSelectedQuota) {
    t46 = () => {
      setSelectedQuota(null);
      setIsModalOpened(false);
      resetQuotaFilters();
    };
    $[97] = resetQuotaFilters;
    $[98] = setSelectedQuota;
    $[99] = t46;
  } else {
    t46 = $[99];
  }
  const t47 = filial == null ? void 0 : filial.Id;
  let t48;
  if ($[100] !== selectedQuota || $[101] !== t46 || $[102] !== t47) {
    t48 = /* @__PURE__ */ jsxRuntimeExports.jsx(UsersQuotaModal, { onClose: t46, quota: selectedQuota, CustomerId: t47 });
    $[100] = selectedQuota;
    $[101] = t46;
    $[102] = t47;
    $[103] = t48;
  } else {
    t48 = $[103];
  }
  let t49;
  if ($[104] !== isModalOpened || $[105] !== t44 || $[106] !== t45 || $[107] !== t48) {
    t49 = /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { size: "450px", opened: isModalOpened, title: t44, onClose: t45, children: t48 });
    $[104] = isModalOpened;
    $[105] = t44;
    $[106] = t45;
    $[107] = t48;
    $[108] = t49;
  } else {
    t49 = $[108];
  }
  let t50;
  if ($[109] !== classes.section || $[110] !== t18 || $[111] !== t24 || $[112] !== t29 || $[113] !== t34 || $[114] !== t36 || $[115] !== t39 || $[116] !== t40 || $[117] !== t42 || $[118] !== t49) {
    t50 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t15, "data-section": DriveInfoPanelsEnum.quotas, children: [
      t18,
      t24,
      t29,
      t34,
      t36,
      t39,
      t40,
      t42,
      t49
    ] });
    $[109] = classes.section;
    $[110] = t18;
    $[111] = t24;
    $[112] = t29;
    $[113] = t34;
    $[114] = t36;
    $[115] = t39;
    $[116] = t40;
    $[117] = t42;
    $[118] = t49;
    $[119] = t50;
  } else {
    t50 = $[119];
  }
  return t50;
};
function _temp$3(state) {
  return state.quotas;
}
const MassAddQuotaForm = ({
  isOpened,
  setIsModalOpened
}) => {
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const {
    filial
  } = useAppSelector((state) => state.filials);
  const [isRoleModalOpen, setIsRoleModalOpen] = reactExports.useState(false);
  const [selectedRoles, setSelectedRoles] = reactExports.useState(null);
  const [setQuotaByRole, {
    isLoading
  }] = useSetQuotaByRoleMutation();
  const validateScheme = objectType({
    RoleId: numberType(),
    QuotaId: numberType({
      invalid_type_error: t("validation.quotaMandatory")
    })
  });
  const form = useForm({
    initialValues: {
      RoleId: null,
      QuotaId: null,
      QuotaName: "",
      IsQuotaDown: false
    },
    validateInputOnChange: false,
    validate: (values) => getValidateErrors(validateScheme, values)
  });
  const closeRoleModal = () => {
    setIsRoleModalOpen(false);
  };
  const setRoleId = async (id) => {
    form.setFieldValue("RoleId", id);
    closeRoleModal();
  };
  const setRolesGroup = async (group) => {
    setSelectedRoles(group);
  };
  const handleRemoveRoles = () => {
    setSelectedRoles(null);
    form.setFieldValue("RoleId", null);
  };
  const closeModal = () => {
    setIsModalOpened(false);
    form.reset();
    setSelectedRoles(null);
  };
  const handleSubmit = async (values_0) => {
    try {
      const res = await setQuotaByRole(values_0);
      if ("error" in res) {
        universalNotification({
          error: `${res == null ? void 0 : res.error}`,
          isError: true,
          isSuccess: false
        });
      } else {
        universalNotification({
          isSuccess: true,
          isError: false,
          error: null,
          successTitle: t("filials.diskSpace.setQuotasSuccess")
        });
        clearApiCacheByTags(usersApi, ["Users"]);
      }
      form.reset();
      closeModal();
    } catch (error) {
      console.error(error);
    }
  };
  const isDisabled = Object.keys(form.errors).length !== 0 || !form.isDirty();
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Modal, { opened: isOpened, title: t("filials.diskSpace.addQuotaByRole"), onClose: () => {
    closeModal();
  }, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { className: classes.modalRoot, onSubmit: form.onSubmit(handleSubmit), children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.modalContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, w: "100%", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, spacing: "xs", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { classNames: {
            wrapper: classes.inputWrapper,
            input: classes.buttonInput
          }, component: "button", type: "button", pointer: true, radius: "8px", rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { onClick: () => setIsRoleModalOpen(true), mr: "5px", children: /* @__PURE__ */ jsxRuntimeExports.jsx(XMe, { color: themeColors.brandGray[0] }) }), onClick: () => setIsRoleModalOpen(true), error: form.getInputProps("RoleId").error, children: t("roles.chooseRole") }),
          selectedRoles && /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Badges, { label: selectedRoles == null ? void 0 : selectedRoles.label, onRemove: handleRemoveRoles }) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(SelectGroupSimpleModal, { onClose: closeRoleModal, isOpened: isRoleModalOpen, title: t("roles.chooseRole"), setGroupId: setRoleId, setGroup: setRolesGroup, filial, ...form.getInputProps("RoleId") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(SelectQuotas, { form, fieldName: "QuotaId", quotaField: "QuotaName", value: form.values.QuotaId, Customer: filial == null ? void 0 : filial.Id, label: t("profile.selectDefaultQuota"), QuotaName: form.values.QuotaName, notClearable: true }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { classNames: {
          input: classes.checkInput,
          label: classes.checkLabel
        }, label: t("filials.diskSpace.massQuotaHint"), ...form.getInputProps("IsQuotaDown", {
          type: "checkbox"
        }) })
      ] }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.modalFooter, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", size: "sm", radius: 8, fullWidth: true, disabled: isDisabled, children: t("filials.diskSpace.assignQuotas") }) })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isLoading })
  ] });
};
const MassAddQuota = () => {
  const $ = compilerRuntimeExports.c(22);
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const [isModalOpened, setIsModalOpened] = reactExports.useState(false);
  const t0 = classes.section;
  const t1 = classes.title;
  let t2;
  if ($[0] !== t) {
    t2 = t("filials.diskSpace.massAddQuota");
    $[0] = t;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  let t3;
  if ($[2] !== classes.title || $[3] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t1, children: t2 });
    $[2] = classes.title;
    $[3] = t2;
    $[4] = t3;
  } else {
    t3 = $[4];
  }
  let t4;
  if ($[5] !== t) {
    t4 = t("filials.diskSpace.massQuotaRule");
    $[5] = t;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  let t5;
  if ($[7] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "14", c: "#667085", children: t4 });
    $[7] = t4;
    $[8] = t5;
  } else {
    t5 = $[8];
  }
  let t6;
  if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
    t6 = () => {
      setIsModalOpened(true);
    };
    $[9] = t6;
  } else {
    t6 = $[9];
  }
  let t7;
  if ($[10] !== t) {
    t7 = t("filials.diskSpace.assignQuotas");
    $[10] = t;
    $[11] = t7;
  } else {
    t7 = $[11];
  }
  let t8;
  if ($[12] !== t7) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "sm", mt: "sm", radius: 8, color: "green", px: "lg", onClick: t6, children: t7 });
    $[12] = t7;
    $[13] = t8;
  } else {
    t8 = $[13];
  }
  let t9;
  if ($[14] !== isModalOpened) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsx(MassAddQuotaForm, { isOpened: isModalOpened, setIsModalOpened });
    $[14] = isModalOpened;
    $[15] = t9;
  } else {
    t9 = $[15];
  }
  let t10;
  if ($[16] !== classes.section || $[17] !== t3 || $[18] !== t5 || $[19] !== t8 || $[20] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t0, "data-section": DriveInfoPanelsEnum.quotas, children: [
      t3,
      t5,
      t8,
      t9
    ] });
    $[16] = classes.section;
    $[17] = t3;
    $[18] = t5;
    $[19] = t8;
    $[20] = t9;
    $[21] = t10;
  } else {
    t10 = $[21];
  }
  return t10;
};
const CalculateQuota = () => {
  var _a, _b, _c;
  const $ = compilerRuntimeExports.c(69);
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const {
    filial
  } = useAppSelector(_temp$2);
  const saveSettings = useSaveSettings();
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      initialValues: {
        rule: QuotaRulesEnum.None
      }
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const form = useForm(t0);
  let t1;
  if ($[1] !== (filial == null ? void 0 : filial.Settings) || $[2] !== form) {
    t1 = () => {
      const {
        QuotaRules
      } = (filial == null ? void 0 : filial.Settings) || {};
      if (!QuotaRules) {
        return;
      }
      const formData = {
        rule: QuotaRules
      };
      form.setValues(formData);
      form.resetDirty(formData);
    };
    $[1] = filial == null ? void 0 : filial.Settings;
    $[2] = form;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  let t2;
  if ($[4] !== filial) {
    t2 = [filial];
    $[4] = filial;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  reactExports.useEffect(t1, t2);
  let t3;
  if ($[6] !== form) {
    t3 = (selectedValue) => {
      form.setFieldValue("rule", selectedValue);
    };
    $[6] = form;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  const handleChange = t3;
  let t4;
  if ($[8] !== filial || $[9] !== form || $[10] !== saveSettings) {
    t4 = () => {
      if (!filial) {
        return;
      }
      saveSettings(filial.Id, SettingsEnum.QuotaRules, {
        QuotaRules: form.values.rule
      });
      form.resetDirty();
    };
    $[8] = filial;
    $[9] = form;
    $[10] = saveSettings;
    $[11] = t4;
  } else {
    t4 = $[11];
  }
  const handleSubmit = t4;
  const errors = form.errors;
  let t5;
  if ($[12] !== form) {
    t5 = form.isDirty();
    $[12] = form;
    $[13] = t5;
  } else {
    t5 = $[13];
  }
  const isDirtyForm = t5;
  let t6;
  if ($[14] !== errors || $[15] !== isDirtyForm) {
    t6 = Object.keys(errors).length !== 0 || !isDirtyForm;
    $[14] = errors;
    $[15] = isDirtyForm;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  const isDisabled = t6;
  const t7 = classes.section;
  const t8 = classes.title;
  let t9;
  if ($[17] !== t) {
    t9 = t("filials.diskSpace.calculateQuotaTitle");
    $[17] = t;
    $[18] = t9;
  } else {
    t9 = $[18];
  }
  let t10;
  if ($[19] !== classes.title || $[20] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t8, children: t9 });
    $[19] = classes.title;
    $[20] = t9;
    $[21] = t10;
  } else {
    t10 = $[21];
  }
  const t11 = classes.radio;
  const t12 = ((_a = form == null ? void 0 : form.values) == null ? void 0 : _a.rule) === QuotaRulesEnum.Large;
  let t13;
  if ($[22] !== handleChange) {
    t13 = () => handleChange(QuotaRulesEnum.Large);
    $[22] = handleChange;
    $[23] = t13;
  } else {
    t13 = $[23];
  }
  let t14;
  if ($[24] !== t) {
    t14 = t("filials.diskSpace.bigQuota");
    $[24] = t;
    $[25] = t14;
  } else {
    t14 = $[25];
  }
  let t15;
  if ($[26] !== classes.radio || $[27] !== t12 || $[28] !== t13 || $[29] !== t14) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { className: t11, size: "xs", checked: t12, onChange: t13, label: t14 });
    $[26] = classes.radio;
    $[27] = t12;
    $[28] = t13;
    $[29] = t14;
    $[30] = t15;
  } else {
    t15 = $[30];
  }
  const t16 = classes.radio;
  const t17 = ((_b = form == null ? void 0 : form.values) == null ? void 0 : _b.rule) === QuotaRulesEnum.Lower;
  let t18;
  if ($[31] !== handleChange) {
    t18 = () => handleChange(QuotaRulesEnum.Lower);
    $[31] = handleChange;
    $[32] = t18;
  } else {
    t18 = $[32];
  }
  let t19;
  if ($[33] !== t) {
    t19 = t("filials.diskSpace.smallQuota");
    $[33] = t;
    $[34] = t19;
  } else {
    t19 = $[34];
  }
  let t20;
  if ($[35] !== classes.radio || $[36] !== t17 || $[37] !== t18 || $[38] !== t19) {
    t20 = /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { className: t16, size: "xs", checked: t17, onChange: t18, label: t19 });
    $[35] = classes.radio;
    $[36] = t17;
    $[37] = t18;
    $[38] = t19;
    $[39] = t20;
  } else {
    t20 = $[39];
  }
  const t21 = classes.radio;
  const t22 = ((_c = form == null ? void 0 : form.values) == null ? void 0 : _c.rule) === QuotaRulesEnum.Summary;
  let t23;
  if ($[40] !== handleChange) {
    t23 = () => handleChange(QuotaRulesEnum.Summary);
    $[40] = handleChange;
    $[41] = t23;
  } else {
    t23 = $[41];
  }
  let t24;
  if ($[42] !== t) {
    t24 = t("filials.diskSpace.sumQuota");
    $[42] = t;
    $[43] = t24;
  } else {
    t24 = $[43];
  }
  let t25;
  if ($[44] !== classes.radio || $[45] !== t22 || $[46] !== t23 || $[47] !== t24) {
    t25 = /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { className: t21, size: "xs", checked: t22, onChange: t23, label: t24 });
    $[44] = classes.radio;
    $[45] = t22;
    $[46] = t23;
    $[47] = t24;
    $[48] = t25;
  } else {
    t25 = $[48];
  }
  let t26;
  if ($[49] !== t) {
    t26 = t("filials.diskSpace.calculateQuotaInfo");
    $[49] = t;
    $[50] = t26;
  } else {
    t26 = $[50];
  }
  let t27;
  if ($[51] !== t26) {
    t27 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "14", c: "#667085", mt: "10px", children: t26 });
    $[51] = t26;
    $[52] = t27;
  } else {
    t27 = $[52];
  }
  let t28;
  if ($[53] !== handleSubmit) {
    t28 = () => {
      handleSubmit();
    };
    $[53] = handleSubmit;
    $[54] = t28;
  } else {
    t28 = $[54];
  }
  let t29;
  if ($[55] !== t) {
    t29 = t("save");
    $[55] = t;
    $[56] = t29;
  } else {
    t29 = $[56];
  }
  let t30;
  if ($[57] !== isDisabled || $[58] !== t28 || $[59] !== t29) {
    t30 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "sm", mt: "sm", radius: 8, px: "40px", type: "submit", disabled: isDisabled, onClick: t28, children: t29 });
    $[57] = isDisabled;
    $[58] = t28;
    $[59] = t29;
    $[60] = t30;
  } else {
    t30 = $[60];
  }
  let t31;
  if ($[61] !== classes.section || $[62] !== t10 || $[63] !== t15 || $[64] !== t20 || $[65] !== t25 || $[66] !== t27 || $[67] !== t30) {
    t31 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t7, "data-section": DriveInfoPanelsEnum.quotas, children: [
      t10,
      t15,
      t20,
      t25,
      t27,
      t30
    ] });
    $[61] = classes.section;
    $[62] = t10;
    $[63] = t15;
    $[64] = t20;
    $[65] = t25;
    $[66] = t27;
    $[67] = t30;
    $[68] = t31;
  } else {
    t31 = $[68];
  }
  return t31;
};
function _temp$2(state) {
  return state.filials;
}
const DOC_VERSION_LIMIT_DEFAULT = 99;
const DOC_VERSION_LIMIT_MIN = 1;
const DOC_VERSION_LIMIT_MAX = 9999;
const DocVersionsLimit = () => {
  var _a, _b;
  const $ = compilerRuntimeExports.c(48);
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const {
    filial
  } = useAppSelector(_temp$1);
  const saveSettings = useSaveSettings();
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      limit: DOC_VERSION_LIMIT_DEFAULT
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  let t1;
  if ($[1] !== t) {
    t1 = {
      initialValues: t0,
      validate: {
        limit: (value) => value < DOC_VERSION_LIMIT_MIN || value > DOC_VERSION_LIMIT_MAX ? t("filials.diskSpace.docVersionsLimit.validationError", {
          min: DOC_VERSION_LIMIT_MIN,
          max: DOC_VERSION_LIMIT_MAX
        }) : null
      }
    };
    $[1] = t;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const form = useForm(t1);
  let t2;
  if ($[3] !== ((_a = filial == null ? void 0 : filial.Settings) == null ? void 0 : _a.DocVersionsLimit) || $[4] !== form) {
    t2 = () => {
      var _a2;
      const limit = ((_a2 = filial == null ? void 0 : filial.Settings) == null ? void 0 : _a2.DocVersionsLimit) ?? DOC_VERSION_LIMIT_DEFAULT;
      const formData = {
        limit
      };
      form.setValues(formData);
      form.resetDirty(formData);
    };
    $[3] = (_b = filial == null ? void 0 : filial.Settings) == null ? void 0 : _b.DocVersionsLimit;
    $[4] = form;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  let t3;
  if ($[6] !== filial) {
    t3 = [filial];
    $[6] = filial;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  reactExports.useEffect(t2, t3);
  let t4;
  if ($[8] !== filial || $[9] !== form || $[10] !== saveSettings) {
    t4 = () => {
      if (!filial) {
        return;
      }
      saveSettings(filial.Id, SettingsEnum.DocVersionsLimit, {
        DocVersionsLimit: form.values.limit
      });
      form.resetDirty();
    };
    $[8] = filial;
    $[9] = form;
    $[10] = saveSettings;
    $[11] = t4;
  } else {
    t4 = $[11];
  }
  const handleSubmit = t4;
  const errors = form.errors;
  let t5;
  if ($[12] !== form) {
    t5 = form.isDirty();
    $[12] = form;
    $[13] = t5;
  } else {
    t5 = $[13];
  }
  const isDirty = t5;
  let t6;
  if ($[14] !== errors || $[15] !== isDirty) {
    t6 = Object.keys(errors).length !== 0 || !isDirty;
    $[14] = errors;
    $[15] = isDirty;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  const isDisabled = t6;
  const t7 = classes.section;
  const t8 = classes.title;
  let t9;
  if ($[17] !== t) {
    t9 = t("filials.diskSpace.docVersionsLimit.title");
    $[17] = t;
    $[18] = t9;
  } else {
    t9 = $[18];
  }
  let t10;
  if ($[19] !== classes.title || $[20] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t8, children: t9 });
    $[19] = classes.title;
    $[20] = t9;
    $[21] = t10;
  } else {
    t10 = $[21];
  }
  let t11;
  if ($[22] !== t) {
    t11 = t("filials.diskSpace.docVersionsLimit.label");
    $[22] = t;
    $[23] = t11;
  } else {
    t11 = $[23];
  }
  let t12;
  if ($[24] !== form) {
    t12 = (value_0) => form.setFieldValue("limit", Number(value_0));
    $[24] = form;
    $[25] = t12;
  } else {
    t12 = $[25];
  }
  let t13;
  if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
    t13 = {
      maxWidth: "160px"
    };
    $[26] = t13;
  } else {
    t13 = $[26];
  }
  let t14;
  if ($[27] !== form.errors.limit || $[28] !== form.values.limit || $[29] !== t11 || $[30] !== t12) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { label: t11, value: form.values.limit, onChange: t12, min: DOC_VERSION_LIMIT_MIN, max: DOC_VERSION_LIMIT_MAX, allowDecimal: false, allowNegative: false, error: form.errors.limit, style: t13, mb: "sm" });
    $[27] = form.errors.limit;
    $[28] = form.values.limit;
    $[29] = t11;
    $[30] = t12;
    $[31] = t14;
  } else {
    t14 = $[31];
  }
  let t15;
  if ($[32] !== t) {
    t15 = t("filials.diskSpace.docVersionsLimit.description");
    $[32] = t;
    $[33] = t15;
  } else {
    t15 = $[33];
  }
  let t16;
  if ($[34] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "14", c: "#667085", mb: "sm", children: t15 });
    $[34] = t15;
    $[35] = t16;
  } else {
    t16 = $[35];
  }
  let t17;
  if ($[36] !== t) {
    t17 = t("save");
    $[36] = t;
    $[37] = t17;
  } else {
    t17 = $[37];
  }
  let t18;
  if ($[38] !== handleSubmit || $[39] !== isDisabled || $[40] !== t17) {
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "sm", mt: "sm", radius: 8, px: "40px", disabled: isDisabled, onClick: handleSubmit, children: t17 });
    $[38] = handleSubmit;
    $[39] = isDisabled;
    $[40] = t17;
    $[41] = t18;
  } else {
    t18 = $[41];
  }
  let t19;
  if ($[42] !== classes.section || $[43] !== t10 || $[44] !== t14 || $[45] !== t16 || $[46] !== t18) {
    t19 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t7, "data-section": DriveInfoPanelsEnum.filialQuota, children: [
      t10,
      t14,
      t16,
      t18
    ] });
    $[42] = classes.section;
    $[43] = t10;
    $[44] = t14;
    $[45] = t16;
    $[46] = t18;
    $[47] = t19;
  } else {
    t19 = $[47];
  }
  return t19;
};
function _temp$1(state) {
  return state.filials;
}
const DiskSpasePage = () => {
  const $ = compilerRuntimeExports.c(6);
  const {
    classes
  } = useStyles();
  const {
    filial
  } = useAppSelector(_temp);
  const currentUser = useAppSelector(_temp2);
  let t0;
  if ($[0] !== classes || $[1] !== currentUser || $[2] !== filial) {
    t0 = filial && /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: classes.container, direction: "column", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(DocVersionsLimit, {}),
      /* @__PURE__ */ jsxRuntimeExports.jsx(FilialQuota, { filial }),
      isSuperAdmin(currentUser) && /* @__PURE__ */ jsxRuntimeExports.jsx(FilialStorage, { filial }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(UsersQuotaList, { filial }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(CalculateQuota, {}),
      /* @__PURE__ */ jsxRuntimeExports.jsx(MassAddQuota, {})
    ] });
    $[0] = classes;
    $[1] = currentUser;
    $[2] = filial;
    $[3] = t0;
  } else {
    t0 = $[3];
  }
  let t1;
  if ($[4] !== t0) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(ErrorBoundary, { componentTitle: "Disk space section", children: t0 });
    $[4] = t0;
    $[5] = t1;
  } else {
    t1 = $[5];
  }
  return t1;
};
function _temp(state) {
  return state.filials;
}
function _temp2(state_0) {
  return state_0.userInfo.User;
}
export {
  DiskSpasePage as default
};
//# sourceMappingURL=index-DLeCAHzh.js.map
