<template>
  <div>
    <div class="trigger-button">
      <div class="icon" @click="openMenu"></div>
    </div>
    <div v-if="dialogVisible" class="dialog-overlay">
      <!-- 左侧折叠区域 -->
      <div class="left-side" :class="{ collapsed: isFold }" id="leftSide">
        <div
          class="addBtn"
          :style="{
            backgroundImage: `url(${isFold ? '/src/assets/images/vent/home/add.svg' : ''})`,
            backgroundColor: isFold ? '' : '#2cb6ff',
            width: isFold ? '20px' : 'auto',
          }"
          @click="fold"
        >
          <span
            class="btn-text-bg"
            :style="{
              backgroundImage: `url(${!isFold ? '/src/assets/images/vent/home/addB.svg' : ''})`,
            }"
          ></span>
          <span v-if="!isFold" class="btn-text">添加新对话</span>
        </div>
        <div class="divider0"></div>
        <div
          v-if="isFold"
          class="historyBtn"
          :style="{ backgroundImage: `url(${isFold ? '/src/assets/images/vent/home/history.svg' : '/src/assets/images/vent/home/history.svg'})` }"
          @click="addNew"
        ></div>
        <div v-else class="historyBtn1">
          <span
            class="btn-text-bg"
            :style="{
              backgroundImage: `url(${!isFold ? '/src/assets/images/vent/home/history.svg' : ''})`,
            }"
          ></span>
          <span v-if="!isFold" class="btn-text">历史对话</span>
          <a-list style="width: 100px" :split="false">
            <a-list-item style="padding: 5px 0 0 30px; color: #5e7081; font-size: 12px; white-space: nowrap; text-overflow: ellipsis"
              >历史数据1</a-list-item
            >
            <a-list-item style="padding: 5px 0 0 30px; color: #5e7081; font-size: 12px; white-space: nowrap; text-overflow: ellipsis"
              >历史数据12</a-list-item
            >
            <a-list-item style="padding: 5px 0 0 30px; color: #5e7081; font-size: 12px; white-space: nowrap; text-overflow: ellipsis"
              >历史数据123</a-list-item
            >
          </a-list>
        </div>
        <div
          class="foldBtn"
          :style="{ backgroundImage: `url(${isFold ? '/src/assets/images/vent/home/Fold.svg' : '/src/assets/images/vent/home/unfold.svg'})` }"
          @click="fold"
        ></div>
      </div>
      <!-- 右侧对话框 -->
      <div class="right-side">
        <div class="input-content">
          <!-- 对话区域 -->
          <div class="dialog-area">
            <div class="ask-message">
              <span>提问提问提问</span>
            </div>
            <div class="answer" style="margin-top: 65px">
              <div class="answerIcon"></div>
              <div class="answer-message">
                <span>回答回答回答回答回答</span>
              </div>
            </div>
          </div>
          <!-- 文本输入区域 -->
          <div class="input-area">
            <textarea v-model="inputText" placeholder="请输入你的问题"> </textarea>
            <!-- 底部操作栏 -->
            <div class="action-bar">
              <!-- 文件上传按钮 -->
              <label class="upload-btn">
                <div class="send-file" />
                <span class="divider"> | </span>
                <div class="send-img" />
              </label>
              <!-- 发送按钮 -->
              <div class="send-btn" @keydown.enter.prevent="handleSend"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, nextTick } from 'vue';

// 响应式变量声明
const dialogVisible = ref(false);
const isFold = ref(false); // 是否折叠
const inputText = ref(''); // 输入框内容
const messages = ref([]); // 消息列表
const openMenu = () => {
  dialogVisible.value = !dialogVisible.value;
};
const fold = () => {
  isFold.value = !isFold.value;
};
const addNew = () => {
  console.log('addNew');
};
const handleSend = () => {
  if (inputText.value) {
    messages.value.push({ text: inputText.value });
    inputText.value = '';
  }
};

// 初始化按钮定位
onMounted(() => {});
</script>

<style lang="less" scoped>
@keyframes menuShow {
  0% {
    width: 0;
    height: 0;
  }
  100% {
    width: 480px;
    height: 100vh;
  }
}
.trigger-button {
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 1000000;
  .icon {
    width: 60px;
    height: 60px;
    position: relative;
    background-image: url('/@/assets/images/vent/home/wakeBtn.png');
    background-position: center;
    background-size: 100% 100%;
  }
}
.dialog-overlay {
  width: 32%;
  height: 55%;
  z-index: 999;
  display: flex;
  position: fixed;
  right: 90px;
  bottom: 20px;
  box-shadow: 0 0 3px 3px #1074c1;
  background-color: #09172c;
}
.left-side {
  background: #0c2842;
  transition: width 0.5s ease; /* 平滑过渡动画 */
  width: 120px; /* 展开时宽度 */
  position: relative; /* 用于按钮定位 */
}
.left-side.collapsed {
  width: 40px; /* 折叠时宽度 */
}

.addBtn {
  height: 30px;
  position: absolute;
  background-size: 100% 100%;
  background-position: center;
  padding: 2px;
  right: 10px;
  top: 10px;
  left: 10px;
  align-items: center;
  border-radius: 3px;
}
.btn-text-bg {
  width: 14px;
  height: 14px;
  position: absolute;
  background-size: 100% 100%;
  right: 10px;
  top: 9px;
  left: 10px;
  bottom: 10px;
}
.btn-text {
  margin-left: 3px;
  font-size: 12px;
  color: #fff;
  white-space: nowrap;
  margin-left: 30px;
  line-height: 26px;
}
.historyBtn {
  width: 20px;
  height: 20px;
  position: absolute;
  background-size: 100% 100%;
  background-position: center;
  padding: 2px;
  right: 10px;
  top: 100px;
}
.historyBtn1 {
  width: 20px;
  height: 20px;
  position: absolute;
  background-size: 100% 100%;
  background-position: center;
  left: 3px;
  top: 80px;
}
.divider0 {
  border-bottom: 1px solid #1074c1;
  width: auto;
  margin: 0 10px;
  height: 13%;
  display: block;
  background: transparent;
}
.foldBtn {
  width: 20px;
  height: 20px;
  position: absolute;
  background-size: 100% 100%;
  background-position: center;
  padding: 2px;
  right: 10px;
  bottom: 10px;
}

.right-side {
  flex: 1; /* 占据剩余空间 */
  background: #09172c;
}

.input-content {
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* 内容底部对齐 */
  height: 100%;
  padding: 20px; /* 统一内边距 */
}
.ask-message {
  float: right;
  max-width: 70%;
  padding: 10px;
  margin: 10px;
  border-radius: 5px;
  color: #fff;
  background: #0c2842;
}
.answer {
  display: flex;
  flex-direction: row;
}
.answerIcon {
  margin-top: 10px;
  width: 35px;
  height: 35px;
  background-image: url('/@/assets/images/vent/home/answerIcon.svg');
  background-size: 100% 100%;
}
.answer-message {
  float: left;
  max-width: 80%;
  padding: 10px;
  margin: 10px;
  border-radius: 5px;
  color: #fff;
  background: #0c2842;
}
.dialog-area {
  flex: 1; /* 占据剩余空间 */
  gap: 10px;
  overflow-y: auto; /* 垂直滚动条 */
  margin-bottom: 10px;
}
.input-area {
  background-color: #043256 !important;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
textarea {
  background-color: #043256 !important;
  width: 100%;
  height: 40px;
  border: none;
  resize: none;
  outline: none;
  overflow: hidden;
  padding: 10px; /* 统一内边距 */
  color: #fff;
}

.action-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.upload-btn {
  display: flex;
  cursor: pointer;
  padding: 6px 12px;
}

.divider {
  color: #ccc;
  font-weight: 300;
  margin: 0 10px;
}

.send-file {
  width: 20px;
  height: 20px;
  background-image: url('/@/assets/images/vent/home/sendFile.svg');
  background-size: 100% 100%;
  border-radius: 4px;
  cursor: pointer;
}
.send-img {
  width: 20px;
  height: 20px;
  background-image: url('/@/assets/images/vent/home/sendImg.svg');
  background-size: 100% 100%;
  border-radius: 4px;
  cursor: pointer;
}
.send-btn {
  width: 20px;
  height: 20px;
  margin-left: auto;
  margin-right: 10px;
  background-color: #1074c1;
  background-image: url('/@/assets/images/vent/home/send.svg');
  background-position: center;
  background-size: 100% 100%;
  border-radius: 2px;
  cursor: pointer;
}
</style>
