"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _comp = require("../../ui/src/comp");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _ui = require("../../ui");
var _dom = require("../../ui/src/dom");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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 _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); }
var _default2 = exports.default = /* define-vxe-component start */(0, _comp.defineVxeComponent)({
  name: 'VxeNoticeBar',
  mixins: [_ui.globalMixins.sizeMixin],
  props: {
    duration: [String, Number],
    direction: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().noticeBar.direction;
      }
    },
    speed: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().noticeBar.speed;
      }
    },
    content: String,
    vertical: Boolean,
    loop: {
      type: Boolean
    },
    size: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().noticeBar.size || (0, _ui.getConfig)().size;
      }
    }
  },
  inject: {
    $xeTabs: {
      from: '$xeTabs',
      default: null
    }
  },
  data: function data() {
    var xID = _xeUtils.default.uniqueId();
    var reactData = {
      animationStatus: false,
      animationDuration: 0
    };
    return {
      xID: xID,
      reactData: reactData
    };
  },
  computed: Object.assign(Object.assign({}, {}), {
    computeNoticeText: function computeNoticeText() {
      var $xeNoticeBar = this;
      var props = $xeNoticeBar;
      var content = props.content;
      return "".concat(content || '');
    },
    computeTabsResizeFlag: function computeTabsResizeFlag() {
      var $xeNoticeBar = this;
      var $xeTabs = $xeNoticeBar.$xeTabs;
      return $xeTabs ? $xeTabs.reactData.resizeFlag : null;
    }
  }),
  methods: {
    //
    // Method
    //
    dispatchEvent: function dispatchEvent(type, params, evnt) {
      var $xeNoticeBar = this;
      $xeNoticeBar.$emit(type, (0, _ui.createEvent)(evnt, {
        $noticeBar: $xeNoticeBar
      }, params));
    },
    updateAnimationStyle: function updateAnimationStyle() {
      var $xeNoticeBar = this;
      var props = $xeNoticeBar;
      var reactData = $xeNoticeBar.reactData;
      var speed = props.speed;
      var contEl = this.$refs.refContentElem;
      if (contEl) {
        var sRate = 46;
        if (speed === 'fast') {
          sRate = 118;
        } else if (speed === 'slow') {
          sRate = 18;
        }
        reactData.animationDuration = Math.ceil(contEl.scrollWidth / sRate);
      }
    },
    animationStartEvent: function animationStartEvent(evnt) {
      var $xeNoticeBar = this;
      var reactData = $xeNoticeBar.reactData;
      reactData.animationStatus = true;
      $xeNoticeBar.dispatchEvent('start', {
        status: true
      }, evnt);
    },
    animationEndEvent: function animationEndEvent(evnt) {
      var $xeNoticeBar = this;
      var reactData = $xeNoticeBar.reactData;
      reactData.animationStatus = false;
      $xeNoticeBar.dispatchEvent('end', {
        status: false
      }, evnt);
    },
    //
    // Render
    //
    renderVN: function renderVN(h) {
      var $xeNoticeBar = this;
      var props = $xeNoticeBar;
      var slots = $xeNoticeBar.$scopedSlots;
      var reactData = $xeNoticeBar.reactData;
      var vertical = props.vertical,
        duration = props.duration,
        direction = props.direction,
        loop = props.loop;
      var animationDuration = reactData.animationDuration,
        animationStatus = reactData.animationStatus;
      var vSize = $xeNoticeBar.computeSize;
      var noticeText = $xeNoticeBar.computeNoticeText;
      var defaultSlot = slots.default;
      var prefixSlot = slots.prefix;
      var suffixSlot = slots.suffix;
      return h('div', {
        ref: 'refElem',
        class: ['vxe-notice-bar', "is--".concat(vertical ? 'vertical' : 'horizontal'), "dir--".concat(direction || 'left'), _defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), 'is--loop', loop)]
      }, [prefixSlot ? h('div', {
        class: 'vxe-notice-bar--prefix'
      }, prefixSlot({})) : (0, _ui.renderEmptyElement)($xeNoticeBar), h('div', {
        class: 'vxe-notice-bar--content'
      }, [h('div', {
        ref: 'refContentElem',
        class: 'vxe-notice-bar--inner'
      }, [h('div', {
        class: ['vxe-notice-bar--wrapper', "is--".concat(animationStatus ? 'progress' : 'end')],
        style: {
          animationDuration: duration ? (0, _dom.toCssUnit)(duration, 's') : "".concat(animationDuration, "s")
        }
      }, defaultSlot ? defaultSlot({}) : noticeText)])]), suffixSlot ? h('div', {
        class: 'vxe-notice-bar--suffix'
      }, suffixSlot({})) : (0, _ui.renderEmptyElement)($xeNoticeBar)]);
    }
  },
  watch: {
    computeTabsResizeFlag: function computeTabsResizeFlag() {
      var $xeNoticeBar = this;
      $xeNoticeBar.updateAnimationStyle();
    }
  },
  mounted: function mounted() {
    var $xeNoticeBar = this;
    _ui.globalEvents.on($xeNoticeBar, 'resize', $xeNoticeBar.updateAnimationStyle);
    $xeNoticeBar.updateAnimationStyle();
  },
  beforeDestroy: function beforeDestroy() {
    var $xeNoticeBar = this;
    _ui.globalEvents.off($xeNoticeBar, 'resize');
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */