import { jsxs as s, jsx as n } from "react/jsx-runtime";
import { useState as m, useEffect as j } from "react";
import { S as g } from "./index-C62tPk5p.js";
const P = () => {
  const [o, d] = m(), [f, i] = m();
  j(() => {
    async function t() {
      var p;
      const r = await fetch("/api/integrations/basecamp3/projects");
      if (!r.ok) return;
      const e = await r.json(), l = e == null ? void 0 : e.currentProject, c = (p = e == null ? void 0 : e.projects) == null ? void 0 : p.map(
        (a) => ({
          value: String(a.id),
          label: a.name
        })
      );
      if (c && (d(c), l)) {
        const a = c.find((h) => h.value === String(l));
        a && i(a);
      }
    }
    t();
  }, []);
  async function u(t) {
    t && (await fetch("/api/integrations/basecamp3/projectMutation", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ projectId: t.value })
    }), i(t));
  }
  return /* @__PURE__ */ s("div", { className: "mt-2 text-sm", children: [
    /* @__PURE__ */ s("div", { className: "flex gap-3", children: [
      /* @__PURE__ */ n("div", { className: "items-center", children: /* @__PURE__ */ n("p", { className: "py-2", children: "Link a Basecamp project to this event:" }) }),
      /* @__PURE__ */ n(
        g,
        {
          placeholder: "Select project",
          options: o,
          isLoading: !o,
          className: "md:min-w-[120px]",
          onChange: u,
          value: f
        }
      )
    ] }),
    /* @__PURE__ */ s("div", { className: "mt-2", children: [
      "Please note that as of now you can only link ",
      /* @__PURE__ */ n("span", { className: "italic", children: "one" }),
      " of your projects to cal.com"
    ] })
  ] });
};
export {
  P as default
};
