import { jsx as e, jsxs as o, Fragment as I } from "react/jsx-runtime";
import { useState as k, useCallback as q, useEffect as Q } from "react";
import { useTranslation as j } from "react-i18next";
import { useNavigate as X, useLocation as Z, Outlet as _, useOutletContext as z } from "react-router-dom";
import { i as K, B as ee } from "./index-Dh9kUeDn.js";
import { Loader2 as B, Settings as O, Upload as W, FileText as G, Clock as V, Save as R, RotateCcw as P, History as L, AlertTriangle as re, Shield as ae } from "lucide-react";
const M = [
  { id: "general", labelKey: "settings.tabs.general", icon: O, route: "/administration/configuration/settings/general" },
  { id: "file-upload", labelKey: "settings.tabs.fileUpload", icon: W, route: "/administration/configuration/settings/file-upload" },
  { id: "legal-file", labelKey: "settings.tabs.legalFile", icon: G, route: "/administration/configuration/settings/legal-file" }
];
function ie() {
  const { t } = j("admin"), w = X(), y = Z(), [v, h] = k([]), [b, m] = k(!0), g = q(async () => {
    try {
      m(!0);
      const u = await K.settings.getAll();
      h(u);
    } catch (u) {
      console.error("Failed to load settings:", u);
    } finally {
      m(!1);
    }
  }, []);
  Q(() => {
    g();
  }, [g]);
  const S = () => {
    const u = y.pathname;
    return M.find((x) => u.includes(x.id))?.id || "general";
  }, $ = (u) => {
    const p = M.find((x) => x.id === u);
    p && w(p.route);
  };
  return b ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center min-h-[400px]", children: /* @__PURE__ */ e(B, { className: "w-8 h-8 animate-spin text-[var(--color-accent-600)]" }) }) : /* @__PURE__ */ o("div", { className: "space-y-6", children: [
    /* @__PURE__ */ e(
      ee,
      {
        items: [
          { label: t("header.title"), href: "/administration" },
          { label: t("settings.title", "Settings") }
        ]
      }
    ),
    /* @__PURE__ */ e("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ o("div", { children: [
      /* @__PURE__ */ e("h1", { className: "text-2xl font-bold text-[var(--text-primary)]", children: t("settings.title") }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)] mt-1", children: t("settings.subtitle") })
    ] }) }),
    /* @__PURE__ */ e("div", { className: "border-b border-[var(--border-color)]", children: /* @__PURE__ */ e("nav", { className: "-mb-px flex space-x-8", "aria-label": "Tabs", children: M.map((u) => {
      const p = u.icon, x = S() === u.id;
      return /* @__PURE__ */ o(
        "button",
        {
          onClick: () => $(u.id),
          className: `
                  group inline-flex items-center py-4 px-1 border-b-2 font-medium text-sm transition-colors
                  ${x ? "border-[var(--color-accent-500)] text-[var(--color-accent-600)]" : "border-transparent text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:border-[var(--border-color)]"}
                `,
          children: [
            /* @__PURE__ */ e(p, { className: `mr-2 h-5 w-5 ${x ? "text-[var(--color-accent-500)]" : "text-[var(--text-tertiary)] group-hover:text-[var(--text-secondary)]"}` }),
            t(u.labelKey)
          ]
        },
        u.id
      );
    }) }) }),
    /* @__PURE__ */ e(_, { context: { settings: v, refreshSettings: g } })
  ] });
}
function J() {
  const { settings: t, refreshSettings: w } = z(), [y, v] = k({}), [h, b] = k(null), [m, g] = k(null), [S, $] = k([]), [u, p] = k(!1), x = (c, l, i) => {
    v((f) => ({
      ...f,
      [`${c}.${l}`]: i
    }));
  }, E = (c) => {
    const l = `${c.category}.${c.key}`;
    return y[l] !== void 0 && y[l] !== c.value;
  }, D = (c) => {
    const l = `${c.category}.${c.key}`;
    return y[l] ?? c.value;
  }, C = (c) => `${c.category}.${c.key}`;
  return {
    settings: t,
    editedValues: y,
    saving: h,
    historyModal: m,
    history: S,
    loadingHistory: u,
    handleValueChange: x,
    hasChanges: E,
    getDisplayValue: D,
    getEditKey: C,
    handleSave: async (c) => {
      const l = C(c), i = y[l];
      if (!(i === void 0 || i === c.value))
        try {
          b(l), await K.settings.update(c.category, c.key, i), v((f) => {
            const T = { ...f };
            return delete T[l], T;
          }), await w();
        } catch (f) {
          console.error("Failed to save setting:", f);
        } finally {
          b(null);
        }
    },
    handleReset: async (c) => {
      const l = C(c);
      try {
        b(l), await K.settings.reset(c.category, c.key), v((i) => {
          const f = { ...i };
          return delete f[l], f;
        }), await w();
      } catch (i) {
        console.error("Failed to reset setting:", i);
      } finally {
        b(null);
      }
    },
    openHistory: async (c, l) => {
      g({ category: c, key: l }), p(!0);
      try {
        const i = await K.settings.getHistory(c, l);
        $(i);
      } catch (i) {
        console.error("Failed to load history:", i);
      } finally {
        p(!1);
      }
    },
    closeHistory: () => g(null)
  };
}
function Y({ category: t, settingKey: w, history: y, loading: v, onClose: h }) {
  const { t: b } = j("admin");
  return /* @__PURE__ */ e("div", { className: "fixed inset-0 z-50 overflow-y-auto", children: /* @__PURE__ */ o("div", { className: "flex items-center justify-center min-h-screen px-4", children: [
    /* @__PURE__ */ e("button", { type: "button", className: "fixed inset-0 bg-black/50", onClick: h, "aria-label": "Close modal" }),
    /* @__PURE__ */ o("div", { className: "relative rounded-[var(--radius-card)] bg-[var(--bg-card)] shadow-xl max-w-2xl w-full p-6", children: [
      /* @__PURE__ */ e("h3", { className: "text-lg font-semibold text-[var(--text-primary)] mb-4", children: b("settings.historyTitle", { key: `${t}.${w}` }) }),
      v && /* @__PURE__ */ e("div", { className: "flex justify-center py-8", children: /* @__PURE__ */ e(B, { className: "w-8 h-8 animate-spin text-[var(--color-accent-600)]" }) }),
      !v && y.length === 0 && /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-secondary)]", children: b("settings.noHistory") }),
      !v && y.length > 0 && /* @__PURE__ */ e("div", { className: "space-y-3 max-h-96 overflow-y-auto", children: y.map((m) => /* @__PURE__ */ o("div", { className: "p-3 bg-[var(--bg-secondary)] rounded-lg", children: [
        /* @__PURE__ */ o("div", { className: "flex justify-between text-sm", children: [
          /* @__PURE__ */ e("span", { className: "text-[var(--text-secondary)]", children: m.changedByUserName || b("settings.system") }),
          /* @__PURE__ */ e("span", { className: "text-[var(--text-tertiary)]", children: new Date(m.changedAt).toLocaleString() })
        ] }),
        /* @__PURE__ */ o("div", { className: "mt-2 text-sm", children: [
          /* @__PURE__ */ e("span", { className: "text-[var(--error-text)] line-through", children: m.oldValue }),
          /* @__PURE__ */ e("span", { className: "mx-2 text-[var(--text-tertiary)]", children: "→" }),
          /* @__PURE__ */ e("span", { className: "text-[var(--success-text)]", children: m.newValue })
        ] })
      ] }, m.id)) }),
      /* @__PURE__ */ e("div", { className: "mt-6 flex justify-end", children: /* @__PURE__ */ e(
        "button",
        {
          onClick: h,
          className: "px-4 py-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] transition-colors",
          children: b("common.cancel")
        }
      ) })
    ] })
  ] }) });
}
function de() {
  const { t } = j("admin"), {
    settings: w,
    saving: y,
    historyModal: v,
    history: h,
    loadingHistory: b,
    handleValueChange: m,
    hasChanges: g,
    getDisplayValue: S,
    getEditKey: $,
    handleSave: u,
    handleReset: p,
    openHistory: x,
    closeHistory: E
  } = J(), D = w.filter((s) => s.category === "Session"), C = w.filter((s) => s.category === "General"), A = (s) => s === "Database" ? "bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)]" : s === "AppSettings" ? "bg-purple-500/10 text-purple-600 dark:text-purple-400" : "bg-[var(--bg-secondary)] text-[var(--text-tertiary)]", F = (s, c, l) => s.valueType === "Bool" ? /* @__PURE__ */ o("label", { className: "relative inline-flex items-center cursor-pointer", children: [
    /* @__PURE__ */ e(
      "input",
      {
        type: "checkbox",
        checked: c === "true",
        onChange: (i) => m(s.category, s.key, i.target.checked ? "true" : "false"),
        disabled: !s.isEditable || l,
        className: "sr-only peer"
      }
    ),
    /* @__PURE__ */ e("div", { className: "w-11 h-6 bg-[var(--bg-tertiary)] peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-[var(--color-accent-500)]/30 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-[var(--border-color)] after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-[var(--color-accent-600)] peer-disabled:opacity-50 peer-disabled:cursor-not-allowed" })
  ] }) : s.valueType === "Int" || s.valueType === "Decimal" ? /* @__PURE__ */ e(
    "input",
    {
      type: "number",
      value: c,
      onChange: (i) => m(s.category, s.key, i.target.value),
      disabled: !s.isEditable || l,
      className: "w-24 px-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-button)] bg-[var(--bg-card)] text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)]"
    }
  ) : /* @__PURE__ */ e(
    "input",
    {
      type: s.isSensitive ? "password" : "text",
      value: s.isSensitive ? "********" : c,
      onChange: (i) => m(s.category, s.key, i.target.value),
      disabled: !s.isEditable || l || s.isSensitive,
      className: "w-48 px-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-button)] bg-[var(--bg-card)] text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)]"
    }
  ), a = (s) => {
    const c = $(s), l = y === c, i = g(s), f = S(s);
    return /* @__PURE__ */ o(
      "div",
      {
        className: "flex items-center justify-between py-4 border-b border-[var(--border-color)] last:border-0",
        children: [
          /* @__PURE__ */ o("div", { className: "flex-1 min-w-0 pr-4", children: [
            /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ e("span", { className: "font-medium text-[var(--text-primary)]", children: t(`settings.keys.${s.category}.${s.key}`, s.key) }),
              !s.isEditable && /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs bg-[var(--bg-secondary)] text-[var(--text-tertiary)] rounded", children: t("settings.readonly") }),
              /* @__PURE__ */ e("span", { className: `px-2 py-0.5 text-xs rounded ${A(s.source)}`, children: s.source })
            ] }),
            s.description && /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)] mt-1", children: t(`settings.descriptions.${s.category}.${s.key}`, s.description) }),
            s.modifiedAt && /* @__PURE__ */ o("p", { className: "text-xs text-[var(--text-tertiary)] mt-1 flex items-center gap-1", children: [
              /* @__PURE__ */ e(V, { className: "w-3 h-3" }),
              t("settings.modifiedBy", { user: s.modifiedByUserName, date: new Date(s.modifiedAt).toLocaleString() })
            ] })
          ] }),
          /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
            F(s, f, l),
            s.isEditable && s.source === "Database" && /* @__PURE__ */ o(I, { children: [
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => u(s),
                  disabled: !i || l,
                  className: "p-2 text-[var(--color-accent-600)] hover:bg-[var(--color-accent-500)]/10 rounded-[var(--radius-button)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
                  title: t("common.save"),
                  children: l ? /* @__PURE__ */ e(B, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(R, { className: "w-4 h-4" })
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => p(s),
                  disabled: s.value === s.defaultValue || l,
                  className: "p-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
                  title: t("settings.resetToDefault"),
                  children: /* @__PURE__ */ e(P, { className: "w-4 h-4" })
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => x(s.category, s.key),
                  className: "p-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] transition-colors",
                  title: t("settings.viewHistory"),
                  children: /* @__PURE__ */ e(L, { className: "w-4 h-4" })
                }
              )
            ] })
          ] })
        ]
      },
      c
    );
  };
  return /* @__PURE__ */ o("div", { className: "space-y-6", children: [
    D.length > 0 && /* @__PURE__ */ o("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] bg-[var(--bg-card)] overflow-hidden shadow-sm", children: [
      /* @__PURE__ */ e("div", { className: "px-6 py-4 bg-gradient-to-r from-[var(--color-accent-500)]/10 to-[var(--color-accent-600)]/5 border-b border-[var(--border-color)]", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ e("div", { className: "p-2 rounded-lg bg-[var(--color-accent-500)]/20", children: /* @__PURE__ */ e(V, { className: "w-5 h-5 text-[var(--color-accent-600)]" }) }),
        /* @__PURE__ */ o("div", { children: [
          /* @__PURE__ */ e("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: t("settings.sections.session") }),
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: t("settings.sections.sessionDescription") })
        ] })
      ] }) }),
      /* @__PURE__ */ e("div", { className: "px-6 py-2", children: D.map(a) })
    ] }),
    C.length > 0 && /* @__PURE__ */ o("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] bg-[var(--bg-card)] overflow-hidden shadow-sm", children: [
      /* @__PURE__ */ e("div", { className: "px-6 py-4 bg-gradient-to-r from-[var(--color-accent-500)]/10 to-[var(--color-accent-600)]/5 border-b border-[var(--border-color)]", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ e("div", { className: "p-2 rounded-lg bg-[var(--color-accent-500)]/20", children: /* @__PURE__ */ e(O, { className: "w-5 h-5 text-[var(--color-accent-600)]" }) }),
        /* @__PURE__ */ o("div", { children: [
          /* @__PURE__ */ e("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: t("settings.sections.general") }),
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: t("settings.sections.generalDescription") })
        ] })
      ] }) }),
      /* @__PURE__ */ e("div", { className: "px-6 py-2", children: C.map(a) })
    ] }),
    D.length === 0 && C.length === 0 && /* @__PURE__ */ e("div", { className: "text-center py-12 text-[var(--text-secondary)]", children: t("settings.noSettings") }),
    v && /* @__PURE__ */ e(
      Y,
      {
        category: v.category,
        settingKey: v.key,
        history: h,
        loading: b,
        onClose: E
      }
    )
  ] });
}
function ve() {
  const { t } = j("admin"), {
    settings: w,
    saving: y,
    historyModal: v,
    history: h,
    loadingHistory: b,
    handleValueChange: m,
    hasChanges: g,
    getDisplayValue: S,
    getEditKey: $,
    handleSave: u,
    handleReset: p,
    openHistory: x,
    closeHistory: E
  } = J(), D = w.filter((a) => a.category === "FileUpload"), C = (a) => {
    try {
      return JSON.parse(a);
    } catch {
      return [];
    }
  }, A = (a, s, c) => a.valueType === "Int" ? /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
    /* @__PURE__ */ e(
      "input",
      {
        type: "number",
        value: s,
        onChange: (l) => m(a.category, a.key, l.target.value),
        disabled: !a.isEditable || c,
        className: "w-24 px-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-button)] bg-[var(--bg-card)] text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)]"
      }
    ),
    a.key === "MaxFileSizeMB" && /* @__PURE__ */ e("span", { className: "text-sm text-[var(--text-secondary)]", children: "MB" })
  ] }) : /* @__PURE__ */ e(
    "input",
    {
      type: a.isSensitive ? "password" : "text",
      value: a.isSensitive ? "********" : s,
      onChange: (l) => m(a.category, a.key, l.target.value),
      disabled: !a.isEditable || c || a.isSensitive,
      className: "w-48 px-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-button)] bg-[var(--bg-card)] text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)]"
    }
  ), F = (a) => {
    const s = $(a), c = y === s, l = g(a), i = S(a);
    if (a.valueType === "Json" && a.key === "AllowedExtensions") {
      const f = C(i);
      return /* @__PURE__ */ o("div", { className: "py-4 border-b border-[var(--border-color)] last:border-0", children: [
        /* @__PURE__ */ o("div", { className: "flex items-center justify-between mb-3", children: [
          /* @__PURE__ */ o("div", { children: [
            /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ e("span", { className: "font-medium text-[var(--text-primary)]", children: t(`settings.keys.${a.category}.${a.key}`, a.key) }),
              !a.isEditable && /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs bg-[var(--bg-secondary)] text-[var(--text-tertiary)] rounded", children: t("settings.readonly") }),
              /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)] rounded", children: a.source })
            ] }),
            a.description && /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)] mt-1", children: t(`settings.descriptions.${a.category}.${a.key}`, a.description) })
          ] }),
          a.isEditable && a.source === "Database" && /* @__PURE__ */ e(
            "button",
            {
              onClick: () => x(a.category, a.key),
              className: "p-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] transition-colors",
              title: t("settings.viewHistory"),
              children: /* @__PURE__ */ e(L, { className: "w-4 h-4" })
            }
          )
        ] }),
        /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-2", children: f.map((T) => /* @__PURE__ */ e(
          "span",
          {
            className: "px-3 py-1 bg-[var(--bg-secondary)] text-[var(--text-secondary)] rounded-full text-sm",
            children: T
          },
          T
        )) })
      ] }, s);
    }
    return /* @__PURE__ */ o(
      "div",
      {
        className: "flex items-center justify-between py-4 border-b border-[var(--border-color)] last:border-0",
        children: [
          /* @__PURE__ */ o("div", { className: "flex-1 min-w-0 pr-4", children: [
            /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ e("span", { className: "font-medium text-[var(--text-primary)]", children: t(`settings.keys.${a.category}.${a.key}`, a.key) }),
              !a.isEditable && /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs bg-[var(--bg-secondary)] text-[var(--text-tertiary)] rounded", children: t("settings.readonly") }),
              /* @__PURE__ */ e("span", { className: `px-2 py-0.5 text-xs rounded ${a.source === "Database" ? "bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)]" : a.source === "AppSettings" ? "bg-purple-500/10 text-purple-600 dark:text-purple-400" : "bg-[var(--bg-secondary)] text-[var(--text-tertiary)]"}`, children: a.source })
            ] }),
            a.description && /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)] mt-1", children: t(`settings.descriptions.${a.category}.${a.key}`, a.description) }),
            a.modifiedAt && /* @__PURE__ */ o("p", { className: "text-xs text-[var(--text-tertiary)] mt-1 flex items-center gap-1", children: [
              /* @__PURE__ */ e(V, { className: "w-3 h-3" }),
              t("settings.modifiedBy", { user: a.modifiedByUserName, date: new Date(a.modifiedAt).toLocaleString() })
            ] })
          ] }),
          /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
            A(a, i, c),
            a.isEditable && a.source === "Database" && /* @__PURE__ */ o(I, { children: [
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => u(a),
                  disabled: !l || c,
                  className: "p-2 text-[var(--color-accent-600)] hover:bg-[var(--color-accent-500)]/10 rounded-[var(--radius-button)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
                  title: t("common.save"),
                  children: c ? /* @__PURE__ */ e(B, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(R, { className: "w-4 h-4" })
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => p(a),
                  disabled: a.value === a.defaultValue || c,
                  className: "p-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
                  title: t("settings.resetToDefault"),
                  children: /* @__PURE__ */ e(P, { className: "w-4 h-4" })
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => x(a.category, a.key),
                  className: "p-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] transition-colors",
                  title: t("settings.viewHistory"),
                  children: /* @__PURE__ */ e(L, { className: "w-4 h-4" })
                }
              )
            ] })
          ] })
        ]
      },
      s
    );
  };
  return /* @__PURE__ */ o("div", { className: "space-y-6", children: [
    /* @__PURE__ */ o("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] bg-[var(--bg-card)] overflow-hidden shadow-sm", children: [
      /* @__PURE__ */ e("div", { className: "px-6 py-4 bg-gradient-to-r from-[var(--color-accent-500)]/10 to-[var(--color-accent-600)]/5 border-b border-[var(--border-color)]", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ e("div", { className: "p-2 rounded-lg bg-[var(--color-accent-500)]/20", children: /* @__PURE__ */ e(W, { className: "w-5 h-5 text-[var(--color-accent-600)]" }) }),
        /* @__PURE__ */ o("div", { children: [
          /* @__PURE__ */ e("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: t("settings.sections.fileUpload") }),
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: t("settings.sections.fileUploadDescription") })
        ] })
      ] }) }),
      /* @__PURE__ */ e("div", { className: "px-6 py-2", children: D.length > 0 ? D.map(F) : /* @__PURE__ */ e("div", { className: "text-center py-8 text-[var(--text-secondary)]", children: t("settings.noSettings") }) })
    ] }),
    v && /* @__PURE__ */ e(
      Y,
      {
        category: v.category,
        settingKey: v.key,
        history: h,
        loading: b,
        onClose: E
      }
    )
  ] });
}
function me() {
  const { t } = j("admin"), { settings: w, refreshSettings: y } = z(), [v, h] = k({}), [b, m] = k(null), [g, S] = k(null), [$, u] = k([]), [p, x] = k(!1), E = w.filter((r) => r.category === "LegalFile"), D = (r, n, d) => {
    h((N) => ({
      ...N,
      [`${r}.${n}`]: d
    }));
  }, C = (r) => {
    const n = `${r.category}.${r.key}`;
    return v[n] !== void 0 && v[n] !== r.value;
  }, A = (r) => {
    const n = `${r.category}.${r.key}`;
    return v[n] ?? r.value;
  }, F = async (r) => {
    const n = `${r.category}.${r.key}`, d = v[n];
    if (!(d === void 0 || d === r.value))
      try {
        m(n), await K.settings.update(r.category, r.key, d), h((N) => {
          const H = { ...N };
          return delete H[n], H;
        }), await y();
      } catch (N) {
        console.error("Failed to save setting:", N);
      } finally {
        m(null);
      }
  }, a = async (r) => {
    const n = `${r.category}.${r.key}`;
    try {
      m(n), await K.settings.reset(r.category, r.key), h((d) => {
        const N = { ...d };
        return delete N[n], N;
      }), await y();
    } catch (d) {
      console.error("Failed to reset setting:", d);
    } finally {
      m(null);
    }
  }, s = async (r, n) => {
    S({ category: r, key: n }), x(!0);
    try {
      const d = await K.settings.getHistory(r, n);
      u(d);
    } catch (d) {
      console.error("Failed to load history:", d);
    } finally {
      x(!1);
    }
  }, c = (r) => {
    const n = Math.floor(r / 365), d = r % 365;
    return d === 0 ? `${n} ${t("settings.years")}` : `${n} ${t("settings.years")} ${d} ${t("settings.days")}`;
  }, l = (r) => !r.isEditable && (r.key === "RetentionDays" || r.key === "EnableWorm"), i = (r, n, d, N) => r.valueType === "Bool" ? /* @__PURE__ */ o("label", { className: "relative inline-flex cursor-pointer", children: [
    /* @__PURE__ */ e("span", { className: "sr-only", children: r.key }),
    /* @__PURE__ */ e(
      "input",
      {
        type: "checkbox",
        checked: n === "true",
        onChange: (H) => N(r.category, r.key, H.target.checked ? "true" : "false"),
        disabled: !r.isEditable || d,
        className: "sr-only peer",
        "aria-label": r.key
      }
    ),
    /* @__PURE__ */ e("div", { className: "w-11 h-6 bg-[var(--bg-tertiary)] peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-[var(--color-accent-500)]/30 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-[var(--border-color)] after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-[var(--color-accent-600)] peer-disabled:opacity-50 peer-disabled:cursor-not-allowed" })
  ] }) : r.valueType === "Int" ? /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
    /* @__PURE__ */ e(
      "input",
      {
        type: "number",
        value: n,
        onChange: (H) => N(r.category, r.key, H.target.value),
        disabled: !r.isEditable || d,
        className: "w-24 px-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-button)] bg-[var(--bg-card)] text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)]"
      }
    ),
    (r.key === "RetentionDays" || r.key === "ArchiveAfterDays") && /* @__PURE__ */ o("span", { className: "text-sm text-[var(--text-secondary)]", children: [
      "(",
      c(parseInt(n) || 0),
      ")"
    ] })
  ] }) : /* @__PURE__ */ e(
    "input",
    {
      type: r.isSensitive ? "password" : "text",
      value: r.isSensitive ? "********" : n,
      onChange: (H) => N(r.category, r.key, H.target.value),
      disabled: !r.isEditable || d || r.isSensitive,
      className: "w-48 px-3 py-2 border border-[var(--border-color)] rounded-[var(--radius-button)] bg-[var(--bg-card)] text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-[var(--color-accent-500)]"
    }
  ), f = (r) => r === "Database" ? "bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)]" : r === "AppSettings" ? "bg-purple-500/10 text-purple-600 dark:text-purple-400" : "bg-[var(--bg-secondary)] text-[var(--text-tertiary)]", T = (r) => {
    const n = `${r.category}.${r.key}`, d = b === n, N = C(r), H = A(r), U = l(r);
    return /* @__PURE__ */ o(
      "div",
      {
        className: `flex items-center justify-between py-4 border-b border-[var(--border-color)] last:border-0 ${U ? "bg-[var(--warning-bg)] -mx-6 px-6" : ""}`,
        children: [
          /* @__PURE__ */ o("div", { className: "flex-1 min-w-0 pr-4", children: [
            /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ e("span", { className: "font-medium text-[var(--text-primary)]", children: t(`settings.keys.${r.category}.${r.key}`, r.key) }),
              U && /* @__PURE__ */ o("span", { className: "px-2 py-0.5 text-xs bg-[var(--warning-bg)] text-[var(--warning-text)] border border-[var(--warning-border)] rounded flex items-center gap-1", children: [
                /* @__PURE__ */ e(ae, { className: "w-3 h-3" }),
                t("settings.legallyProtected")
              ] }),
              !r.isEditable && !U && /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs bg-[var(--bg-secondary)] text-[var(--text-tertiary)] rounded", children: t("settings.readonly") }),
              /* @__PURE__ */ e("span", { className: `px-2 py-0.5 text-xs rounded ${f(r.source)}`, children: r.source })
            ] }),
            r.description && /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)] mt-1", children: t(`settings.descriptions.${r.category}.${r.key}`, r.description) }),
            r.modifiedAt && /* @__PURE__ */ o("p", { className: "text-xs text-[var(--text-tertiary)] mt-1 flex items-center gap-1", children: [
              /* @__PURE__ */ e(V, { className: "w-3 h-3" }),
              t("settings.modifiedBy", { user: r.modifiedByUserName, date: new Date(r.modifiedAt).toLocaleString() })
            ] })
          ] }),
          /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
            i(r, H, d, D),
            r.isEditable && r.source === "Database" && /* @__PURE__ */ o(I, { children: [
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => F(r),
                  disabled: !N || d,
                  className: "p-2 text-[var(--color-accent-600)] hover:bg-[var(--color-accent-500)]/10 rounded-[var(--radius-button)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
                  title: t("common.save"),
                  children: d ? /* @__PURE__ */ e(B, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(R, { className: "w-4 h-4" })
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => a(r),
                  disabled: r.value === r.defaultValue || d,
                  className: "p-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
                  title: t("settings.resetToDefault"),
                  children: /* @__PURE__ */ e(P, { className: "w-4 h-4" })
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => s(r.category, r.key),
                  className: "p-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] transition-colors",
                  title: t("settings.viewHistory"),
                  children: /* @__PURE__ */ e(L, { className: "w-4 h-4" })
                }
              )
            ] })
          ] })
        ]
      },
      n
    );
  };
  return /* @__PURE__ */ o("div", { className: "space-y-6", children: [
    /* @__PURE__ */ e("div", { className: "bg-[var(--warning-bg)] border border-[var(--warning-border)] rounded-[var(--radius-card)] p-4", children: /* @__PURE__ */ o("div", { className: "flex items-start gap-3", children: [
      /* @__PURE__ */ e(re, { className: "w-5 h-5 text-[var(--warning-text)] flex-shrink-0 mt-0.5" }),
      /* @__PURE__ */ o("div", { children: [
        /* @__PURE__ */ e("h4", { className: "font-medium text-[var(--warning-text)]", children: t("settings.legalWarningTitle") }),
        /* @__PURE__ */ e("p", { className: "text-sm text-[var(--warning-text)] opacity-90 mt-1", children: t("settings.legalWarningDescription") })
      ] })
    ] }) }),
    /* @__PURE__ */ o("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] bg-[var(--bg-card)] overflow-hidden shadow-sm", children: [
      /* @__PURE__ */ e("div", { className: "px-6 py-4 bg-gradient-to-r from-amber-500/10 to-amber-600/5 border-b border-[var(--border-color)]", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ e("div", { className: "p-2 rounded-lg bg-amber-500/20", children: /* @__PURE__ */ e(G, { className: "w-5 h-5 text-amber-600" }) }),
        /* @__PURE__ */ o("div", { children: [
          /* @__PURE__ */ e("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: t("settings.sections.legalFile") }),
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: t("settings.sections.legalFileDescription") })
        ] })
      ] }) }),
      /* @__PURE__ */ e("div", { className: "px-6 py-2", children: E.length > 0 ? E.map(T) : /* @__PURE__ */ e("div", { className: "text-center py-8 text-[var(--text-secondary)]", children: t("settings.noSettings") }) })
    ] }),
    g && /* @__PURE__ */ e("div", { className: "fixed inset-0 z-50 overflow-y-auto", children: /* @__PURE__ */ o("div", { className: "flex items-center justify-center min-h-screen px-4", children: [
      /* @__PURE__ */ e("button", { type: "button", className: "fixed inset-0 bg-black/50", onClick: () => S(null), "aria-label": "Close modal" }),
      /* @__PURE__ */ o("div", { className: "relative rounded-[var(--radius-card)] bg-[var(--bg-card)] shadow-xl max-w-2xl w-full p-6", children: [
        /* @__PURE__ */ e("h3", { className: "text-lg font-semibold text-[var(--text-primary)] mb-4", children: t("settings.historyTitle", { key: `${g.category}.${g.key}` }) }),
        p && /* @__PURE__ */ e("div", { className: "flex justify-center py-8", children: /* @__PURE__ */ e(B, { className: "w-8 h-8 animate-spin text-[var(--color-accent-600)]" }) }),
        !p && $.length === 0 && /* @__PURE__ */ e("p", { className: "text-center py-8 text-[var(--text-secondary)]", children: t("settings.noHistory") }),
        !p && $.length > 0 && /* @__PURE__ */ e("div", { className: "space-y-3 max-h-96 overflow-y-auto", children: $.map((r) => /* @__PURE__ */ o("div", { className: "p-3 bg-[var(--bg-secondary)] rounded-lg", children: [
          /* @__PURE__ */ o("div", { className: "flex justify-between text-sm", children: [
            /* @__PURE__ */ e("span", { className: "text-[var(--text-secondary)]", children: r.changedByUserName || t("settings.system") }),
            /* @__PURE__ */ e("span", { className: "text-[var(--text-tertiary)]", children: new Date(r.changedAt).toLocaleString() })
          ] }),
          /* @__PURE__ */ o("div", { className: "mt-2 text-sm", children: [
            /* @__PURE__ */ e("span", { className: "text-[var(--error-text)] line-through", children: r.oldValue }),
            /* @__PURE__ */ e("span", { className: "mx-2 text-[var(--text-tertiary)]", children: "→" }),
            /* @__PURE__ */ e("span", { className: "text-[var(--success-text)]", children: r.newValue })
          ] })
        ] }, r.id)) }),
        /* @__PURE__ */ e("div", { className: "mt-6 flex justify-end", children: /* @__PURE__ */ e(
          "button",
          {
            onClick: () => S(null),
            className: "px-4 py-2 text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] rounded-[var(--radius-button)] transition-colors",
            children: t("common.cancel")
          }
        ) })
      ] })
    ] }) })
  ] });
}
export {
  ve as FileUploadSettingsSection,
  de as GeneralSettingsSection,
  me as LegalFileSettingsSection,
  ie as SettingsPage
};
//# sourceMappingURL=index-BrR9KFxV.js.map
