<template>
  <van-popup v-model="showPopup" position="bottom" round >
    <div class="refund-info-popup">
      <div class="header flex-default">
        <div class="left" />
        <div class="title">{{ title }}</div>
        <m-icon
          icon="icon-close-square"
          :size="14"
          @click="showPopup = false"
        />
      </div>
      <div class="list">
        <div
          class="item flex-default"
          v-for="(item, index) of list"
          :key="`info-item-${index}`"
          @click="handleSelect(index, item)"
        >
          <span class="label">{{ item.label }}</span>
          <m-icon
            :icon="currentIndex === index ? 'icon-radio-round-check' : 'icon-radio-round'"
            :size="16"
          />
        </div>
      </div>
    </div>
  </van-popup>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    title: String,
    list: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      showPopup: false,
      currentIndex: "",
    };
  },
  watch: {
    value(val) {
      this.showPopup = val
    },
    showPopup(val){
      this.$emit("input", val)
    }
  },
  methods: {
    handleSelect(index, item) {
      this.currentIndex = index;
      this.$emit("select", index, item);
      setTimeout(() => {
        this.showPopup = false
      }, 200);
    },
  },
};
</script>

<style lang="less">
.refund-info-popup {
  padding: 16px;
  background: #ffffff;
  border-radius: 10px 10px 0px 0px;
  > .header {
    align-items: center;
    justify-content: space-between;
    margin-bottom: 26px;
    .left {
      width: 14px;
      height: 14px;
    }
    .title {
      font-size: 16px;
      font-weight: bold;
      color: #140603;
    }
  }
  > .list {
    height: 350px;
    overflow-y: auto;
    .item {
      align-items: center;
      justify-content: space-between;
      margin-bottom: 26px;
      &:nth-last-of-type(1) {
        margin-bottom: 0;
      }
    }
    .item .label {
      font-size: 14px;
      color: #140603;
    }
  }
}
</style>