"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DEFAULT_COLOR_PICKER_COLUMNS = void 0;
exports.getColorsPerRowFromPalette = getColorsPerRowFromPalette;
Object.defineProperty(exports, "getSelectedRowAndColumn", {
  enumerable: true,
  get: function get() {
    return _getSelectedRowAndColumn.getSelectedRowAndColumn;
  }
});
exports.getSelectedRowAndColumnFromPalette = getSelectedRowAndColumnFromPalette;
exports.getTokenCSSVariableValue = void 0;
var _getSelectedRowAndColumn = require("./getSelectedRowAndColumn");
var DEFAULT_COLOR_PICKER_COLUMNS = exports.DEFAULT_COLOR_PICKER_COLUMNS = 7;

// Ignored via go/ees005
// eslint-disable-next-line require-unicode-regexp
var CSS_VAR_EXPRESSION_REGEX = /var\(([^,\)]+)(,.*)?\)/;

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
function getColorsPerRowFromPalette(palette) {
  var cols = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_COLOR_PICKER_COLUMNS;
  return palette.reduce(function (resultArray, item, index) {
    var chunkIndex = Math.floor(index / cols);
    resultArray[chunkIndex] = resultArray[chunkIndex] || []; // start a new chunk
    resultArray[chunkIndex].push(item);
    return resultArray;
  }, []);
}

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
function getSelectedRowAndColumnFromPalette(palette, selectedColor) {
  var cols = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_COLOR_PICKER_COLUMNS;
  var colorsPerRow = getColorsPerRowFromPalette(palette, cols);
  return (0, _getSelectedRowAndColumn.getSelectedRowAndColumn)(colorsPerRow, selectedColor);
}

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var getTokenCSSVariableValue = exports.getTokenCSSVariableValue = function getTokenCSSVariableValue(variableExpression) {
  var matcher = variableExpression.match(CSS_VAR_EXPRESSION_REGEX);
  if (matcher) {
    var variable = matcher[1].trim();
    var fallback = matcher[2] ? matcher[2].replace(',', '').trim() : '';
    if (typeof document === 'undefined') {
      return fallback;
    }
    var value = window.getComputedStyle(document.documentElement).getPropertyValue(variable).trim();
    return value || fallback;
  }
  return '';
};
// eslint-disable-next-line @atlaskit/editor/no-re-export