<template>
  <div class="page-container">
    <div class="nav-bar">
      <div class="left-icon" @click="goBack">
        <van-icon name="arrow-left" size="20" color="#333" />
      </div>
      <div class="nav-title">盈亏分析</div>
      <div class="right-placeholder"></div> </div>

    <div class="content-body">

      <div class="header-section">
        <div class="label-text">期权总资产(USDT)</div>
        <div class="total-asset">1,125,158.00</div>
        <div class="approx-value">≈35,458.00</div>

        <div class="daily-pnl-row">
          <div class="col">
            <div class="label-text">今日盈亏(USDT)</div>
            <div class="value-text bold">5,678.00</div>
          </div>
          <div class="col right-align">
            <div class="label-text">盈亏率(%)</div>
            <div class="value-text bold">5.25</div>
          </div>
        </div>
      </div>

      <div class="stats-list">
        <div class="stat-row" v-for="(item, index) in statsData" :key="index">
          <span class="stat-label">{{ item.label }}</span>
          <span class="stat-value">{{ item.value }}</span>
        </div>
      </div>

      <div class="history-section">
        <div class="section-title" @click="showModal = true">
          历史盈亏 <van-icon name="question-o" color="#999" size="14" style="margin-left:4px" />
        </div>

        <div class="history-card" v-for="(card, idx) in historyList" :key="idx">
          <div class="card-header">{{ card.date }}</div>
          <div class="card-body">
            <div class="info-row">
              <span class="info-label">账户总权益</span>
              <span class="info-value">{{ card.equity }}</span>
            </div>
            <div class="info-row">
              <span class="info-label">每日盈亏</span>
              <span class="info-value">{{ card.dailyPnl }}</span>
            </div>
            <div class="info-row">
              <span class="info-label">累计盈亏(%)</span>
              <span class="info-value">{{ card.cumulative }}</span>
            </div>
            <div class="info-row">
              <span class="info-label">净划入</span>
              <span class="info-value">{{ card.netIn }}</span>
            </div>
          </div>
        </div>
      </div>

    </div>
    <ExplanationModal v-model:visible="showModal"></ExplanationModal>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router'; // 引入路由钩子
import { Popup as vanPopup, Icon as vanIcon } from 'vant';
import ExplanationModal from '@/views/bitcoin/lever/components/ExplanationModal.vue'

const router = useRouter();

// 返回上一页
const goBack = () => {
  router.back();
  // 或者跳转指定路由: router.push('/home');
};

// 模拟数据：统计列表
const statsData = ref([
  { label: '总盈利', value: '152 USDT' },
  { label: '总亏损', value: '0.0000 USDT' },
  { label: '净盈利/亏损', value: '100 USDT' },
  { label: '胜率', value: '2.51%' },
  { label: '亏损天数', value: '10 天' },
  { label: '盈利天数', value: '10 天' },
  { label: '持平天数', value: '10 天' },
]);
//历史盈亏说明
const showModal = ref(false);
// 模拟数据：历史记录
const historyList = ref([
  {
    date: '2025-11-07',
    equity: '0.2525 USDT',
    dailyPnl: '0.4875 USDT',
    cumulative: '0.0000 USDT(0.00%)',
    netIn: '0.2525 USDT'
  },
  {
    date: '2025-11-06',
    equity: '0.2525 USDT',
    dailyPnl: '0.4875 USDT',
    cumulative: '0.0000 USDT(0.00%)',
    netIn: '0.2525 USDT'
  },
  {
    date: '2025-11-05',
    equity: '0.2525 USDT',
    dailyPnl: '0.4875 USDT',
    cumulative: '0.0000 USDT(0.00%)',
    netIn: '0.2525 USDT'
  },
]);
</script>

<style scoped>
/* 全局容器设置 */
.page-container {
  min-height: 100vh;
  background-color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  color: #333;
  padding-top: 44px; /* 为固定导航栏留出空间 */
}

/* 1. 导航栏样式 */
.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #fff;
  z-index: 99;
  /* border-bottom: 1px solid #f5f5f5; 可选 */
}
.left-icon, .right-placeholder {
  width: 40px; /* 保持左右平衡 */
}
.nav-title {
  font-size: 17px;
  font-weight: 600;
  color: #000;
}

/* 主体内容内边距 */
.content-body {
  padding: 0 16px 40px; /* 底部留白 */
}

/* 2. 头部总资产区域 */
.header-section {
  margin-top: 10px;
  margin-bottom: 24px;
}
.label-text {
  font-size: 13px;
  color: #86909C;
  margin-bottom: 8px;
}
.total-asset {
  font-size: 32px;
  font-weight: 700;
  color: #1D2129;
  line-height: 1.2;
  font-family: "DIN Alternate", "Roboto", sans-serif; /* 数字字体优化 */
}
.approx-value {
  font-size: 14px;
  color: #F53F3F; /* 红色 */
  margin-top: 4px;
  font-weight: 500;
}

.daily-pnl-row {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
}
.daily-pnl-row .value-text {
  font-size: 18px;
  color: #1D2129;
  margin-top: 4px;
}
.bold {
  font-weight: 600;
}
.right-align {
  text-align: right;
}

/* 3. 统计列表样式 */
.stats-list {
  margin-bottom: 30px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  font-size: 14px;
}
.stat-label {
  color: #4E5969;
}
.stat-value {
  color: #86909C;
}

/* 4. 历史盈亏样式 */
.history-section {
  margin-top: 10px;
}
.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #1D2129;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
}

/* 卡片样式 */
.history-card {
  background: #fff;
  border: 1px solid #E5E6EB; /* 边框 */
  border-radius: 8px;
  padding: 0 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}
.card-header {
  padding: 12px 0;
  font-size: 16px;
  font-weight: 500;
  color: #1D2129;
  border-bottom: 1px solid #F2F3F5;
}
.card-body {
  padding: 8px 0;
}
.info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
}
.info-row:last-child {
  margin-bottom: 0;
}
.info-label {
  color: #86909C;
}
.info-value {
  color: #4E5969;
  font-family: "Helvetica Neue", sans-serif;
}
</style>