"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var CustomInput_exports = {};
__export(CustomInput_exports, {
  default: () => CustomInput
});
module.exports = __toCommonJS(CustomInput_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_ink = require("ink");
function CustomInput({
  value,
  onChange,
  onSubmit,
  placeholder,
  isProcessing = false,
  onWordDelete,
  onLineDelete,
  onToggleMultiLine
}) {
  (0, import_ink.useInput)(
    (inputChar, key) => {
      if (isProcessing) return;
      if (key.return && key.shift) {
        onToggleMultiLine?.();
        return;
      }
      if (key.return) {
        onSubmit(value);
        return;
      }
      if (key.ctrl && inputChar === "u") {
        onLineDelete?.();
        return;
      }
      if (key.ctrl && inputChar === "w") {
        onWordDelete?.();
        return;
      }
      if (key.backspace || key.delete) {
        onChange(value.slice(0, -1));
        return;
      }
      if (inputChar && !key.ctrl && !key.meta) {
        onChange(value + inputChar);
      }
    },
    { isActive: true }
  );
  if (!value && placeholder) {
    const firstChar = placeholder[0] || " ";
    const rest = placeholder.slice(1);
    return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "black", backgroundColor: "green", children: firstChar }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: rest })
    ] });
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { children: [
    value,
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "black", backgroundColor: "green", children: " " })
  ] });
}
