import { r as registerInstance, c as createEvent, h, H as Host } from './index-c948674f.js';
import Taro from '@rtarojs/taro';
import { c as classnames } from './index-394db4c1.js';

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

const Navigator = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.onSuccess = createEvent(this, "cuccess", 7);
    this.onFail = createEvent(this, "fail", 7);
    this.onComplete = 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.navigateTo({
          url: this.url
        });
        break;
      case 'redirect':
        promise = Taro.redirectTo({
          url: this.url
        });
        break;
      case 'switchTab':
        promise = Taro.switchTab({
          url: this.url
        });
        break;
      case 'reLaunch':
        promise = Taro.reLaunch({
          url: this.url
        });
        break;
      case 'navigateBack':
        promise = Taro.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 (h(Host, { class: classnames({
        [hoverClass]: isHover
      }) }));
  }
};
Navigator.style = indexCss;

export { Navigator as taro_navigator_core };

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