import { MorsePwd } from '../morse-pwd/morse-pwd.mjs';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';

/**
 * 摩斯密码的 Vue mixin，方便实用
 * @param {array} pwd 密钥
 * @param {Function} cb 回到函数
 * @returns 换入内容
 * @example
 * ```ts
 * getMorsePwdMixin([1, 1, 1, 1, 1], function () {
 *   if (isInIFrame()) return;
 *   this.onShowLaunchApp();
 * }),
 * ```
 */
var getMorsePwdMixin = function getMorsePwdMixin(pwd, _cb) {
  return {
    data: function data() {
      return {
        morsePwd: null
      };
    },
    mounted: function mounted() {
      var _this = this;
      var envType = 'MP';
      this.morsePwd = MorsePwd.init({
        pwd: pwd,
        cb: function cb() {
          if (typeof _cb === 'function') {
            _cb.call(_this);
          }
        },
        envType: envType
      });
    },
    beforeDestroy: function beforeDestroy() {
      this.morsePwd.clear();
    },
    methods: {
      onMorsePwdLongPress: function onMorsePwdLongPress() {
        this.morsePwd.longPress();
      },
      onMorsePwdClick: function onMorsePwdClick() {
        this.morsePwd.click();
      }
    }
  };
};
var morsePwdMixin = getMorsePwdMixin;

export { getMorsePwdMixin, morsePwdMixin };
