/* eslint-disable */
import style from './picker-column/style.sjs';

const REGEXP = getRegExp('^-?\d+(\.\d+)?$');

function addUnit(value) {
  if (value == null) {
    return undefined;
  }
  return REGEXP.test('' + value) ? value + 'px' : value;
}

function isArray(array) {
  return array && array.constructor === 'Array';
}

function columnsStyle(data) {
  return style.style({
    height: addUnit(data.itemHeight * data.visibleItemCount),
  });
}

function maskStyle(data) {
  return style.style({
    'background-size':
      '100% ' + addUnit((data.itemHeight * (data.visibleItemCount - 1)) / 2),
  });
}

function frameStyle(data) {
  return style.style({
    height: addUnit(data.itemHeight),
  });
}

function columns(columns) {
  if (!isArray(columns)) {
    return [];
  }

  if (columns.length && !columns[0].values) {
    return [{ values: columns }];
  }

  return columns;
}

function containerStyle(show, position) {
  if (!show) return '';
  const styles = {};
  if (position === 'top') {
    styles.paddingTop = '44px';
  } else {
    styles.paddingBottom = '44px';
  }
  return style.style(styles)
}

export default {
  containerStyle: containerStyle,
  columnsStyle: columnsStyle,
  frameStyle: frameStyle,
  maskStyle: maskStyle,
  columns: columns,
};
