<template>
    <tr>
        <td colspan="2" style="padding: 0px; border:0px">
            <table>
                <tbody id="cnxt_scm_list_databases edited2">
                    <tr class="schema_node" id="cnxt_scm_node_EXAMPLE" :active="schema.selected" node_type="schema" state="collapsed" @click='selectedSchema' :showItemObject='active'>
                        <td style="width: 24px;border:0">&nbsp;</td>
                        <td style="width: 20px;cursor: pointer;border:0"><i class="fa fa-cog" style="font-size: 14px"></i></td>
                        <td style="cursor: pointer;width: 100%;border:0">{{name}}</td>
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <object-list :showViews="showViews" :schema="name" :idConnection='idConnection' :object='object' v-if="schema.selected" @getColumns="getColumns" @getSource="getSource" :selectedSchema="schema" :tableName='tableName'></object-list>
</template>
<script lang="ts">
import { Attribute } from '@/domain/models/Attribute.interface';
import { Connection } from '@/domain/models/connections/Connection';
import { jsonUtilities } from '@/infrastructure/utilities/jsonUtilities';
import { ConnectionService } from '@/domain/services/Connection.service';
import ObjectList from '@/lib-components/component/ConnectionExplorerComponent//ObjectList.vue';

export default{
    name : 'ItemSchema',
    emits : ['getColumns', 'selectedSchema',  'getSource', 'getObject'],
    props:{
        name : { type: String, default: '' },
        idConnection : { type: String, default: '' },
        connection : { type: Connection, default: null },
        schemaList : [],
        schema : {} as any,
        object : { type: String, default: '' },
        tableName : { type: String, default: '' },
        showViews: { type: Boolean, default: true },
    },
    components: {
        ObjectList
    },
    data : () => {
        return {
            connectionService : {} as ConnectionService,
            showDatabaseObjects : false,
            active : false,
            columnList : [],
            source : '',
        }
    },
    methods: {
        getColumns(columnList : []){
            this.columnList = columnList;
            this.$emit("getColumns", this.columnList);
        },
        async selectedSchema(){
            this.schema.selected =  true;
            this.$emit("selectedSchema",this.name);
        },
        getValueAttribute(attribute : Attribute, prop : String){
            return jsonUtilities.getJsonArrayEntrybyValue<Attribute>(attribute, prop).value;
        },
        getSource(source : String){
            this.source =  source;
            this.$emit("getSource",source);
        },
    },
    async mounted(){
        this.connectionService = new ConnectionService();
    },
}
</script>
<style scoped>
td{
    border:0;
}
</style>
