<template>
  <view class="content-tabs">
    <view
      v-for="(tab, index) in tabs"
      :key="tab.key"
      class="tab-item"
      :class="{ active: modelValue === tab.key }"
      :data-key="tab.key"
      @click="handleTabClick"
    >
      <!-- 背景图片 -->
      <!-- <image class="tab-bg" :class="{ 'tab-bg-inactive': modelValue !== tab.key }"
        src="/static/nft/dingbutubiao_liang.png" mode="scaleToFill" /> -->
      <!-- 左侧图标，绝对浮动覆盖背景左侧色块，不影响文字布局 -->
      <view class="tab-left">
        <!-- <text v-if="tab.emoji" class="tab-emoji">{{ tab.emoji }}</text>
        <image v-else class="tab-icon" :src="tab.icon" mode="aspectFill"
          :style="{ width: tab.iconWidth + 'rpx', height: tab.iconHeight + 'rpx' }" /> -->
        <!-- 右侧文字 -->
        <text class="tab-label">{{ tab.label }}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
const props = defineProps({
  modelValue: { type: String, default: "xinghe" },
});

const emit = defineEmits(["update:modelValue"]);

const handleTabClick = (e) => {
  const key = e.currentTarget.dataset.key;
  console.log(key);
  emit("update:modelValue", key);
};

const tabs = [
  {
    key: "xinghe",
    label: "星河",
    emoji: null,
    icon: "/static/square/1.png",
    iconWidth: 32,
    iconHeight: 40,
  },
  {
    key: "xingbang",
    label: "星榜",
    emoji: null,
    icon: "/static/square/1.png",
    iconWidth: 32,
    iconHeight: 40,
  },
  {
    key: "guangchang",
    label: "广场",
    emoji: null,
    icon: "/static/square/1.png",
    iconWidth: 32,
    iconHeight: 40,
  },
];
</script>

<style scoped>
.content-tabs {
  position: relative;
  left: 50%;
  bottom: 0.25rem;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8rpx 16rpx;
  padding: 0 8rpx;
  width: 336rpx;
  height: 64rpx;
  border-radius: 16px;
  overflow: visible;
  /* 玻璃光边：顶部白色高光渐变到底部半透明灰（对应 Figma GLASS 效果） */
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.55) 0%,
    rgba(255, 255, 255, 0.2) 28%,
    rgba(217, 217, 217, 0.11) 100%
  );
  box-shadow:
    inset 0 1rpx 0 rgba(255, 255, 255, 0.6),
    0px 4px 4px 0px #b3323240;
}

.tab-item {
  width: 112rpx;
  height: 42rpx;
  border-radius: 21rpx;
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

/* 背景图片铺满整个 tab */
.tab-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 1;
}

/* 未选中时加透明度 */
.tab-bg-inactive {
  opacity: 0.4;
}

/* 左侧图标，绝对浮动覆盖背景左侧色块，不影响文字布局 */
.tab-left {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease;
}

/* 选中时图标上移 */
/* .tab-item.active .tab-left {
  transform: translateY(-70%);
} */

.tab-emoji {
  font-size: 52rpx;
  line-height: 1;
  margin-top: -4rpx;
}

.tab-icon {
  display: block;
}

.tab-label {
  position: relative;
  z-index: 1;
  font-size: 24rpx;
  font-weight: 600;
  color: #ffffff;
  opacity: 0.8;
  text-shadow: 0 4rpx 5.6rpx rgba(0, 0, 0, 0.73);
  white-space: nowrap;
  margin-left: 14rpx;
}

.tab-item.active{
  /* 渐变方向 135deg 对应 Figma GLASS lightAngle: -45（光从左上照入） */
  background: linear-gradient(
    135deg,
    rgba(255, 222, 8, 0.49) 0%,
    rgba(252, 100, 102, 1) 61.1%,
    rgba(244, 88, 104, 1) 100%
  );
  box-shadow:
    inset 0 1rpx 0 rgba(255, 255, 255, 0.45),
    2px 2px 4px 0px #f2151578;
  opacity: 0.84;
}
</style>
