import { E as compilerRuntimeExports, j as jsxRuntimeExports, r as reactExports, T as useNavigate, a1 as NavLink, a as r } from "./vendor-react-DYNCg6N5.js";
import { aY as defaultIcon, aZ as defaultIcon$1, c as useAppSelector, a_ as useLazyCheckDomainQuery, a$ as useLazyAddDomainQuery, b0 as useLazyGetLinkRecordQuery, aV as EditIcon, b1 as useLazyDomainSettingsQuery, b2 as useLazyDeleteDomainQuery, b3 as useLazyGetDomainsQuery, b4 as useLazyDeleteEmailServerQuery, b5 as useLazyGetEmailServerQuery, i as isSaaS } from "./index-DfebxkL9.js";
import { u as useStyles$1 } from "./styles-rKP3r-bS.js";
import { A as AddButton } from "./index-72JBTuLT.js";
import { M as MailServerForm } from "./serverForm-BbGb2r52.js";
import { T as TEMPLATE_MAIL_SERVER, E as EmailServerIntegrationType } from "./types-DVpDEwlm.js";
import { n as useDisclosure, T as Text, S as Stack, P as Paper, aj as clsx, $ as Table, d as Checkbox, V as LoadingOverlay, b as Box, ak as Title, B as Button, C as Container, g as Loader, c as createStyles, W as useMediaQuery, z as useForm, F as Flex, k as Tooltip, h as ActionIcon, L as List, E as TextInput, U as UnstyledButton, s as showNotification, G as Group, l as ScrollArea, al as Anchor, Y as Skeleton, K as Divider } from "./vendor-mantine-h0WlM2Mj.js";
import { u as useTranslation, t } from "./vendor-i18n-wisIXUFi.js";
import { I as InfiniteScroll } from "./index.es-BTZFX8B-.js";
import { M as B8, _ as _ze, C as ES, N as DW, S as Se, O as IconArrowUpRight, H as IconPencil, Q as IconSettings, y as IconTrash, T as CX } from "./vendor-icons-xWhXK_Ui.js";
import { P as PopUpUI } from "./index-DGrXxZ89.js";
import { M as Modal } from "./index-DqcA8P_y.js";
import { m as modalTheme } from "./styles-3NoIlzov.js";
import { g as getValidateErrors } from "./validation-Ds00Zghx.js";
import { D as DomainResponse, R as RecordName, a as RecordType } from "./types-Cx44Kkix.js";
import { o as objectType, s as stringType } from "./types-espwwxTQ.js";
import { C as Controls } from "./index-DMTgSMwy.js";
import "./utiils-DzEu0_6s.js";
const CreateMailServer = (t0) => {
  const $ = compilerRuntimeExports.c(15);
  const {
    CustomerId,
    handleChange
  } = t0;
  const [opened, t1] = useDisclosure(false);
  const {
    open,
    close
  } = t1;
  const {
    t: t2
  } = useTranslation();
  let t22;
  if ($[0] !== t2) {
    t22 = t2("servers.create");
    $[0] = t2;
    $[1] = t22;
  } else {
    t22 = $[1];
  }
  let t3;
  if ($[2] !== t22) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: "600", fz: "14", children: t22 });
    $[2] = t22;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  let t4;
  if ($[4] !== open || $[5] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { onClick: open, children: t3 });
    $[4] = open;
    $[5] = t3;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  let t5;
  if ($[7] !== CustomerId || $[8] !== close || $[9] !== handleChange || $[10] !== opened) {
    t5 = opened && /* @__PURE__ */ jsxRuntimeExports.jsx(MailServerForm, { CustomerId, mailServer: TEMPLATE_MAIL_SERVER.TEMPLATE_MAIL_SERVER_ENTITY, handleChange, opened, handleClose: close, isEditing: false });
    $[7] = CustomerId;
    $[8] = close;
    $[9] = handleChange;
    $[10] = opened;
    $[11] = t5;
  } else {
    t5 = $[11];
  }
  let t6;
  if ($[12] !== t4 || $[13] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t4,
      t5
    ] });
    $[12] = t4;
    $[13] = t5;
    $[14] = t6;
  } else {
    t6 = $[14];
  }
  return t6;
};
const loadingWrapper = "_loadingWrapper_e2pw9_1";
const header = "_header_e2pw9_9";
const fetchLoading = "_fetchLoading_e2pw9_15";
const defaultHeight = "_defaultHeight_e2pw9_23";
const defaultClasses = {
  loadingWrapper,
  header,
  fetchLoading,
  defaultHeight
};
const DefaultTableLayout = (props) => {
  const $ = compilerRuntimeExports.c(7);
  const {
    name,
    children,
    className
  } = props;
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      width: "100%"
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  let t1;
  if ($[1] !== name) {
    t1 = name && /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { c: "#343A40", ml: 10, mt: 10, fz: 18, fw: 500, size: "xl", children: name });
    $[1] = name;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] !== children || $[4] !== className || $[5] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className, style: t0, children: [
      t1,
      children
    ] });
    $[3] = children;
    $[4] = className;
    $[5] = t1;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  return t2;
};
const ContextMenu = (t0) => {
  const $ = compilerRuntimeExports.c(16);
  const {
    items,
    triggerRef
  } = t0;
  const [visible, setVisible] = reactExports.useState(false);
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = {
      x: 0,
      y: 0
    };
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const [position, setPosition] = reactExports.useState(t1);
  const menuRef = reactExports.useRef(null);
  let t2;
  let t3;
  if ($[1] !== items.length || $[2] !== triggerRef) {
    t2 = () => {
      if (!items.length) {
        return;
      }
      const trigger = triggerRef.current;
      if (!trigger) {
        return;
      }
      const handleContextMenu = (e) => {
        e.preventDefault();
        setPosition({
          x: e.clientX,
          y: e.clientY
        });
        setVisible(true);
      };
      const handleClick = (e_0) => {
        if (menuRef.current && !menuRef.current.contains(e_0.target)) {
          setVisible(false);
        }
      };
      trigger.addEventListener("contextmenu", handleContextMenu);
      document.addEventListener("click", handleClick);
      return () => {
        trigger.removeEventListener("contextmenu", handleContextMenu);
        document.removeEventListener("click", handleClick);
      };
    };
    t3 = [triggerRef, items.length];
    $[1] = items.length;
    $[2] = triggerRef;
    $[3] = t2;
    $[4] = t3;
  } else {
    t2 = $[3];
    t3 = $[4];
  }
  reactExports.useEffect(t2, t3);
  if (!visible || !items.length) {
    return null;
  }
  let t4;
  if ($[5] !== position.x || $[6] !== position.y) {
    t4 = {
      position: "fixed",
      top: position.y,
      left: position.x,
      zIndex: 1e3
    };
    $[5] = position.x;
    $[6] = position.y;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  let t5;
  if ($[8] !== items) {
    let t62;
    if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
      t62 = (item, index) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { onClick: () => setVisible(false), children: item.component() }, index);
      $[10] = t62;
    } else {
      t62 = $[10];
    }
    t5 = items.map(t62);
    $[8] = items;
    $[9] = t5;
  } else {
    t5 = $[9];
  }
  let t6;
  if ($[11] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Stack, { gap: 0, children: t5 });
    $[11] = t5;
    $[12] = t6;
  } else {
    t6 = $[12];
  }
  let t7;
  if ($[13] !== t4 || $[14] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Paper, { ref: menuRef, shadow: "md", style: t4, children: t6 });
    $[13] = t4;
    $[14] = t6;
    $[15] = t7;
  } else {
    t7 = $[15];
  }
  return t7;
};
const tableRow = "_tableRow_100mj_1";
const value = "_value_100mj_11";
const contextTr = "_contextTr_100mj_23";
const classes$1 = {
  tableRow,
  value,
  contextTr
};
const RowContainer = (props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  const $ = compilerRuntimeExports.c(45);
  const {
    children,
    schema,
    item,
    setSelected,
    selected,
    reload,
    className
  } = props;
  const navigate = useNavigate();
  const [isLoading, setIsLoadingRow] = reactExports.useState(false);
  const rowRef = reactExports.useRef(null);
  let t0;
  if ($[0] !== ((_a = schema.settings) == null ? void 0 : _a.contextMenu)) {
    t0 = ((_b = schema == null ? void 0 : schema.settings) == null ? void 0 : _b.contextMenu) || [];
    $[0] = (_c = schema.settings) == null ? void 0 : _c.contextMenu;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  let t1;
  if ($[2] !== item || $[3] !== reload || $[4] !== t0) {
    let t22;
    if ($[6] !== item || $[7] !== reload) {
      t22 = (action) => ({
        component: () => action({
          item,
          onSuccess: () => reload().then(() => setIsLoadingRow(false)),
          setIsLoadingRow
        })
      });
      $[6] = item;
      $[7] = reload;
      $[8] = t22;
    } else {
      t22 = $[8];
    }
    t1 = t0.map(t22);
    $[2] = item;
    $[3] = reload;
    $[4] = t0;
    $[5] = t1;
  } else {
    t1 = $[5];
  }
  const menuItems = t1;
  let t2;
  if ($[9] !== item || $[10] !== schema) {
    t2 = (_d = schema == null ? void 0 : schema.rowHandler) == null ? void 0 : _d.call(schema, item);
    $[9] = item;
    $[10] = schema;
    $[11] = t2;
  } else {
    t2 = $[11];
  }
  const toLink = t2;
  let t3;
  if ($[12] !== navigate || $[13] !== toLink) {
    t3 = () => {
      toLink && navigate(toLink);
    };
    $[12] = navigate;
    $[13] = toLink;
    $[14] = t3;
  } else {
    t3 = $[14];
  }
  const goToLink = t3;
  let t4;
  if ($[15] !== item || $[16] !== schema) {
    t4 = (_e = schema == null ? void 0 : schema.selectedHandler) == null ? void 0 : _e.call(schema, item);
    $[15] = item;
    $[16] = schema;
    $[17] = t4;
  } else {
    t4 = $[17];
  }
  const currentId = t4;
  let t5;
  if ($[18] !== currentId || $[19] !== setSelected) {
    t5 = (e) => {
      e.stopPropagation();
      if (currentId) {
        setSelected((prev) => {
          if (prev.includes(currentId)) {
            return prev.filter((id) => id !== currentId);
          }
          return [...prev, currentId];
        });
      }
    };
    $[18] = currentId;
    $[19] = setSelected;
    $[20] = t5;
  } else {
    t5 = $[20];
  }
  const handleSelect = t5;
  let t6;
  if ($[21] !== currentId || $[22] !== selected) {
    t6 = selected == null ? void 0 : selected.find((i) => i === currentId);
    $[21] = currentId;
    $[22] = selected;
    $[23] = t6;
  } else {
    t6 = $[23];
  }
  const selectedItem = t6;
  let t7;
  if ($[24] !== className) {
    t7 = clsx(className, classes$1.tableRow);
    $[24] = className;
    $[25] = t7;
  } else {
    t7 = $[25];
  }
  const rowClasses = t7;
  let t8;
  if ($[26] !== currentId || $[27] !== handleSelect || $[28] !== ((_f = schema.settings) == null ? void 0 : _f.selectable) || $[29] !== selectedItem) {
    t8 = ((_g = schema.settings) == null ? void 0 : _g.selectable) && currentId && /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { w: 52, p: 0, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { checked: !!selectedItem, onClick: handleSelect }) });
    $[26] = currentId;
    $[27] = handleSelect;
    $[28] = (_h = schema.settings) == null ? void 0 : _h.selectable;
    $[29] = selectedItem;
    $[30] = t8;
  } else {
    t8 = $[30];
  }
  let t9;
  if ($[31] === Symbol.for("react.memo_cache_sentinel")) {
    t9 = {
      width: 0,
      padding: 0,
      overflow: "visible"
    };
    $[31] = t9;
  } else {
    t9 = $[31];
  }
  let t10;
  if ($[32] !== isLoading) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { w: 0, p: 0, style: t9, children: /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { zIndex: 5, visible: isLoading }) });
    $[32] = isLoading;
    $[33] = t10;
  } else {
    t10 = $[33];
  }
  let t11;
  if ($[34] !== children || $[35] !== goToLink || $[36] !== rowClasses || $[37] !== t10 || $[38] !== t8) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Table.Tr, { onClick: goToLink, ref: rowRef, className: rowClasses, children: [
      t8,
      children,
      t10
    ] });
    $[34] = children;
    $[35] = goToLink;
    $[36] = rowClasses;
    $[37] = t10;
    $[38] = t8;
    $[39] = t11;
  } else {
    t11 = $[39];
  }
  let t12;
  if ($[40] !== menuItems) {
    t12 = menuItems.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Tr, { h: 0, className: classes$1.contextTr, children: /* @__PURE__ */ jsxRuntimeExports.jsx("td", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(ContextMenu, { items: menuItems, triggerRef: rowRef }) }) });
    $[40] = menuItems;
    $[41] = t12;
  } else {
    t12 = $[41];
  }
  let t13;
  if ($[42] !== t11 || $[43] !== t12) {
    t13 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t11,
      t12
    ] });
    $[42] = t11;
    $[43] = t12;
    $[44] = t13;
  } else {
    t13 = $[44];
  }
  return t13;
};
function getNestedValue(obj, key) {
  return key.split(".").reduce((acc, part) => {
    if (acc === null || acc === void 0) {
      return void 0;
    }
    return acc[part];
  }, obj);
}
const RenderCell = (props) => {
  var _a;
  const $ = compilerRuntimeExports.c(23);
  const {
    schema,
    item,
    column,
    reload
  } = props;
  let t0;
  if ($[0] !== column.key || $[1] !== item) {
    t0 = column.key.includes(".") ? getNestedValue(item, column.key) : item[column.key];
    $[0] = column.key;
    $[1] = item;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  const value2 = t0;
  let t1;
  if ($[3] !== column.key || $[4] !== schema.header) {
    t1 = (_a = schema.header.find((header2) => header2.key === column.key)) == null ? void 0 : _a.renderRowCell;
    $[3] = column.key;
    $[4] = schema.header;
    $[5] = t1;
  } else {
    t1 = $[5];
  }
  const CellComponent = t1;
  if (CellComponent) {
    let t22;
    if ($[6] !== CellComponent || $[7] !== column || $[8] !== item || $[9] !== reload || $[10] !== schema || $[11] !== value2) {
      t22 = /* @__PURE__ */ jsxRuntimeExports.jsx(CellComponent, { reload, column, schema, value: value2, item });
      $[6] = CellComponent;
      $[7] = column;
      $[8] = item;
      $[9] = reload;
      $[10] = schema;
      $[11] = value2;
      $[12] = t22;
    } else {
      t22 = $[12];
    }
    let t32;
    if ($[13] !== column.cellProps || $[14] !== column.key || $[15] !== t22) {
      t32 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { "data-key": column.key, ...column.cellProps, children: t22 });
      $[13] = column.cellProps;
      $[14] = column.key;
      $[15] = t22;
      $[16] = t32;
    } else {
      t32 = $[16];
    }
    return t32;
  }
  const t2 = value2 || "-";
  let t3;
  if ($[17] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes$1.value, children: t2 });
    $[17] = t2;
    $[18] = t3;
  } else {
    t3 = $[18];
  }
  let t4;
  if ($[19] !== column.cellProps || $[20] !== column.key || $[21] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Td, { "data-key": column.key, ...column.cellProps, children: t3 });
    $[19] = column.cellProps;
    $[20] = column.key;
    $[21] = t3;
    $[22] = t4;
  } else {
    t4 = $[22];
  }
  return t4;
};
const DefaultTableRow = (props) => {
  const $ = compilerRuntimeExports.c(7);
  const {
    item,
    schema,
    reload
  } = props;
  if (!schema || !schema.header) {
    return null;
  }
  let t0;
  if ($[0] !== item || $[1] !== reload || $[2] !== schema) {
    t0 = schema.header.slice().sort(_temp$2).map((column, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(RenderCell, { item, column, schema, reload }, index));
    $[0] = item;
    $[1] = reload;
    $[2] = schema;
    $[3] = t0;
  } else {
    t0 = $[3];
  }
  let t1;
  if ($[4] !== props || $[5] !== t0) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(RowContainer, { ...props, children: t0 });
    $[4] = props;
    $[5] = t0;
    $[6] = t1;
  } else {
    t1 = $[6];
  }
  return t1;
};
function _temp$2(a, b) {
  return (a.order ?? Infinity) - (b.order ?? Infinity);
}
const root = "_root_ld3fs_1";
const container = "_container_ld3fs_9";
const image = "_image_ld3fs_19";
const title = "_title_ld3fs_29";
const classes = {
  root,
  container,
  image,
  title
};
const EmptyListComponent = (props) => {
  const $ = compilerRuntimeExports.c(17);
  let t0;
  if ($[0] !== props.icon || $[1] !== props.title) {
    t0 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: props.icon, className: classes.image, alt: props.title }) });
    $[0] = props.icon;
    $[1] = props.title;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  let t1;
  if ($[3] !== props.title) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(Title, { fw: 500, fz: 26, className: classes.title, children: props.title });
    $[3] = props.title;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  let t2;
  if ($[5] !== props.description) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { c: "dimmed", fz: 16, children: props.description });
    $[5] = props.description;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  let t3;
  if ($[7] !== t1 || $[8] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { mt: 24, mb: 24, children: [
      t1,
      t2
    ] });
    $[7] = t1;
    $[8] = t2;
    $[9] = t3;
  } else {
    t3 = $[9];
  }
  const t4 = props.slot && props.slot;
  let t5;
  if ($[10] !== props.createContact) {
    t5 = props.createContact && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { radius: "md", mt: 2, mb: 6, size: "md", component: NavLink, to: "/contact/add", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: 14, fw: 600, size: "md", children: t("createContact") }) });
    $[10] = props.createContact;
    $[11] = t5;
  } else {
    t5 = $[11];
  }
  let t6;
  if ($[12] !== t0 || $[13] !== t3 || $[14] !== t4 || $[15] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Container, { className: `${classes.root}`, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.container, children: [
      t0,
      t3,
      t4,
      t5
    ] }) });
    $[12] = t0;
    $[13] = t3;
    $[14] = t4;
    $[15] = t5;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  return t6;
};
const DefaultLoadingError = (t0) => {
  const $ = compilerRuntimeExports.c(10);
  const {
    icon,
    title: title2,
    description
  } = t0;
  const {
    t: t2
  } = useTranslation();
  const t1 = icon ?? defaultIcon;
  let t22;
  if ($[0] !== t2 || $[1] !== title2) {
    t22 = title2 ?? t2("groups.title");
    $[0] = t2;
    $[1] = title2;
    $[2] = t22;
  } else {
    t22 = $[2];
  }
  let t3;
  if ($[3] !== description || $[4] !== t2) {
    t3 = description ?? t2("groups.table.thereIsNoGroup");
    $[3] = description;
    $[4] = t2;
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  let t4;
  if ($[6] !== t1 || $[7] !== t22 || $[8] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(EmptyListComponent, { icon: t1, title: t22, description: t3 });
    $[6] = t1;
    $[7] = t22;
    $[8] = t3;
    $[9] = t4;
  } else {
    t4 = $[9];
  }
  return t4;
};
const LoadingProps = (_props) => {
  const $ = compilerRuntimeExports.c(1);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { color: "blue" }) });
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  return t0;
};
const DefaultNoData = (t0) => {
  const $ = compilerRuntimeExports.c(4);
  const {
    name,
    icon,
    title: title2,
    description
  } = t0;
  const t1 = icon ?? defaultIcon$1;
  const t2 = title2 ?? name;
  let t3;
  if ($[0] !== description || $[1] !== t1 || $[2] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(EmptyListComponent, { icon: t1, title: t2, description });
    $[0] = description;
    $[1] = t1;
    $[2] = t2;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  return t3;
};
const RenderHeaderCell = (props) => {
  var _a;
  const $ = compilerRuntimeExports.c(16);
  let t0;
  if ($[0] !== props.item || $[1] !== props.items) {
    t0 = props.item.renderHeaderLabel ? props.item.renderHeaderLabel(props.items) : props.item.title;
    $[0] = props.item;
    $[1] = props.items;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  const title2 = t0;
  const CellHeaderComponent = props.item.renderHeaderCell;
  const thProps = (_a = props.item) == null ? void 0 : _a.headerProps;
  if (CellHeaderComponent) {
    let t12;
    if ($[3] !== CellHeaderComponent || $[4] !== props.item || $[5] !== props.items || $[6] !== props.schema) {
      t12 = /* @__PURE__ */ jsxRuntimeExports.jsx(CellHeaderComponent, { items: props.items, item: props.item, schema: props.schema });
      $[3] = CellHeaderComponent;
      $[4] = props.item;
      $[5] = props.items;
      $[6] = props.schema;
      $[7] = t12;
    } else {
      t12 = $[7];
    }
    let t22;
    if ($[8] !== t12 || $[9] !== thProps) {
      t22 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { ...thProps, children: t12 });
      $[8] = t12;
      $[9] = thProps;
      $[10] = t22;
    } else {
      t22 = $[10];
    }
    return t22;
  }
  let t1;
  if ($[11] !== title2) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { c: "rgba(169, 180, 198, 1)", tt: "uppercase", fz: 10, fw: 500, children: title2 });
    $[11] = title2;
    $[12] = t1;
  } else {
    t1 = $[12];
  }
  let t2;
  if ($[13] !== t1 || $[14] !== thProps) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Th, { ...thProps, children: t1 });
    $[13] = t1;
    $[14] = thProps;
    $[15] = t2;
  } else {
    t2 = $[15];
  }
  return t2;
};
const DefaultTableHeader = (props) => {
  var _a, _b, _c, _d;
  const $ = compilerRuntimeExports.c(15);
  const {
    schema,
    selected,
    setSelected,
    items
  } = props;
  let t0;
  if ($[0] !== items || $[1] !== schema || $[2] !== setSelected) {
    t0 = () => {
      if (!schema.selectedHandler) {
        return;
      }
      setSelected((selected_0) => {
        if (selected_0.length === items.length) {
          return [];
        }
        return items.map((item) => {
          var _a2;
          return ((_a2 = schema.selectedHandler) == null ? void 0 : _a2.call(schema, item)) ?? "";
        });
      });
    };
    $[0] = items;
    $[1] = schema;
    $[2] = setSelected;
    $[3] = t0;
  } else {
    t0 = $[3];
  }
  const handleSelect = t0;
  let t1;
  if ($[4] !== handleSelect || $[5] !== items || $[6] !== ((_a = schema.settings) == null ? void 0 : _a.selectable) || $[7] !== selected) {
    t1 = ((_b = schema.settings) == null ? void 0 : _b.selectable) && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { checked: selected.length === items.length, onChange: handleSelect, defaultChecked: true }) });
    $[4] = handleSelect;
    $[5] = items;
    $[6] = (_c = schema.settings) == null ? void 0 : _c.selectable;
    $[7] = selected;
    $[8] = t1;
  } else {
    t1 = $[8];
  }
  let t2;
  if ($[9] !== props.items || $[10] !== schema) {
    t2 = (_d = schema.header) == null ? void 0 : _d.slice().sort(_temp$1).map((item_0, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(RenderHeaderCell, { items: props.items, schema, item: item_0 }, index));
    $[9] = props.items;
    $[10] = schema;
    $[11] = t2;
  } else {
    t2 = $[11];
  }
  let t3;
  if ($[12] !== t1 || $[13] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Table.Tr, { h: 52, children: [
      t1,
      t2
    ] });
    $[12] = t1;
    $[13] = t2;
    $[14] = t3;
  } else {
    t3 = $[14];
  }
  return t3;
};
function _temp$1(a, b) {
  return (a.order ?? Infinity) - (b.order ?? Infinity);
}
const defaultLayouts = {
  TableLayout: DefaultTableLayout,
  TableRow: DefaultTableRow,
  LoadingError: DefaultLoadingError,
  Loading: LoadingProps,
  NoData: DefaultNoData,
  TableHeader: DefaultTableHeader
};
const TableSimple = (props) => {
  const {
    items = [],
    schema,
    error = false,
    loading = false,
    layoutProps,
    noData,
    infiniteScrollProps,
    reload = () => Promise.resolve(),
    classes: classes2
  } = props;
  const [selected, setSelected] = r.useState([]);
  if (!schema) return null;
  const {
    TableLayout = defaultLayouts.TableLayout,
    TableRow = defaultLayouts.TableRow,
    LoadingError = defaultLayouts.LoadingError,
    Loading = defaultLayouts.Loading,
    NoData = defaultLayouts.NoData,
    TableHeader = defaultLayouts.TableHeader
  } = schema.layouts || defaultLayouts;
  const layoutProperties = {
    name: "",
    className: defaultClasses.defaultHeight,
    infiniteScrollProps: {
      height: "300px"
    },
    ...layoutProps
  };
  if (error) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx(TableLayout, { ...layoutProperties, children: /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingError, { ...schema.loadingErrorContent || {} }) });
  }
  if (loading) {
    layoutProperties.className = defaultClasses.loadingWrapper;
    return /* @__PURE__ */ jsxRuntimeExports.jsx(TableLayout, { ...layoutProperties, name: "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loading, {}) });
  }
  if (noData && !loading) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx(TableLayout, { ...layoutProperties, name: "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(NoData, { name: layoutProperties.name, ...schema.noDataContent || {} }) });
  }
  const {
    next = () => Promise.resolve(),
    hasMore = false,
    dataLength = items.length,
    scrollThreshold = "200px",
    height = "calc(100vh - 110px)",
    loader = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: defaultClasses.fetchLoading, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { color: "blue" }) }),
    scrollableTarget = "scrollableDiv",
    ...otherProps
  } = infiniteScrollProps || {};
  return /* @__PURE__ */ jsxRuntimeExports.jsx(TableLayout, { ...layoutProperties, children: /* @__PURE__ */ jsxRuntimeExports.jsx(InfiniteScroll, { dataLength, hasMore, scrollThreshold, height, loader, scrollableTarget, next, style: {
    width: "100%"
  }, ...otherProps, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Table, { w: "100%", style: {
    tableLayout: "fixed"
  }, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("colgroup", { children: [
      schema.header.slice().sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity)).map((col, i) => /* @__PURE__ */ jsxRuntimeExports.jsx("col", { style: {
        width: col.width
      } }, i)),
      /* @__PURE__ */ jsxRuntimeExports.jsx("col", { style: {
        width: 0
      } })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Thead, { className: defaultClasses.header, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TableHeader, { selected, setSelected, items, schema: props.schema }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Table.Tbody, { children: items.map((item, index) => {
      var _a;
      const uniqueKey = ((_a = schema.selectedHandler) == null ? void 0 : _a.call(schema, item)) || index;
      return /* @__PURE__ */ jsxRuntimeExports.jsx(TableRow, { className: (classes2 == null ? void 0 : classes2.rowClass) || "", reload, selected, setSelected, items, schema: props.schema, item }, uniqueKey);
    }) })
  ] }) }) });
};
const Listing = (props) => {
  const $ = compilerRuntimeExports.c(2);
  let t0;
  if ($[0] !== props) {
    t0 = /* @__PURE__ */ jsxRuntimeExports.jsx(TableSimple, { ...props });
    $[0] = props;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  return t0;
};
const useStyles = createStyles((theme) => {
  var _a, _b, _c, _d;
  return {
    modalFooter: {
      ...modalTheme(theme).footer,
      position: "fixed",
      bottom: 0
    },
    modalCancelBtn: modalTheme(theme).cancelBtn,
    title: {
      fontWeight: 600
    },
    textFieldInput: {
      "& .mantine-TextInput-label, .mantine-InputWrapper-label": {
        color: theme.colors.brandGray[0],
        fontSize: "12px"
      },
      "& .mantine-TextInput-input": {
        borderRadius: "8px",
        border: "1px solid #D0D5DD"
      }
    },
    domainText: {
      borderRadius: "8px",
      border: `1px solid ${theme.colors.brandGray[0]}`,
      width: "40%",
      padding: "4px",
      paddingLeft: "16px",
      marginRight: "32px"
    },
    domainDisabled: {
      backgroundColor: "#f1f3f5",
      opacity: "0.4"
    },
    addButton: {
      borderRadius: "8px",
      border: `1px solid ${theme.colors.brandGray[0]}`,
      maxWidth: "300px",
      "&:hover": {
        backgroundColor: "#f6f7f8"
      },
      "& .mantine-Button-inner": {
        display: "flex",
        flexDirection: "row",
        alignItems: "center",
        justifyContent: "space-between"
      },
      "& .mantine-Button-label": {
        color: theme.black
      }
    },
    loader: {
      display: "flex",
      paddingTop: "8px",
      alignItems: "center"
    },
    grid: {
      alignItems: "center"
    },
    linkValue: {
      wordBreak: "break-all"
    },
    cancelBtn: {
      display: "flex",
      alignItems: "center",
      justifyContent: "center",
      height: "36px",
      borderRadius: "8px",
      padding: `8px ${(_a = theme.spacing) == null ? void 0 : _a.sm}`,
      backgroundColor: ((_b = theme.colors) == null ? void 0 : _b.brandGray) ? (_c = theme.colors) == null ? void 0 : _c.brandGray[1] : "",
      fontSize: "14px",
      color: "#101828",
      fontWeight: 600,
      lineHeight: "17px",
      "&:hover": {
        backgroundColor: "#eff0f4"
      },
      "&:active": {
        transform: `translateY(1px)`
      }
    },
    scrollContainer: {
      maxHeight: "550px",
      overflowY: "auto",
      paddingRight: (_d = theme.spacing) == null ? void 0 : _d.lg,
      paddingLeft: theme.spacing.sm,
      "&::-webkit-scrollbar": {
        width: "8px",
        height: "10px"
      },
      "&::-webkit-scrollbar-thumb": {
        borderRadius: "8px",
        background: "#98A2B3"
      },
      "&::-webkit-scrollbar-track": {
        background: "#F9FAFB",
        borderRadius: "8px"
      },
      scrollbarColor: "#98A2B3 #F9FAFB"
    }
  };
});
const AddDomainModal = ({
  handleClose,
  setOpenPreviewModal,
  serverId,
  handleChange,
  setDomainDetails
}) => {
  const {
    classes: classes2,
    theme
  } = useStyles();
  const {
    t: t2
  } = useTranslation();
  const fieldName = "Domain";
  const isMobile = useMediaQuery("(max-width: 576px)");
  const {
    filial
  } = useAppSelector((state) => state.filials);
  const [checkDomainExist, {
    isLoading,
    isFetching
  }] = useLazyCheckDomainQuery();
  const [addDomain, {
    isLoading: addDomainLoading
  }] = useLazyAddDomainQuery();
  const [getLinkRecord, {
    data: linkRecord,
    isLoading: loadingLinkRecord
  }] = useLazyGetLinkRecordQuery();
  const domainFormSchema = objectType({
    Domain: stringType().regex(/^(?!-)[A-Za-z0-9-]+(\.[a-z0-9]+)*\.[A-Za-z]{2,6}$/, {
      message: t2("addDomain.errors.invalidName")
    })
  });
  const domainForm = useForm({
    initialValues: {
      Domain: ""
    },
    validateInputOnChange: true,
    validate: (values) => getValidateErrors(domainFormSchema, values)
  });
  const errors = domainForm.errors;
  const isDirtyForm = domainForm.isDirty();
  const isDisabled = !isDirtyForm || !linkRecord || errors.Domain === t2("addDomain.errors.invalidName");
  reactExports.useEffect(() => {
    handleGetLinkRecord();
  }, []);
  const handleGetLinkRecord = async () => {
    await getLinkRecord({
      serverid: serverId
    });
  };
  const modalClose = () => {
    handleClose();
    domainForm.reset();
  };
  const handleSubmit = async (values_0) => {
    await handleValidateField(values_0.Domain);
  };
  const handleAddDomain = async () => {
    var _a;
    if (filial) {
      try {
        const res = await addDomain({
          Domain: domainForm.values.Domain,
          ServerId: serverId,
          CustomerId: filial.Id
        });
        if ("error" in res) {
          showNotification({
            title: `${(_a = res == null ? void 0 : res.error) == null ? void 0 : _a.data}`,
            message: "",
            autoClose: true,
            color: "red",
            style: {
              zIndex: 1003
            }
          });
        } else {
          showNotification({
            title: t2("addDomain.succes"),
            message: "",
            autoClose: true,
            color: "green",
            style: {
              zIndex: 1003
            }
          });
          modalClose();
          if (handleChange) {
            handleChange();
          }
          setOpenPreviewModal(true);
          setDomainDetails(res.data);
        }
      } catch (err) {
        console.warn(t2("addDomain.errors.notCreated"), err);
      }
    }
  };
  const handleValidateField = async (domain) => {
    var _a;
    if ((domain == null ? void 0 : domain.length) && domainForm.isDirty(fieldName) && (filial == null ? void 0 : filial.Id) && linkRecord) {
      const response = await checkDomainExist({
        domain: domainForm.values.Domain,
        customerId: filial.Id,
        serverId
      });
      switch ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.Status) {
        case DomainResponse.SUCCESS:
          await handleAddDomain();
          break;
        case DomainResponse.EXISTS:
          domainForm.setFieldError(fieldName, t2("addDomain.errors.exists"));
          break;
        case DomainResponse.NONEXISTS:
          domainForm.setFieldError(fieldName, t2("addDomain.errors.nonExists"));
          break;
        case DomainResponse.ERROR:
          domainForm.setFieldError(fieldName, t2("addDomain.errors.error"));
          break;
        case DomainResponse.NONEXISTSRECORD:
          domainForm.setFieldError(fieldName, t2("addDomain.errors.nonExistsRecord"));
          break;
        default:
          domainForm.setFieldError(fieldName, t2("addDomain.errors.error"));
          break;
      }
    }
  };
  const ListItem = ({
    label,
    value: value2
  }) => /* @__PURE__ */ jsxRuntimeExports.jsx(List.Item, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", wrap: "wrap", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { size: "sm", children: [
      label,
      ": "
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: "bold", size: "sm", className: classes2.linkValue, children: value2 ? value2 : /* @__PURE__ */ jsxRuntimeExports.jsx(NoRecordLinkElement, {}) })
  ] }) });
  const NoRecordLinkElement = () => /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { align: "center", children: loadingLinkRecord ? /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "xs" }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: "bold", children: t2("loadingError") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { sx: {
      background: theme.colors.brandGray[1],
      borderRadius: theme.spacing.xs,
      padding: "8px"
    }, label: t2("reload"), c: theme.colors.dark[8], children: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { variant: "transparent", ml: "xs", onClick: () => handleGetLinkRecord(), children: /* @__PURE__ */ jsxRuntimeExports.jsx(_ze, { size: "20", cursor: "pointer" }) }) })
  ] }) });
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { p: "24px", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", mb: "sm", children: t2("addDomain.text1") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", mb: "xs", children: t2("addDomain.text2") }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { px: "sm", pt: "sm", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { children: [
            " ",
            t2("addDomain.text3")
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { sx: {
            background: theme.colors.brandGray[1],
            borderRadius: theme.spacing.xs,
            padding: "8px",
            width: isMobile ? "300px" : "500px"
          }, zIndex: 1400, c: theme.colors.dark[8], multiline: true, position: "top", label: /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { size: "sm", children: [
            t2("addDomain.hint1"),
            /* @__PURE__ */ jsxRuntimeExports.jsx("br", {}),
            t2("addDomain.hint2")
          ] }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { variant: "transparent", ml: "xs", children: /* @__PURE__ */ jsxRuntimeExports.jsx(B8, { size: "20", color: "gray", cursor: "pointer" }) }) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(List, { size: "sm", pl: "sm", pt: "sm", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(ListItem, { label: t2("type"), value: "TXT" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(ListItem, { label: t2("name"), value: "@" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(ListItem, { label: t2("domains.textMeaning"), value: linkRecord == null ? void 0 : linkRecord.LinkRecord })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: domainForm.onSubmit(handleSubmit), children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { px: "24px", pb: "24px", mb: "70px", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", mb: "sm", children: t2("addDomain.inputLabel") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: classes2.textFieldInput, withAsterisk: true, label: t2("domains.domain"), placeholder: "yourcompany.com", ...domainForm.getInputProps("Domain") }),
        (isLoading || isFetching) && /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes2.loader, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "xs" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", ml: "xs", color: "dimmed", children: "Загрузка ..." })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes2.modalFooter, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { w: "49%", type: "submit", disabled: isDisabled, children: t2("add") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(UnstyledButton, { w: "49%", className: classes2.modalCancelBtn, onClick: handleClose, children: t2("cancel") })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: addDomainLoading, overlayProps: {
      blur: 2
    } })
  ] });
};
const DomainItem = (t0) => {
  const $ = compilerRuntimeExports.c(23);
  const {
    domain,
    setOpenPreviewModal,
    setOpenDeleteModal,
    setDomainDetails
  } = t0;
  const {
    classes: classes2,
    cx
  } = useStyles();
  let t1;
  if ($[0] !== domain || $[1] !== setDomainDetails || $[2] !== setOpenPreviewModal) {
    t1 = () => {
      setOpenPreviewModal(true);
      setDomainDetails(domain);
    };
    $[0] = domain;
    $[1] = setDomainDetails;
    $[2] = setOpenPreviewModal;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  const openDomainSettings = t1;
  let t2;
  if ($[4] !== domain || $[5] !== setDomainDetails || $[6] !== setOpenDeleteModal) {
    t2 = () => {
      setOpenDeleteModal(true);
      setDomainDetails(domain);
    };
    $[4] = domain;
    $[5] = setDomainDetails;
    $[6] = setOpenDeleteModal;
    $[7] = t2;
  } else {
    t2 = $[7];
  }
  const openDeleteModal = t2;
  const t3 = !domain.Id;
  let t4;
  if ($[8] !== classes2.domainDisabled || $[9] !== classes2.domainText || $[10] !== cx || $[11] !== t3) {
    t4 = cx(classes2.domainText, {
      [classes2.domainDisabled]: t3
    });
    $[8] = classes2.domainDisabled;
    $[9] = classes2.domainText;
    $[10] = cx;
    $[11] = t3;
    $[12] = t4;
  } else {
    t4 = $[12];
  }
  let t5;
  if ($[13] !== domain.Domain || $[14] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t4, w: "100%", maw: "400px", children: domain.Domain });
    $[13] = domain.Domain;
    $[14] = t4;
    $[15] = t5;
  } else {
    t5 = $[15];
  }
  let t6;
  if ($[16] !== domain.Id || $[17] !== openDeleteModal || $[18] !== openDomainSettings) {
    t6 = domain.Id && /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { display: "flex", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { size: 24, mr: 20, onClick: () => openDomainSettings(), children: /* @__PURE__ */ jsxRuntimeExports.jsx(EditIcon, { size: 12 }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { size: 24, onClick: () => openDeleteModal(), children: /* @__PURE__ */ jsxRuntimeExports.jsx(ES, { color: "#667085" }) }) })
    ] });
    $[16] = domain.Id;
    $[17] = openDeleteModal;
    $[18] = openDomainSettings;
    $[19] = t6;
  } else {
    t6 = $[19];
  }
  let t7;
  if ($[20] !== t5 || $[21] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { w: "100%", align: "center", mb: "15px", children: [
      t5,
      t6
    ] });
    $[20] = t5;
    $[21] = t6;
    $[22] = t7;
  } else {
    t7 = $[22];
  }
  return t7;
};
const DomainSettings = ({
  handleClose,
  domain
}) => {
  const {
    classes: classes2
  } = useStyles();
  const {
    t: t2
  } = useTranslation();
  const [getDomainSettings, {
    data,
    isSuccess,
    isFetching,
    isLoading,
    isError
  }] = useLazyDomainSettingsQuery();
  reactExports.useEffect(() => {
    handleGetDomainSettings();
  }, [domain]);
  const handleGetDomainSettings = () => {
    if (domain && domain.Id) {
      getDomainSettings({
        id: domain.Id
      });
    }
  };
  const numbersToType = (value2) => {
    return value2 === RecordType.MX ? "MX" : "TXT";
  };
  const numbersToRecordName = (value_0) => {
    switch (value_0) {
      case RecordName.MX:
        return t2("domains.mxRecord");
      case RecordName.SPF:
        return t2("domains.spfRecord");
      case RecordName.DKIM:
        return t2("domains.dkimRecord");
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { p: "24px", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes2.scrollContainer, children: [
      (isFetching || isLoading) && !isError && /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { h: data ? "" : "350px", children: /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isFetching, overlayProps: {
        blur: 2
      } }) }),
      (data == null ? void 0 : data.Records.length) && (data == null ? void 0 : data.Records.some((record) => !record.IsSussess)) && /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t2("domains.settingsError") }),
      isSuccess && (data == null ? void 0 : data.Records.length) ? [...data.Records].sort((a, b) => a.Record - b.Record).map((record_0, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { py: "xs", children: [
          record_0.IsSussess ? /* @__PURE__ */ jsxRuntimeExports.jsx(DW, { color: "green", stroke: 4 }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Se, { color: "red", stroke: 2 }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { pl: "xs", children: numbersToRecordName(record_0.Record) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(List, { size: "sm", pl: "xl", pr: "xs", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs(List.Item, { children: [
            t2("type"),
            ": ",
            /* @__PURE__ */ jsxRuntimeExports.jsx("b", { children: numbersToType(record_0.Type) })
          ] }),
          record_0.Record !== RecordName.MX && /* @__PURE__ */ jsxRuntimeExports.jsxs(List.Item, { children: [
            t2("name"),
            ": ",
            /* @__PURE__ */ jsxRuntimeExports.jsx("b", { children: record_0.Name })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs(List.Item, { children: [
            t2("domains.textMeaning"),
            ": ",
            /* @__PURE__ */ jsxRuntimeExports.jsx("b", { className: classes2.linkValue, children: record_0.Value })
          ] }),
          record_0.Record === RecordName.MX && /* @__PURE__ */ jsxRuntimeExports.jsxs(List.Item, { children: [
            t2("domains.priority"),
            ": ",
            /* @__PURE__ */ jsxRuntimeExports.jsx("b", { children: record_0.Priority })
          ] })
        ] })
      ] }, index)) : null
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Controls, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { grow: true, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: () => handleGetDomainSettings(), children: t2("verify") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(UnstyledButton, { className: classes2.cancelBtn, onClick: handleClose, children: t2("cancel") })
    ] }) })
  ] });
};
const DeleteDomain = ({
  domain,
  handleChange,
  setDeleteStep,
  setDomainDetails
}) => {
  const {
    classes: classes2
  } = useStyles();
  const {
    t: t2
  } = useTranslation();
  const [deleteDomain, {
    isLoading
  }] = useLazyDeleteDomainQuery();
  const handleDelete = async () => {
    var _a;
    if (domain && domain.Id) {
      try {
        const res = await deleteDomain({
          id: domain.Id
        });
        if ("error" in res) {
          showNotification({
            title: `${(_a = res == null ? void 0 : res.error) == null ? void 0 : _a.data}`,
            message: "",
            autoClose: true,
            color: "red",
            style: {
              zIndex: 1003
            }
          });
        } else {
          showNotification({
            title: t2("domains.deleteSuccess"),
            message: "",
            autoClose: true,
            color: "green",
            style: {
              zIndex: 1003
            }
          });
          setDeleteStep(false);
          if (handleChange) {
            handleChange();
          }
          setDomainDetails(domain);
        }
      } catch (err) {
        console.warn(t2("domains.deleteError"), err);
      }
    }
  };
  const handleCloseModal = () => {
    setDeleteStep(false);
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { mb: "1rem", p: "24px", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { mb: "1rem", fz: "md", children: t2("domains.deleteWarning") }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { fz: "md", children: [
        t2("domains.confirmDelete"),
        " ",
        /* @__PURE__ */ jsxRuntimeExports.jsx("b", { children: domain && domain.Domain }),
        "?"
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Controls, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { grow: true, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { color: "red", onClick: handleDelete, children: t2("delete") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(UnstyledButton, { className: classes2.cancelBtn, onClick: handleCloseModal, children: t2("cancel") })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isLoading, overlayProps: {
      blur: 2
    } })
  ] });
};
const DomainsContent = ({
  serverId,
  onTitleChange,
  onBackClick
}) => {
  const {
    classes: classes2
  } = useStyles();
  const {
    t: t2
  } = useTranslation();
  const [opened, {
    open,
    close
  }] = useDisclosure(false);
  const [domainDetails, setDomainDetails] = reactExports.useState();
  const {
    filial
  } = useAppSelector((state) => state.filials);
  const [addDomainStep, setAddDomainStep] = reactExports.useState(false);
  const [previewStep, setPreviewStep] = reactExports.useState(false);
  const [deleteStep, setDeleteStep] = reactExports.useState(false);
  const [getDomainsList, {
    data: DomainsList,
    isFetching
  }] = useLazyGetDomainsQuery();
  const handleChange = reactExports.useCallback(() => {
    (filial == null ? void 0 : filial.Id) && getDomainsList({
      ServerId: serverId,
      CustomerId: filial.Id
    });
  }, [filial]);
  reactExports.useEffect(() => {
    if (filial == null ? void 0 : filial.Id) {
      getDomainsList({
        ServerId: serverId,
        CustomerId: filial.Id
      });
    }
  }, [filial]);
  const handleCloseAddDomainModal = () => {
    close();
    setAddDomainStep(false);
  };
  const handleBack = reactExports.useCallback(() => {
    if (addDomainStep) setAddDomainStep(false);
    else if (deleteStep) setDeleteStep(false);
    else setPreviewStep(false);
  }, [addDomainStep, deleteStep]);
  const isSubStep = addDomainStep || previewStep || deleteStep;
  const getTitle = reactExports.useCallback(() => {
    if (addDomainStep) return t2("addDomain.title");
    if (previewStep) return `${t2("domains.settings")} ${(domainDetails == null ? void 0 : domainDetails.Domain) || ""}`;
    if (deleteStep) return t2("domains.delete");
    return t2("domains.title");
  }, [addDomainStep, previewStep, deleteStep, domainDetails, t2]);
  reactExports.useEffect(() => {
    onTitleChange == null ? void 0 : onTitleChange(getTitle());
  }, [getTitle]);
  reactExports.useEffect(() => {
    onBackClick == null ? void 0 : onBackClick(isSubStep ? handleBack : null);
  }, [isSubStep, handleBack]);
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { miw: 320, children: [
    !addDomainStep && !previewStep && !deleteStep && /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { p: "24px", children: [
      DomainsList == null ? void 0 : DomainsList.map((domain, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(DomainItem, { domain, setOpenPreviewModal: setPreviewStep, setOpenDeleteModal: setDeleteStep, setDomainDetails }, index)),
      isFetching && /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { h: DomainsList ? "" : "100px", pos: "relative", children: /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isFetching, overlayProps: {
        blur: 2
      } }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { className: classes2.addButton, w: "100%", onClick: () => {
        open();
        setAddDomainStep(true);
      }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t2("addDomain.action") }) })
    ] }),
    addDomainStep && opened && /* @__PURE__ */ jsxRuntimeExports.jsx(AddDomainModal, { serverId, handleClose: handleCloseAddDomainModal, setOpenPreviewModal: setPreviewStep, handleChange, setDomainDetails }),
    previewStep && /* @__PURE__ */ jsxRuntimeExports.jsx(DomainSettings, { handleClose: () => setPreviewStep(false), domain: domainDetails }),
    deleteStep && /* @__PURE__ */ jsxRuntimeExports.jsx(DeleteDomain, { setDeleteStep, domain: domainDetails, handleChange, setDomainDetails })
  ] });
};
const Domains = (t0) => {
  const $ = compilerRuntimeExports.c(12);
  const {
    isOpened,
    onClose,
    serverId
  } = t0;
  const [title2, setTitle] = reactExports.useState("");
  const backHandlerRef = reactExports.useRef(null);
  const [hasBack, setHasBack] = reactExports.useState(false);
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = (fn) => {
      backHandlerRef.current = fn;
      setHasBack(fn !== null);
    };
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const handleBackClick = t1;
  let t2;
  if ($[1] !== hasBack) {
    t2 = hasBack ? () => {
      var _a;
      return (_a = backHandlerRef.current) == null ? void 0 : _a.call(backHandlerRef);
    } : false;
    $[1] = hasBack;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  let t3;
  if ($[3] !== onClose || $[4] !== serverId) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(DomainsContent, { serverId, onClose, onTitleChange: setTitle, onBackClick: handleBackClick });
    $[3] = onClose;
    $[4] = serverId;
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  let t4;
  if ($[6] !== isOpened || $[7] !== onClose || $[8] !== t2 || $[9] !== t3 || $[10] !== title2) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { opened: isOpened, onClose, zIndex: 1300, size: "600px", title: title2, onBackClick: t2, scrollAreaComponent: ScrollArea.Autosize, children: t3 });
    $[6] = isOpened;
    $[7] = onClose;
    $[8] = t2;
    $[9] = t3;
    $[10] = title2;
    $[11] = t4;
  } else {
    t4 = $[11];
  }
  return t4;
};
const DeleteMailServerModal = (t0) => {
  const $ = compilerRuntimeExports.c(34);
  const {
    mailServer,
    onClose,
    onSuccess
  } = t0;
  const {
    t: t2
  } = useTranslation();
  const [deleteEmailServer] = useLazyDeleteEmailServerQuery();
  const [isFetching, setIsFetching] = reactExports.useState(false);
  let t1;
  if ($[0] !== deleteEmailServer || $[1] !== mailServer.Id || $[2] !== mailServer.Name || $[3] !== onSuccess || $[4] !== t2) {
    t1 = async () => {
      if (!mailServer.Id) {
        return;
      }
      setIsFetching(true);
      const result = await deleteEmailServer({
        Id: mailServer.Id
      });
      setIsFetching(false);
      if (!("error" in result)) {
        showNotification({
          title: t2("deleted"),
          message: mailServer.Name,
          autoClose: true,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
        onSuccess();
      }
    };
    $[0] = deleteEmailServer;
    $[1] = mailServer.Id;
    $[2] = mailServer.Name;
    $[3] = onSuccess;
    $[4] = t2;
    $[5] = t1;
  } else {
    t1 = $[5];
  }
  const handleDelete = t1;
  let t22;
  if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
    t22 = {
      wordBreak: "break-word"
    };
    $[6] = t22;
  } else {
    t22 = $[6];
  }
  let t3;
  if ($[7] !== t2) {
    t3 = t2("servers.warning");
    $[7] = t2;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  let t4;
  if ($[9] !== mailServer.Name) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx("b", { children: mailServer.Name });
    $[9] = mailServer.Name;
    $[10] = t4;
  } else {
    t4 = $[10];
  }
  let t5;
  if ($[11] !== t3 || $[12] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { fz: "md", style: t22, children: [
      t3,
      ": ",
      t4,
      "?"
    ] });
    $[11] = t3;
    $[12] = t4;
    $[13] = t5;
  } else {
    t5 = $[13];
  }
  let t6;
  if ($[14] !== t2) {
    t6 = t2("cancel");
    $[14] = t2;
    $[15] = t6;
  } else {
    t6 = $[15];
  }
  let t7;
  if ($[16] !== onClose || $[17] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "default", flex: 1, onClick: onClose, children: t6 });
    $[16] = onClose;
    $[17] = t6;
    $[18] = t7;
  } else {
    t7 = $[18];
  }
  let t8;
  if ($[19] !== t2) {
    t8 = t2("continue");
    $[19] = t2;
    $[20] = t8;
  } else {
    t8 = $[20];
  }
  let t9;
  if ($[21] !== handleDelete || $[22] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { color: "red", flex: 1, onClick: handleDelete, children: t8 });
    $[21] = handleDelete;
    $[22] = t8;
    $[23] = t9;
  } else {
    t9 = $[23];
  }
  let t10;
  if ($[24] !== t7 || $[25] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { gap: 8, children: [
      t7,
      t9
    ] });
    $[24] = t7;
    $[25] = t9;
    $[26] = t10;
  } else {
    t10 = $[26];
  }
  let t11;
  if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
    t11 = {
      blur: 2
    };
    $[27] = t11;
  } else {
    t11 = $[27];
  }
  let t12;
  if ($[28] !== isFetching) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isFetching, overlayProps: t11 });
    $[28] = isFetching;
    $[29] = t12;
  } else {
    t12 = $[29];
  }
  let t13;
  if ($[30] !== t10 || $[31] !== t12 || $[32] !== t5) {
    t13 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { p: 16, direction: "column", gap: 12, maw: 300, pos: "relative", children: [
      t5,
      t10,
      t12
    ] });
    $[30] = t10;
    $[31] = t12;
    $[32] = t5;
    $[33] = t13;
  } else {
    t13 = $[33];
  }
  return t13;
};
const ActionTrigger = (t0) => {
  const $ = compilerRuntimeExports.c(7);
  const {
    setIsOpen,
    isOpen
  } = t0;
  let t1;
  if ($[0] !== setIsOpen) {
    t1 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const t2 = `${isOpen ? "black" : "rgba(186, 197, 212, 1)"}`;
  let t3;
  if ($[2] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(CX, { color: t2 });
    $[2] = t2;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  let t4;
  if ($[4] !== t1 || $[5] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { onClick: t1, variant: "subtle", children: t3 });
    $[4] = t1;
    $[5] = t3;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  return t4;
};
function getServerLink(item) {
  var _a, _b, _c;
  return ((_c = (_b = (_a = item.Integration) == null ? void 0 : _a.Api) == null ? void 0 : _b.ApiAuth20Settings) == null ? void 0 : _c.UrlAuth20) || null;
}
const MailServerActionCell = (t0) => {
  const $ = compilerRuntimeExports.c(24);
  const {
    item,
    reload,
    isDefaultSaasServer
  } = t0;
  const {
    t: t2
  } = useTranslation();
  let t1;
  if ($[0] !== item) {
    t1 = getServerLink(item);
    $[0] = item;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const serverLink = t1;
  const [domainsOpened, t22] = useDisclosure(false);
  const {
    open: openDomains,
    close: closeDomains
  } = t22;
  const [editOpened, t3] = useDisclosure(false);
  const {
    open: openEdit,
    close: closeEdit
  } = t3;
  let t4;
  if ($[2] !== isDefaultSaasServer || $[3] !== item || $[4] !== openDomains || $[5] !== openEdit || $[6] !== reload || $[7] !== serverLink || $[8] !== t2) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { desktopPosition: "right-start", mobileSize: "100%", withinPortal: true, trigger: ActionTrigger, children: (t52) => {
      var _a;
      const {
        handleClosePopUp
      } = t52;
      return /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { p: 6, gap: 4, direction: "column", align: "stretch", children: [
        ((_a = item.Integration) == null ? void 0 : _a.Api) && /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { label: t2("servers.goToServerLinkNotGenerated"), disabled: !!serverLink, withArrow: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Anchor, { href: serverLink ?? void 0, target: "_blank", rel: "noreferrer", underline: "never", style: {
          pointerEvents: serverLink ? void 0 : "none"
        }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, justify: "flex-start", size: "sm", variant: "white", color: "black", fw: "lighter", disabled: !serverLink, leftSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconArrowUpRight, { size: 16 }), children: t2("servers.goToServer") }) }) }) }),
        !isDefaultSaasServer && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, justify: "flex-start", size: "sm", variant: "white", color: "black", fw: "lighter", leftSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconPencil, { size: 16 }), onClick: () => {
          handleClosePopUp();
          openEdit();
        }, children: t2("servers.editServer") }),
        item.Integration && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, justify: "flex-start", size: "sm", variant: "white", color: "black", fw: "lighter", leftSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconSettings, { size: 16 }), onClick: () => {
          handleClosePopUp();
          openDomains();
        }, children: t2("domains.title") }),
        !isDefaultSaasServer && /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { desktopPosition: "right-start", mobileSize: "100%", withinPortal: true, triggerWidth: "100%", trigger: (t62) => {
          const {
            setIsOpen
          } = t62;
          return /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, justify: "flex-start", size: "sm", variant: "white", color: "red", fw: "lighter", leftSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconTrash, { size: 16 }), onClick: () => setIsOpen(true), children: t2("delete") });
        }, children: (t72) => {
          const {
            isOpen,
            handleClosePopUp: closeDelete
          } = t72;
          return /* @__PURE__ */ jsxRuntimeExports.jsx(DeleteMailServerModal, { isOpen, mailServer: item, onClose: closeDelete, onSuccess: () => {
            closeDelete();
            handleClosePopUp();
            reload();
          } });
        } })
      ] });
    } });
    $[2] = isDefaultSaasServer;
    $[3] = item;
    $[4] = openDomains;
    $[5] = openEdit;
    $[6] = reload;
    $[7] = serverLink;
    $[8] = t2;
    $[9] = t4;
  } else {
    t4 = $[9];
  }
  let t5;
  if ($[10] !== closeEdit || $[11] !== editOpened || $[12] !== item || $[13] !== reload) {
    t5 = editOpened && /* @__PURE__ */ jsxRuntimeExports.jsx(MailServerForm, { CustomerId: item.CustomerId, opened: editOpened, handleClose: closeEdit, handleChange: reload, mailServer: item, isEditing: true });
    $[10] = closeEdit;
    $[11] = editOpened;
    $[12] = item;
    $[13] = reload;
    $[14] = t5;
  } else {
    t5 = $[14];
  }
  let t6;
  if ($[15] !== closeDomains || $[16] !== domainsOpened || $[17] !== item.Id || $[18] !== item.Integration) {
    t6 = item.Integration && /* @__PURE__ */ jsxRuntimeExports.jsx(Domains, { isOpened: domainsOpened, onClose: closeDomains, serverId: item.Id ?? 0 });
    $[15] = closeDomains;
    $[16] = domainsOpened;
    $[17] = item.Id;
    $[18] = item.Integration;
    $[19] = t6;
  } else {
    t6 = $[19];
  }
  let t7;
  if ($[20] !== t4 || $[21] !== t5 || $[22] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t4,
      t5,
      t6
    ] });
    $[20] = t4;
    $[21] = t5;
    $[22] = t6;
    $[23] = t7;
  } else {
    t7 = $[23];
  }
  return t7;
};
function getIntegrationLabel(item) {
  var _a, _b, _c;
  const type = (_a = item.Integration) == null ? void 0 : _a.Type;
  if (type === EmailServerIntegrationType.Ssh || ((_b = item.Integration) == null ? void 0 : _b.Ssh)) return "SSH";
  if (type === EmailServerIntegrationType.Api || ((_c = item.Integration) == null ? void 0 : _c.Api)) return "API";
  return "—";
}
const MailServersLoading = () => {
  const $ = compilerRuntimeExports.c(3);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { height: 20, radius: "sm", style: {
      flex: "0 0 calc(50% - 64px)"
    } });
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  let t1;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { height: 20, radius: "sm", style: {
      flex: "0 0 30%"
    } });
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  let t2;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { w: "100%", direction: "column", gap: 8, pt: 8, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { w: "100%", gap: 8, align: "center", mb: 10, children: [
        t0,
        t1,
        /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { height: 20, radius: "sm", style: {
          flex: "0 0 20%"
        } })
      ] }),
      [1, 2, 3].map(_temp)
    ] });
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  return t2;
};
const MailServersPage = () => {
  const {
    classes: classes2
  } = useStyles$1();
  const {
    t: t2
  } = useTranslation();
  const {
    filial
  } = useAppSelector((state) => state.filials);
  const {
    Settings
  } = useAppSelector((state_0) => state_0.userInfo);
  const [getEmailServerList, {
    data: emailServerList,
    isFetching,
    isError
  }] = useLazyGetEmailServerQuery();
  const handleChange = reactExports.useCallback(async () => {
    if (filial == null ? void 0 : filial.Id) {
      await getEmailServerList({
        Id: filial.Id
      });
    }
  }, [filial]);
  reactExports.useEffect(() => {
    if (filial == null ? void 0 : filial.Id) {
      getEmailServerList({
        Id: filial.Id
      });
    }
  }, [filial]);
  const schema = reactExports.useMemo(() => ({
    name: t2("servers.title"),
    selectedHandler: (item) => String(item.Id),
    noDataContent: {
      description: t2("servers.emptyData")
    },
    layouts: {
      Loading: MailServersLoading
    },
    header: [{
      key: "Name",
      title: t2("servers.name"),
      order: 0,
      width: "calc(50% - 64px)",
      renderRowCell: ({
        item: item_0
      }) => {
        var _a, _b;
        const apiHost = (_b = (_a = item_0.Integration) == null ? void 0 : _a.Api) == null ? void 0 : _b.Host;
        return /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", gap: 4, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { style: {
            textOverflow: "nowrap",
            display: "block"
          }, fz: "sm", children: item_0.Name }),
          apiHost && /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { component: "a", href: apiHost, target: "_blank", rel: "noreferrer", variant: "subtle", size: "xs", children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconArrowUpRight, { size: 14 }) })
        ] });
      }
    }, {
      key: "SmtpServer",
      title: t2("servers.server"),
      order: 1,
      width: "30%"
    }, {
      key: "Integration",
      title: t2("servers.integration"),
      order: 2,
      width: "20%",
      renderRowCell: ({
        item: item_1
      }) => {
        var _a;
        return /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", c: ((_a = item_1.Integration) == null ? void 0 : _a.Type) ? void 0 : "dimmed", children: getIntegrationLabel(item_1) });
      }
    }, {
      key: "Id",
      title: "",
      order: 3,
      width: "44px",
      /* eslint-disable react/prop-types */
      renderRowCell: (props) => {
        var _a;
        return /* @__PURE__ */ jsxRuntimeExports.jsx(MailServerActionCell, { ...props, isDefaultSaasServer: isSaaS(Settings) && ((_a = emailServerList == null ? void 0 : emailServerList[0]) == null ? void 0 : _a.Id) === props.item.Id });
      }
      /* eslint-enable react/prop-types */
    }]
  }), [t2, Settings, emailServerList]);
  const items = emailServerList ?? [];
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes2.container, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: classes2.section, align: "flex-start", direction: "column", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes2.title, children: t2("servers.title") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Listing, { name: t2("servers.title"), schema, items, loading: isFetching, error: isError, infiniteScrollProps: {
      height: "fit-content"
    }, noData: !isFetching && items.length === 0, reload: handleChange }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { mt: "sm", children: /* @__PURE__ */ jsxRuntimeExports.jsx(CreateMailServer, { CustomerId: (filial == null ? void 0 : filial.Id) || 0, handleChange }) })
  ] }) });
};
function _temp(i) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(r.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { w: "100%", gap: 8, align: "center", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { height: 40, radius: "sm", style: {
        flex: "0 0 calc(50% - 64px)"
      } }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { height: 40, radius: "sm", style: {
        flex: "0 0 30%"
      } }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { height: 40, radius: "sm", style: {
        flex: "0 0 20%"
      } }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { height: 40, radius: "sm", width: 44 })
    ] }),
    i !== 3 && /* @__PURE__ */ jsxRuntimeExports.jsx(Divider, {})
  ] }, i);
}
export {
  MailServersPage as default
};
//# sourceMappingURL=index-BPIuUjBu.js.map
