<template>
  <van-tabs
    v-model="inside_value"
    class="m-tabs"
    @change="handleChange"
    @click="handleClick"
    :background="background"
  >
    <van-tab
      v-for="(item, index) of tabs"
      :key="`tab-item-${index}`"
      :title="item[nameKey]"
    />
  </van-tabs>
</template>

<script>
export default {
  props: {
    tabs: {
      type: Array,
      default() {
        return [];
      },
    },
    nameKey: {
      type: String,
      default: "name",
    },
    value: {
      type: [String, Number],
      default: 0,
    },
    background: {
      type: String,
      default: "white"
    }
  },
  data() {
    return {
      inside_value: "",
    };
  },
  watch: {
    value(val) {
      this.inside_value = val;
    },
    inside_value(val) {
      this.$emit("input", val);
    },
  },
  methods: {
    handleChange(index, title) {
      this.$emit("change", index, title);
    },
    handleClick(index, title) {
      this.$emit("click", index, title);
    },
  },
  mounted() {
    this.inside_value = this.value;
  },
};
</script>

<style lang="less">
.m-tabs {
  border-bottom: 1px solid #f1f1f1;
  .van-tab--active > .van-tab__text {
    font-weight: bold;
    color: @mall-primary-color;
  }
  .van-tab__text {
    font-size: 15px;
    color: #140603;
  }
  .van-tabs__line {
    width: 17px;
    height: 3px;
    border-radius: 1px;
    background: linear-gradient(295deg, #488FF7 0%, #2C66F5 100%);
  }
}
</style>