import { bm as I, b3 as j, aX as _, aV as S, aW as s, bn as B, b7 as i, e as b, aq as g, bo as O, bp as P, aZ as k, bq as C, bd as u, B as q, A as E, K as R, aT as T } from "./index-6jcTChn4.js";
function $(e) {
  const { status: r } = I.useSession();
  return j.viewer.appById.useQuery(
    { appId: e },
    {
      enabled: r === "authenticated"
    }
  );
}
function L({
  appId: e,
  className: r,
  returnTo: c,
  teamId: l
}) {
  const { t: a } = _(), { data: n } = $(e), m = j.useUtils(), o = S(null, {
    returnTo: c,
    onSuccess: (t) => {
      m.viewer.appById.invalidate({ appId: e }), m.viewer.integrations.invalidate({
        extendsFeature: "EventType",
        ...l && { teamId: l }
      }), !(t != null && t.setupPending) && g(a("app_successfully_installed"), "success");
    },
    onError: (t) => {
      t instanceof Error && g(t.message || a("app_could_not_be_installed"), "error");
    }
  });
  return n ? /* @__PURE__ */ s.jsx(
    B,
    {
      type: n.type,
      teamsPlanRequired: n.teamsPlanRequired,
      wrapperClassName: i("[@media(max-width:260px)]:w-full", r),
      render: ({ useDefaultComponent: t, ...d }) => (t && (d = {
        ...d,
        onClick: () => {
          o.mutate({
            type: n.type,
            variant: n.variant,
            slug: n.slug,
            ...l && { teamId: l }
          });
        }
      }), /* @__PURE__ */ s.jsx(
        b,
        {
          loading: o.isPending,
          color: "secondary",
          className: "[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center",
          StartIcon: "plus",
          ...d,
          children: a("add")
        }
      ))
    }
  ) : null;
}
function U({
  app: e,
  description: r,
  switchOnClick: c,
  switchChecked: l,
  children: a,
  returnTo: n,
  teamId: m,
  disableSwitch: o,
  switchTooltip: t,
  hideSettingsIcon: d = !1,
  hideAppCardOptions: v = !1
}) {
  const { t: x } = O(), [N] = P(), { setAppData: w, LockedIcon: y, disabled: A } = k(), f = C();
  return /* @__PURE__ */ s.jsxs(
    "div",
    {
      className: i(
        "border-subtle",
        (e == null ? void 0 : e.isInstalled) && "mb-4 rounded-md border",
        !e.enabled && "grayscale"
      ),
      children: [
        /* @__PURE__ */ s.jsx("div", { className: i(e.isInstalled ? "p-4 text-sm sm:p-4" : "px-5 py-4 text-sm sm:px-5"), children: /* @__PURE__ */ s.jsxs("div", { className: "flex w-full flex-col gap-2 sm:flex-row sm:gap-0", children: [
          /* @__PURE__ */ s.jsx(
            u,
            {
              href: `/apps/${e.slug}`,
              className: i(e != null && e.isInstalled ? "mr-[11px]" : "mr-3", "h-auto w-10 rounded-sm"),
              children: /* @__PURE__ */ s.jsx(
                "img",
                {
                  className: i(
                    (e == null ? void 0 : e.logo.includes("-dark")) && "dark:invert",
                    e != null && e.isInstalled ? "min-w-[42px]" : "min-w-[40px]",
                    "w-full"
                  ),
                  src: e == null ? void 0 : e.logo,
                  alt: e == null ? void 0 : e.name
                }
              )
            }
          ),
          /* @__PURE__ */ s.jsxs("div", { className: "flex flex-col pe-3", children: [
            /* @__PURE__ */ s.jsxs("div", { className: "text-emphasis", children: [
              /* @__PURE__ */ s.jsx("span", { className: i((e == null ? void 0 : e.isInstalled) && "text-base", "font-semibold leading-4"), children: e == null ? void 0 : e.name }),
              !(e != null && e.isInstalled) && /* @__PURE__ */ s.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__ */ s.jsx("p", { title: e == null ? void 0 : e.description, className: "text-default line-clamp-1 pt-1 text-sm font-normal", children: r || (e == null ? void 0 : e.description) })
          ] }),
          /* @__PURE__ */ s.jsxs("div", { className: "ml-auto flex items-center space-x-2", children: [
            e.credentialOwner && !f && /* @__PURE__ */ s.jsx("div", { className: "ml-auto", children: /* @__PURE__ */ s.jsx(q, { variant: "gray", children: /* @__PURE__ */ s.jsxs("div", { className: "flex items-center", children: [
              /* @__PURE__ */ s.jsx(
                E,
                {
                  className: "mr-2",
                  alt: e.credentialOwner.name || "Credential Owner Name",
                  size: "sm",
                  imageSrc: e.credentialOwner.avatar
                }
              ),
              e.credentialOwner.name
            ] }) }) }),
            e != null && e.isInstalled || e.credentialOwner ? /* @__PURE__ */ s.jsx("div", { className: "ml-auto flex items-center", children: /* @__PURE__ */ s.jsx(
              R,
              {
                disabled: !e.enabled || A || o,
                onCheckedChange: (h) => {
                  c && c(h), w("enabled", h);
                },
                checked: l,
                LockedIcon: y,
                "data-testid": `${e.slug}-app-switch`,
                tooltip: t
              }
            ) }) : /* @__PURE__ */ s.jsx(
              L,
              {
                className: "ml-auto flex items-center",
                appId: e.slug,
                returnTo: n,
                teamId: m
              }
            )
          ] })
        ] }) }),
        v ? null : /* @__PURE__ */ s.jsxs("div", { ref: N, children: [
          (e == null ? void 0 : e.isInstalled) && l && /* @__PURE__ */ s.jsx("hr", { className: "border-subtle" }),
          e != null && e.isInstalled && l ? e.isSetupAlready === void 0 || e.isSetupAlready ? /* @__PURE__ */ s.jsxs("div", { className: "relative p-4 pt-5 text-sm [&_input]:mb-0 [&_input]:leading-4", children: [
            !d && !f && /* @__PURE__ */ s.jsx(u, { href: `/apps/${e.slug}/setup`, className: "absolute right-4 top-4", children: /* @__PURE__ */ s.jsx(T, { name: "settings", className: "text-default h-4 w-4", "aria-hidden": "true" }) }),
            a
          ] }) : /* @__PURE__ */ s.jsxs("div", { className: "flex h-64 w-full flex-col items-center justify-center gap-4 ", children: [
            /* @__PURE__ */ s.jsx("p", { children: x("this_app_is_not_setup_already") }),
            /* @__PURE__ */ s.jsx(u, { href: `/apps/${e.slug}/setup`, children: /* @__PURE__ */ s.jsx(b, { StartIcon: "settings", children: x("setup") }) })
          ] }) : null
        ] })
      ]
    }
  );
}
export {
  U as A
};
