import { q as t, ah as B, ai as g, N as a, O as S, aj as D, z as N, r as V, u as W, ak as H, s as A, $ as w, al as T, v as q, af as L, am as m, p as F } from "./index-jYYVpIDL.js";
import * as c from "react";
var b = c.forwardRef((e, r) => {
  const { children: s, ...n } = e, l = c.Children.toArray(s), i = l.find(M);
  if (i) {
    const o = i.props.children, u = l.map((d) => d === i ? c.Children.count(o) > 1 ? c.Children.only(null) : c.isValidElement(o) ? o.props.children : null : d);
    return /* @__PURE__ */ t.jsx(h, { ...n, ref: r, children: c.isValidElement(o) ? c.cloneElement(o, void 0, u) : null });
  }
  return /* @__PURE__ */ t.jsx(h, { ...n, ref: r, children: s });
});
b.displayName = "Slot";
var h = c.forwardRef((e, r) => {
  const { children: s, ...n } = e;
  if (c.isValidElement(s)) {
    const l = Z(s);
    return c.cloneElement(s, {
      ...Q(n, s.props),
      // @ts-ignore
      ref: r ? B(r, l) : l
    });
  }
  return c.Children.count(s) > 1 ? c.Children.only(null) : null;
});
h.displayName = "SlotClone";
var U = ({ children: e }) => /* @__PURE__ */ t.jsx(t.Fragment, { children: e });
function M(e) {
  return c.isValidElement(e) && e.type === U;
}
function Q(e, r) {
  const s = { ...r };
  for (const n in r) {
    const l = e[n], i = r[n];
    /^on[A-Z]/.test(n) ? l && i ? s[n] = (...u) => {
      i(...u), l(...u);
    } : l && (s[n] = l) : n === "style" ? s[n] = { ...l, ...i } : n === "className" && (s[n] = [l, i].filter(Boolean).join(" "));
  }
  return { ...e, ...s };
}
function Z(e) {
  var n, l;
  let r = (n = Object.getOwnPropertyDescriptor(e.props, "ref")) == null ? void 0 : n.get, s = r && "isReactWarning" in r && r.isReactWarning;
  return s ? e.ref : (r = (l = Object.getOwnPropertyDescriptor(e, "ref")) == null ? void 0 : l.get, s = r && "isReactWarning" in r && r.isReactWarning, s ? e.props.ref : e.props.ref || e.ref);
}
const z = ({
  children: e,
  ref: r,
  className: s
}) => {
  const [n] = g();
  return /* @__PURE__ */ t.jsx("div", { ref: n, className: a("bg-muted flex flex-col gap-4 rounded-2xl p-4", s), children: e });
}, C = ({
  children: e,
  ref: r,
  as: s
}) => {
  const n = s ? b : "h2";
  return /* @__PURE__ */ t.jsx(n, { ref: r, className: "text-emphasis text-base font-semibold leading-none", children: e });
}, R = ({
  children: e,
  ref: r,
  as: s
}) => {
  const n = s ? b : "h3";
  return /* @__PURE__ */ t.jsx(n, { ref: r, className: "text-subtle line-clamp-1 text-sm", children: e });
}, j = ({
  ref: e,
  name: r,
  size: s = "md",
  iconSlot: n
}) => /* @__PURE__ */ t.jsx(
  "div",
  {
    ref: e,
    className: a(
      "bg-default border-subtle border-subtle flex items-center justify-center border",
      s === "sm" && "rounded-md p-1",
      s === "md" && "rounded-[10px] p-1.5"
    ),
    children: n || /* @__PURE__ */ t.jsx(S, { name: r, className: a(s === "sm" && "h-4 w-4", s === "md" && "h-6 w-6") })
  }
), G = ({
  children: e,
  ref: r,
  icon: s,
  title: n,
  description: l,
  iconSlot: i,
  rawHeading: o
}) => /* @__PURE__ */ t.jsxs("div", { ref: r, className: "flex items-center justify-between gap-3", children: [
  /* @__PURE__ */ t.jsxs("div", { className: "flex items-center gap-2", children: [
    s && !i && /* @__PURE__ */ t.jsx(j, { name: s }),
    i && /* @__PURE__ */ t.jsx(j, { iconSlot: i }),
    /* @__PURE__ */ t.jsxs("div", { className: "flex flex-col gap-0.5", children: [
      n && /* @__PURE__ */ t.jsx(C, { children: n }),
      l && /* @__PURE__ */ t.jsx(R, { children: l }),
      o && o
    ] })
  ] }),
  e
] }), J = ({ children: e, ref: r }) => /* @__PURE__ */ t.jsx("div", { ref: r, className: "flex flex-col gap-4", children: e }), K = ({ children: e, ref: r }) => {
  const [s] = g();
  return /* @__PURE__ */ t.jsx("div", { ref: s, className: "border-muted bg-default flex flex-col gap-4 rounded-xl border p-3", children: e });
}, X = ({
  children: e,
  ref: r,
  icon: s,
  title: n,
  classNames: l,
  justify: i = "between",
  labelFor: o
}) => /* @__PURE__ */ t.jsxs(
  "div",
  {
    ref: r,
    className: a(
      "flex items-center gap-2",
      i === "between" ? "justify-between" : "justify-start",
      l == null ? void 0 : l.container
    ),
    children: [
      /* @__PURE__ */ t.jsxs("div", { className: a("flex items-center gap-2", l == null ? void 0 : l.title), children: [
        s && /* @__PURE__ */ t.jsx(j, { name: s, size: "sm" }),
        /* @__PURE__ */ t.jsx("div", { className: a("flex", l == null ? void 0 : l.title), children: /* @__PURE__ */ t.jsx("h4", { className: "text-default text-sm font-medium leading-none", id: o, children: n }) })
      ] }),
      e
    ]
  }
), Y = ({
  children: e,
  ref: r,
  invert: s,
  classNames: n
}) => /* @__PURE__ */ t.jsx(
  "div",
  {
    ref: r,
    className: a(
      "bg-muted flex flex-col rounded-lg px-[6px] py-1",
      s && "bg-default border-subtle border",
      n == null ? void 0 : n.container
    ),
    children: e
  }
), p = ({
  children: e,
  ref: r
}) => /* @__PURE__ */ t.jsx("div", { ref: r, className: "bg-default border-subtle flex flex-col gap-2 rounded-xl border p-2", children: e }), x = Object.assign(z, {
  Header: G,
  Content: J,
  Title: C,
  Description: R,
  SubSection: K,
  SubSectionHeader: X,
  SubSectionContent: Y,
  SubSectionNested: p
});
function $(e) {
  const { status: r } = D.useSession();
  return N.viewer.apps.appById.useQuery(
    { appId: e },
    {
      enabled: r === "authenticated"
    }
  );
}
function ee({
  appId: e,
  className: r,
  returnTo: s,
  teamId: n
}) {
  const { t: l } = V(), { data: i } = $(e), o = N.useUtils(), u = W(null, {
    returnTo: s,
    onSuccess: (d) => {
      o.viewer.apps.appById.invalidate({ appId: e }), o.viewer.apps.integrations.invalidate({
        extendsFeature: "EventType",
        ...n && { teamId: n }
      }), !(d != null && d.setupPending) && w(l("app_successfully_installed"), "success");
    },
    onError: (d) => {
      d instanceof Error && w(d.message || l("app_could_not_be_installed"), "error");
    }
  });
  return i ? /* @__PURE__ */ t.jsx(
    H,
    {
      type: i.type,
      teamsPlanRequired: i.teamsPlanRequired,
      wrapperClassName: a("[@media(max-width:260px)]:w-full", r),
      render: ({ useDefaultComponent: d, ...f }) => (d && (f = {
        ...f,
        onClick: () => {
          u.mutate({
            type: i.type,
            variant: i.variant,
            slug: i.slug,
            ...n && { teamId: n }
          });
        }
      }), /* @__PURE__ */ t.jsx(
        A,
        {
          loading: u.isPending,
          color: "secondary",
          className: "[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center",
          StartIcon: "plus",
          ...f,
          children: l("add")
        }
      ))
    }
  ) : null;
}
function se({
  app: e,
  description: r,
  switchOnClick: s,
  switchChecked: n,
  children: l,
  returnTo: i,
  teamId: o,
  disableSwitch: u,
  switchTooltip: d,
  hideSettingsIcon: f = !1,
  hideAppCardOptions: _ = !1
}) {
  const { t: v } = T(), [E] = g(), { setAppData: I, LockedIcon: P, disabled: k } = q(), O = L();
  return /* @__PURE__ */ t.jsxs(x, { className: a(!(e != null && e.isInstalled) && "rounded-xl"), children: [
    /* @__PURE__ */ t.jsx(
      x.Header,
      {
        rawHeading: /* @__PURE__ */ t.jsxs("div", { children: [
          /* @__PURE__ */ t.jsxs("div", { className: "flex w-full items-center gap-1", children: [
            /* @__PURE__ */ t.jsx(x.Title, { children: e == null ? void 0 : e.name }),
            !(e != null && e.isInstalled) && /* @__PURE__ */ t.jsx("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.jsx(x.Description, { children: e == null ? void 0 : e.description })
        ] }),
        iconSlot: /* @__PURE__ */ t.jsx(m, { href: `/apps/${e.slug}`, className: "flex h-8 w-8 items-center justify-center", children: /* @__PURE__ */ t.jsx(
          "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.jsx("div", { children: /* @__PURE__ */ t.jsx("div", { children: e != null && e.isInstalled || e.credentialOwner ? /* @__PURE__ */ t.jsx("div", { className: "ml-auto flex items-center", children: /* @__PURE__ */ t.jsx(
          F,
          {
            size: "sm",
            disabled: !e.enabled || k || u,
            onCheckedChange: (y) => {
              s && s(y), I("enabled", y);
            },
            checked: n,
            LockedIcon: P,
            "data-testid": `${e.slug}-app-switch`,
            tooltip: d
          }
        ) }) : /* @__PURE__ */ t.jsx(
          ee,
          {
            className: "ml-auto flex items-center",
            appId: e.slug,
            returnTo: i,
            teamId: o
          }
        ) }) })
      }
    ),
    _ ? null : (e == null ? void 0 : e.isInstalled) && n && /* @__PURE__ */ t.jsx("div", { ref: E, children: e.isSetupAlready === void 0 || e.isSetupAlready ? /* @__PURE__ */ t.jsxs("div", { className: "relative text-sm [&_input]:mb-0 [&_input]:leading-4", children: [
      !f && !O && /* @__PURE__ */ t.jsx(m, { href: `/apps/${e.slug}/setup`, className: "absolute right-4 top-4", children: /* @__PURE__ */ t.jsx(S, { name: "settings", className: "text-default h-4 w-4", "aria-hidden": "true" }) }),
      l
    ] }) : /* @__PURE__ */ t.jsxs("div", { className: "flex h-64 w-full flex-col items-center justify-center gap-4 ", children: [
      /* @__PURE__ */ t.jsx("p", { children: v("this_app_is_not_setup_already") }),
      /* @__PURE__ */ t.jsx(m, { href: `/apps/${e.slug}/setup`, children: /* @__PURE__ */ t.jsx(A, { StartIcon: "settings", children: v("setup") }) })
    ] }) })
  ] });
}
export {
  se as A,
  x as S
};
