function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { extend } from '../../vue';
import { NAME_OVERLAY } from '../../constants/components';
import { EVENT_NAME_CLICK, EVENT_NAME_HIDDEN, EVENT_NAME_SHOWN } from '../../constants/events';
import { PROP_TYPE_BOOLEAN, PROP_TYPE_BOOLEAN_STRING, PROP_TYPE_NUMBER_STRING, PROP_TYPE_STRING } from '../../constants/props';
import { SLOT_NAME_OVERLAY } from '../../constants/slots';
import { toFloat } from '../../utils/number';
import { normalizeSlotMixin } from '../../mixins/normalize-slot';
import { makeProp, makePropsConfigurable } from '../../utils/props';
import { BSpinner } from '../spinner/spinner';
import { BVTransition } from '../transition/bv-transition';

// --- Constants ---

var POSITION_COVER = {
  top: 0,
  left: 0,
  bottom: 0,
  right: 0
};

// --- Props ---

export var props = makePropsConfigurable({
  // Alternative to variant, allowing a specific
  // CSS color to be applied to the overlay
  bgColor: makeProp(PROP_TYPE_STRING),
  blur: makeProp(PROP_TYPE_STRING, '2px'),
  fixed: makeProp(PROP_TYPE_BOOLEAN, false),
  noCenter: makeProp(PROP_TYPE_BOOLEAN, false),
  noFade: makeProp(PROP_TYPE_BOOLEAN, false),
  // If `true, does not render the default slot
  // and switches to absolute positioning
  noWrap: makeProp(PROP_TYPE_BOOLEAN, false),
  opacity: makeProp(PROP_TYPE_NUMBER_STRING, 0.85, function (value) {
    var number = toFloat(value, 0);
    return number >= 0 && number <= 1;
  }),
  overlayTag: makeProp(PROP_TYPE_STRING, 'div'),
  rounded: makeProp(PROP_TYPE_BOOLEAN_STRING, false),
  show: makeProp(PROP_TYPE_BOOLEAN, false),
  spinnerSmall: makeProp(PROP_TYPE_BOOLEAN, false),
  spinnerType: makeProp(PROP_TYPE_STRING, 'border'),
  spinnerVariant: makeProp(PROP_TYPE_STRING),
  variant: makeProp(PROP_TYPE_STRING, 'light'),
  wrapTag: makeProp(PROP_TYPE_STRING, 'div'),
  zIndex: makeProp(PROP_TYPE_NUMBER_STRING, 10)
}, NAME_OVERLAY);

// --- Main component ---

// @vue/component
export var BOverlay = /*#__PURE__*/extend({
  name: NAME_OVERLAY,
  mixins: [normalizeSlotMixin],
  props: props,
  computed: {
    computedRounded: function computedRounded() {
      var rounded = this.rounded;
      return rounded === true || rounded === '' ? 'rounded' : !rounded ? '' : "rounded-".concat(rounded);
    },
    computedVariant: function computedVariant() {
      var variant = this.variant;
      return variant && !this.bgColor ? "bg-".concat(variant) : '';
    },
    slotScope: function slotScope() {
      return {
        spinnerType: this.spinnerType || null,
        spinnerVariant: this.spinnerVariant || null,
        spinnerSmall: this.spinnerSmall
      };
    }
  },
  methods: {
    defaultOverlayFn: function defaultOverlayFn(_ref) {
      var spinnerType = _ref.spinnerType,
        spinnerVariant = _ref.spinnerVariant,
        spinnerSmall = _ref.spinnerSmall;
      return this.$createElement(BSpinner, {
        props: {
          type: spinnerType,
          variant: spinnerVariant,
          small: spinnerSmall
        }
      });
    }
  },
  render: function render(h) {
    var _this = this;
    var show = this.show,
      fixed = this.fixed,
      noFade = this.noFade,
      noWrap = this.noWrap,
      slotScope = this.slotScope;
    var $overlay = h();
    if (show) {
      var $background = h('div', {
        staticClass: 'position-absolute',
        class: [this.computedVariant, this.computedRounded],
        style: _objectSpread(_objectSpread({}, POSITION_COVER), {}, {
          opacity: this.opacity,
          backgroundColor: this.bgColor || null,
          backdropFilter: this.blur ? "blur(".concat(this.blur, ")") : null
        })
      });
      var $content = h('div', {
        staticClass: 'position-absolute',
        style: this.noCenter ? /* istanbul ignore next */_objectSpread({}, POSITION_COVER) : {
          top: '50%',
          left: '50%',
          transform: 'translateX(-50%) translateY(-50%)'
        }
      }, [this.normalizeSlot(SLOT_NAME_OVERLAY, slotScope) || this.defaultOverlayFn(slotScope)]);
      $overlay = h(this.overlayTag, {
        staticClass: 'b-overlay',
        class: {
          'position-absolute': !noWrap || noWrap && !fixed,
          'position-fixed': noWrap && fixed
        },
        style: _objectSpread(_objectSpread({}, POSITION_COVER), {}, {
          zIndex: this.zIndex || 10
        }),
        on: {
          click: function click(event) {
            return _this.$emit(EVENT_NAME_CLICK, event);
          }
        },
        key: 'overlay'
      }, [$background, $content]);
    }

    // Wrap in a fade transition
    $overlay = h(BVTransition, {
      props: {
        noFade: noFade,
        appear: true
      },
      on: {
        'after-enter': function afterEnter() {
          return _this.$emit(EVENT_NAME_SHOWN);
        },
        'after-leave': function afterLeave() {
          return _this.$emit(EVENT_NAME_HIDDEN);
        }
      }
    }, [$overlay]);
    if (noWrap) {
      return $overlay;
    }
    return h(this.wrapTag, {
      staticClass: 'b-overlay-wrap position-relative',
      attrs: {
        'aria-busy': show ? 'true' : null
      }
    }, noWrap ? [$overlay] : [this.normalizeSlot(), $overlay]);
  }
});