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