import { jsx as t, jsxs as c } from "react/jsx-runtime";
import { aw as w, z as a, ax as _, G as S, ay as P, az as q, o as A, u as E, aA as H, B as N, ar as y, q as L, aB as T, aC as b, n as O, aD as z } from "./index-C62tPk5p.js";
const G = ({
  children: e,
  ref: n,
  className: l
}) => {
  const [s] = w();
  return /* @__PURE__ */ t("div", { ref: s, className: a("bg-cal-muted flex flex-col gap-4 rounded-2xl p-4", l), children: e });
}, C = ({
  children: e,
  ref: n,
  as: l
}) => /* @__PURE__ */ t(l ? _ : "h2", { ref: n, className: "text-emphasis text-base font-semibold leading-none", children: e }), I = ({
  children: e,
  ref: n,
  as: l
}) => /* @__PURE__ */ t(l ? _ : "h3", { ref: n, className: "text-subtle line-clamp-1 text-sm break-all", children: e }), v = ({
  ref: e,
  name: n,
  size: l = "md",
  iconSlot: s
}) => /* @__PURE__ */ t(
  "div",
  {
    ref: e,
    className: a(
      "bg-default border-subtle border-subtle flex items-center justify-center border",
      l === "sm" && "rounded-md p-1",
      l === "md" && "rounded-[10px] p-1.5"
    ),
    children: s || /* @__PURE__ */ t(S, { name: n, className: a(l === "sm" && "h-4 w-4", l === "md" && "h-6 w-6") })
  }
), M = ({
  children: e,
  ref: n,
  icon: l,
  title: s,
  description: r,
  iconSlot: o,
  rawHeading: i
}) => /* @__PURE__ */ c("div", { ref: n, className: "flex items-center justify-between flex-wrap sm:flex-nowrap gap-3", children: [
  /* @__PURE__ */ c("div", { className: "flex items-center gap-2", children: [
    l && !o && /* @__PURE__ */ t(v, { name: l }),
    o && /* @__PURE__ */ t(v, { iconSlot: o }),
    /* @__PURE__ */ c("div", { className: "flex flex-col gap-0.5", children: [
      s && /* @__PURE__ */ t(C, { children: s }),
      r && /* @__PURE__ */ t(I, { children: r }),
      i && i
    ] })
  ] }),
  e
] }), Q = ({ children: e, ref: n }) => /* @__PURE__ */ t("div", { ref: n, className: "flex flex-col gap-4", children: e }), U = ({ children: e, ref: n }) => {
  const [l] = w();
  return /* @__PURE__ */ t("div", { ref: l, className: "border-muted bg-default flex flex-col gap-4 rounded-xl border p-3", children: e });
}, W = ({
  children: e,
  ref: n,
  icon: l,
  title: s,
  classNames: r,
  justify: o = "between",
  labelFor: i
}) => /* @__PURE__ */ c(
  "div",
  {
    ref: n,
    className: a(
      "flex items-center gap-2",
      o === "between" ? "justify-between" : "justify-start",
      r == null ? void 0 : r.container
    ),
    children: [
      /* @__PURE__ */ c("div", { className: a("flex items-center gap-2", r == null ? void 0 : r.title), children: [
        l && /* @__PURE__ */ t(v, { name: l, size: "sm" }),
        /* @__PURE__ */ t("div", { className: a("flex", r == null ? void 0 : r.title), children: /* @__PURE__ */ t("h4", { className: "text-default text-sm font-medium leading-none", id: i, children: s }) })
      ] }),
      e
    ]
  }
), F = ({
  children: e,
  ref: n,
  invert: l,
  classNames: s
}) => /* @__PURE__ */ t(
  "div",
  {
    ref: n,
    className: a(
      "bg-cal-muted flex flex-col rounded-lg px-[6px] py-1",
      l && "bg-default border-subtle border",
      s == null ? void 0 : s.container
    ),
    children: e
  }
), J = ({
  children: e,
  ref: n
}) => /* @__PURE__ */ t("div", { ref: n, className: "bg-default border-subtle flex flex-col gap-2 rounded-xl border p-2", children: e }), h = Object.assign(G, {
  Header: M,
  Content: Q,
  Title: C,
  Description: I,
  SubSection: U,
  SubSectionHeader: W,
  SubSectionContent: F,
  SubSectionNested: J
});
function K(e, n) {
  const { status: l } = P.useSession();
  return q.viewer.apps.appById.useQuery(
    { appId: e },
    {
      enabled: l === "authenticated" && ((n == null ? void 0 : n.enabled) ?? !0)
    }
  );
}
function V({
  appId: e,
  app: n,
  className: l,
  returnTo: s,
  teamId: r,
  onAppInstallSuccess: o
}) {
  const { t: i } = A(), { data: x } = K(e, { enabled: !n }), u = n ?? x, f = E(null, {
    returnTo: s,
    onSuccess: (d) => {
      o(), !(d != null && d.setupPending) && y(i("app_successfully_installed"), "success");
    },
    onError: (d) => {
      d instanceof Error && y(d.message || i("app_could_not_be_installed"), "error");
    }
  });
  return u ? /* @__PURE__ */ t(
    H,
    {
      type: u.type,
      teamsPlanRequired: u.teamsPlanRequired,
      wrapperClassName: a("[@media(max-width:260px)]:w-full", l),
      render: ({ useDefaultComponent: d, ...m }) => (d && (m = {
        ...m,
        onClick: () => {
          f.mutate({
            type: u.type,
            variant: u.variant,
            slug: u.slug,
            ...r && { teamId: r }
          });
        }
      }), /* @__PURE__ */ t(
        N,
        {
          loading: f.isPending,
          color: "secondary",
          className: "[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center",
          StartIcon: "plus",
          ...m,
          children: i("add")
        }
      ))
    }
  ) : null;
}
function Z({
  app: e,
  switchOnClick: n,
  switchChecked: l,
  children: s,
  returnTo: r,
  teamId: o,
  disableSwitch: i,
  switchTooltip: x,
  hideSettingsIcon: u = !1,
  hideAppCardOptions: f = !1,
  onAppInstallSuccess: d
}) {
  const { t: m } = A(), [j] = w(), { setAppData: k, LockedIcon: B, disabled: R } = L(), D = T();
  return /* @__PURE__ */ c(h, { className: a(!(e != null && e.isInstalled) && "rounded-xl"), children: [
    /* @__PURE__ */ t(
      h.Header,
      {
        rawHeading: /* @__PURE__ */ c("div", { children: [
          /* @__PURE__ */ c("div", { className: "flex w-full items-center gap-1", children: [
            /* @__PURE__ */ t(h.Title, { children: e == null ? void 0 : e.name }),
            !(e != null && e.isInstalled) && /* @__PURE__ */ t("span", { className: "bg-emphasis ml-1 rounded px-1 py-0.5 text-xs font-medium leading-3 tracking-[0.01em]", children: (e == null ? void 0 : e.categories[0].charAt(0).toUpperCase()) + (e == null ? void 0 : e.categories[0].slice(1)) })
          ] }),
          /* @__PURE__ */ t(h.Description, { children: e == null ? void 0 : e.description })
        ] }),
        iconSlot: /* @__PURE__ */ t(b, { href: `/apps/${e.slug}`, className: "flex h-8 w-8 items-center justify-center", children: /* @__PURE__ */ t(
          "img",
          {
            className: a(
              (e == null ? void 0 : e.logo.includes("-dark")) && "dark:invert",
              "max-h-full max-w-full object-contain"
            ),
            src: e == null ? void 0 : e.logo,
            alt: e == null ? void 0 : e.name
          }
        ) }),
        children: /* @__PURE__ */ t("div", { children: /* @__PURE__ */ t("div", { children: e != null && e.isInstalled || e.credentialOwner ? /* @__PURE__ */ t("div", { className: "ml-auto flex items-center", children: /* @__PURE__ */ t(
          O,
          {
            size: "sm",
            disabled: !e.enabled || R || i,
            onCheckedChange: (g) => {
              z.capture("event_type_app_switch_toggled", {
                app_slug: e.slug,
                enabled: g
              }), n && n(g), k("enabled", g);
            },
            checked: l,
            LockedIcon: B,
            "data-testid": `${e.slug}-app-switch`,
            tooltip: x
          }
        ) }) : /* @__PURE__ */ t(
          V,
          {
            className: "ml-auto flex items-center",
            appId: e.slug,
            app: e,
            returnTo: r,
            teamId: o,
            onAppInstallSuccess: d
          }
        ) }) })
      }
    ),
    f ? null : (e == null ? void 0 : e.isInstalled) && l && /* @__PURE__ */ t("div", { ref: j, children: e.isSetupAlready === void 0 || e.isSetupAlready ? /* @__PURE__ */ c("div", { className: "relative text-sm [&_input]:mb-0 [&_input]:leading-4", children: [
      !u && !D && /* @__PURE__ */ t(b, { href: `/apps/${e.slug}/setup`, className: "absolute right-0 top-0 ", children: /* @__PURE__ */ t(S, { name: "settings", className: "text-default h-4 w-4", "aria-hidden": "true" }) }),
      s
    ] }) : /* @__PURE__ */ c("div", { className: "flex h-64 w-full flex-col items-center justify-center gap-4 ", children: [
      /* @__PURE__ */ t("p", { children: m("this_app_is_not_setup_already") }),
      /* @__PURE__ */ t(b, { href: `/apps/${e.slug}/setup`, children: /* @__PURE__ */ t(N, { StartIcon: "settings", children: m("setup") }) })
    ] }) })
  ] });
}
export {
  Z as A,
  h as S
};
