"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.platformSpecificSpaceUnits = void 0;

var _lodash = _interopRequireDefault(require("lodash.get"));

var _reactNative = require("react-native");

var _utils = require("./utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const platformSpecificSpaceUnits = theme => {
  const scales = ['space', 'sizes', 'fontSizes'];
  const newTheme = { ...theme
  };
  const isWeb = _reactNative.Platform.OS === 'web';
  console.log('is web', isWeb);
  scales.forEach(key => {
    const scale = (0, _lodash.default)(theme, key, {});
    const newScale = { ...scale
    };

    for (const scaleKey in scale) {
      const val = scale[scaleKey];

      if (typeof val !== 'object') {
        const isAbsolute = typeof val === 'number';
        const isPx = !isAbsolute && val.endsWith('px');
        const isRem = !isAbsolute && val.endsWith('rem'); // If platform is web, we need to convert absolute unit to rem. e.g. 16 to 1rem

        if (isWeb) {
          if (isAbsolute) {
            newScale[scaleKey] = (0, _utils.convertAbsoluteToRem)(val);
          }
        } // If platform is not web, we need to convert px unit to absolute and rem unit to absolute. e.g. 16px to 16. 1rem to 16.
        else {
            if (isRem) {
              newScale[scaleKey] = (0, _utils.convertRemToAbsolute)(parseFloat(val));
            } else if (isPx) {
              newScale[scaleKey] = parseFloat(val);
            }
          }
      }
    } //@ts-ignore


    newTheme[key] = newScale;
  });
  return newTheme;
};

exports.platformSpecificSpaceUnits = platformSpecificSpaceUnits;
//# sourceMappingURL=platformSpecificSpaceUnits.js.map