"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 footer_exports = {};
__export(footer_exports, {
  Footer: () => Footer
});
module.exports = __toCommonJS(footer_exports);
var import_design_system = require("@wix/design-system");
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_ts_utils = require("../ts-utils.js");
var import_ai_image_modal_scss = __toESM(require("./ai-image-modal-scss.js"));
var import_image_style_selector = require("./image-style-selector.js");
const PROMPT_CHAR_LIMIT = 500;
const Footer = import_react.default.forwardRef(
  ({
    modalRef,
    zIndex,
    state,
    goBack,
    retryPrompt,
    isConvertedPromptHelperVisible,
    setPromptValue,
    setImageStyleValue,
    cancelPrompt,
    closeOptimisedPromptHelper,
    submitPrompt,
    publishModalAction
  }, ref) => {
    const { t } = import_react.default.useContext(import_ricos_context.RicosContext);
    const inputRef = import_react.default.useRef(null);
    import_react.default.useImperativeHandle(ref, () => {
      return {
        focus() {
          inputRef.current?.focus();
        }
      };
    }, []);
    if (!modalRef) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(import_design_system.SidePanel.Footer, { noPadding: true, showDivider: !(0, import_ts_utils.isOfType)(["INITIAL", "INITIALIZING"], state) }, /* @__PURE__ */ import_react.default.createElement(
      import_design_system.Box,
      {
        paddingTop: "SP3",
        paddingBottom: "SP2",
        paddingLeft: "SP4",
        paddingRight: "SP4",
        align: "right",
        className: import_ai_image_modal_scss.default.footer
      },
      (() => {
        switch (state.type) {
          case "ERROR": {
            return /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { gap: "SP2", paddingBottom: "SP1" }, /* @__PURE__ */ import_react.default.createElement(
              import_design_system.Button,
              {
                dataHook: import_data_hooks.AI_IMAGE_MODAL_ERROR_CANCEL_BUTTON,
                size: "small",
                priority: "secondary",
                onClick: () => {
                  goBack();
                  publishModalAction("back_from_error");
                }
              },
              t("AIPlugin_Error_Button_GoBack")
            ), /* @__PURE__ */ import_react.default.createElement(
              import_design_system.Button,
              {
                dataHook: import_data_hooks.AI_IMAGE_MODAL_ERROR_RETRY_BUTTON,
                size: "small",
                priority: "primary",
                onClick: () => {
                  retryPrompt();
                  publishModalAction("retry_from_error");
                }
              },
              t("AIPlugin_Error_Button_Retry")
            ));
          }
          default: {
            return /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { direction: "vertical", gap: "SP2", width: "100%" }, /* @__PURE__ */ import_react.default.createElement(
              import_design_system.Popover,
              {
                dataHook: import_data_hooks.AI_IMAGE_MODAL_PROMPT_HELPER_POPOVER,
                fixed: true,
                shown: isConvertedPromptHelperVisible,
                appendTo: modalRef,
                placement: "top-start",
                theme: "dark",
                zIndex,
                showArrow: true
              },
              /* @__PURE__ */ import_react.default.createElement(import_design_system.Popover.Element, null, /* @__PURE__ */ import_react.default.createElement(
                import_prompt_input_area.PromptInputArea,
                {
                  minRowsAutoGrow: 2,
                  maxHeight: "48px",
                  dataHook: import_data_hooks.AI_IMAGE_MODAL_PROMPT_INPUT,
                  readonly: (0, import_ts_utils.isOfType)(["IN_PROGRESS"], state),
                  busy: (0, import_ts_utils.isOfType)(["INITIALIZING"], state),
                  value: state.type === "INITIALIZING" ? "" : state.textualPrompt,
                  busyValue: state.type === "INITIALIZING" ? t("AIPlugin_Loading_Initialising") : state.textualPrompt,
                  errorMessage: (0, import_ts_utils.isOfType)(["INITIAL", "RESULTS"], state) ? state.validationError || state.rateLimitError : void 0,
                  onChange: setPromptValue,
                  onSubmit: () => {
                    if (!(0, import_ts_utils.isOfType)(["INITIALIZING", "IN_PROGRESS"], state)) {
                      submitPrompt(state.textualPrompt, state.imageStyle, {
                        isDirty: state.isDirty
                      });
                    }
                  },
                  onCancel: () => {
                    cancelPrompt();
                  },
                  ref: inputRef,
                  maxLength: PROMPT_CHAR_LIMIT,
                  zIndex,
                  placeholder: t("AIPlugin_Input_ImageGeneratePlaceholder_Text")
                }
              )),
              /* @__PURE__ */ import_react.default.createElement(import_design_system.Popover.Content, null, /* @__PURE__ */ import_react.default.createElement(
                import_design_system.CloseButton,
                {
                  dataHook: import_data_hooks.AI_IMAGE_MODAL_PROMPT_HELPER_POPOVER_CLOSE,
                  className: import_ai_image_modal_scss.default.closeButton,
                  onClick: closeOptimisedPromptHelper,
                  skin: "light",
                  size: "medium"
                }
              ), /* @__PURE__ */ import_react.default.createElement(
                import_design_system.Box,
                {
                  paddingTop: "SP3",
                  paddingBottom: "SP3",
                  paddingLeft: "SP4",
                  paddingRight: "SP4",
                  direction: "vertical",
                  maxWidth: "380px",
                  gap: "SP2"
                },
                /* @__PURE__ */ import_react.default.createElement(import_design_system.Text, { size: "small", light: true, weight: "thin" }, t("AIPlugin_Helper_GenerateImage_Optimise")),
                /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, null, /* @__PURE__ */ import_react.default.createElement(
                  import_design_system.Button,
                  {
                    skin: "light",
                    size: "small",
                    priority: "secondary",
                    onClick: closeOptimisedPromptHelper
                  },
                  t("AIPlugin_Helper_GenerateImage_Button")
                ))
              ))
            ), /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { direction: "horizontal", align: "space-between", verticalAlign: "middle" }, /* @__PURE__ */ import_react.default.createElement(
              import_image_style_selector.ImageStyleSelector,
              {
                disabled: (0, import_ts_utils.isOfType)(["IN_PROGRESS", "INITIALIZING"], state),
                value: state.imageStyle,
                onChange: setImageStyleValue,
                zIndex,
                modalRef
              }
            ), /* @__PURE__ */ import_react.default.createElement(
              import_design_system.Button,
              {
                size: "small",
                disabled: state.type === "INITIALIZING" || state.textualPrompt.length === 0,
                dataHook: state.type === "IN_PROGRESS" ? import_data_hooks.AI_IMAGE_MODAL_CANCEL_BUTTON : import_data_hooks.AI_IMAGE_MODAL_SUBMIT_BUTTON,
                priority: (0, import_ts_utils.isOfType)(["INITIAL", "INITIALIZING"], state) ? "primary" : "secondary",
                onClick: () => {
                  if (state.type === "INITIALIZING") {
                    return;
                  }
                  if (state.type === "IN_PROGRESS") {
                    cancelPrompt();
                    return;
                  }
                  submitPrompt(state.textualPrompt, state.imageStyle, {
                    isDirty: state.isDirty
                  });
                }
              },
              t(
                state.type === "IN_PROGRESS" ? "AIPlugin_Action_StopGenerating" : (0, import_ts_utils.isOfType)(["INITIAL", "INITIALIZING"], state) ? "AIPlugin_Action_Generate" : "AIPlugin_Action_Regenerate"
              )
            )));
          }
        }
      })()
    ));
  }
);
//# sourceMappingURL=footer.js.map
