<template>
  <div>
    <div class="row">
      <div class="col-sm-2"></div>
      <div class="col-sm-10 tag-list">
        <p>Selecteer tags die bij deze asset horen</p>
        <div class="checkbox" v-for="tag in tags">
          <label>
            <input type="checkbox" :value="tag.name" v-model="valueCopy"> {{tag.name}}
          </label>
        </div>
      </div>
    </div>
    <div class="form-group row">
      <div class="col-sm-2"></div>
      <div class="col-sm-10">
        <p>Tag niet gevonden?</p>
        <div class="input-group">
          <input v-model="newTag" type="text" class="form-control" placeholder="Nieuwe tag...">
          <span class="input-group-btn">
            <button @click.prevent="addNewTag" class="btn btn-secondary" type="button">
              Voeg toe
            </button>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { assetStore } from '../tools/asset-store.js';
  import { ValueSyncMixin } from '../shared/value-sync-mixin.js';

  export default {
    name: 'asset-tag-picker',
    mixins: [ValueSyncMixin],
    props: {
      value: {
        required: true
      }
    },
    data() {
      return {
        newTag: '',
      };
    },
    computed: {
      tags: () => assetStore.tags
    },
    methods: {
      addNewTag() {
        if(!this.newTag) {
          return;
        }
        assetStore.tags.push({
          name: this.newTag
        });
        this.newTag = '';
      }
    }
  };
</script>
