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

<smart-popup
  show="{{ show }}"
  position="bottom"
  round="{{ round }}"
  z-index="{{ zIndex }}"
  overlay="{{ overlay }}"
  custom-class="smart-bottom-sheet custom-class"
  native-disabled="{{ nativeDisabled }}"
  customStyle="{{computed.getCustomStyle(draggable, contentHeight, maxHeight)}}"
  safe-area-inset-bottom="{{false}}"
  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"
  id="{{curInstanceId}}"
  lock-scroll="{{ lockScroll }}"
>
  <block wx:if="{{draggable}}">
    <view
      id="{{curInstanceId}}"
      tick="{{ts}}"
      change:tick="{{computed.init(curInstanceId, currentHeight)}}"
    >
      <view class="smart-bottom-sheet__dragger" 
        bind:touchstart="{{computed.onDragStart(curInstanceId)}}" 
        catch:touchmove="{{computed.onDrag(curInstanceId, { maxDragHeight, lockMaxDrag })}}"
        bind:touchend="{{computed.onDragEnd(curInstanceId, { maxDragHeight, minDragHeight, windowHeight, midDragHeight, closeDragHeight })}}"
      >
        <view class="smart-bottom-sheet__dragger_node"></view>
      </view>
      <view class="smart-bottom-sheet__header">
        <view wx:if="{{ title }}">{{ title }}</view>
        <slot name="title" />
      </view>
      <view
        class="smart-bottom-sheet__content"
      >
        <slot />
      </view>
    </view>
  </block>
  <block wx:else>
    <view class="smart-bottom-sheet__header">
      <view wx:if="{{ title }}">{{ title }}</view>
      <smart-icon
        wx:if="{{ title && showClose }}"
        name="{{ xmarkIcon }}"
        class="smart-bottom-sheet__icon"
        size="{{ iconSize }}"
        color="{{ xmarkIconColor }}"
        ariaRole="button"
        ariaLabel="{{ closeIconAriaLabel }}"
        bind:click="onClose"
      />
      <slot name="title" />
    </view>
    <view wx:if="{{ contentHeight !== null }}" class="smart-bottom-sheet__content smart-bottom-sheet__content_height" style="{{computed.getHeight(contentHeight)}}">
      <slot />
    </view>
    <scroll-view wx:else class="smart-bottom-sheet__content">
      <slot />
    </scroll-view>
  </block>
</smart-popup>
