<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>{{title}}</h6>
                </div>
                <div v-show="hasCheck" class="col text-right text-check">
                    <i  :class="[selectAll ? 'fas fa-check' : 'far fa-square' ]" id="ufd_all" style="color: rgb(255, 255, 255); cursor: pointer;" @click="setCheckAll" active="false">
                    </i>
                    <span class="spinner-border spinner-border-sm align-top" role="status" id="ufd_cnx_list_fields_spn" style="display: none;"></span>
                </div>
            </div>
        </div>
        <div class="table-responsive table-bordered field_list_view" style="overflow: auto;height: 240px;border: 1px dashed #d1d3e2;font-size: 12px;">
            <table class="table table-bordered table-sm">
                <tbody id="ufd_cnx_list_fields">
                    <check-box-item :hasCheck="hasCheck" v-for="(checkItem, indexItem) of columnList" :key="indexItem" :checkItem='checkItem' @itemDoubleClick='itemDoubleClick'></check-box-item>
                </tbody>
            </table>
        </div>
    </div>
</template>
<script lang="ts">
import CheckBoxItem from '@/lib-components/component/CheckBoxListComponent/CheckBoxItem.vue';

export default {
    name : 'CheckBoxList',
    emits : ['getColumns', 'chkItemDoubleClick'],
    props:{
        title : { type: String, default: '' },
        schemaList : [],
        columnList : [],
        hasCheck: { type: Boolean, default: true },
    },
    components: {
        CheckBoxItem
    },
    data : () => {
        return {
            showDatabaseObjects : false,
            active : false,
            selectAll : false,
            isEditing: false,
        }
    },
    watch:{
        columnList: function(){
            this.isEditing = true;
            this.$emit('update:isEditing', this.isEditing);
        }
    },
    methods: {
        setCheckAll(){
            this.selectAll = !(this.selectAll);
            for(let indexItem = 0; indexItem < this.columnList.length; indexItem++){
                this.columnList[indexItem].checked = this.selectAll;
            }
        },
        itemDoubleClick(selectedText : String){
            console.log(selectedText);
            if(!this.hasCheck){
                this.$emit('chkItemDoubleClick', selectedText);
            }
        }
    },
    async mounted(){
    },
}
</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>