import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _get from "lodash/get";
import { getAssetSrc } from "../../../../utils/common";
var scaling = {
  cover: {
    backgroundSize: "cover",
    backgroundRepeat: "no-repeat"
  },
  contain: {
    backgroundSize: "contain",
    backgroundRepeat: "no-repeat"
  },
  originalSize: {
    backgroundSize: "auto",
    backgroundRepeat: "no-repeat"
  },
  tile: {
    backgroundSize: "auto",
    backgroundRepeat: "repeat"
  },
  tileHorizontally: {
    backgroundSize: "auto",
    backgroundRepeat: "repeat-x"
  },
  tileVertically: {
    backgroundSize: "auto",
    backgroundRepeat: "repeat-y"
  }
};
export default {
  name: "pb-render-page-element-style-background",
  type: "pb-render-page-element-style",
  renderStyle: function renderStyle(_ref) {
    var element = _ref.element,
        style = _ref.style;

    var _get2 = _get(element, "data.settings", {}),
        background = _get2.background;

    if (!background) {
      return style;
    }

    var color = background.color,
        image = background.image;

    var src = _get(image, "file.src");

    if (src) {
      var bgUrl = src;

      if (typeof src === 'string') {
        bgUrl = getAssetSrc(src);
      } else if (typeof src === 'object') {
        if (src.guid && src.fileName) {
          bgUrl = getAssetSrc("/".concat(src.path, "/").concat(src.fileName));
        } else {
          bgUrl = getAssetSrc(src.path);
        }
      }

      return _objectSpread(_objectSpread(_objectSpread({}, style), scaling[image.scaling || "cover"]), {}, {
        backgroundImage: "url(".concat(bgUrl, ")"),
        backgroundPosition: image.position || "center center"
      });
    }

    if (color) {
      return _objectSpread(_objectSpread({}, style), {}, {
        backgroundColor: color
      });
    }

    return style;
  }
};
//# sourceMappingURL=index.js.map