<wxs src="./chat-sender.wxs" module="_this" />

<view
  class="class {{classPrefix}}"
  style="{{_this._style([style, customStyle, inputStyle])}}"
  bindtap="handleOutsideClick"
>
  <view
    class="{{classPrefix}}__header"
    style="{{(attachmentsProps.items && attachmentsProps.items.length > 0)?'margin-top:-8rpx;':''}}"
  >
    <block wx:if="{{attachmentsProps.items && attachmentsProps.items.length > 0}}">
      <view class="{{classPrefix}}__attachments">
        <attachments
          items="{{attachmentsProps.items}}"
          removable="{{attachmentsProps.removable}}"
          imageViewer="{{attachmentsProps.imageViewer}}"
          bind:fileClick="handleFileClick"
          bind:remove="handleFileRemove"
        >
        </attachments>
      </view>
    </block>
    <block wx:else>
      <slot name="header" />
    </block>
  </view>

  <view class="{{classPrefix}}__actions">
    <view class="{{classPrefix}}__textarea">
      <slot name="input-prefix" />
      <textarea
        class="{{classPrefix}}__textarea--control"
        style="{{_this.textareaStyle(textareaProps.autosize)}}"
        disabled="{{disabled}}"
        auto-height="{{!!textareaProps.autosize}}"
        confirm-type="send"
        adjust-position="{{adjustPosition}}"
        disable-default-padding="{{false}}"
        cursor-spacing="30"
        maxlength="-1"
        value="{{value}}"
        bindchange="textChange"
        bindfocus="focusFn"
        bindblur="blurFn"
        bindtap="handlerClick"
        bindinput="textChange"
        bindkeyboardheightchange="onkeyboardheightchange"
        bindconfirm="handleSendClick"
      >
      </textarea>
      <view class="{{classPrefix}}__textarea--placeholder {{focusFlag || value ? 'hide' : ''}}"
        >{{placeholder || globalConfig.placeholder}}</view
      >
    </view>

    <view class="{{classPrefix}}__footer">
      <view class="{{classPrefix + '__mode'}}">
        <slot name="footer-prefix" />
      </view>
      <view class="{{classPrefix}}__sendbtn">
        <block wx:if="{{renderPresets}}">
          <view class="{{classPrefix}}__sendbtn--default">
            <block wx:for="{{renderPresets}}" wx:for-item="item" wx:for-index="index" wx:key="index">
              <view>
                <block wx:if="{{item.name === 'upload'}}">
                  <view class="plus-btn {{item.status === 'disabled' ? 'disabled' : ''}}">
                    <block>
                      <view class="btn-func" data-status="{{item.status}}" catchtap="handleUploadClick">
                        <t-icon name="{{visible? 'close' : 'add'}}" size="40rpx" />
                      </view>
                    </block>
                  </view>
                </block>

                <block wx:if="{{item.name === 'send'}}">
                  <block wx:if="{{item.type === 'text'}}">
                    <view
                      class="send-btn-{{item.type}} {{value || loading ? 'active' : 'disabled'}}"
                      bindtap="handleSendClick"
                    >
                      {{loading ? globalConfig.sendText : globalConfig.stopText}}
                    </view>
                  </block>
                  <block wx:else>
                    <view
                      class="send-btn-icon send-btn-{{item.type}} {{value || loading ? 'active' : 'disabled'}} {{loading ? 'stop' : ''}}"
                      bindtap="handleSendClick"
                    >
                      <block wx:if="{{!loading}}">
                        <t-icon name="send-filled" size="32rpx" />
                      </block>
                      <block wx:else>
                        <view style="width: 24rpx; height: 24rpx; background-color: #ffffff" />
                      </block>
                    </view>
                  </block>
                </block>
              </view>
            </block>
          </view>
        </block>
        <block wx:else>
          <slot name="suffix" />
        </block>
      </view>
    </view>
  </view>
</view>
<view wx:if="{{visible}}" class="{{classPrefix}}__upload" catchtap="handleUploadClick">
  <block wx:for="{{uploadNames}}" wx:for-item="name" wx:for-index="index" wx:key="index">
    <view class="{{classPrefix}}__upload-item" data-name="{{name}}" bindtap="handleUploadEntryClick">
      <view class="{{classPrefix}}__upload-item__icon">
        <t-icon name="{{uploadConfig[name].iconClass}}" size="56rpx" />
      </view>
      <view class="{{classPrefix}}__upload-item__text"> {{uploadConfig[name].text}} </view>
    </view>
  </block>
</view>
