import { j as u, i as k } from "./index-CwSaRXXg.js";
import { jsx as a, jsxs as o } from "react/jsx-runtime";
import { useTranslation as h } from "react-i18next";
import { Cloud as y, Users as g, AlertCircle as C, Mail as D, AlertTriangle as w, Calendar as T, CheckCircle as $, Link2 as E, Building2 as M, Merge as S, SkipForward as j, X as L, Loader2 as V } from "lucide-react";
import { f as A } from "./formatPhone-CUNTVwt7.js";
import { useMemo as b, useState as R, useCallback as F, useEffect as P } from "react";
const I = (r) => ({
  get: (t, e) => u.get(t, {
    ...e,
    headers: r ? { ...e?.headers, "X-Tenant-Slug": r } : e?.headers
  }).then((s) => s.data),
  post: (t, e, s) => u.post(t, e, {
    ...s,
    headers: r ? { ...s?.headers, "X-Tenant-Slug": r } : s?.headers
  }).then((c) => c.data),
  put: (t, e, s) => u.put(t, e, {
    ...s,
    headers: r ? { ...s?.headers, "X-Tenant-Slug": r } : s?.headers
  }).then((c) => c.data),
  delete: (t, e) => u.delete(t, {
    ...e,
    headers: r ? { ...e?.headers, "X-Tenant-Slug": r } : e?.headers
  }).then((s) => s.data)
}), U = (r) => {
  const t = r ? I(r) : k;
  return {
    // Settings / Configuration
    settings: {
      /**
       * Get current Entra configuration
       */
      getConfiguration: () => t.get("/api/administration/entra/configuration"),
      /**
       * Test connection to Microsoft Entra ID with provided credentials
       */
      testConnection: (e) => t.post("/api/administration/entra/test-connection", e),
      /**
       * Test connection using stored credentials from database
       */
      testStoredConnection: () => t.post("/api/administration/entra/test-stored-connection"),
      /**
       * Save Entra credentials (TenantId, ClientId, ClientSecret)
       */
      saveCredentials: (e) => t.put("/api/administration/entra/configuration/credentials", e),
      /**
       * Save Entra sync settings
       */
      saveSyncSettings: (e) => t.put("/api/administration/entra/configuration/sync-settings", e)
    },
    // Dashboard / Sync Status
    dashboard: {
      /**
       * Get sync status for all resource types (Users, Groups, Memberships)
       */
      getSyncStatus: () => t.get("/api/administration/entra/sync/status")
    },
    // Sync Operations
    sync: {
      /**
       * Trigger full synchronization of all resources
       */
      syncAll: (e) => t.post("/api/administration/entra/sync", e),
      /**
       * Trigger users synchronization only
       */
      syncUsers: (e) => t.post("/api/administration/entra/sync/users", e),
      /**
       * Trigger groups synchronization only
       */
      syncGroups: (e) => t.post("/api/administration/entra/sync/groups", e),
      /**
       * Trigger memberships synchronization only
       */
      syncMemberships: () => t.post("/api/administration/entra/sync/memberships"),
      /**
       * Force full sync (ignores delta tokens, re-syncs everything)
       */
      forceFullSync: () => t.post("/api/administration/entra/sync/force-full"),
      /**
       * Get sync history with pagination
       */
      getHistory: (e = 1, s = 10) => t.get(`/api/administration/entra/sync/history?page=${e}&pageSize=${s}`),
      /**
       * Cancel a running sync session
       */
      cancelSession: (e) => t.post(`/api/administration/entra/sync/session/${e}/cancel`)
    },
    // Groups Management
    groups: {
      /**
       * Get all Entra groups
       */
      getAll: () => t.get("/api/administration/entra/groups"),
      /**
       * Get a specific Entra group by ID
       */
      getById: (e) => t.get(`/api/administration/entra/groups/${e}`),
      /**
       * Assign a role to an Entra group
       */
      assignRole: (e, s) => t.post(`/api/administration/entra/groups/${e}/roles`, s),
      /**
       * Remove a role from an Entra group
       */
      removeRole: (e, s) => t.delete(`/api/administration/entra/groups/${e}/roles/${s}`),
      /**
       * Get members of an Entra group
       */
      getMembers: (e) => t.get(`/api/administration/entra/groups/${e}/members`)
    },
    // Users Management (Entra-related)
    users: {
      /**
       * Get Entra groups for a specific user
       */
      getGroups: (e) => t.get(`/api/administration/entra/users/${e}/groups`)
    },
    // Conflicts Management
    conflicts: {
      /**
       * Get all pending sync conflicts
       */
      getAll: () => t.get("/api/administration/entra/conflicts"),
      /**
       * Resolve a specific conflict
       */
      resolve: (e, s) => t.post(`/api/administration/entra/conflicts/${e}/resolve`, s)
    }
  };
}, Q = U(), N = (r) => r == null || r === "" ? null : r.trim(), f = (r, t = !1) => r ? t && A(r, "CH", "international") || r : "-";
function X({ entraData: r, localData: t }) {
  const { t: e } = h(["entra", "common"]);
  if (!r && !t)
    return null;
  const s = {
    firstName: e("entra:conflicts.fields.firstName", "First Name"),
    lastName: e("entra:conflicts.fields.lastName", "Last Name"),
    displayName: e("entra:conflicts.fields.displayName", "Display Name"),
    email: e("entra:conflicts.fields.upn", "UPN"),
    phoneNumber: e("entra:conflicts.fields.phoneNumber", "Phone"),
    mobilePhone: e("entra:conflicts.fields.mobilePhone", "Mobile"),
    department: e("entra:conflicts.fields.department", "Department"),
    jobTitle: e("entra:conflicts.fields.jobTitle", "Job Title")
  }, c = ["phoneNumber", "mobilePhone"], l = Object.keys(s).map((n) => {
    const m = N(r?.[n]), p = N(t?.[n]), v = m !== p && (m !== null || p !== null);
    return {
      key: n,
      label: s[n],
      entraValue: m,
      localValue: p,
      isDifferent: v
    };
  });
  return l.some((n) => n.isDifferent) ? /* @__PURE__ */ o("div", { className: "mt-4 pt-4 border-t border-[var(--border-color)]", children: [
    /* @__PURE__ */ a("div", { className: "overflow-hidden rounded-[var(--radius-card)] border border-[var(--border-color)]", children: /* @__PURE__ */ o("table", { className: "w-full text-sm", children: [
      /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ o("tr", { className: "bg-[var(--bg-secondary)]", children: [
        /* @__PURE__ */ a("th", { className: "px-4 py-2 text-left font-medium text-[var(--text-secondary)] w-1/4", children: e("entra:conflicts.field", "Field") }),
        /* @__PURE__ */ a("th", { className: "px-4 py-2 text-left font-medium text-[var(--color-accent-600)] w-[37.5%]", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ a(y, { className: "w-4 h-4" }),
          e("entra:conflicts.entraData", "Entra")
        ] }) }),
        /* @__PURE__ */ a("th", { className: "px-4 py-2 text-left font-medium text-[var(--success-text)] w-[37.5%]", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ a(g, { className: "w-4 h-4" }),
          e("entra:conflicts.localData", "Local")
        ] }) })
      ] }) }),
      /* @__PURE__ */ a("tbody", { className: "divide-y divide-[var(--border-color)]", children: l.filter((n) => n.isDifferent).map((n) => /* @__PURE__ */ o(
        "tr",
        {
          className: "bg-[var(--bg-card)] hover:bg-[var(--bg-secondary)] transition-colors",
          children: [
            /* @__PURE__ */ a("td", { className: "px-4 py-3 font-medium text-[var(--text-primary)]", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ a(C, { className: "w-4 h-4 text-[var(--color-accent-500)]" }),
              n.label
            ] }) }),
            /* @__PURE__ */ a("td", { className: "px-4 py-3", children: n.entraValue ? /* @__PURE__ */ a("span", { className: "text-[var(--color-accent-700)] bg-[var(--color-accent-500)]/10 px-2 py-1 rounded", children: f(n.entraValue, c.includes(n.key)) }) : /* @__PURE__ */ a("span", { className: "text-[var(--text-tertiary)] italic", children: f(n.entraValue, c.includes(n.key)) }) }),
            /* @__PURE__ */ a("td", { className: "px-4 py-3", children: n.localValue ? /* @__PURE__ */ a("span", { className: "text-[var(--success-text)] bg-[var(--success-bg)] px-2 py-1 rounded", children: f(n.localValue, c.includes(n.key)) }) : /* @__PURE__ */ a("span", { className: "text-[var(--text-tertiary)] italic", children: f(n.localValue, c.includes(n.key)) }) })
          ]
        },
        n.key
      )) })
    ] }) }),
    /* @__PURE__ */ a("p", { className: "mt-2 text-xs text-[var(--text-tertiary)]", children: e("entra:conflicts.diffCount", "{{count}} field(s) with differences", {
      count: l.filter((n) => n.isDifferent).length
    }) })
  ] }) : /* @__PURE__ */ a("div", { className: "mt-4 pt-4 border-t border-[var(--border-color)]", children: /* @__PURE__ */ a("p", { className: "text-sm text-[var(--text-secondary)] italic", children: e("entra:conflicts.noDifferences", "No field differences detected") }) });
}
function z() {
  const { i18n: r } = h(), t = b(() => ({
    fr: "fr-FR",
    en: "en-US",
    de: "de-DE",
    it: "it-IT"
  })[r.language] || "en-US", [r.language]), e = b(() => (l, d) => {
    const n = {
      dateStyle: "medium",
      timeStyle: "short"
    };
    return new Intl.DateTimeFormat(t, d || n).format(
      typeof l == "string" ? new Date(l) : l
    );
  }, [t]), s = b(() => (l, d) => new Intl.NumberFormat(t, d).format(l), [t]), c = b(() => (l, d = "EUR") => new Intl.NumberFormat(t, {
    style: "currency",
    currency: d
  }).format(l), [t]);
  return {
    locale: t,
    formatDate: e,
    formatNumber: s,
    formatCurrency: c
  };
}
const G = (r) => {
  switch (r) {
    case "User":
      return g;
    case "Group":
      return M;
    case "Membership":
      return E;
    default:
      return y;
  }
}, O = (r) => r === "Duplicate" ? {
  bg: "bg-[var(--error-bg)]",
  text: "text-[var(--error-text)]",
  border: "border-[var(--error-border)]"
} : {
  bg: "bg-[var(--color-accent-500)]/10",
  text: "text-[var(--color-accent-700)]",
  border: "border-[var(--color-accent-300)]"
};
function Y({ conflict: r, onResolve: t, className: e = "" }) {
  const { t: s } = h(["entra"]), { formatDate: c } = z(), l = G(r.resourceType), d = O(r.conflictType);
  return /* @__PURE__ */ o("div", { className: `h-full flex flex-col rounded-[var(--radius-card)] border border-[var(--border-color)] bg-[var(--bg-card)] overflow-hidden shadow-sm hover:shadow-md transition-shadow ${e}`, children: [
    /* @__PURE__ */ a("div", { className: "px-4 py-3 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 justify-between", children: [
      /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ a("div", { className: "p-2 rounded-lg bg-[var(--color-accent-500)]/20", children: /* @__PURE__ */ a(l, { className: "w-5 h-5 text-[var(--color-accent-600)]" }) }),
        /* @__PURE__ */ o("div", { children: [
          /* @__PURE__ */ a("h3", { className: "font-semibold text-[var(--text-primary)]", children: r.entraDisplayName }),
          r.entraEmail && /* @__PURE__ */ o("div", { className: "flex items-center gap-1 text-sm text-[var(--text-secondary)]", children: [
            /* @__PURE__ */ a(D, { className: "w-3.5 h-3.5" }),
            r.entraEmail
          ] })
        ] })
      ] }),
      /* @__PURE__ */ o("span", { className: `inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${d.bg} ${d.text} border ${d.border}`, children: [
        /* @__PURE__ */ a(w, { className: "w-3.5 h-3.5" }),
        s(`entra:conflicts.types.${r.conflictType}`)
      ] })
    ] }) }),
    /* @__PURE__ */ o("div", { className: "flex-1 flex flex-col p-4 space-y-4", children: [
      /* @__PURE__ */ a("p", { className: "text-sm text-[var(--text-secondary)]", children: r.conflictDescription }),
      /* @__PURE__ */ a(X, { entraData: r.entraData, localData: r.localData }),
      /* @__PURE__ */ o("div", { className: "mt-auto flex items-center justify-between pt-4 border-t border-[var(--border-color)]", children: [
        /* @__PURE__ */ o("div", { className: "flex items-center gap-1.5 text-xs text-[var(--text-tertiary)]", children: [
          /* @__PURE__ */ a(T, { className: "w-3.5 h-3.5" }),
          s("entra:conflicts.createdAt", { date: c(r.createdAt) })
        ] }),
        /* @__PURE__ */ o(
          "button",
          {
            onClick: () => t(r),
            className: "inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] transition-colors shadow-sm",
            children: [
              /* @__PURE__ */ a($, { className: "w-4 h-4" }),
              s("entra:conflicts.resolve")
            ]
          }
        )
      ] })
    ] })
  ] });
}
const x = 500, B = (r) => {
  switch (r) {
    case "primary":
      return "bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] border-transparent";
    case "success":
      return "bg-[var(--success-bg)] text-[var(--success-text)] hover:opacity-90 border-[var(--success-border)]";
    case "secondary":
      return "bg-[var(--bg-secondary)] text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] border-[var(--border-color)]";
    case "ghost":
      return "bg-transparent text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] border-[var(--border-color)]";
    default:
      return "bg-[var(--bg-secondary)] text-[var(--text-primary)] border-[var(--border-color)]";
  }
};
function Z({
  conflict: r,
  onClose: t,
  onResolve: e,
  resolving: s = !1
}) {
  const { t: c } = h(["entra"]), [l, d] = R(""), n = [
    {
      key: "EntraPriority",
      icon: y,
      label: c("entra:conflicts.resolutions.entraWins"),
      variant: "primary"
    },
    {
      key: "LocalPriority",
      icon: g,
      label: c("entra:conflicts.resolutions.localWins"),
      variant: "success"
    },
    {
      key: "MergeToExisting",
      icon: S,
      label: c("entra:conflicts.resolutions.merge"),
      variant: "secondary"
    },
    {
      key: "SkipImport",
      icon: j,
      label: c("entra:conflicts.resolutions.skip"),
      variant: "ghost"
    }
  ], m = F((i) => {
    i.key === "Escape" && !s && t();
  }, [t, s]);
  P(() => (document.addEventListener("keydown", m), document.body.style.overflow = "hidden", () => {
    document.removeEventListener("keydown", m), document.body.style.overflow = "";
  }), [m]);
  const p = async (i) => {
    await e(i, l.trim() || void 0);
  }, v = (i) => {
    i.length <= x && d(i);
  };
  return /* @__PURE__ */ a(
    "div",
    {
      className: "fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",
      onClick: (i) => {
        i.target === i.currentTarget && !s && t();
      },
      onKeyDown: (i) => {
        i.key === "Escape" && !s && t();
      },
      role: "dialog",
      "aria-modal": "true",
      "aria-label": "Resolve conflict",
      children: /* @__PURE__ */ o("div", { className: "w-full max-w-lg rounded-[var(--radius-card)] bg-[var(--bg-card)] shadow-2xl overflow-hidden", children: [
        /* @__PURE__ */ a("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 justify-between", children: [
          /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
            /* @__PURE__ */ a("div", { className: "p-2 rounded-lg bg-[var(--color-accent-500)]/20", children: /* @__PURE__ */ a(w, { className: "w-5 h-5 text-[var(--color-accent-600)]" }) }),
            /* @__PURE__ */ a("h2", { className: "text-lg font-semibold text-[var(--text-primary)]", children: c("entra:conflicts.resolveTitle") })
          ] }),
          /* @__PURE__ */ a(
            "button",
            {
              onClick: t,
              disabled: s,
              className: "p-2 rounded-lg text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-secondary)] transition-colors disabled:opacity-50",
              children: /* @__PURE__ */ a(L, { className: "w-5 h-5" })
            }
          )
        ] }) }),
        /* @__PURE__ */ o("div", { className: "p-6 space-y-4", children: [
          /* @__PURE__ */ o("div", { className: "p-4 rounded-lg bg-[var(--bg-secondary)] border border-[var(--border-color)]", children: [
            /* @__PURE__ */ a("p", { className: "font-medium text-[var(--text-primary)]", children: r.entraDisplayName }),
            /* @__PURE__ */ a("p", { className: "text-sm text-[var(--text-secondary)] mt-1", children: r.conflictDescription })
          ] }),
          /* @__PURE__ */ o("div", { children: [
            /* @__PURE__ */ o("div", { className: "flex items-center justify-between mb-2", children: [
              /* @__PURE__ */ a("label", { className: "block text-sm font-medium text-[var(--text-primary)]", children: c("entra:conflicts.notes") }),
              /* @__PURE__ */ o("span", { className: "text-xs text-[var(--text-tertiary)]", children: [
                l.length,
                "/",
                x
              ] })
            ] }),
            /* @__PURE__ */ a(
              "textarea",
              {
                value: l,
                onChange: (i) => v(i.target.value),
                placeholder: c("entra:conflicts.notesPlaceholder"),
                maxLength: x,
                disabled: s,
                className: "w-full px-3 py-2.5 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)] placeholder-[var(--text-tertiary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)] focus:border-transparent transition-shadow resize-none disabled:opacity-50",
                rows: 3
              }
            )
          ] }),
          /* @__PURE__ */ a("div", { className: "space-y-2", children: n.map((i) => /* @__PURE__ */ o(
            "button",
            {
              onClick: () => p(i.key),
              disabled: s,
              className: `w-full flex items-center gap-3 px-4 py-3 rounded-[var(--radius-button)] border font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed ${B(i.variant)}`,
              children: [
                s ? /* @__PURE__ */ a(V, { className: "w-5 h-5 animate-spin" }) : /* @__PURE__ */ a(i.icon, { className: "w-5 h-5" }),
                /* @__PURE__ */ a("span", { children: i.label })
              ]
            },
            i.key
          )) })
        ] })
      ] })
    }
  );
}
export {
  Y as C,
  Z as R,
  U as c,
  Q as e
};
//# sourceMappingURL=ResolutionModal-Bg7XZmR1.js.map
