<template>
  <view class="baby-switcher-container">
    <view class="baby-switcher-mask" @click.self="onClose"> </view>
    <view class="baby-switcher-popup">
      <view
        v-for="baby in babyList"
        :key="baby.id"
        class="baby-item"
        @click="selectBaby(baby)"
      >
        <text v-if="baby.babyStage == 0">备孕</text>
        <text v-else-if="baby.babyStage == 1">孕中</text>

        <text v-else>{{ baby.babyName || "暂无昵称" }}</text>
        <view
          class="selected-icon"
          :style="{ backgroundColor: baby.selected ? '#d3a358' : '#E8E8E8' }"
        />
      </view>
      <view
        v-if="babyList.length < 3"
        class="baby-item add-item"
        @click="onAdd"
      >
        <image :src="addIcon" class="add-icon" />
      </view>
    </view>
  </view>
</template>

<script setup>
import { defineProps, defineEmits } from "vue";

const props = defineProps({
  show: Boolean,
  babyList: {
    type: Array,
    default: () => [],
  },
  addIcon: {
    type: String,
    default: "", // 传入新增icon路径
  },
});
const emits = defineEmits(["close", "select", "add"]);

function onClose() {
  emits("close");
}
function selectBaby(baby) {
  emits("select", baby);
}
function onAdd() {
  emits("add");
}
</script>

<style lang="less" scoped>
.baby-switcher-container {
  touch-action: none;
}
.baby-switcher-mask {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}
.baby-switcher-popup {
  position: absolute;
  left: 0;
  top: 40rpx;
  z-index: 2;
  background: #fff;
  border-radius: 16rpx;
  padding: 10rpx 36rpx 22rpx 36rpx;
  box-shadow: 0 0 30rpx rgba(204, 204, 204, 0.8);
  box-sizing: border-box;
  min-width: 247rpx;
}
.baby-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20rpx 25rpx;
  font-size: 26rpx;
  font-weight: 500;
  color: #1d1e25;
  flex-wrap: nowrap;
  border-bottom: 1px solid #eee;
  &:nth-child(3) {
    border-bottom: none;
  }
  text {
    white-space: nowrap;
  }
}
.selected-icon {
  width: 12rpx;
  height: 12rpx;
  margin-left: 17rpx;
  background-color: #e8e8e8;
  border-radius: 50%;
}
.add-item {
  margin-top: 10rpx;
  padding-top: 20rpx;
  padding: 10rpx 0;
  border-bottom: none;
}
.add-icon {
  width: 96rpx;
  height: 36rpx;
  display: block;
}
</style> 