"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 textual_prompt_input_area_exports = {};
__export(textual_prompt_input_area_exports, {
  TextualPromptInputArea: () => TextualPromptInputArea
});
module.exports = __toCommonJS(textual_prompt_input_area_exports);
var import_design_system = require("@wix/design-system");
var import_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../../ricos-context/index.js");
var import_data_hooks = require("../../data-hooks.js");
var import_prompt_input_area = require("../../prompt-input-area/prompt-input-area.js");
var import_textual_prompt_input_area_scss = __toESM(require("./textual-prompt-input-area-scss.js"));
const TextualPromptInputArea = import_react.default.forwardRef(
  ({
    value,
    onChange,
    maxLength,
    onSubmit,
    handleTextAreaEnter,
    busy,
    onCancel,
    zIndex,
    placeholder,
    isSubmitButtonVisible
  }, ref) => {
    const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
    const inputRef = import_react.default.useRef(null);
    import_react.default.useImperativeHandle(ref, () => {
      return {
        focus() {
          inputRef.current?.focus();
        }
      };
    }, []);
    import_react.default.useEffect(() => {
      setTimeout(() => {
        inputRef.current?.focus();
      }, 0);
    }, []);
    const isVisibleSubmit = isSubmitButtonVisible ? isSubmitButtonVisible() && !busy : !busy && value.length;
    return /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, null, /* @__PURE__ */ import_react.default.createElement(
      import_prompt_input_area.PromptInputArea,
      {
        ref: inputRef,
        busy,
        placeholder: t(placeholder ?? "AIPlugin_Input_Placeholder_Text"),
        maxLength,
        onChange,
        value,
        busyValue: t("AIPlugin_Input_Loading_Text"),
        onCancel: () => onCancel(),
        onSubmit: () => {
          if (handleTextAreaEnter) {
            onSubmit(value);
          }
        },
        zIndex,
        dataHook: import_data_hooks.AI_MODAL_PROMPT_INPUT
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      import_design_system.Box,
      {
        className: (0, import_classnames.default)(import_textual_prompt_input_area_scss.default.buttonWrapper, {
          [import_textual_prompt_input_area_scss.default.visibleSubmit]: isVisibleSubmit,
          [import_textual_prompt_input_area_scss.default.visibleCancel]: busy
        })
      },
      /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { flexGrow: 1, marginLeft: "SP2", verticalAlign: "middle" }, /* @__PURE__ */ import_react.default.createElement(
        import_design_system.Button,
        {
          dataHook: import_data_hooks.AI_MODAL_CANCEL_BUTTON,
          disabled: !busy,
          className: import_textual_prompt_input_area_scss.default.cancelButton,
          size: "small",
          priority: "secondary",
          onClick: onCancel
        },
        t("AIPlugin_Button_Stop_Text")
      ), /* @__PURE__ */ import_react.default.createElement(
        import_design_system.IconButton,
        {
          dataHook: import_data_hooks.AI_MODAL_SUBMIT_BUTTON,
          disabled: busy,
          className: import_textual_prompt_input_area_scss.default.submitButton,
          size: "small",
          onClick: () => onSubmit(value),
          tabIndex: isVisibleSubmit ? 0 : -1
        },
        /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.ArrowUp, null)
      ))
    ));
  }
);
//# sourceMappingURL=textual-prompt-input-area.js.map
