<template>
  <div class="card sticky-top">
    <div class="card-header">
      <ul class="nav nav-tabs card-header-tabs">
        <li v-for="(tab, index) in tabs" :key="index" class="nav-item">
          <button type="button" class="nav-link" :class="{active: !isCollapsed[index]}" @click="navigate(index)">{{tab}}</button>
        </li>
      </ul>
    </div>
    <div class="card-body card-body-tabs">
      <div v-for="(tab, index) in tabs" :key="index">
        <slot :name="index" :collapsed="isCollapsed[index]" />
      </div>
    </div>
  </div>

</template>

<script>
import {ref} from 'vue'
export default {
  setup: function(props) {
    const isCollapsed = ref({})

    let first = true
    for(const key in props.tabs){
      isCollapsed.value[key] = !first
      first = false
    }

    const navigate = function(tab){
      for(const key in props.tabs){
        isCollapsed.value[key] = true
      }
      isCollapsed.value[tab] = false
    }

    return {isCollapsed, navigate}
  },
  props: {
    tabs: {
      type: Object,
      required: true
    }
  }
}
</script>
