"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.parseUrl = exports.parseGradient = exports.parseColor = exports.getBackgroundStyles = void 0;
var _gradientParser = _interopRequireDefault(require("gradient-parser"));
var _color = _interopRequireDefault(require("color"));
var _UrlUtils = require("../utils/UrlUtils");
var parseVar = fill => {
  if (fill != null && fill.trim().startsWith('var(')) {
    return fill;
  }
  return;
};
var parseColor = fill => {
  try {
    return (0, _color.default)(fill);
  } catch (_unused) {
    return;
  }
};
exports.parseColor = parseColor;
var parseGradient = fill => {
  if (fill != null && fill.trim().startsWith('conic-gradient') || fill != null && fill.trim().startsWith('radial-gradient')) {
    return fill;
  }
  try {
    return _gradientParser.default.parse(fill);
  } catch (_unused2) {
    return;
  }
};
exports.parseGradient = parseGradient;
var parseUrl = fill => {
  if ((0, _UrlUtils.isUrl)(fill)) {
    return fill;
  }
  if (/.jpg|.png|.svg/.test(fill)) {
    return "".concat(location.hostname, "/").concat(fill);
  }
  return;
};
exports.parseUrl = parseUrl;
var getBackgroundStyles = fill => {
  if (Array.isArray(fill)) {
    return fill.slice(0, 4).map(color => ({
      backgroundColor: color
    }));
  }
  if (typeof fill === 'string' && parseUrl(fill)) {
    return {
      backgroundImage: "url('".concat(fill, "')"),
      backgroundSize: 'cover',
      backgroundPosition: 'center center',
      backgroundRepeat: 'no-repeat'
    };
  }
  if (typeof fill === 'string' && (parseVar(fill) || parseColor(fill))) {
    return [{
      backgroundColor: fill
    }];
  }
  if (typeof fill === 'string' && parseGradient(fill)) {
    return {
      backgroundImage: fill
    };
  }
  return {};
};
exports.getBackgroundStyles = getBackgroundStyles;
//# sourceMappingURL=FillPreview.utils.js.map