import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _typeof from "@babel/runtime/helpers/esm/typeof";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

export var breakpoints = ['sm', 'md', 'lg', 'xl'];
var responsivePrefixes = ['', 'md', 'lg', 'xl'];
export function mergeResponsiveProps(props) {
  // convert to objects
  var propObjects = props.map(function (prop) {
    if (prop === null || prop === undefined) {
      return {};
    } else if (_typeof(prop) !== 'object') {
      return {
        sm: prop,
        md: prop,
        lg: prop,
        xl: prop
      };
    } else if (Array.isArray(prop)) {
      return (prop.length > 4 ? prop.slice(0, 4) : prop).reduce(function (acc, next, index) {
        if (next !== null && next !== undefined) {
          acc[breakpoints[index]] = next;
        }

        return acc;
      }, {});
    } else {
      return _objectSpread({}, prop);
    }
  }); // fill empty breakpoints when other props have values

  var lastRowValues = [];
  breakpoints.forEach(function (breakpoint) {
    var valueBreakpointExist = propObjects.some(function (propObject) {
      return propObject[breakpoint] !== null && propObject[breakpoint] !== undefined;
    });

    if (valueBreakpointExist) {
      // eslint-disable-next-line no-loop-func
      propObjects.forEach(function (propObject, propObjectsIndex) {
        if (lastRowValues[propObjectsIndex] && !propObject[breakpoint]) {
          propObject[breakpoint] = lastRowValues[propObjectsIndex];
        }
      });
    }

    lastRowValues = propObjects.map(function (propObject) {
      return propObject[breakpoint];
    });
  });
  breakpoints.forEach; // merge

  return breakpoints.reduce(function (acc, breakpoint) {
    if (propObjects.every(function (propObject) {
      return propObject[breakpoint] !== null && propObject[breakpoint] !== undefined;
    })) {
      acc[breakpoint] = propObjects.map(function (propObject) {
        return propObject[breakpoint];
      });
    }

    return acc;
  }, {});
}
export function generateResponsiveClassNames(createBaseClassName, prop) {
  if (prop === null || prop === undefined) {
    return [];
  }

  if (_typeof(prop) !== 'object') {
    return [createBaseClassName(prop)];
  }

  if (Array.isArray(prop)) {
    return (prop.length > 4 ? prop.slice(0, 4) : prop).reduce(function (acc, propBreakpointValue, index) {
      if (propBreakpointValue === null || propBreakpointValue === undefined) {
        return acc;
      } else if (!createBaseClassName(propBreakpointValue)) {
        return acc;
      } else {
        acc.push("".concat(responsivePrefixes[index] ? "".concat(responsivePrefixes[index], ":") : '').concat(createBaseClassName(propBreakpointValue)));
        return acc;
      }
    }, []);
  }

  return breakpoints.map(function (breakpoint) {
    if (prop[breakpoint] === null || prop[breakpoint] === undefined) {
      return '';
    } else if (!createBaseClassName(prop[breakpoint])) {
      return '';
    } else {
      return breakpoint === 'sm' ? createBaseClassName(prop[breakpoint]) : "".concat(breakpoint, ":").concat(createBaseClassName(prop[breakpoint]));
    }
  }).filter(function (className) {
    return className;
  });
}