<template>
  <loader>
    <div class="search-container">
      <input type="text" v-model="search" class="form-control" placeholder="zoek..."/>
    </div>
    <ul class="asset-overview">
      <li class="asset" v-for="asset in filteredAssets">
        <asset-overview-item :asset="asset" v-model="valueCopy"></asset-overview-item>
      </li>
    </ul>
  </loader>
</template>

<style lang="scss" scoped>
  .search-container {
    padding: 0 50% 0 0;
  }

  .asset-overview {
    display: flex;
    flex-wrap: wrap;
    padding: 0;
    margin: 1rem -.5rem 0;
  }

  .asset {
    display: flex;
    flex: 0 200px;
    list-style: none;
    margin: .25rem;
  }
</style>

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

  import assetOverviewItem from './asset-overview-item.vue';
  import loader from '../shared/loader.vue';

  export default {
    name: 'asset-overview',
    mixins: [ValueSyncMixin],
    props: {
      value: {
        type: Object,
        required: false
      }
    },
    data() {
      return {
        search: '',
      };
    },
    computed: {
      filteredAssets() {
        return assetStore.assets.filter(asset => asset.title.toLowerCase().includes(this.search.toLowerCase()));
      },
      isLoading() {
        return assetStore.isLoading
      }
    },
    components: {
      assetOverviewItem,
      loader
    }
  };
</script>
