"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _ComposerButtonSt = require("./ComposerButton.st.css.js");
var _ButtonCore = _interopRequireDefault(require("../Button/ButtonCore"));
var _Tooltip = _interopRequireDefault(require("../Tooltip"));
var _ComposerButton = require("./ComposerButton.constants");
var _Text = _interopRequireDefault(require("../Text"));
var _generateDataAttr = require("../utils/generateDataAttr");
var _excluded = ["dataHook", "label", "children", "shape", "color", "ellipsis", "maxLines", "disabled"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/ComposerButton/ComposerButton.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var ComposerButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
  var buttonRef = _react.default.useRef(null);
  var [isEllipsisActive, setIsEllipsisActive] = (0, _react.useState)(false);
  var {
      dataHook,
      label,
      children,
      shape = _ComposerButton.SHAPES.square,
      color = _ComposerButton.COLORS.standard,
      ellipsis = true,
      maxLines = 1,
      disabled
    } = props,
    rest = (0, _objectWithoutProperties2.default)(props, _excluded);
  (0, _react.useImperativeHandle)(ref, () => {
    return {
      focus() {
        buttonRef.current && buttonRef.current.focus();
      }
    };
  }, [buttonRef]);
  var onEllipsisStateChange = (0, _react.useCallback)(_isEllipsisActive => {
    if (isEllipsisActive !== _isEllipsisActive) {
      setIsEllipsisActive(_isEllipsisActive);
    }
  }, [isEllipsisActive]);
  return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
    className: (0, _ComposerButtonSt.st)(_ComposerButtonSt.classes.tooltip),
    disabled: !isEllipsisActive,
    content: label,
    "data-hook": dataHook,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 53,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement(_ButtonCore.default, (0, _extends2.default)({}, rest, {
    ref: buttonRef,
    className: (0, _ComposerButtonSt.st)(_ComposerButtonSt.classes.root, {
      color,
      disabled
    }),
    disabled: disabled
  }, (0, _generateDataAttr.generateDataAttr)(props, ['shape', 'color']), {
    "data-hook": _ComposerButton.dataHooks.button,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 59,
      columnNumber: 9
    }
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _ComposerButtonSt.st)(_ComposerButtonSt.classes.iconContainer, {
      disabled,
      shape,
      color
    }),
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 67,
      columnNumber: 11
    }
  }, children), /*#__PURE__*/_react.default.createElement(_Text.default, {
    size: "tiny",
    weight: "thin",
    className: (0, _ComposerButtonSt.st)(_ComposerButtonSt.classes.label),
    disabled: disabled,
    ellipsis: ellipsis,
    maxLines: maxLines,
    tooltipProps: {
      disabled: true
    },
    onEllipsisStateChange: onEllipsisStateChange,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 72,
      columnNumber: 11
    }
  }, label)));
});
ComposerButton.displayName = 'ComposerButton';
var _default = exports.default = ComposerButton;
//# sourceMappingURL=ComposerButton.js.map