"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
require("./index.scss");
var _excluded = ["height", "bgImg", "isBgColor", "bgOpacity", "repeat", "bgColor", "bgSize", "bgPosition", "text", "font", "fontSize", "fontPosition", "fontColor", "fontOpacity"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var banner = function banner(_ref) {
  var _ref$height = _ref.height,
    height = _ref$height === void 0 ? 300 : _ref$height,
    bgImg = _ref.bgImg,
    isBgColor = _ref.isBgColor,
    bgOpacity = _ref.bgOpacity,
    repeat = _ref.repeat,
    bgColor = _ref.bgColor,
    bgSize = _ref.bgSize,
    bgPosition = _ref.bgPosition,
    text = _ref.text,
    font = _ref.font,
    fontSize = _ref.fontSize,
    fontPosition = _ref.fontPosition,
    fontColor = _ref.fontColor,
    fontOpacity = _ref.fontOpacity,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _split = (bgPosition || 'cc').split(''),
    bgH = _split[0],
    bgV = _split[1];
  var horizontal = {
    l: 'left',
    c: 'center',
    r: 'right'
  };
  var vertical = {
    t: 'top',
    c: 'center',
    b: 'bottom'
  };
  var _split2 = (fontPosition || 'cc').split(''),
    fontH = _split2[0],
    fontV = _split2[1];
  var fontTextCss = {
    opacity: fontOpacity / 100,
    color: fontColor,
    fontSize: fontSize + "px",
    fontFamily: font
  };
  switch (fontH) {
    case 'l':
      Object.assign(fontTextCss, {
        left: '2%'
      });
      break;
    case 'r':
      Object.assign(fontTextCss, {
        right: '2%'
      });
      break;
    case 'c':
      Object.assign(fontTextCss, {
        transform: 'translateX(-50%)'
      });
    // eslint-disable-next-line no-fallthrough
    default:
      Object.assign(fontTextCss, {
        left: '50%'
      });
  }
  switch (fontV) {
    case 't':
      Object.assign(fontTextCss, {
        top: '2%'
      });
      break;
    case 'b':
      Object.assign(fontTextCss, {
        bottom: '2%'
      });
      break;
    case 'c':
      Object.assign(fontTextCss, {
        transform: 'translateY(-50%)'
      });
    // eslint-disable-next-line no-fallthrough
    default:
      Object.assign(fontTextCss, {
        top: '50%'
      });
      break;
  }
  if (fontPosition === 'cc') Object.assign(fontTextCss, {
    transform: 'translate(-50%)'
  });

  // transform: rotate(45deg);
  var _otherProps = Object.assign({
    style: {
      height: height,
      backgroundColor: isBgColor ? bgColor : ''
    }
  }, otherProps) || {};
  var bannerBgStyle = {
    style: {
      opacity: bgOpacity / 100,
      backgroundImage: "url(" + bgImg + "?imageMogr2/interlace/1)",
      backgroundSize: typeof bgSize === 'number' ? bgSize + "%" : bgSize,
      backgroundPosition: horizontal[bgH] + " " + vertical[bgV],
      backgroundRepeat: ['no-repeat', 'repeat-x', 'repeat-y', 'repeat'][repeat]
    }
  };
  return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: "banner"
  }, _otherProps), /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
    className: "banner-bg"
  }, bannerBgStyle)), /*#__PURE__*/React.createElement("div", {
    className: "title-text",
    style: fontTextCss
  }, text));
};
var _default = banner;
exports["default"] = _default;