<template>
<div class="card-body" style="padding: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;">
    <div class="table-header table-theme">
        <div class="row">
            <div class="col text">
                <h6>Columns</h6>
            </div>
        </div>
    </div>
    <div class="table-responsive table-bordered field_list_view" style="overflow: auto;height: 240px;border: 1px dashed #d1d3e2;font-size: 12px;" @drop="onDrop($event, columnList)" @dragenter.prevent @dragover.prevent>
        <table class="table table-hover table-sm">
            <tbody id="ufd_definitions_map">
                <tr  v-for="(column, indexItem) of columnList" :key="indexItem">
                    <td class="text-center align-middle" style="width: 20px;">
                        <i :class="column.getIco()" data-v-a15d8858="" style="font-size: 14px;"></i>
                    </td>
                    <td class="text-center align-middle">
                        <input type="text" attribute="col_name" :value="column.text" class="form-control-sm form-control" style="background: #ffffff00;border-style: none; font-size: 12px;" maxlength="32" readonly='true' required data-placement="top" title="column name"  />
                    </td>
                    <td style="width:20px" class="align-middle">
                        <a @click="deleteItem(indexItem)" class="btn">
                            <i class="fa fa-trash"></i>
                        </a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

</template>
<script lang="ts">
import { ColumnItem } from '../../../domain/models/ColumnItem.class';
export default {
    name : 'SelectedColumnList',
    props:{
        title : { type: String, default: '' },
        columnList: []
    },
    data: ()=>{
        return{
            isEditing: false,
        }
    },
    watch:{
        columnList: function(){
            this.isEditing = true;
            this.$emit('update:isEditing', this.isEditing);
        }
    },
    methods: {
        onDrop(event, list){
            const itemList = JSON.parse(event.dataTransfer.getData('columnList'));
            if(itemList.length > 0){
                itemList.forEach((item: any) => {
                    let column: ColumnItem;
                    column =  new ColumnItem();
                    column.text = item.text;
                    column.datatype = item.datatype;
                    list.push(column);
                });
            }else{
                const item = JSON.parse(event.dataTransfer.getData('column'));
                let column: ColumnItem;
                column =  new ColumnItem();
                column.text = item.text;
                column.datatype = item.datatype;
                list.push(column);
            }
            this.$emit('updateSelectedList', list);
        },
        deleteItem(index: Number){
            this.columnList.splice(index,1);
        }
    },
}
</script>
<style scoped>
.table-theme {
    background: var(--table-header-background-color);
    color: var(--table-header-color);
}
.table-header {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    margin-bottom: 0;
    background-color: var(--table-header-background-color);
    border-bottom: 1px solid  var(--table-header-background-color);
    border-radius: calc(0.35rem - 1px) calc(0.35rem - 1px) 0 0;
}
.text{
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
}
.text-check{
    padding-top: 0.25rem;
}
h6{
    margin-bottom: 0px !important;
    font-weight: bold;
    color: var(--table-header-color);
    font-size: 14px;
}
</style>