"use strict";
const uni_modules_tdesignUniapp_components_common_validator = require("../common/validator.js");
const uni_modules_tdesignUniapp_components_common_src_instantiationDecorator = require("../common/src/instantiationDecorator.js");
const uni_modules_tdesignUniapp_components_common_config = require("../common/config.js");
const uni_modules_tdesignUniapp_components_dialog_props = require("./props.js");
const uni_modules_tdesignUniapp_components_common_utils = require("../common/utils.js");
const uni_modules_tdesignUniapp_components_mixins_usingCustomNavbar = require("../mixins/using-custom-navbar.js");
const uni_modules_tdesignUniapp_components_common_utils_wxs = require("../common/utils.wxs.js");
const uni_modules_tdesignUniapp_components_dialog_computed = require("./computed.js");
const uni_modules_tdesignUniapp_components_common_functional_mixin = require("../common/functional/mixin.js");
const uni_modules_tdesignUniapp_components_common_version = require("../common/version.js");
const common_vendor = require("../../../../common/vendor.js");
const TPopup = () => "../popup/popup.js";
const TIcon = () => "../icon/icon.js";
const TButton = () => "../button/button.js";
const name = `${uni_modules_tdesignUniapp_components_common_config.prefix}-dialog`;
const _sfc_main = uni_modules_tdesignUniapp_components_common_src_instantiationDecorator.uniComponent({
  name,
  options: {
    styleIsolation: "shared"
  },
  externalClasses: [
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-content`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-confirm`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-cancel`,
    `${uni_modules_tdesignUniapp_components_common_config.prefix}-class-action`
  ],
  mixins: [uni_modules_tdesignUniapp_components_common_functional_mixin.getFunctionalMixin(uni_modules_tdesignUniapp_components_dialog_props.props), uni_modules_tdesignUniapp_components_mixins_usingCustomNavbar.useCustomNavbarBehavior],
  components: {
    TPopup,
    TIcon,
    TButton
  },
  props: {
    ...uni_modules_tdesignUniapp_components_dialog_props.props
  },
  data() {
    return {
      prefix: uni_modules_tdesignUniapp_components_common_config.prefix,
      classPrefix: name,
      buttonVariant: "text",
      tools: uni_modules_tdesignUniapp_components_common_utils_wxs.tools,
      _confirm: null,
      _cancel: null,
      useVirtualHost: uni_modules_tdesignUniapp_components_common_version.canUseVirtualHost()
    };
  },
  watch: {
    dataConfirmBtn: {
      handler() {
        this.onWatchBtn(this.dataConfirmBtn, this.dataCancelBtn);
      },
      immediate: true
    },
    dataCancelBtn: {
      handler() {
        this.onWatchBtn(this.dataConfirmBtn, this.dataCancelBtn);
      },
      immediate: true
    }
  },
  methods: {
    coalesce: uni_modules_tdesignUniapp_components_common_utils.coalesce,
    getActionClass: uni_modules_tdesignUniapp_components_dialog_computed.getActionClass,
    onWatchBtn(confirm, cancel) {
      const { prefix, classPrefix, dataButtonLayout } = this;
      const rect = { buttonVariant: "text" };
      const useBaseVariant = [confirm, cancel].some((item) => uni_modules_tdesignUniapp_components_common_validator.isObject(item) && item.variant && item.variant !== "text");
      const buttonMap = { confirm, cancel };
      const cls = [`${classPrefix}__button`];
      const externalCls = [];
      if (useBaseVariant) {
        rect.buttonVariant = "base";
        cls.push(`${classPrefix}__button--${dataButtonLayout}`);
      } else {
        cls.push(`${classPrefix}__button--text`);
        externalCls.push(`${classPrefix}-button`);
      }
      const useVirtualHost = uni_modules_tdesignUniapp_components_common_version.canUseVirtualHost();
      Object.keys(buttonMap).forEach((key) => {
        const btn = buttonMap[key];
        const rootClass = [...cls, `${classPrefix}__button--${key}`];
        const tClass = [...externalCls, this[uni_modules_tdesignUniapp_components_common_utils.toCamel(`${prefix}-class-${key}`)], ...rootClass].join(" ");
        const base = {
          block: true,
          rootClass,
          tClass: useVirtualHost ? tClass : "",
          class: !useVirtualHost ? tClass : "",
          variant: rect.buttonVariant,
          openType: ""
        };
        if (key === "cancel" && rect.buttonVariant === "base") {
          base.theme = "light";
        }
        if (typeof btn === "string") {
          rect[`_${key}`] = { ...base, content: btn };
        } else if (btn && typeof btn === "object") {
          rect[`_${key}`] = { ...base, ...btn };
        } else {
          rect[`_${key}`] = null;
        }
      });
      Object.keys(rect).forEach((key) => {
        this[key] = rect[key];
      });
    },
    onTplButtonTap(e, { type, extra }) {
      var _a, _b, _c;
      const evtType = e.type;
      const button = this[`_${type}`];
      const cbName = `bind${evtType}`;
      if (type === "action") {
        this.onActionTap(extra);
        return;
      }
      if (typeof (button == null ? void 0 : button[cbName]) === "function") {
        const closeFlag = button[cbName](e);
        if (closeFlag) {
          this.close();
        }
      }
      const hasOpenType = !!(button == null ? void 0 : button.openType);
      if (!hasOpenType && ["confirm", "cancel"].includes(type)) {
        (_a = this[uni_modules_tdesignUniapp_components_common_utils.toCamel(`on-${type}`)]) == null ? void 0 : _a.call(this, type);
      }
      if (evtType !== "click") {
        const success = ((_c = (_b = e.detail) == null ? void 0 : _b.errMsg) == null ? void 0 : _c.indexOf("ok")) > -1;
        this.$emit(success ? "open-type-event" : "open-type-error-event", e.detail);
      }
    },
    onConfirm(e) {
      this.$emit("confirm", { e });
      if (this._onConfirm) {
        this._onConfirm({ trigger: "confirm" });
        this.close();
      }
    },
    onCancel(e) {
      const trigger = { trigger: "cancel" };
      this.$emit("cancel", { e });
      this.$emit("close", trigger);
      if (this._onCancel) {
        this._onCancel(trigger);
        this.close();
      }
    },
    onClose() {
      var _a;
      const trigger = { trigger: "close-btn" };
      this.$emit("close", trigger);
      (_a = this._onCancel) == null ? void 0 : _a.call(this, trigger);
      this.close();
    },
    close() {
      this.dataVisible = false;
    },
    overlayClick(e) {
      var _a;
      this.$emit("overlay-click", { e });
      if (this.dataCloseOnOverlayClick) {
        const trigger = { trigger: "overlay" };
        this.$emit("close", trigger);
        (_a = this._onCancel) == null ? void 0 : _a.call(this, trigger);
        this.close();
      }
    },
    onActionTap(index) {
      this.$emit("action", { index });
      if (this._onAction) {
        this._onAction({ index });
        this.close();
      }
    }
  }
});
if (!Array) {
  const _easycom_t_icon2 = common_vendor.resolveComponent("t-icon");
  const _easycom_t_button2 = common_vendor.resolveComponent("t-button");
  const _easycom_t_popup2 = common_vendor.resolveComponent("t-popup");
  (_easycom_t_icon2 + _easycom_t_button2 + _easycom_t_popup2)();
}
const _easycom_t_icon = () => "../icon/icon.js";
const _easycom_t_button = () => "../button/button.js";
const _easycom_t_popup = () => "../popup/popup.js";
if (!Math) {
  (_easycom_t_icon + _easycom_t_button + _easycom_t_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: _ctx.dataCloseBtn
  }, _ctx.dataCloseBtn ? common_vendor.e({
    b: _ctx.tools.isObject(_ctx.dataCloseBtn)
  }, _ctx.tools.isObject(_ctx.dataCloseBtn) ? {
    c: common_vendor.p({
      ["custom-style"]: _ctx.dataCloseBtn.style || "",
      prefix: _ctx.dataCloseBtn.prefix,
      name: _ctx.dataCloseBtn.name || "close",
      size: _ctx.dataCloseBtn.size || 22,
      color: _ctx.dataCloseBtn.color,
      ["aria-hidden"]: true,
      ["aria-label"]: _ctx.dataCloseBtn.ariaLabel,
      ["aria-role"]: _ctx.dataCloseBtn.ariaRole
    })
  } : {
    d: common_vendor.p({
      name: "close",
      size: "44rpx"
    })
  }, {
    e: common_vendor.n(_ctx.classPrefix + "__close-btn"),
    f: common_vendor.o((...args) => _ctx.onClose && _ctx.onClose(...args))
  }) : {}, {
    g: _ctx.dataTitle
  }, _ctx.dataTitle ? {
    h: common_vendor.t(_ctx.dataTitle),
    i: common_vendor.n(_ctx.classPrefix + "__header")
  } : {}, {
    j: _ctx.dataContent
  }, _ctx.dataContent ? {
    k: common_vendor.t(_ctx.dataContent),
    l: common_vendor.n(_ctx.classPrefix + "__body-text"),
    m: common_vendor.n(_ctx.classPrefix + "__body")
  } : {}, {
    n: common_vendor.n(_ctx.classPrefix + "__content " + _ctx.tClassContent),
    o: _ctx.dataActions
  }, _ctx.dataActions ? {
    p: common_vendor.f(_ctx.dataActions, (actionItem, index, i0) => {
      return common_vendor.e({
        a: actionItem.useDefaultSlot || false
      }, actionItem.useDefaultSlot || false ? {} : {}, {
        b: index,
        c: common_vendor.n(!_ctx.useVirtualHost ? _ctx.getActionClass(_ctx.classPrefix, _ctx.dataButtonLayout, actionItem, _ctx.tClassAction) : ""),
        d: _ctx.coalesce(actionItem.index, index),
        e: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        f: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        g: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        h: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        i: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        j: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        k: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        l: common_vendor.o(($event) => _ctx.onTplButtonTap($event, {
          type: "action",
          extra: index
        }), index),
        m: "8dd4352e-3-" + i0 + ",8dd4352e-0",
        n: common_vendor.p({
          ["t-id"]: actionItem.tId,
          ["custom-style"]: actionItem.style,
          block: _ctx.coalesce(actionItem.block, true),
          ["t-class"]: _ctx.useVirtualHost ? _ctx.getActionClass(_ctx.classPrefix, _ctx.dataButtonLayout, actionItem, _ctx.tClassAction) : "",
          disabled: actionItem.disabled,
          ["custom-dataset"]: actionItem.customDataset,
          content: actionItem.content,
          icon: actionItem.icon,
          loading: actionItem.loading,
          ["loading-props"]: actionItem.loadingProps,
          theme: actionItem.theme,
          ghost: actionItem.ghost,
          shape: actionItem.shape,
          size: actionItem.size,
          variant: actionItem.variant,
          ["open-type"]: actionItem.openType,
          ["hover-class"]: actionItem.hoverClass,
          ["hover-stop-propagation"]: actionItem.hoverStopPropagation,
          ["hover-start-time"]: actionItem.hoverStartTime,
          ["hover-stay-time"]: actionItem.hoverStayTime,
          lang: actionItem.lang,
          ["session-from"]: actionItem.sessionFrom,
          ["send-message-title"]: actionItem.sendMessageTitle,
          ["send-message-path"]: actionItem.sendMessagePath,
          ["send-message-img"]: actionItem.sendMessageImg,
          ["app-parameter"]: actionItem.appParameter,
          ["show-message-card"]: actionItem.showMessageCard,
          ["aria-label"]: actionItem.ariaLabel
        })
      });
    })
  } : {}, {
    q: _ctx._cancel
  }, _ctx._cancel ? common_vendor.e({
    r: _ctx._cancel.useDefaultSlot || false
  }, _ctx._cancel.useDefaultSlot || false ? {} : {}, {
    s: common_vendor.n(_ctx._cancel.class),
    t: _ctx._cancel.index,
    v: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    w: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    x: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    y: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    z: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    A: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    B: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    C: common_vendor.o(($event) => _ctx.onCancel($event, {
      type: "action",
      extra: 0
    })),
    D: common_vendor.p({
      ["t-id"]: _ctx._cancel.tId,
      ["custom-style"]: _ctx._cancel.style,
      block: _ctx._cancel.block,
      ["t-class"]: _ctx._cancel.tClass,
      disabled: _ctx._cancel.disabled,
      ["custom-dataset"]: _ctx._cancel.customDataset,
      content: _ctx._cancel.content,
      icon: _ctx._cancel.icon,
      loading: _ctx._cancel.loading,
      ["loading-props"]: _ctx._cancel.loadingProps,
      theme: _ctx._cancel.theme,
      ghost: _ctx._cancel.ghost,
      shape: _ctx._cancel.shape,
      size: _ctx._cancel.size,
      variant: _ctx._cancel.variant,
      ["open-type"]: _ctx._cancel.openType,
      ["hover-class"]: _ctx._cancel.hoverClass,
      ["hover-stop-propagation"]: _ctx._cancel.hoverStopPropagation,
      ["hover-start-time"]: _ctx._cancel.hoverStartTime,
      ["hover-stay-time"]: _ctx._cancel.hoverStayTime,
      lang: _ctx._cancel.lang,
      ["session-from"]: _ctx._cancel.sessionFrom,
      ["send-message-title"]: _ctx._cancel.sendMessageTitle,
      ["send-message-path"]: _ctx._cancel.sendMessagePath,
      ["send-message-img"]: _ctx._cancel.sendMessageImg,
      ["app-parameter"]: _ctx._cancel.appParameter,
      ["show-message-card"]: _ctx._cancel.showMessageCard,
      ["aria-label"]: _ctx._cancel.ariaLabel
    })
  }) : {}, {
    E: _ctx._confirm
  }, _ctx._confirm ? common_vendor.e({
    F: _ctx._confirm.useDefaultSlot || false
  }, _ctx._confirm.useDefaultSlot || false ? {} : {}, {
    G: common_vendor.n(_ctx._confirm.class),
    H: _ctx._confirm.index,
    I: common_vendor.o(($event) => _ctx.onConfirm($event, {
      type: "action",
      extra: 0
    })),
    J: common_vendor.o(($event) => _ctx.onConfirm($event, {
      type: "action",
      extra: 0
    })),
    K: common_vendor.o(($event) => _ctx.onConfirm($event, {
      type: "action",
      extra: 0
    })),
    L: common_vendor.o(($event) => _ctx.onConfirm($event, {
      type: "action",
      extra: 0
    })),
    M: common_vendor.o(($event) => _ctx.onTplButtonConfirmonTap($event, {
      type: "action",
      extra: 0
    })),
    N: common_vendor.o(($event) => _ctx.onConfirm($event, {
      type: "action",
      extra: 0
    })),
    O: common_vendor.o(($event) => _ctx.onConfirm($event, {
      type: "action",
      extra: 0
    })),
    P: common_vendor.o(($event) => _ctx.onConfirm($event, {
      type: "action",
      extra: 0
    })),
    Q: common_vendor.p({
      ["t-id"]: _ctx._confirm.tId,
      ["custom-style"]: _ctx._confirm.style,
      block: _ctx._confirm.block,
      ["t-class"]: _ctx._confirm.tClass,
      disabled: _ctx._confirm.disabled,
      ["custom-dataset"]: _ctx._confirm.customDataset,
      content: _ctx._confirm.content,
      icon: _ctx._confirm.icon,
      loading: _ctx._confirm.loading,
      ["loading-props"]: _ctx._confirm.loadingProps,
      theme: _ctx._confirm.theme || "primary",
      ghost: _ctx._confirm.ghost,
      shape: _ctx._confirm.shape,
      size: _ctx._confirm.size,
      variant: _ctx._confirm.variant,
      ["open-type"]: _ctx._confirm.openType,
      ["hover-class"]: _ctx._confirm.hoverClass,
      ["hover-stop-propagation"]: _ctx._confirm.hoverStopPropagation,
      ["hover-start-time"]: _ctx._confirm.hoverStartTime,
      ["hover-stay-time"]: _ctx._confirm.hoverStayTime,
      lang: _ctx._confirm.lang,
      ["session-from"]: _ctx._confirm.sessionFrom,
      ["send-message-title"]: _ctx._confirm.sendMessageTitle,
      ["send-message-path"]: _ctx._confirm.sendMessagePath,
      ["send-message-img"]: _ctx._confirm.sendMessageImg,
      ["app-parameter"]: _ctx._confirm.appParameter,
      ["show-message-card"]: _ctx._confirm.showMessageCard,
      ["aria-label"]: _ctx._confirm.ariaLabel
    })
  }) : {}, {
    R: common_vendor.n(_ctx.tools.cls(_ctx.classPrefix + "__footer", [["column", _ctx.dataButtonLayout === "vertical"], ["full", _ctx.buttonVariant == "text" && (!_ctx.dataActions || _ctx.dataActions.length == 0)]])),
    S: common_vendor.n(_ctx.classPrefix + " " + _ctx.tClass),
    T: common_vendor.o(_ctx.overlayClick),
    U: common_vendor.p({
      name: "dialog",
      ["custom-style"]: _ctx.tools._style([_ctx.customStyle]),
      ["t-class"]: _ctx.classPrefix + "__wrapper",
      visible: _ctx.dataVisible,
      ["show-overlay"]: _ctx.dataShowOverlay,
      ["close-on-overlay-click"]: _ctx.dataCloseOnOverlayClick,
      ["prevent-scroll-through"]: _ctx.dataPreventScrollThrough,
      ["overlay-props"]: _ctx.dataOverlayProps,
      ["z-index"]: _ctx.dataZIndex,
      placement: "center",
      ["using-custom-navbar"]: _ctx.dataUsingCustomNavbar
    })
  });
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-8dd4352e"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/dialog/dialog.js.map
