import { E as compilerRuntimeExports, j as jsxRuntimeExports, T as useNavigate, r as reactExports, L as Link } from "./vendor-react-DYNCg6N5.js";
import { e as IconCircleCheckFilled, f as IconAlertTriangleFilled, h as iRe, D as DR, j as GV, k as zte, x as xN } from "./vendor-icons-xWhXK_Ui.js";
import { a9 as FilialInfoPanelsEnum, a4 as useHomeWidgetSlice, R as ROUTES, c as useAppSelector } from "./index-DfebxkL9.js";
import { C as CreateUserModal } from "./index-C7llsr9G.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { c as createStyles, T as Text, F as Flex, b as Box, O as Badge, n as useDisclosure, S as Stack, a1 as Progress, g as Loader, B as Button, K as Divider } from "./vendor-mantine-h0WlM2Mj.js";
import { a as formatDataSizeUnits } from "./format-CMT-x-V3.js";
import { m as modalTheme } from "./styles-3NoIlzov.js";
import { M as Modal } from "./index-DqcA8P_y.js";
const useStyles$4 = createStyles((_, __, utils) => ({
  container: {
    backgroundColor: "white",
    padding: "20px 24px 24px 24px",
    borderRadius: "16px",
    border: "1px solid #F1F3F5",
    "& svg.icon-tabler *": {
      vectorEffect: "non-scaling-stroke"
    }
  },
  fixedWidth: {
    width: "340px",
    [utils.smallerThan("xs")]: {
      width: "100%"
    }
  }
}));
const CardContainer = (t0) => {
  const $ = compilerRuntimeExports.c(16);
  const {
    sectionName,
    Icon,
    children,
    subscriptionPage
  } = t0;
  const {
    classes,
    cx
  } = useStyles$4();
  let t1;
  if ($[0] !== classes.container || $[1] !== classes.fixedWidth || $[2] !== cx || $[3] !== subscriptionPage) {
    t1 = cx(classes.container, {
      [classes.fixedWidth]: subscriptionPage
    });
    $[0] = classes.container;
    $[1] = classes.fixedWidth;
    $[2] = cx;
    $[3] = subscriptionPage;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  let t2;
  if ($[5] !== sectionName) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "lg", fw: "500", children: sectionName });
    $[5] = sectionName;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  let t3;
  if ($[7] !== Icon) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { size: 24, color: "#A4B0C2", strokeWidth: "1.5" });
    $[7] = Icon;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  let t4;
  if ($[9] !== t2 || $[10] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", align: "center", mb: "18px", children: [
      t2,
      t3
    ] });
    $[9] = t2;
    $[10] = t3;
    $[11] = t4;
  } else {
    t4 = $[11];
  }
  let t5;
  if ($[12] !== children || $[13] !== t1 || $[14] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t1, "data-name": "card-container", children: [
      t4,
      children
    ] });
    $[12] = children;
    $[13] = t1;
    $[14] = t4;
    $[15] = t5;
  } else {
    t5 = $[15];
  }
  return t5;
};
const useStyles$3 = createStyles(() => ({
  itemName: {
    fontSize: "14px",
    color: "#848E98"
  },
  interactiveItemName: {
    cursor: "pointer",
    "&:hover": {
      color: "#339AF0",
      textDecoration: "underline"
    }
  },
  badgeRoot: {
    textTransform: "none",
    fontSize: "12px",
    fontWeight: 400,
    lineHeight: "18px",
    borderRadius: "16px",
    padding: `0px 6px`,
    backgroundColor: "#D0EBFF"
  },
  badgeInner: {
    color: "#228BE6",
    fontSize: "10px",
    fontWeight: 500
  }
}));
const ListItem = (t0) => {
  const $ = compilerRuntimeExports.c(16);
  const {
    withCheck,
    items
  } = t0;
  const navigate = useNavigate();
  const {
    classes,
    cx
  } = useStyles$3();
  const {
    t
  } = useTranslation();
  let t1;
  if ($[0] !== navigate || $[1] !== t) {
    t1 = async (t22) => {
      const {
        link,
        name,
        openModal
      } = t22;
      if (link) {
        scrollTo(0, 0);
        navigate(link);
      }
      if (openModal) {
        openModal();
      }
      if (name === t("filialSecurity.passwordSecurity") && link) {
        const checkElement = () => {
          const element = document.querySelector(`[data-section=${FilialInfoPanelsEnum.passwordLimit}]`);
          if (element) {
            element.scrollIntoView({
              behavior: "smooth"
            });
          } else {
            setTimeout(checkElement, 100);
          }
        };
        setTimeout(checkElement, 100);
      }
    };
    $[0] = navigate;
    $[1] = t;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const handleRedirect = t1;
  let t2;
  if ($[3] !== classes || $[4] !== cx || $[5] !== handleRedirect || $[6] !== items || $[7] !== withCheck) {
    let t32;
    if ($[9] !== classes || $[10] !== cx || $[11] !== handleRedirect || $[12] !== withCheck) {
      t32 = (item, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", align: "center", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { onClick: () => handleRedirect(item), className: cx(classes.itemName, {
          [classes.interactiveItemName]: Boolean(item.link || item.openModal)
        }), children: item.name }),
        withCheck ? item.valid ? /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { sx: {
          color: "#51CF66"
        }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconCircleCheckFilled, { size: 22 }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { sx: {
          color: "#FA5252"
        }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconAlertTriangleFilled, { fill: "red", size: "22" }) }) : null,
        item.badge ? /* @__PURE__ */ jsxRuntimeExports.jsx(Badge, { classNames: {
          root: classes.badgeRoot,
          label: classes.badgeInner
        }, variant: "filled", children: item.badge }) : null
      ] }, index);
      $[9] = classes;
      $[10] = cx;
      $[11] = handleRedirect;
      $[12] = withCheck;
      $[13] = t32;
    } else {
      t32 = $[13];
    }
    t2 = items.map(t32);
    $[3] = classes;
    $[4] = cx;
    $[5] = handleRedirect;
    $[6] = items;
    $[7] = withCheck;
    $[8] = t2;
  } else {
    t2 = $[8];
  }
  let t3;
  if ($[14] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: t2 });
    $[14] = t2;
    $[15] = t3;
  } else {
    t3 = $[15];
  }
  return t3;
};
const UsersSection = ({
  filialId,
  subscriptionPage
}) => {
  const {
    t
  } = useTranslation();
  const [opened, {
    open,
    close
  }] = useDisclosure(false);
  const [{
    data
  }] = useHomeWidgetSlice().useUsersWidget().useState();
  const {
    LoadUsersSection
  } = useHomeWidgetSlice().actions;
  reactExports.useEffect(() => {
    LoadUsersSection(filialId);
  }, []);
  const usersMenu = {
    withCheck: false,
    items: [{
      name: t("users.list"),
      link: ROUTES.users.path,
      badge: data == null ? void 0 : data.TotalCount
    }, {
      name: t("filials.modules.addUser"),
      openModal: open
    }, {
      name: t("filials.linkInvite"),
      link: `${ROUTES.filials.edit.clearPath}/${filialId}/${ROUTES.filials.edit.pages.auth.invite}`
    }]
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(CardContainer, { sectionName: t("navigation.users"), Icon: iRe, subscriptionPage, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Stack, { gap: "11px", sx: {
      width: "100%"
    }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ListItem, { items: usersMenu.items, withCheck: usersMenu.withCheck }) }) }),
    opened && /* @__PURE__ */ jsxRuntimeExports.jsx(CreateUserModal, { opened, modalClose: close, onSuccess: () => LoadUsersSection(filialId || 0) })
  ] });
};
const useStyles$2 = createStyles(() => ({
  bar: {
    background: "linear-gradient(90deg, #4DABF7, #CC5DE8)"
  }
}));
const ProgressBar = (t0) => {
  const $ = compilerRuntimeExports.c(21);
  const {
    quotaDetails: t1
  } = t0;
  let t2;
  if ($[0] !== t1) {
    t2 = t1 === void 0 ? {} : t1;
    $[0] = t1;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const {
    QuotaSize,
    UsedSize
  } = t2;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles$2();
  const progressValue = QuotaSize && UsedSize && QuotaSize > 0 ? UsedSize / QuotaSize * 100 : 0;
  const displayValue = QuotaSize === 0 ? UsedSize !== 0 ? 100 : 0 : progressValue;
  let t3;
  if ($[2] !== classes.bar) {
    t3 = {
      section: classes.bar
    };
    $[2] = classes.bar;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  let t4;
  if ($[4] !== displayValue || $[5] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(Progress, { size: "xl", value: displayValue, classNames: t3, radius: "16px" });
    $[4] = displayValue;
    $[5] = t3;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  let t5;
  if ($[7] !== t) {
    t5 = t("filials.diskSpace.table.used");
    $[7] = t;
    $[8] = t5;
  } else {
    t5 = $[8];
  }
  let t6;
  if ($[9] !== UsedSize) {
    t6 = formatDataSizeUnits(UsedSize);
    $[9] = UsedSize;
    $[10] = t6;
  } else {
    t6 = $[10];
  }
  let t7;
  if ($[11] !== QuotaSize || $[12] !== t) {
    t7 = QuotaSize === 0 ? "" : ` ${t("statistics.from")} ${formatDataSizeUnits(QuotaSize)}`;
    $[11] = QuotaSize;
    $[12] = t;
    $[13] = t7;
  } else {
    t7 = $[13];
  }
  let t8;
  if ($[14] !== t5 || $[15] !== t6 || $[16] !== t7) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { fz: "12px", c: "#848E98", mt: "4px", children: [
      t5,
      " ",
      t6,
      t7
    ] });
    $[14] = t5;
    $[15] = t6;
    $[16] = t7;
    $[17] = t8;
  } else {
    t8 = $[17];
  }
  let t9;
  if ($[18] !== t4 || $[19] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { mb: "16px", children: [
      t4,
      t8
    ] });
    $[18] = t4;
    $[19] = t8;
    $[20] = t9;
  } else {
    t9 = $[20];
  }
  return t9;
};
const DiskSpaceSection = ({
  filialId,
  subscriptionPage
}) => {
  const {
    t
  } = useTranslation();
  const [{
    data: quotaData,
    isLoading
  }] = useHomeWidgetSlice().useDiskSpaceWidget().useState();
  const {
    LoadDiskSpaceSection
  } = useHomeWidgetSlice().actions;
  reactExports.useEffect(() => {
    LoadDiskSpaceSection(filialId);
  }, []);
  const diskSpaceMenu = {
    withCheck: false,
    items: [{
      name: t("filials.diskSpace.diskConfig"),
      link: `${ROUTES.filials.edit.clearPath}/${filialId}/${ROUTES.filials.edit.pages.common.diskSpace}`
    }, {
      name: t("navigation.statistics"),
      link: `${ROUTES.statistics.fullPath}/${ROUTES.statistics.links.diskSpace}`
    }]
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(CardContainer, { sectionName: t("statistics.disk_space"), Icon: DR, subscriptionPage, children: isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "100%", align: "center", justify: "center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "sm" }) }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(ProgressBar, { quotaDetails: quotaData }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Stack, { gap: "11px", sx: {
      width: "100%"
    }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ListItem, { items: diskSpaceMenu.items, withCheck: diskSpaceMenu.withCheck }) })
  ] }) });
};
const GB = 1024;
const formatAmount = (amount) => {
  const formattedAmount = Number.isInteger(amount) ? amount : amount.toFixed(2);
  return +formattedAmount < 1 ? `${formattedAmount} Мб` : `${formattedAmount} Гб`;
};
const capitalizeFirstLetter = (name) => {
  if (name) {
    return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
  }
};
const useStyles$1 = createStyles((theme) => ({
  modalRoot: modalTheme(theme).root,
  modalContainer: modalTheme(theme).container,
  boxContainer: {
    border: "4px solid #FF6B6B",
    borderRadius: "8px",
    padding: "8px 16px 16px 16px"
  },
  spaceBox: {
    display: "flex",
    alignItems: "center",
    backgroundColor: "#FFF5F5",
    borderRadius: "13px",
    padding: "3px 8px 3px 3px",
    maxWidth: "fit-content"
  },
  infoBox: {
    padding: "6px",
    display: "flex",
    cursor: "pointer",
    backgroundColor: "#FFF5F5",
    borderRadius: "13px"
  },
  infoGroup: {
    color: "#848E98"
  }
}));
const ExpiredPayment = (t0) => {
  const $ = compilerRuntimeExports.c(85);
  const {
    usedSpace,
    link
  } = t0;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles$1();
  const [openModal, setOpenModal] = reactExports.useState(false);
  const [usedAmmount, setUsedAmmount] = reactExports.useState("");
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = () => {
      setOpenModal(false);
    };
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const handleCloseModal = t1;
  const getUsedSpace = _temp;
  let t2;
  let t3;
  if ($[1] !== usedSpace) {
    t2 = () => {
      if (!usedSpace) {
        setUsedAmmount("0");
      }
      if (usedSpace) {
        setUsedAmmount(getUsedSpace(usedSpace));
      }
    };
    t3 = [usedSpace];
    $[1] = usedSpace;
    $[2] = t2;
    $[3] = t3;
  } else {
    t2 = $[2];
    t3 = $[3];
  }
  reactExports.useEffect(t2, t3);
  const t4 = classes.boxContainer;
  let t5;
  if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = {
      textAlign: "center"
    };
    $[4] = t5;
  } else {
    t5 = $[4];
  }
  let t6;
  if ($[5] !== t) {
    t6 = t("filials.diskSpace.expiredPayment");
    $[5] = t;
    $[6] = t6;
  } else {
    t6 = $[6];
  }
  let t7;
  if ($[7] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", fw: "500", sx: t5, children: t6 });
    $[7] = t6;
    $[8] = t7;
  } else {
    t7 = $[8];
  }
  let t8;
  if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
    t8 = {
      textAlign: "center"
    };
    $[9] = t8;
  } else {
    t8 = $[9];
  }
  let t9;
  if ($[10] !== t) {
    t9 = t("filials.diskSpace.warning");
    $[10] = t;
    $[11] = t9;
  } else {
    t9 = $[11];
  }
  let t10;
  if ($[12] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { sx: t8, fz: "xs", c: "#848E98", children: t9 });
    $[12] = t9;
    $[13] = t10;
  } else {
    t10 = $[13];
  }
  let t11;
  if ($[14] !== t10 || $[15] !== t7) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { direction: "column", gap: "8px", py: "8px", children: [
      t7,
      t10
    ] });
    $[14] = t10;
    $[15] = t7;
    $[16] = t11;
  } else {
    t11 = $[16];
  }
  const t12 = classes.spaceBox;
  let t13;
  if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
    t13 = /* @__PURE__ */ jsxRuntimeExports.jsx(GV, { size: 20, color: "#FF6B6B", stroke: 1.5 });
    $[17] = t13;
  } else {
    t13 = $[17];
  }
  let t14;
  if ($[18] !== t) {
    t14 = t("filials.diskSpace.usedSpace");
    $[18] = t;
    $[19] = t14;
  } else {
    t14 = $[19];
  }
  let t15;
  if ($[20] !== t14 || $[21] !== usedAmmount) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { ml: "2px", c: "#FF6B6B", fz: "xs", children: [
      t14,
      " ",
      usedAmmount
    ] });
    $[20] = t14;
    $[21] = usedAmmount;
    $[22] = t15;
  } else {
    t15 = $[22];
  }
  let t16;
  if ($[23] !== classes.spaceBox || $[24] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t12, children: [
      t13,
      t15
    ] });
    $[23] = classes.spaceBox;
    $[24] = t15;
    $[25] = t16;
  } else {
    t16 = $[25];
  }
  let t17;
  let t18;
  if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
    t17 = () => setOpenModal(true);
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsx(zte, { size: 14, color: "#FF6B6B", stroke: 1.5 });
    $[26] = t17;
    $[27] = t18;
  } else {
    t17 = $[26];
    t18 = $[27];
  }
  let t19;
  if ($[28] !== classes.infoBox) {
    t19 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.infoBox, onClick: t17, children: t18 });
    $[28] = classes.infoBox;
    $[29] = t19;
  } else {
    t19 = $[29];
  }
  let t20;
  if ($[30] !== t16 || $[31] !== t19) {
    t20 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", align: "center", children: [
      t16,
      t19
    ] });
    $[30] = t16;
    $[31] = t19;
    $[32] = t20;
  } else {
    t20 = $[32];
  }
  let t21;
  if ($[33] !== t11 || $[34] !== t20) {
    t21 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { gap: "8px", children: [
      t11,
      t20
    ] });
    $[33] = t11;
    $[34] = t20;
    $[35] = t21;
  } else {
    t21 = $[35];
  }
  let t22;
  if ($[36] !== t) {
    t22 = t("filials.expiredTitle");
    $[36] = t;
    $[37] = t22;
  } else {
    t22 = $[37];
  }
  const t23 = classes.modalRoot;
  const t24 = classes.modalContainer;
  const t25 = classes.infoGroup;
  let t26;
  if ($[38] !== t) {
    t26 = t("filials.expiredInfo1");
    $[38] = t;
    $[39] = t26;
  } else {
    t26 = $[39];
  }
  let t27;
  if ($[40] !== t26) {
    t27 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t26 });
    $[40] = t26;
    $[41] = t27;
  } else {
    t27 = $[41];
  }
  let t28;
  if ($[42] !== t) {
    t28 = t("filials.expiredSubtitle1");
    $[42] = t;
    $[43] = t28;
  } else {
    t28 = $[43];
  }
  let t29;
  if ($[44] !== t28) {
    t29 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: "500", c: "#343A40", children: t28 });
    $[44] = t28;
    $[45] = t29;
  } else {
    t29 = $[45];
  }
  let t30;
  if ($[46] !== t) {
    t30 = t("filials.expiredInfo2");
    $[46] = t;
    $[47] = t30;
  } else {
    t30 = $[47];
  }
  let t31;
  if ($[48] !== t30) {
    t31 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t30 });
    $[48] = t30;
    $[49] = t31;
  } else {
    t31 = $[49];
  }
  let t32;
  if ($[50] !== t) {
    t32 = t("filials.expiredSubtitle2");
    $[50] = t;
    $[51] = t32;
  } else {
    t32 = $[51];
  }
  let t33;
  if ($[52] !== t32) {
    t33 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: "500", c: "#343A40", children: t32 });
    $[52] = t32;
    $[53] = t33;
  } else {
    t33 = $[53];
  }
  let t34;
  if ($[54] !== t) {
    t34 = t("filials.expiredInfo3");
    $[54] = t;
    $[55] = t34;
  } else {
    t34 = $[55];
  }
  let t35;
  if ($[56] !== t34) {
    t35 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t34 });
    $[56] = t34;
    $[57] = t35;
  } else {
    t35 = $[57];
  }
  let t36;
  if ($[58] !== classes.infoGroup || $[59] !== t27 || $[60] !== t29 || $[61] !== t31 || $[62] !== t33 || $[63] !== t35) {
    t36 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { gap: "10px", className: t25, children: [
      t27,
      t29,
      t31,
      t33,
      t35
    ] });
    $[58] = classes.infoGroup;
    $[59] = t27;
    $[60] = t29;
    $[61] = t31;
    $[62] = t33;
    $[63] = t35;
    $[64] = t36;
  } else {
    t36 = $[64];
  }
  const t37 = link ?? "#";
  let t38;
  if ($[65] !== t) {
    t38 = t("filials.diskSpace.activateTariff");
    $[65] = t;
    $[66] = t38;
  } else {
    t38 = $[66];
  }
  let t39;
  if ($[67] !== t37 || $[68] !== t38) {
    t39 = /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "100%", justify: "flex-end", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { mt: "16px", fw: "500", component: Link, target: "_self", to: t37, radius: "8px", children: t38 }) });
    $[67] = t37;
    $[68] = t38;
    $[69] = t39;
  } else {
    t39 = $[69];
  }
  let t40;
  if ($[70] !== classes.modalContainer || $[71] !== t36 || $[72] !== t39) {
    t40 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t24, children: [
      t36,
      t39
    ] });
    $[70] = classes.modalContainer;
    $[71] = t36;
    $[72] = t39;
    $[73] = t40;
  } else {
    t40 = $[73];
  }
  let t41;
  if ($[74] !== classes.modalRoot || $[75] !== t40) {
    t41 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: t23, children: t40 });
    $[74] = classes.modalRoot;
    $[75] = t40;
    $[76] = t41;
  } else {
    t41 = $[76];
  }
  let t42;
  if ($[77] !== openModal || $[78] !== t22 || $[79] !== t41) {
    t42 = /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { size: "lg", title: t22, opened: openModal, onClose: handleCloseModal, children: t41 });
    $[77] = openModal;
    $[78] = t22;
    $[79] = t41;
    $[80] = t42;
  } else {
    t42 = $[80];
  }
  let t43;
  if ($[81] !== classes.boxContainer || $[82] !== t21 || $[83] !== t42) {
    t43 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t4, children: [
      t21,
      t42
    ] });
    $[81] = classes.boxContainer;
    $[82] = t21;
    $[83] = t42;
    $[84] = t43;
  } else {
    t43 = $[84];
  }
  return t43;
};
function _temp(amount) {
  const currentAmount = amount / GB;
  return formatAmount(currentAmount);
}
const useStyles = createStyles(() => ({
  boxContainer: {
    borderRadius: "8px",
    padding: "16px 16px 16px 24px",
    marginBottom: "16px"
  },
  divider: {
    color: "#A2B0C359",
    margin: "0 16px"
  },
  dateBox: {
    display: "inline-block",
    lineHeight: "40px"
  }
}));
const ValidPayment = (t0) => {
  const $ = compilerRuntimeExports.c(24);
  const {
    name,
    remainingDays
  } = t0;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const borderColor = remainingDays > 5 ? "#74C0FC" : "#FCC419";
  const t1 = `4px solid ${borderColor}`;
  let t2;
  if ($[0] !== t1) {
    t2 = {
      border: t1
    };
    $[0] = t1;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const t3 = classes.boxContainer;
  const t4 = remainingDays >= 30 ? "center" : "space-between";
  const t5 = remainingDays >= 30 ? "100%" : "60%";
  let t6;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t6 = {
      textAlign: "center"
    };
    $[2] = t6;
  } else {
    t6 = $[2];
  }
  let t7;
  if ($[3] !== t) {
    t7 = t("filials.diskSpace.plan");
    $[3] = t;
    $[4] = t7;
  } else {
    t7 = $[4];
  }
  let t8;
  if ($[5] !== name) {
    t8 = capitalizeFirstLetter(name);
    $[5] = name;
    $[6] = t8;
  } else {
    t8 = $[6];
  }
  let t9;
  if ($[7] !== t5 || $[8] !== t7 || $[9] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { fz: "sm", fw: "500", w: t5, sx: t6, children: [
      t7,
      " «",
      t8,
      "»"
    ] });
    $[7] = t5;
    $[8] = t7;
    $[9] = t8;
    $[10] = t9;
  } else {
    t9 = $[10];
  }
  let t10;
  if ($[11] !== classes.dateBox || $[12] !== classes.divider || $[13] !== remainingDays || $[14] !== t) {
    t10 = remainingDays < 30 && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Divider, { orientation: "vertical", size: "xs", className: classes.divider }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", direction: "column", gap: "8px", w: "40%", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "10px", fw: "500", c: "#848E98", sx: {
          lineHeight: "10px",
          transform: "uppercase"
        }, children: t("filials.diskSpace.remainingDays") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "56px", fw: "500", className: classes.dateBox, children: remainingDays })
      ] })
    ] });
    $[11] = classes.dateBox;
    $[12] = classes.divider;
    $[13] = remainingDays;
    $[14] = t;
    $[15] = t10;
  } else {
    t10 = $[15];
  }
  let t11;
  if ($[16] !== t10 || $[17] !== t4 || $[18] !== t9) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", justify: t4, children: [
      t9,
      t10
    ] });
    $[16] = t10;
    $[17] = t4;
    $[18] = t9;
    $[19] = t11;
  } else {
    t11 = $[19];
  }
  let t12;
  if ($[20] !== classes.boxContainer || $[21] !== t11 || $[22] !== t2) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { sx: t2, className: t3, children: t11 });
    $[20] = classes.boxContainer;
    $[21] = t11;
    $[22] = t2;
    $[23] = t12;
  } else {
    t12 = $[23];
  }
  return t12;
};
const PaymentSection = ({
  subscriptionPage,
  filialId,
  paymentsDate
}) => {
  var _a;
  const {
    t
  } = useTranslation();
  const [{
    data,
    isLoading
  }] = useHomeWidgetSlice().usePaymentWidget().useState();
  const {
    LoadPaymentSection
  } = useHomeWidgetSlice().actions;
  const modules = useAppSelector((state) => {
    var _a2, _b;
    return (_b = (_a2 = state.userInfo.Settings) == null ? void 0 : _a2.ModuleSettings) == null ? void 0 : _b.ModuleUrls;
  });
  reactExports.useEffect(() => {
    LoadPaymentSection({
      id: filialId,
      paymentsDate
    });
  }, [paymentsDate]);
  const paymentModule = Array.isArray(modules) ? modules.find((module) => module.Name === "Payments") : void 0;
  const PayLink = paymentModule == null ? void 0 : paymentModule.Url;
  const isPayedTariff = () => {
    var _a2;
    return ((_a2 = data == null ? void 0 : data.Tariff) == null ? void 0 : _a2.Type) !== -1;
  };
  const isExpiredPayment = () => {
    const tariffDate = (data == null ? void 0 : data.Date) ? new Date(data.Date) : /* @__PURE__ */ new Date();
    return tariffDate <= /* @__PURE__ */ new Date();
  };
  const getUserCount = () => {
    var _a2;
    if (!((_a2 = data == null ? void 0 : data.UserCounter) == null ? void 0 : _a2.PossibleAmount)) return 0;
    return `${data.UserCounter.CurrentAmount} / ${data.UserCounter.PossibleAmount}`;
  };
  const calculateDaysRemaining = (expiringDate) => {
    if (!expiringDate) return 0;
    const currentDate = /* @__PURE__ */ new Date();
    const futureDate = new Date(expiringDate);
    const timeDifference = futureDate.getTime() - currentDate.getTime();
    return Math.ceil(timeDifference / (1e3 * 60 * 60 * 24));
  };
  const remainingDays = calculateDaysRemaining(data == null ? void 0 : data.Date);
  const isExpired = isExpiredPayment();
  if (isLoading) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx(CardContainer, { sectionName: t("filials.payments"), Icon: xN, subscriptionPage, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "100%", align: "center", justify: "center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "sm" }) }) });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(CardContainer, { sectionName: t("filials.payments"), Icon: xN, subscriptionPage, children: [
    isExpired && /* @__PURE__ */ jsxRuntimeExports.jsx(ExpiredPayment, { usedSpace: data == null ? void 0 : data.DiskCounter.CurrentAmount, link: PayLink }),
    !isExpired && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(ValidPayment, { name: data == null ? void 0 : data.Name, remainingDays }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { gap: "4px", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", c: "#848E98", children: t("filials.diskSpace.validity") }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", fw: "500", children: isPayedTariff() ? (data == null ? void 0 : data.Date) ? `${t("filials.diskSpace.to")} ${new Date(data.Date).toLocaleDateString("ru-RU")}` : "" : t("filials.diskSpace.unlimited") })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", c: "#848E98", children: t("filials.diskSpace.usersNumber") }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", fw: "500", children: isPayedTariff() ? getUserCount() : ((_a = data == null ? void 0 : data.UserCounter) == null ? void 0 : _a.CurrentAmount) || 1 })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { w: "100%", mt: "16px", fw: "500", component: Link, target: !subscriptionPage ? "_blank" : "_self", to: PayLink ?? "#", radius: "4px", children: remainingDays > 30 ? t("change") : t("filials.diskSpace.activateTariff") })
  ] });
};
export {
  CardContainer as C,
  DiskSpaceSection as D,
  ListItem as L,
  PaymentSection as P,
  UsersSection as U
};
//# sourceMappingURL=index-BIbihtfI.js.map
