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