<template>
    <div class="hand" v-if="this.Hand">
        <tile v-for="tile of this.Hand.tiles_left" :key="tile.idobject" :id="tile.id_tuile" @tileClicked="tileClickedListener"/>
    </div>
</template>

<script>
import Tile from '@/components/Tile.vue';
import TileModel from '@/model/TileModel.js';
import Hand from '@/model/HandModel.js';

export default {
    name: 'Hand',
    components: { Tile },
    props: {
        
    },
    data(){ 
        return{
        Hand: null,
        }
    },
    mounted(){
        let startingHand = [8,11,11,14,16,7,4,5,20,21,22,6,0];
        this.Hand= new Hand();
        startingHand.forEach(tile => {
            this.Hand.draw(new TileModel(tile));
        });
        this.Hand.sort(); 
    },
    updated(){
    },
    methods: {      
        tileClickedListener: function(event){
            let dicarded = this.Hand.discard(event.id_tuile);
            console.log(dicarded);
        }
    }
}
</script>

<style>
.hand{
    display:flex;

}
</style>
