"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _Button = _interopRequireDefault(require("../Button"));
var _Input = _interopRequireDefault(require("../Input"));
var _Translate = _interopRequireDefault(require("../Translate"));
var _enUS = _interopRequireDefault(require("./locale/en-US"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.

const Editor = _ref => {
  let {
    value: initialValue = '',
    onSave,
    onCancel,
    baseClassName
  } = _ref;
  const [value, setValue] = (0, _react.useState)(initialValue);
  const handleChange = event => {
    setValue(event.target.value);
  };
  const handleSave = () => onSave(value);
  const handleInputKeyDown = event => {
    if (event.key === 'Escape') {
      onCancel();
    } else if (event.key === 'Enter') {
      handleSave();
    }
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: `${baseClassName}__edit`,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Input.default, {
      className: `${baseClassName}__edit-input`,
      value: value,
      onChange: handleChange,
      onKeyDown: handleInputKeyDown,
      autoFocus: true
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: `${baseClassName}__edit-actions`,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
        ghost: true,
        className: (0, _classnames.default)(`${baseClassName}__control-button`, `${baseClassName}__control-button--ok`),
        icon: "check-mark",
        onClick: handleSave,
        tooltip: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Translate.default, {
          content: "InPlaceEdit.okButtonHint",
          fallback: _enUS.default.okButtonHint
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
        ghost: true,
        className: (0, _classnames.default)(`${baseClassName}__control-button`, `${baseClassName}__control-button--cancel`),
        icon: "cross-mark",
        onClick: onCancel,
        tooltip: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Translate.default, {
          content: "InPlaceEdit.cancelButtonHint",
          fallback: _enUS.default.cancelButtonHint
        })
      })]
    })]
  });
};
var _default = exports.default = Editor;