import { getSelectedRowAndColumn } from './getSelectedRowAndColumn';
export const DEFAULT_COLOR_PICKER_COLUMNS = 7;
export function getColorsPerRowFromPalette(palette, cols = DEFAULT_COLOR_PICKER_COLUMNS) {
  return palette.reduce((resultArray, item, index) => {
    const chunkIndex = Math.floor(index / cols);
    resultArray[chunkIndex] = resultArray[chunkIndex] || []; // start a new chunk
    resultArray[chunkIndex].push(item);
    return resultArray;
  }, []);
}
export function getSelectedRowAndColumnFromPalette(palette, selectedColor, cols = DEFAULT_COLOR_PICKER_COLUMNS) {
  const colorsPerRow = getColorsPerRowFromPalette(palette, cols);
  return getSelectedRowAndColumn(colorsPerRow, selectedColor);
}
export const getTokenCSSVariableValue = variableExpression => {
  // Ignored via go/ees005
  // eslint-disable-next-line require-unicode-regexp
  const matcher = variableExpression.match(/var\(([^,\)]+)(,.*)?\)/);
  if (matcher) {
    const variable = matcher[1].trim();
    const fallback = matcher[2] ? matcher[2].replace(',', '').trim() : '';
    if (typeof document === 'undefined') {
      return fallback;
    }
    const value = window.getComputedStyle(document.documentElement).getPropertyValue(variable).trim();
    return value || fallback;
  }
  return '';
};
// eslint-disable-next-line @atlaskit/editor/no-re-export
export { getSelectedRowAndColumn } from './getSelectedRowAndColumn';