import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { d6 as Dictionary, d7 as Module, d8 as useCurrentUser, d9 as useGetNotificationSettingsQuery, da as useUpdateNotificationSettingsMutation } from "./index-DfebxkL9.js";
import { u as useTranslation, t } from "./vendor-i18n-wisIXUFi.js";
import { W as useMediaQuery, T as Text, g as Loader, F as Flex, aJ as SegmentedControl, P as Paper, L as List, S as Stack, b as Box } from "./vendor-mantine-h0WlM2Mj.js";
import { ao as ev, ap as EIe, aq as kv } from "./vendor-icons-xWhXK_Ui.js";
const NotificationSettingValue = {
  Off: 0,
  All: 1,
  Self: 2
};
const NotificationType = {
  DocumentShare: 1,
  DocumentComment: 2,
  DocumentMention: 3,
  DirectoryShare: 200,
  ProjectShare: 400,
  TaskCreated: 401,
  TaskDeleted: 402,
  TaskUpdated: 403,
  TaskMoved: 404,
  TaskStatusChanged: 405,
  TaskCommentAdded: 406,
  MyTaskDeleted: 420,
  MyTaskUpdated: 421,
  MyTaskMoved: 422,
  MyTaskStatusChanged: 423,
  MyTaskCommentAdded: 424,
  UnassignedFromTask: 425,
  AssignedToTask: 426,
  TaskCommentMention: 427,
  TaskAttachmentAdded: 429,
  SprintCreated: 450,
  RoleAssigned: 500,
  RoleDeleted: 501,
  ImportantNewEmailMessage: 550,
  NewEmailMessage: 551,
  CalendarShare: 600,
  CalendarEventCancel: 601,
  CalendarEventInvite: 602,
  CalendarEventChange: 603,
  CalendarUpcomingEvent: 604,
  RoomShare: 201
};
const NotificationSettingItem = (t0) => {
  const $ = compilerRuntimeExports.c(29);
  const {
    item,
    renderLabel,
    onChange,
    source
  } = t0;
  const {
    t: t2
  } = useTranslation();
  const isMobile = useMediaQuery("(max-width: 32em)");
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const isEmpty = item.notificationTypes.length === 0;
  let t1;
  if ($[0] !== renderLabel || $[1] !== t2) {
    const notificationSettingValueDictionary = new NotificationSettingValueDictionary(t2);
    t1 = notificationSettingValueDictionary.toSegmentedControlItems(renderLabel);
    $[0] = renderLabel;
    $[1] = t2;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const segmentedData = t1;
  let t22;
  if ($[3] !== item || $[4] !== onChange || $[5] !== source) {
    t22 = async (value) => {
      setIsLoading(true);
      await (onChange == null ? void 0 : onChange(Number(value), item, source));
      setIsLoading(false);
    };
    $[3] = item;
    $[4] = onChange;
    $[5] = source;
    $[6] = t22;
  } else {
    t22 = $[6];
  }
  const onChangeHandler = t22;
  const t3 = item.id;
  let t4;
  if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = {
      base: "xs",
      sm: "md"
    };
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  const t5 = item.id;
  let t6;
  if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
    t6 = {
      flex: "1 1 150px"
    };
    $[8] = t6;
  } else {
    t6 = $[8];
  }
  let t7;
  if ($[9] !== item.title) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { c: "#101828", size: "md", style: t6, children: item.title });
    $[9] = item.title;
    $[10] = t7;
  } else {
    t7 = $[10];
  }
  let t8;
  if ($[11] !== isLoading) {
    t8 = isLoading && /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "xs" });
    $[11] = isLoading;
    $[12] = t8;
  } else {
    t8 = $[12];
  }
  let t9;
  if ($[13] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "xs", align: "center", children: t8 });
    $[13] = t8;
    $[14] = t9;
  } else {
    t9 = $[14];
  }
  const t10 = isLoading || isEmpty;
  const t11 = isMobile ? "vertical" : "horizontal";
  const t12 = String(item.value);
  let t13;
  if ($[15] !== onChangeHandler || $[16] !== segmentedData || $[17] !== t10 || $[18] !== t11 || $[19] !== t12) {
    t13 = /* @__PURE__ */ jsxRuntimeExports.jsx(SegmentedControl, { disabled: t10, data: segmentedData, color: "accent", bg: "white", radius: "md", size: "md", orientation: t11, value: t12, onChange: onChangeHandler });
    $[15] = onChangeHandler;
    $[16] = segmentedData;
    $[17] = t10;
    $[18] = t11;
    $[19] = t12;
    $[20] = t13;
  } else {
    t13 = $[20];
  }
  let t14;
  if ($[21] !== item.id || $[22] !== t13 || $[23] !== t7 || $[24] !== t9) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", align: "center", wrap: "wrap", gap: "sm", children: [
      t7,
      t9,
      t13
    ] }, t5);
    $[21] = item.id;
    $[22] = t13;
    $[23] = t7;
    $[24] = t9;
    $[25] = t14;
  } else {
    t14 = $[25];
  }
  let t15;
  if ($[26] !== item.id || $[27] !== t14) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx(Paper, { radius: "md", py: "xs", pl: t4, pr: "xs", bg: "grey.0", children: t14 }, t3);
    $[26] = item.id;
    $[27] = t14;
    $[28] = t15;
  } else {
    t15 = $[28];
  }
  return t15;
};
class NotificationSettingValueDictionary extends Dictionary {
  constructor(t2) {
    super(NotificationSettingValue, t2, "notificationSetting");
  }
  // TODO type any
  toSegmentedControlItems(renderLabel = (item) => item.title) {
    return this.getAll().map((item) => ({
      value: String(item.id),
      label: renderLabel(item)
    }));
  }
}
const calculateValue = (settings, notificationTypes) => {
  const foundSettings = settings.filter((setting) => notificationTypes.includes(setting.notificationType));
  if (foundSettings.length === 0) {
    return null;
  }
  const [firstSetting, ...remainingSettings] = foundSettings;
  const firstValue = firstSetting.value;
  if (remainingSettings.length === 0) {
    return firstValue;
  }
  return remainingSettings.every((setting) => setting.value === firstValue) ? firstValue : null;
};
const useGroupedSettings = (t0) => {
  const $ = compilerRuntimeExports.c(121);
  let t1;
  if ($[0] !== t0) {
    t1 = t0 === void 0 ? [] : t0;
    $[0] = t0;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const settings = t1;
  let t2;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = t("module.Admin");
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  let t3;
  let t4;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t3 = t("notificationSettingType.RoleChange");
    t4 = [NotificationType.RoleAssigned, NotificationType.RoleDeleted];
    $[3] = t3;
    $[4] = t4;
  } else {
    t3 = $[3];
    t4 = $[4];
  }
  let t5;
  if ($[5] !== settings) {
    t5 = calculateValue(settings, [NotificationType.RoleAssigned, NotificationType.RoleDeleted]) ?? NotificationSettingValue.All;
    $[5] = settings;
    $[6] = t5;
  } else {
    t5 = $[6];
  }
  let t6;
  if ($[7] !== t5) {
    t6 = {
      id: Module.Admin,
      title: t2,
      items: [{
        id: "admin:roleChange",
        title: t3,
        notificationTypes: t4,
        value: t5
      }]
    };
    $[7] = t5;
    $[8] = t6;
  } else {
    t6 = $[8];
  }
  let t7;
  if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
    t7 = t("module.Projects");
    $[9] = t7;
  } else {
    t7 = $[9];
  }
  let t8;
  let t9;
  if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
    t8 = t("notificationSettingType.TaskChange");
    t9 = [NotificationType.TaskCreated, NotificationType.TaskDeleted, NotificationType.TaskUpdated, NotificationType.TaskMoved, NotificationType.TaskStatusChanged, NotificationType.TaskCommentAdded, NotificationType.TaskAttachmentAdded];
    $[10] = t8;
    $[11] = t9;
  } else {
    t8 = $[10];
    t9 = $[11];
  }
  let t10;
  if ($[12] !== settings) {
    t10 = calculateValue(settings, [NotificationType.TaskCreated, NotificationType.TaskDeleted, NotificationType.TaskUpdated, NotificationType.TaskMoved, NotificationType.TaskStatusChanged, NotificationType.TaskCommentAdded, NotificationType.TaskAttachmentAdded]) ?? NotificationSettingValue.Off;
    $[12] = settings;
    $[13] = t10;
  } else {
    t10 = $[13];
  }
  let t11;
  if ($[14] !== t10) {
    t11 = {
      id: "projects:taskChange",
      title: t8,
      notificationTypes: t9,
      value: t10
    };
    $[14] = t10;
    $[15] = t11;
  } else {
    t11 = $[15];
  }
  let t12;
  let t13;
  if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
    t12 = t("notificationSettingType.AssignedTaskChange");
    t13 = [NotificationType.MyTaskDeleted, NotificationType.MyTaskUpdated, NotificationType.MyTaskMoved, NotificationType.MyTaskStatusChanged, NotificationType.MyTaskCommentAdded];
    $[16] = t12;
    $[17] = t13;
  } else {
    t12 = $[16];
    t13 = $[17];
  }
  let t14;
  if ($[18] !== settings) {
    t14 = calculateValue(settings, [NotificationType.MyTaskDeleted, NotificationType.MyTaskUpdated, NotificationType.MyTaskMoved, NotificationType.MyTaskStatusChanged, NotificationType.MyTaskCommentAdded]) ?? NotificationSettingValue.Self;
    $[18] = settings;
    $[19] = t14;
  } else {
    t14 = $[19];
  }
  let t15;
  if ($[20] !== t14) {
    t15 = {
      id: "projects:assignedTaskChanged",
      title: t12,
      notificationTypes: t13,
      value: t14
    };
    $[20] = t14;
    $[21] = t15;
  } else {
    t15 = $[21];
  }
  let t16;
  let t17;
  if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
    t16 = t("notificationSettingType.TaskAssign");
    t17 = [NotificationType.AssignedToTask, NotificationType.UnassignedFromTask];
    $[22] = t16;
    $[23] = t17;
  } else {
    t16 = $[22];
    t17 = $[23];
  }
  let t18;
  if ($[24] !== settings) {
    t18 = calculateValue(settings, [NotificationType.AssignedToTask, NotificationType.UnassignedFromTask]) ?? NotificationSettingValue.All;
    $[24] = settings;
    $[25] = t18;
  } else {
    t18 = $[25];
  }
  let t19;
  if ($[26] !== t18) {
    t19 = {
      id: "projects:taskAssign",
      title: t16,
      notificationTypes: t17,
      value: t18
    };
    $[26] = t18;
    $[27] = t19;
  } else {
    t19 = $[27];
  }
  let t20;
  let t21;
  if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
    t20 = t("notificationSettingType.CommentMention");
    t21 = [NotificationType.TaskCommentMention];
    $[28] = t20;
    $[29] = t21;
  } else {
    t20 = $[28];
    t21 = $[29];
  }
  let t22;
  if ($[30] !== settings) {
    t22 = calculateValue(settings, [NotificationType.TaskCommentMention]) ?? NotificationSettingValue.All;
    $[30] = settings;
    $[31] = t22;
  } else {
    t22 = $[31];
  }
  let t23;
  if ($[32] !== t22) {
    t23 = {
      id: "projects:commentMention",
      title: t20,
      notificationTypes: t21,
      value: t22
    };
    $[32] = t22;
    $[33] = t23;
  } else {
    t23 = $[33];
  }
  let t24;
  let t25;
  if ($[34] === Symbol.for("react.memo_cache_sentinel")) {
    t24 = t("notificationSettingType.ProjectAccess");
    t25 = [NotificationType.ProjectShare];
    $[34] = t24;
    $[35] = t25;
  } else {
    t24 = $[34];
    t25 = $[35];
  }
  let t26;
  if ($[36] !== settings) {
    t26 = calculateValue(settings, [NotificationType.ProjectShare]) ?? NotificationSettingValue.All;
    $[36] = settings;
    $[37] = t26;
  } else {
    t26 = $[37];
  }
  let t27;
  if ($[38] !== t26) {
    t27 = {
      id: "projects:projectAccess",
      title: t24,
      notificationTypes: t25,
      value: t26
    };
    $[38] = t26;
    $[39] = t27;
  } else {
    t27 = $[39];
  }
  let t28;
  let t29;
  if ($[40] === Symbol.for("react.memo_cache_sentinel")) {
    t28 = t("notificationSettingType.SprintCreated");
    t29 = [NotificationType.SprintCreated];
    $[40] = t28;
    $[41] = t29;
  } else {
    t28 = $[40];
    t29 = $[41];
  }
  let t30;
  if ($[42] !== settings) {
    t30 = calculateValue(settings, [NotificationType.SprintCreated]) ?? NotificationSettingValue.Self;
    $[42] = settings;
    $[43] = t30;
  } else {
    t30 = $[43];
  }
  let t31;
  if ($[44] !== t30) {
    t31 = {
      id: "projects:sprintCreated",
      title: t28,
      notificationTypes: t29,
      value: t30
    };
    $[44] = t30;
    $[45] = t31;
  } else {
    t31 = $[45];
  }
  let t32;
  if ($[46] !== t11 || $[47] !== t15 || $[48] !== t19 || $[49] !== t23 || $[50] !== t27 || $[51] !== t31) {
    t32 = {
      id: Module.Projects,
      title: t7,
      items: [t11, t15, t19, t23, t27, t31]
    };
    $[46] = t11;
    $[47] = t15;
    $[48] = t19;
    $[49] = t23;
    $[50] = t27;
    $[51] = t31;
    $[52] = t32;
  } else {
    t32 = $[52];
  }
  let t33;
  if ($[53] === Symbol.for("react.memo_cache_sentinel")) {
    t33 = t("module.Mail");
    $[53] = t33;
  } else {
    t33 = $[53];
  }
  let t34;
  let t35;
  if ($[54] === Symbol.for("react.memo_cache_sentinel")) {
    t34 = t("notificationSettingType.NewMessage");
    t35 = [NotificationType.NewEmailMessage];
    $[54] = t34;
    $[55] = t35;
  } else {
    t34 = $[54];
    t35 = $[55];
  }
  let t36;
  if ($[56] !== settings) {
    t36 = calculateValue(settings, [NotificationType.NewEmailMessage]) ?? NotificationSettingValue.Off;
    $[56] = settings;
    $[57] = t36;
  } else {
    t36 = $[57];
  }
  let t37;
  if ($[58] !== t36) {
    t37 = {
      id: "mail:newMessage",
      title: t34,
      notificationTypes: t35,
      value: t36
    };
    $[58] = t36;
    $[59] = t37;
  } else {
    t37 = $[59];
  }
  let t38;
  let t39;
  if ($[60] === Symbol.for("react.memo_cache_sentinel")) {
    t38 = t("notificationSettingType.ReplyToImportantMessage");
    t39 = [NotificationType.ImportantNewEmailMessage];
    $[60] = t38;
    $[61] = t39;
  } else {
    t38 = $[60];
    t39 = $[61];
  }
  let t40;
  if ($[62] !== settings) {
    t40 = calculateValue(settings, [NotificationType.ImportantNewEmailMessage]) ?? NotificationSettingValue.All;
    $[62] = settings;
    $[63] = t40;
  } else {
    t40 = $[63];
  }
  let t41;
  if ($[64] !== t40) {
    t41 = {
      id: "mail:replyToImportantMessage",
      title: t38,
      notificationTypes: t39,
      value: t40
    };
    $[64] = t40;
    $[65] = t41;
  } else {
    t41 = $[65];
  }
  let t42;
  if ($[66] !== t37 || $[67] !== t41) {
    t42 = {
      id: Module.Mail,
      title: t33,
      items: [t37, t41]
    };
    $[66] = t37;
    $[67] = t41;
    $[68] = t42;
  } else {
    t42 = $[68];
  }
  let t43;
  if ($[69] === Symbol.for("react.memo_cache_sentinel")) {
    t43 = t("module.Disk");
    $[69] = t43;
  } else {
    t43 = $[69];
  }
  let t44;
  let t45;
  if ($[70] === Symbol.for("react.memo_cache_sentinel")) {
    t44 = t("notificationSettingType.DiskCommentMention");
    t45 = [NotificationType.DocumentMention, NotificationType.DocumentComment];
    $[70] = t44;
    $[71] = t45;
  } else {
    t44 = $[70];
    t45 = $[71];
  }
  let t46;
  if ($[72] !== settings) {
    t46 = calculateValue(settings, [NotificationType.DocumentMention, NotificationType.DocumentComment]) ?? NotificationSettingValue.All;
    $[72] = settings;
    $[73] = t46;
  } else {
    t46 = $[73];
  }
  let t47;
  if ($[74] !== t46) {
    t47 = {
      id: "disk:diskCommentMention",
      title: t44,
      notificationTypes: t45,
      value: t46
    };
    $[74] = t46;
    $[75] = t47;
  } else {
    t47 = $[75];
  }
  let t48;
  let t49;
  if ($[76] === Symbol.for("react.memo_cache_sentinel")) {
    t48 = t("notificationSettingType.DiskAccess");
    t49 = [NotificationType.DocumentShare, NotificationType.DirectoryShare, NotificationType.RoomShare];
    $[76] = t48;
    $[77] = t49;
  } else {
    t48 = $[76];
    t49 = $[77];
  }
  let t50;
  if ($[78] !== settings) {
    t50 = calculateValue(settings, [NotificationType.DocumentShare, NotificationType.DirectoryShare, NotificationType.RoomShare]) ?? NotificationSettingValue.All;
    $[78] = settings;
    $[79] = t50;
  } else {
    t50 = $[79];
  }
  let t51;
  if ($[80] !== t50) {
    t51 = {
      id: "disk:diskAccess",
      title: t48,
      notificationTypes: t49,
      value: t50
    };
    $[80] = t50;
    $[81] = t51;
  } else {
    t51 = $[81];
  }
  let t52;
  if ($[82] !== t47 || $[83] !== t51) {
    t52 = {
      id: Module.Disk,
      title: t43,
      items: [t47, t51]
    };
    $[82] = t47;
    $[83] = t51;
    $[84] = t52;
  } else {
    t52 = $[84];
  }
  let t53;
  if ($[85] === Symbol.for("react.memo_cache_sentinel")) {
    t53 = t("module.Calendar");
    $[85] = t53;
  } else {
    t53 = $[85];
  }
  let t54;
  let t55;
  if ($[86] === Symbol.for("react.memo_cache_sentinel")) {
    t54 = t("notificationSettingType.EventInvite");
    t55 = [NotificationType.CalendarEventInvite];
    $[86] = t54;
    $[87] = t55;
  } else {
    t54 = $[86];
    t55 = $[87];
  }
  let t56;
  if ($[88] !== settings) {
    t56 = calculateValue(settings, [NotificationType.CalendarEventInvite]) ?? NotificationSettingValue.All;
    $[88] = settings;
    $[89] = t56;
  } else {
    t56 = $[89];
  }
  let t57;
  if ($[90] !== t56) {
    t57 = {
      id: "calendar:eventInvite",
      title: t54,
      notificationTypes: t55,
      value: t56
    };
    $[90] = t56;
    $[91] = t57;
  } else {
    t57 = $[91];
  }
  let t58;
  let t59;
  if ($[92] === Symbol.for("react.memo_cache_sentinel")) {
    t58 = t("notificationSettingType.EventUpcomingNotification");
    t59 = [NotificationType.CalendarUpcomingEvent];
    $[92] = t58;
    $[93] = t59;
  } else {
    t58 = $[92];
    t59 = $[93];
  }
  let t60;
  if ($[94] !== settings) {
    t60 = calculateValue(settings, [NotificationType.CalendarUpcomingEvent]) ?? NotificationSettingValue.All;
    $[94] = settings;
    $[95] = t60;
  } else {
    t60 = $[95];
  }
  let t61;
  if ($[96] !== t60) {
    t61 = {
      id: "calendar:EventUpcomingNotification",
      title: t58,
      notificationTypes: t59,
      value: t60
    };
    $[96] = t60;
    $[97] = t61;
  } else {
    t61 = $[97];
  }
  let t62;
  let t63;
  if ($[98] === Symbol.for("react.memo_cache_sentinel")) {
    t62 = t("notificationSettingType.EventChange");
    t63 = [NotificationType.CalendarEventChange, NotificationType.CalendarEventCancel];
    $[98] = t62;
    $[99] = t63;
  } else {
    t62 = $[98];
    t63 = $[99];
  }
  let t64;
  if ($[100] !== settings) {
    t64 = calculateValue(settings, [NotificationType.CalendarEventChange, NotificationType.CalendarEventCancel]) ?? NotificationSettingValue.Self;
    $[100] = settings;
    $[101] = t64;
  } else {
    t64 = $[101];
  }
  let t65;
  if ($[102] !== t64) {
    t65 = {
      id: "calendar:eventChange",
      title: t62,
      notificationTypes: t63,
      value: t64
    };
    $[102] = t64;
    $[103] = t65;
  } else {
    t65 = $[103];
  }
  let t66;
  let t67;
  if ($[104] === Symbol.for("react.memo_cache_sentinel")) {
    t66 = t("notificationSettingType.CalendarShared");
    t67 = [NotificationType.CalendarShare];
    $[104] = t66;
    $[105] = t67;
  } else {
    t66 = $[104];
    t67 = $[105];
  }
  let t68;
  if ($[106] !== settings) {
    t68 = calculateValue(settings, [NotificationType.CalendarShare]) ?? NotificationSettingValue.All;
    $[106] = settings;
    $[107] = t68;
  } else {
    t68 = $[107];
  }
  let t69;
  if ($[108] !== t68) {
    t69 = {
      id: "calendar:calendarShared",
      title: t66,
      notificationTypes: t67,
      value: t68
    };
    $[108] = t68;
    $[109] = t69;
  } else {
    t69 = $[109];
  }
  let t70;
  if ($[110] !== t57 || $[111] !== t61 || $[112] !== t65 || $[113] !== t69) {
    t70 = {
      id: Module.Calendar,
      title: t53,
      items: [t57, t61, t65, t69]
    };
    $[110] = t57;
    $[111] = t61;
    $[112] = t65;
    $[113] = t69;
    $[114] = t70;
  } else {
    t70 = $[114];
  }
  let t71;
  if ($[115] !== t32 || $[116] !== t42 || $[117] !== t52 || $[118] !== t6 || $[119] !== t70) {
    t71 = [t6, t32, t42, t52, t70];
    $[115] = t32;
    $[116] = t42;
    $[117] = t52;
    $[118] = t6;
    $[119] = t70;
    $[120] = t71;
  } else {
    t71 = $[120];
  }
  return t71;
};
const NotificationSettings = () => {
  const $ = compilerRuntimeExports.c(14);
  const {
    userId
  } = useCurrentUser();
  const t0 = userId;
  let t1;
  if ($[0] !== t0) {
    t1 = {
      userId: t0
    };
    $[0] = t0;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const t2 = !userId;
  let t3;
  if ($[2] !== t2) {
    t3 = {
      skip: t2
    };
    $[2] = t2;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  const {
    data: settings,
    isLoading
  } = useGetNotificationSettingsQuery(t1, t3);
  const [updateSetting] = useUpdateNotificationSettingsMutation();
  const groupedSettings = useGroupedSettings(settings);
  const renderLabel = _temp;
  let t4;
  if ($[4] !== settings || $[5] !== updateSetting || $[6] !== userId) {
    t4 = async (value, item_0, source) => {
      if (value === item_0.value || !userId) {
        return;
      }
      const existingSettings = new Map((settings == null ? void 0 : settings.map(_temp2)) ?? []);
      const updatedSettings = item_0.notificationTypes.reduce((acc, type) => {
        acc.set(type, {
          id: type,
          notificationType: type,
          source,
          value
        });
        return acc;
      }, existingSettings);
      await updateSetting({
        userId,
        settings: Array.from(updatedSettings.values())
      });
    };
    $[4] = settings;
    $[5] = updateSetting;
    $[6] = userId;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  const handleSettingsChange = t4;
  if (isLoading) {
    let t52;
    if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
      t52 = /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { justify: "center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, {}) });
      $[8] = t52;
    } else {
      t52 = $[8];
    }
    return t52;
  }
  let t5;
  if ($[9] !== groupedSettings || $[10] !== handleSettingsChange) {
    t5 = groupedSettings == null ? void 0 : groupedSettings.map((source_0) => {
      var _a;
      return /* @__PURE__ */ jsxRuntimeExports.jsxs(List, { title: source_0.title, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "xl", fw: 500, mb: "xs", c: "primary", children: source_0.title }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Stack, { gap: "sm", children: (_a = source_0.items) == null ? void 0 : _a.map((item_1) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(NotificationSettingItem, { item: item_1, source: source_0.id, renderLabel, onChange: handleSettingsChange }, item_1.id) }, item_1.id)) })
      ] }, source_0.id);
    });
    $[9] = groupedSettings;
    $[10] = handleSettingsChange;
    $[11] = t5;
  } else {
    t5 = $[11];
  }
  let t6;
  if ($[12] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Stack, { gap: "xl", children: t5 }) });
    $[12] = t5;
    $[13] = t6;
  } else {
    t6 = $[13];
  }
  return t6;
};
function _temp(item) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { gap: "xs", align: "center", children: [
    item.id === NotificationSettingValue.Off && /* @__PURE__ */ jsxRuntimeExports.jsx(ev, { size: 16 }),
    item.id === NotificationSettingValue.Self && /* @__PURE__ */ jsxRuntimeExports.jsx(EIe, { size: 16 }),
    item.id === NotificationSettingValue.All && /* @__PURE__ */ jsxRuntimeExports.jsx(kv, { size: 16 }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", children: item.title })
  ] });
}
function _temp2(setting) {
  return [setting.id, setting];
}
function NotificationSettingsPage() {
  const $ = compilerRuntimeExports.c(8);
  const {
    t: t2
  } = useTranslation();
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      base: "xs",
      sm: "md"
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  let t1;
  if ($[1] !== t2) {
    t1 = t2("profile.notificationSettings");
    $[1] = t2;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t22;
  if ($[3] !== t1) {
    t22 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: 500, fz: "md", mb: "md", children: t1 });
    $[3] = t1;
    $[4] = t22;
  } else {
    t22 = $[4];
  }
  let t3;
  if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Stack, { w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(NotificationSettings, {}) });
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  let t4;
  if ($[6] !== t22) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Paper, { bg: "white", radius: "md", p: t0, children: [
      t22,
      t3
    ] });
    $[6] = t22;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  return t4;
}
export {
  NotificationSettingsPage as default
};
//# sourceMappingURL=notification-settings.page-DmRC7Fwx.js.map
