<template>
  <view>
    <up-popup :show="show" mode="center">
      <view class="popup-content">
        <view class="top u-flex u-row-between">
          <text class="font-bold u-font-32 color-333">{{ title }}</text>
          <up-icon size="18" name="close" @click="show = false"></up-icon>
        </view>
        <up-line></up-line>
        <scroll-view style="max-height: 50vh" :scroll-y="true">
          <view class="u-flex servingStyles">
            <view
              v-for="(item, index) in servingStyles"
              :key="index"
              @click="servingSel = item.value"
               :class="[servingSel == item.value ? 'active' : '']"
              class="item tranistion"
            >
              <text>{{ item.name }}</text>
            </view>
          </view>
        </scroll-view>
        <up-line></up-line>

        <view class="bottom u-row-right">
          <view
            class="btn success"
            @click="confirm"
            :class="[btnShape]"
            >{{ confirmText }}</view
          >
        </view>
      </view>
    </up-popup>
  </view>
</template>

<script setup>
import { servingStyles } from "@/data/index.js";
import { ref } from "vue";
const props = defineProps({
  title: {
    type: String,
    default: "上菜方式",
  },
  confirmText: {
    type: String,
    default: "确定",
  },
  cancelText: {
    type: String,
    default: "取消",
  },
  btnShape: {
    type: String,
    default: "round",
  },
});

const servingSel =defineModel("servingSel",{
  type: String,
  default: servingStyles[0].value,
});

const show = defineModel({
  type: Boolean,
  default: false,
});
const emits = defineEmits(["close", "confirm"]);
function close() {
  show.value = false;
  emits("close");
}
function confirm() {
  emits("confirm", servingSel.value);
}
</script>
<style lang="scss">
.popup-content {
  background: #fff;
  width: 640rpx;
  border-radius: 18rpx;
}
.top {
  padding: 40rpx 48rpx;
}
.bottom {
  padding: 48rpx 52rpx;
  display: flex;
  gap: 50rpx;
  .btn {
    text-align: center;
    padding: 18rpx 60rpx;
    font-size: 32rpx;
    border: 2rpx solid transparent;
    border-radius: 8rpx;
    &.success {
      background-color: $my-main-color;
      color: #fff;
    }
    &.cancel {
      border-color: #d9d9d9;
      box-shadow: 0 4rpx 0 0 #00000005;
    }
  }
}
.servingStyles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  padding: 38rpx;
  gap: 26rpx;
  .item {
    padding: 14rpx 38rpx;
    border-radius: 16rpx;
    border: 2rpx solid $my-main-color;
    color: $my-main-color;
    font-size: 28rpx;
    &.active {
      background-color: $my-main-color;
      color: #fff;
    }
  }
}
</style>
