<wxs src="../wxs/utils.wxs" module="utils" />

<smart-popup
  show="{{ show }}"
  z-index="{{ zIndex }}"
  overlay="{{ overlay }}"
  transition="{{ transition }}"
  custom-class="smart-dialog smart-dialog--{{ theme }} {{ className }} custom-class"
  custom-style="width: {{ utils.addUnit(width) }};{{ customStyle }}"
  overlay-style="{{ overlayStyle }}"
  native-disabled="{{ nativeDisabled }}"
  close-on-click-overlay="{{ closeOnClickOverlay }}"
  root-portal="{{ rootPortal }}"
  full-cover-view="{{ fullCoverView }}"
  bind:close="onClickOverlay"
  bind:before-enter="onBeforeEnter"
  bind:enter="onEnter"
  bind:after-enter="onAfterEnter"
  bind:before-leave="onBeforeLeave"
  bind:leave="onLeave"
  bind:after-leave="onAfterLeave"
  bind:enter-error="onPopUpError"
  bind:leave-error="onPopUpError"
>
  <view
    wx:if="{{ title || useTitleSlot }}"
    class="{{ utils.bem('dialog__header', { isolated: !(message || useSlot) }) }}"
  >
    <smart-icon wx:if="{{ icon }}" class="smart-dialog__header-icon" custom-class="header-icon-class" name="{{ icon === true ? warningIcon : icon }}" size="{{iconSize}}" color="{{iconColor}}" />
    <slot wx:if="{{ useTitleSlot }}" name="title" />
    <block wx:elif="{{ title }}">{{ title }}</block>
  </view>

  <input
    wx:if="{{ value !== null }}"
    class="smart-dialog__input"
    value="{{ value }}"
    type="{{ type }}"
    password="{{ password }}"
    placeholder="{{ placeholder }}"
    maxlength="{{ maxlength }}"
    bind:input="onInput"
  />

  <slot wx:if="{{ useSlot }}" />
  <view
    wx:elif="{{ message }}"
    class="{{ utils.bem('dialog__message', [theme, messageAlign, { hasTitle: title }]) }}"
  >
    <text class="smart-dialog__message-text">{{ message }}</text>
  </view>

  <smart-goods-action wx:if="{{ theme === 'round-button' }}" custom-class="smart-dialog__footer--round-button">
    <smart-goods-action-button
      wx:if="{{ showCancelButton }}"
      loading="{{ loaing.cancel }}"
      is-first
      class="smart-dialog__button smart-hairline--right"
      custom-class="smart-dialog__cancel cancel-button-class"
      custom-style="{{ cancelButtonColor ? 'color: ' + cancelButtonColor : '' }}"
      bind:click="onCancel"
    >
      {{ cancelButtonText }}
    </smart-goods-action-button>
    <smart-goods-action-button
      wx:if="{{ showConfirmButton }}"
      class="smart-dialog__button"
      loading="{{ loading.confirm }}"
      is-last
      custom-class="smart-dialog__confirm confirm-button-class"
      custom-style="{{ confirmButtonColor ? 'color: ' + confirmButtonColor : '' }}"
      button-id="{{ confirmButtonId }}"
      open-type="{{ confirmButtonOpenType }}"
      lang="{{ lang }}"
      business-id="{{ businessId }}"
      session-from="{{ sessionFrom }}"
      send-message-title="{{ sendMessageTitle }}"
      send-message-path="{{ sendMessagePath }}"
      send-message-img="{{ sendMessageImg }}"
      show-message-card="{{ showMessageCard }}"
      app-parameter="{{ appParameter }}"
      bindagreeprivacyauthorization="onAgreePrivacyAuthorization"
      bindgetRealTimePhoneNumber="onGetRealTimePhoneNumber"
      bind:click="onConfirm"
      bindgetuserinfo="onGetUserInfo"
      bindcontact="onContact"
      bindgetphonenumber="onGetPhoneNumber"
      binderror="onError"
      bindlaunchapp="onLaunchApp"
      bindopensetting="onOpenSetting"
    >
      {{ confirmButtonText }}
    </smart-goods-action-button>
  </smart-goods-action>

  <view wx:elif="{{ showCancelButton || showConfirmButton }}" class="smart-hairline--top smart-dialog__footer">
    <block wx:if="{{ showCancelButton }}">
      <slot wx:if="{{ useCancelButtonSlot }}" name="cancel-button" />

      <smart-button
        wx:else
        size="large"
        loading="{{ loading.cancel }}"
        class="smart-dialog__button smart-hairline--right"
        custom-class="smart-dialog__cancel cancel-button-class"
        custom-style="color: {{ cancelButtonColor || 'var(--dialog-cancel-color, var(--app-B4-N3, rgba(0, 0, 0, 0.5)))' }}"
        bind:click="onCancel"
      >
        {{ cancelButtonText }}
      </smart-button>
    </block>

    <block wx:if="{{ showConfirmButton }}">
      <slot wx:if="{{ useConfirmButtonSlot }}" name="confirm-button" />

      <smart-button
        wx:else
        size="large"
        class="smart-dialog__button"
        loading="{{ loading.confirm }}"
        custom-class="smart-dialog__confirm {{ inputValue === '' && emptyDisabled ? 'smart-dialog__confirm--disabled' : '' }} confirm-button-class"
        custom-style="color: {{ confirmButtonColor || 'var(--dialog-confirm-color, var(--app-B4-N1, rgba(0, 0, 0, 1)))' }}"
        button-id="{{ confirmButtonId }}"
        open-type="{{ confirmButtonOpenType }}"
        lang="{{ lang }}"
        business-id="{{ businessId }}"
        session-from="{{ sessionFrom }}"
        send-message-title="{{ sendMessageTitle }}"
        send-message-path="{{ sendMessagePath }}"
        send-message-img="{{ sendMessageImg }}"
        show-message-card="{{ showMessageCard }}"
        app-parameter="{{ appParameter }}"
        bindagreeprivacyauthorization="onAgreePrivacyAuthorization"
        bindgetRealTimePhoneNumber="onGetRealTimePhoneNumber"
        bind:click="onConfirm"
        bindgetuserinfo="onGetUserInfo"
        bindcontact="onContact"
        bindgetphonenumber="onGetPhoneNumber"
        binderror="onError"
        bindlaunchapp="onLaunchApp"
        bindopensetting="onOpenSetting"
      >
        {{ confirmButtonText }}
      </smart-button>
    </block>
  </view>
</smart-popup>
