Liferay.Loader.define("layout-content-page-editor-web@2.0.110/page_editor/common/components/ColorPicker", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/drop-down', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/shared', 'frontend-js-react-web$classnames', 'frontend-js-react-web$react'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _dropDown = _interopRequireDefault(require("@frontend-taglib-clay$clayui/drop-down"));

    var _form = require("@frontend-taglib-clay$clayui/form");

    var _shared = require("@frontend-taglib-clay$clayui/shared");

    var _classnames = _interopRequireDefault(require("frontend-js-react-web$classnames"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var ColorPicker = function ColorPicker(_ref) {
      var colors = _ref.colors,
          disabled = _ref.disabled,
          _ref$onValueChange = _ref.onValueChange,
          onValueChange = _ref$onValueChange === void 0 ? function () {} : _ref$onValueChange,
          small = _ref.small,
          _ref$value = _ref.value,
          value = _ref$value === void 0 ? '#FFFFFF' : _ref$value;
      var triggerElementRef = (0, _react.useRef)(null);
      var splotchRef = (0, _react.useRef)(null);
      var dropdownContainerRef = (0, _react.useRef)(null);

      var _useState = (0, _react.useState)(false),
          _useState2 = _slicedToArray(_useState, 2),
          active = _useState2[0],
          setActive = _useState2[1];

      return (/*#__PURE__*/_react.default.createElement(_shared.FocusScope, {
          arrowKeysUpDown: false
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "clay-color-picker"
        }, /*#__PURE__*/_react.default.createElement(_form.ClayInput.Group, {
          className: "clay-color",
          ref: triggerElementRef,
          small: small
        }, /*#__PURE__*/_react.default.createElement(_form.ClayInput.GroupItem, {
          shrink: true
        }, /*#__PURE__*/_react.default.createElement(_form.ClayInput.GroupText, {
          className: "page-editor__ColorPicker__input-group-text--rounded-left"
        }, /*#__PURE__*/_react.default.createElement(Splotch, {
          className: "dropdown-toggle",
          disabled: disabled,
          onClick: function onClick() {
            setActive(function (active) {
              return !active;
            });

            if (splotchRef.current) {
              splotchRef.current.focus();
            }
          },
          ref: splotchRef,
          value: value
        }))), /*#__PURE__*/_react.default.createElement(_dropDown.default.Menu, {
          active: active,
          alignElementRef: triggerElementRef,
          className: "clay-color-dropdown-menu",
          focusRefOnEsc: splotchRef,
          onSetActive: setActive,
          ref: dropdownContainerRef
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "clay-color-swatch"
        }, colors.map(function (_ref2, i) {
          var label = _ref2.label,
              name = _ref2.name,
              value = _ref2.value;
          return (/*#__PURE__*/_react.default.createElement("div", {
              className: "clay-color-swatch-item",
              key: i
            }, /*#__PURE__*/_react.default.createElement(Splotch, {
              onClick: function onClick() {
                onValueChange({
                  label: label,
                  name: name,
                  value: value
                });
                setActive(function (active) {
                  return !active;
                });

                if (splotchRef.current) {
                  splotchRef.current.focus();
                }
              },
              title: label,
              value: value
            }))
          );
        }))))))
      );
    };

    var Splotch = /*#__PURE__*/_react.default.forwardRef(function (_ref3, ref) {
      var active = _ref3.active,
          className = _ref3.className,
          onClick = _ref3.onClick,
          size = _ref3.size,
          title = _ref3.title,
          value = _ref3.value;
      return (/*#__PURE__*/_react.default.createElement("button", {
          className: (0, _classnames.default)('btn clay-color-btn clay-color-btn-bordered', _defineProperty({
            active: active
          }, className, !!className)),
          onClick: onClick,
          ref: ref,
          style: {
            background: "".concat(value),
            height: size,
            width: size
          },
          title: title,
          type: "button"
        })
      );
    });

    var _default = ColorPicker;
    exports.default = _default;
    //# sourceMappingURL=ColorPicker.js.map
  }
});
//# sourceMappingURL=ColorPicker.js.map