import { _ as _defineProperty } from '../defineProperty-18999f8e.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { I as Icon } from '../index-4e01772f.js';
import Tooltip from '../tooltip/index.js';
import cx from 'classnames';
import '../extends-e61fd370.js';
import '../slicedToArray-5b664d46.js';
import '../objectWithoutProperties-72d23964.js';
import '../typeof-6c6d8d7a.js';
import '../toConsumableArray-f2f53597.js';
import '../index-81a9bdac.js';
import 'react-dom';
import '../icon/assets/icon-map/index.js';
import '../social-icon/index.js';
import '@fortawesome/react-fontawesome';
import '../social-icon/icons.js';
import '../social-icon/library.js';
import '@fortawesome/fontawesome-svg-core';
import '@fortawesome/free-solid-svg-icons';
import '@fortawesome/free-brands-svg-icons';
import '../button/button-group.js';
import '@reach/visually-hidden';
import '../auto-id.esm-2b54f757.js';
import '../utils.esm-514fad91.js';
import '../warning-ed2bf294.js';
import '../portal.esm-613949dc.js';
import '../portal/index.js';
import '../use-rerender-once/index.js';
import '../use-force-update/index.js';

var MAX_COLOR_ARRAY_LENGTH = 5;

var isColorsArray = function isColorsArray(props, propName, componentName) {
  var colorsArray = props[propName];

  if (!Array.isArray(colorsArray)) {
    return new Error("Invalid prop ".concat(propName, " passed to ").concat(componentName, ". Expected an array."));
  }

  if (colorsArray.length > MAX_COLOR_ARRAY_LENGTH) {
    return new Error("Invalid prop ".concat(propName, " passed to ").concat(componentName, ". Expected an array with length of 5 or less."));
  }
};

var SavedColorShape = {
  colors: isColorsArray,
  handleColorSelect: PropTypes.func,
  handleColorsEdit: PropTypes.func.isRequired
};

function SavedColorTile(_ref) {
  var color = _ref.color,
      handleColorSelect = _ref.handleColorSelect;
  var styles = {
    background: color
  };
  var buttonClasses = "h-6 w-6 rounded border border-transparent hover:border-gray-200 focus:outline-blue";
  var label = "Select color ".concat(color);
  return /*#__PURE__*/React__default.createElement("button", {
    className: buttonClasses,
    style: styles,
    onClick: function onClick() {
      return handleColorSelect(color);
    },
    "aria-label": label
  });
}

function SettingsTile(_ref2) {
  var colors = _ref2.colors,
      handleColorsEdit = _ref2.handleColorsEdit;
  var buttonClasses = "h-6 w-6 mr-2 grid place-content-center rounded border border-solid text-gray-700 hover:text-gray-900 focus:text-gray-900 bg-white hover:bg-gray-300 focus:outline-blue";
  var icon = colors !== null && colors !== void 0 && colors.length ? "settings-sliders" : "plus";
  return /*#__PURE__*/React__default.createElement(Tooltip, {
    label: "Edit saved colors"
  }, /*#__PURE__*/React__default.createElement("button", {
    "aria-label": "Edit saved colors",
    onClick: handleColorsEdit,
    className: buttonClasses
  }, /*#__PURE__*/React__default.createElement(Icon, {
    name: icon,
    size: "sm"
  })));
}

function SavedColorTiles(_ref3) {
  var colors = _ref3.colors,
      handleColorSelect = _ref3.handleColorSelect,
      handleColorsEdit = _ref3.handleColorsEdit;
  var tiles = colors.map(function (color, index) {
    return /*#__PURE__*/React__default.createElement(SavedColorTile, {
      color: color,
      key: index,
      tileIndex: index,
      handleColorSelect: handleColorSelect
    });
  });
  return /*#__PURE__*/React__default.createElement("div", {
    className: "grid grid-cols-6 gap-2"
  }, tiles, /*#__PURE__*/React__default.createElement(SettingsTile, {
    colors: colors,
    handleColorsEdit: handleColorsEdit
  }));
}

function ColorsUpdaterToolbar(_ref4) {
  var _ref4$colors = _ref4.colors,
      colors = _ref4$colors === void 0 ? [] : _ref4$colors,
      handleColorSelect = _ref4.handleColorSelect,
      handleColorsEdit = _ref4.handleColorsEdit,
      _ref4$className = _ref4.className,
      className = _ref4$className === void 0 ? "" : _ref4$className;
  var title = colors !== null && colors !== void 0 && colors.length ? "Saved colors" : "Click + to add saved colors";
  var classes = cx("border-t w-auto", _defineProperty({
    "mt-4 -mx-3": !(className !== null && className !== void 0 && className.length)
  }, className, className === null || className === void 0 ? void 0 : className.length));
  return /*#__PURE__*/React__default.createElement("div", {
    className: classes
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "pl-3 mr-3 w-auto"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "text-gray-800 text-xs font-semibold mt-3 mb-2"
  }, title), /*#__PURE__*/React__default.createElement(SavedColorTiles, {
    colors: colors,
    handleColorSelect: handleColorSelect,
    handleColorsEdit: handleColorsEdit
  })));
}

ColorsUpdaterToolbar.propTypes = {
  colors: PropTypes.array,
  handleColorSelect: PropTypes.func,
  handleColorsEdit: PropTypes.func.isRequired,
  className: PropTypes.string
};

export { SavedColorShape, ColorsUpdaterToolbar as default };
