<template>
  <div class="tabs is-fullwidth">
    <ul>
      <li
        v-for="item in items"
        :key="item[metakey]"
        :class="{ 'is-active': value === item[metakey] }">
        <a
          class="is-family-sans-serif"
          @click="onClick(item)">
          {{ item[metavalue] }}
        </a>
      </li>
    </ul>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'

import ChangeEvent from '../../core/events/ChangeEvent'

interface Dictionary<T> {
    [Key: string]: T;
}

@Component({
  name: 'base-tab'
})
export default class BaseTabs extends Vue {
  @Prop() items!: Dictionary<string>[]
  @Prop() value!: string
  @Prop({ default: 'key' }) metakey!: string
  @Prop({ default: 'value' }) metavalue!: string

  onClick ($item: Dictionary<string>) {
    const event = new ChangeEvent<string>()
    event.value = $item.key
    this.$emit('change', event)
  }
}
</script>

<style lang="scss" scoped>
@import "../../core/base/bulma.scss";
$tabs-toggle-link-active-border-color: $revas-purple;
@import "bulma/sass/components/tabs.sass";
</style>
