"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var env_config_exports = {};
__export(env_config_exports, {
  EnvConfig: () => EnvConfig
});
module.exports = __toCommonJS(env_config_exports);
var import_buffer = __toESM(require("buffer"));
var import_browser = __toESM(require("process/browser"));
var import_console_browserify = __toESM(require("console-browserify"));
var buffer = {
  Buffer: import_buffer.default
};
var import_jsx_runtime = require("react/jsx-runtime");
var import_antd = require("antd");
var import_react = require("react");
var import_misc = require("./misc");
var import_store = require("./store");
function EnvConfig() {
  const { config, configString, loadConfig } = (0, import_store.useEnvConfig)();
  const [isModalOpen, setIsModalOpen] = (0, import_react.useState)(false);
  const [tempConfigString, setTempConfigString] = (0, import_react.useState)(configString);
  const showModal = (e) => {
    setIsModalOpen(true);
    e.preventDefault();
  };
  const handleOk = () => {
    setIsModalOpen(false);
    loadConfig(tempConfigString);
  };
  const handleCancel = () => {
    setIsModalOpen(false);
  };
  const editBtn = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Button, { type: "link", size: "small", onClick: showModal, children: "Edit" });
  const [showEditButton, setShowEditButton] = (0, import_react.useState)(false);
  const configTip = Object.keys(config).length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
    (0, import_misc.iconForStatus)("failed"),
    " No config",
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_antd.Tooltip,
      {
        title: "Please set up your environment variables to use Midscene.",
        placement: "right",
        open: !isModalOpen,
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Button, { type: "primary", onClick: showModal, children: "Click to set up" })
      }
    ) })
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    "div",
    {
      onMouseEnter: () => setShowEditButton(true),
      onMouseLeave: () => setShowEditButton(false),
      children: Object.entries(config).map(([key, value]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { lineHeight: "1.8" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
        (0, import_misc.iconForStatus)("success"),
        " ",
        key,
        ":",
        " ",
        key === "MIDSCENE_MODEL_NAME" ? value : "***",
        " ",
        showEditButton && editBtn
      ] }) }, key))
    }
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
    configTip,
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      import_antd.Modal,
      {
        title: "Env Config",
        open: isModalOpen,
        onOk: handleOk,
        onCancel: handleCancel,
        okText: "Save",
        style: { width: "800px" },
        children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_antd.Input.TextArea,
            {
              rows: 7,
              placeholder: "OPENAI_API_KEY=sk-...\nMIDSCENE_MODEL_NAME=gpt-4o-2024-08-06\n...",
              value: tempConfigString,
              onChange: (e) => setTempConfigString(e.target.value),
              style: { whiteSpace: "nowrap", wordWrap: "break-word" }
            }
          ),
          /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "The format is KEY=VALUE and separated by new lines." }),
            /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
              "These data will be saved ",
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "locally in your browser" }),
              "."
            ] })
          ] })
        ]
      }
    )
  ] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  EnvConfig
});
