var l = {}, c = {};
Object.defineProperty(c, "__esModule", { value: !0 });
c.useExecuteCommand = void 0;
const x = window.figApiBindings, i = window.React, w = (e) => {
  let t, n;
  if ("command" in e && e.command)
    t = "bash", n = ["-c", e.command];
  else if ("args" in e && e.args.length > 0)
    t = e.args[0], n = e.args.slice(1);
  else
    throw new Error("Invalid input");
  const [r, a] = (0, i.useState)({
    status: "loading"
  });
  return (0, i.useEffect)(() => {
    x.Process.run({
      executable: t,
      args: n,
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      terminalSessionId: window == null ? void 0 : window.globalTerminalSessionId
    }).then(({ exitCode: s, stderr: m, stdout: u }) => {
      a({
        status: "success",
        exitCode: s,
        stderr: m,
        stdout: u
      });
    }).catch((s) => {
      a({
        status: "error",
        error: s
      });
    });
  }, [t, n]), r;
};
c.useExecuteCommand = w;
(function(e) {
  Object.defineProperty(e, "__esModule", { value: !0 }), e.useExecuteCommand = void 0;
  const t = c;
  Object.defineProperty(e, "useExecuteCommand", { enumerable: !0, get: function() {
    return t.useExecuteCommand;
  } });
})(l);
const o = window.jsxRuntime.jsx, d = window.jsxRuntime.jsxs, h = ({
  suggestion: e,
  shellContext: t,
  maxHeight: n
}) => {
  const r = l.useExecuteCommand({
    args: [
      "ls",
      "-1ApL",
      Array.isArray(e.name) ? e.name[0] : e.name
    ]
  }), a = r.status === "success" ? r.stdout.split(`
`).map((s) => s.trim()).filter((s) => s !== "" && s !== ".DS_Store").map((s) => /* @__PURE__ */ d("li", { className: "text-sm flex flex-row items-center", children: [
    /* @__PURE__ */ o(
      "img",
      {
        src: `fig://path/${t.currentWorkingDirectory}/${s}`,
        className: "w-4 h-4 mr-2"
      }
    ),
    /* @__PURE__ */ o("span", { className: "font-mono", children: s })
  ] }, s)) : [];
  return /* @__PURE__ */ d(
    "div",
    {
      className: "bg-shade0 text-shade6 p-2 rounded overflow-y-auto overflow-x-hidden shadow-[0px_0px_3px_0px_rgb(85,_85,_85)]",
      style: {
        maxHeight: n
      },
      children: [
        /* @__PURE__ */ o("h1", { className: "font-semibold", children: "Preview" }),
        a.length === 0 ? /* @__PURE__ */ o("span", { className: "opacity-70", children: "No items" }) : /* @__PURE__ */ o("ul", { className: "whitespace-pre", children: a })
      ]
    }
  );
};
export {
  h as default
};
