'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-e1b469cd.js');
const Taro = require('@rtarojs/taro');
const index$1 = require('./index-067a58c1.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

const Taro__default = /*#__PURE__*/_interopDefaultLegacy(Taro);

const indexCss = ".navigator-hover{background:#efefef}";

const Navigator = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.onSuccess = index.createEvent(this, "cuccess", 7);
    this.onFail = index.createEvent(this, "fail", 7);
    this.onComplete = index.createEvent(this, "Complete", 7);
    this.hoverClass = undefined;
    this.url = undefined;
    this.openType = 'navigate';
    this.isHover = false;
    this.delta = 0;
  }
  onClick() {
    const { openType, onSuccess, onFail, onComplete } = this;
    let promise = Promise.resolve();
    switch (openType) {
      case 'navigate':
        promise = Taro__default['default'].navigateTo({
          url: this.url
        });
        break;
      case 'redirect':
        promise = Taro__default['default'].redirectTo({
          url: this.url
        });
        break;
      case 'switchTab':
        promise = Taro__default['default'].switchTab({
          url: this.url
        });
        break;
      case 'reLaunch':
        promise = Taro__default['default'].reLaunch({
          url: this.url
        });
        break;
      case 'navigateBack':
        promise = Taro__default['default'].navigateBack({
          delta: this.delta
        });
        break;
      case 'exit':
        promise = Promise.reject(new Error('navigator:fail 暂不支持"openType: exit"'));
        break;
    }
    if (promise) {
      promise.then(res => {
        onSuccess.emit(res);
      }).catch(res => {
        onFail.emit(res);
      }).finally(() => {
        onComplete.emit();
      });
    }
  }
  render() {
    const { isHover, hoverClass } = this;
    return (index.h(index.Host, { class: index$1.classnames({
        [hoverClass]: isHover
      }) }));
  }
};
Navigator.style = indexCss;

exports.taro_navigator_core = Navigator;

//# sourceMappingURL=taro-navigator-core.cjs.entry.js.map