<template>
  <div class="settings-container">
    <div class="header">
      <div class="drag-handle"></div>
      <div class="title">栏位设置</div>
    </div>

    <div class="scroll-area">
      <div
        v-for="(item, index) in columns"
        :key="item.key"
        class="list-item"
        @click="toggleItem(index)"
      >
        <span class="label">{{ item.label }}</span>

        <div class="checkbox-icon" :class="{ active: item.checked }">
          <svg v-if="item.checked" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
            <polyline points="20 6 9 17 4 12"></polyline>
          </svg>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 定义父组件可能需要的事件（比如关闭弹窗或保存设置）
const emit = defineEmits(['update:columns']);

// 模拟数据 (完全还原图中文字)
const columns = ref([
  { label: '买价', key: 'bid', checked: true },
  { label: '标记价格', key: 'mark', checked: true },
  { label: '卖价', key: 'ask', checked: true }, // 图中写的是'买价'可能是笔误，这里修正为卖价，或者你改成图中的文字
  { label: '仓位', key: 'position', checked: true },
  { label: '持仓量', key: 'open_interest', checked: true },
  { label: '买价数量', key: 'bid_size', checked: false },
  { label: '卖价数量', key: 'ask_size', checked: false },
  { label: '24h成交量', key: 'volume_24h', checked: false },
  { label: 'Gamma', key: 'gamma', checked: false },
  { label: 'Delta', key: 'delta', checked: false },
  { label: 'Vega', key: 'vega', checked: false },
  { label: 'Theta', key: 'theta', checked: false },
  { label: '杠杆倍数', key: 'leverage', checked: false },
  { label: '24h涨跌', key: 'change_24h', checked: false },
  { label: '最新价格', key: 'last_price', checked: false },
  { label: '24h最高/最低价', key: 'high_low_24h', checked: false },
]);

// 切换选中状态
const toggleItem = (index) => {
  columns.value[index].checked = !columns.value[index].checked;
  // 触发更新事件给父组件（可选）
  emit('update:columns', columns.value);
};
</script>

<style scoped>
/* 容器：白色背景，圆角顶部 (适配底部弹窗) */
.settings-container {
  width: 100%;
  background: #fff;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  display: flex;
  flex-direction: column;
  /* 限制最大高度，大概占屏幕 60%-70% */
  max-height: 70vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
}

/* --- 头部区域 --- */
.header {
  padding: 10px 16px 16px;
  background: #fff;
  position: relative;
  z-index: 10;
  flex-shrink: 0; /* 防止被压缩 */
}

/* 顶部灰色小把手 */
.drag-handle {
  width: 36px;
  height: 4px;
  background: #e5e6eb;
  border-radius: 2px;
  margin: 0 auto 12px; /* 居中 */
}

.title {
  font-size: 16px;
  font-weight: 600;
  color: #1d2129;
  text-align: left;
}

/* --- 列表区域 --- */
.scroll-area {
  flex: 1;
  overflow-y: auto; /* 允许纵向滚动 */
  padding-bottom: 30px; /* 底部留白 */
  /* iOS 顺滑滚动 */
  -webkit-overflow-scrolling: touch;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  /* 点击反馈 */
  cursor: pointer;
  transition: background-color 0.2s;
}

.list-item:active {
  background-color: #f7f8fa;
}

.label {
  font-size: 14px;
  color: #4e5969; /* 未选中通常是深灰色 */
}

/* 如果需要在选中时文字变黑/变红，可以加逻辑，这里还原图示保持灰色即可 */

/* --- 复选框样式 (纯CSS画圆) --- */
.checkbox-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #c9cdd4; /* 默认灰色边框 */
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  transition: all 0.2s;
}

/* 选中状态 */
.checkbox-icon.active {
  background-color: #F53F3F; /* 你的主题红 */
  border-color: #F53F3F;
  color: #fff;
}

/* 列表滚动条隐藏 (可选) */
.scroll-area::-webkit-scrollbar {
  display: none;
}
</style>