<template>
    <div class="right-layout-container">
        <v-toolbar color="primary" dark>
            <v-toolbar-title class="white--text">Inventaris Item</v-toolbar-title>
            <v-spacer></v-spacer>
        </v-toolbar>

        <v-card class="pa-2">
            <v-layout row wrap>
                <v-flex xs12 pa-1>
                    <h2>Setting Default Akun Inventaris</h2>
                </v-flex>
                <v-flex xs4 pa-1>
                    <strong>Akun Inventaris: </strong> <br>
                    {{ selected_inventaris_gol.CoaInventarisAccountNo }} <br>
                    {{ selected_inventaris_gol.CoaInventarisDescription }} <br>
                </v-flex>
                <v-flex xs4 pa-1>
                    <strong>Akun Inventaris Hutang: </strong> <br>
                    {{ selected_inventaris_gol.CoaHutangAccountNo }} <br>
                    {{ selected_inventaris_gol.CoaHutangDescription }} <br>
                </v-flex>
                <v-flex xs4 pa-1>
                    <strong>Akun Inventaris Beban Depresiasi: </strong> <br>
                    {{ selected_inventaris_gol.CoaBebanPenyusutanAccountNo }} <br>
                    {{ selected_inventaris_gol.CoaBebanPenyusutanDescription }} <br>
                </v-flex>
                <v-flex xs4 pa-1>
                    <strong>Akun Inventaris Akumulasi Depresiasi: </strong> <br>
                    {{ selected_inventaris_gol.CoaAkumulasiPenyusutanAccountNo }} <br>
                    {{ selected_inventaris_gol.CoaAkumulasiPenyusutanDescription }} <br>
                </v-flex>
                <v-flex xs4 pa-1>
                    <strong>Akun Inventaris Laba Pelepasan: </strong> <br>
                    {{ selected_inventaris_gol.CoaLabaPelepasanAccountNo }} <br>
                    {{ selected_inventaris_gol.CoaLabaPelepasanDescription }} <br>
                </v-flex>
                <v-flex xs4 pa-1>
                    <strong>Akun Inventaris Rugi Pelepasan: </strong> <br>
                    {{ selected_inventaris_gol.CoaRugiPelepasanAccountNo }} <br>
                    {{ selected_inventaris_gol.CoaRugiPelepasanDescription }} <br>
                </v-flex>
            </v-layout>
        </v-card>

        <v-card class="pa-2 table-card mt-2">
            <v-layout row wrap>
                <v-flex xs3 pa-1>
                    <v-text-field hide-details outline label="Cari" placeholder="Cari"></v-text-field>
                </v-flex>
            </v-layout>
            <div class="table-scroll-wrapper">
                <v-data-table :headers="headers" :items="list_item_inventaris.records" :pagination.sync="pagination"
                    :rows-per-page-items="[5, 10, 25]" class="elevation-1">
                    <template v-slot:items="props">
                        <tr>
                            <td class="text-xs-center pa-1">
                                {{ props.index + 1 }}
                            </td>
                            <td class="text-xs-left pa-1">
                                {{ props.item.M_ItemDesc }}
                            </td>
                            <td class="text-xs-left pa-1">
                                <v-layout row wrap>
                                    <v-flex xs4 pa-1>
                                        <strong>Akun Inventaris: </strong> <br>
                                        {{ props.item.CoaInventarisAccountNo }} <br>
                                        {{ props.item.CoaInventarisDescription }} <br>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <strong>Akun Inventaris Hutang: </strong> <br>
                                        {{ props.item.CoaHutangAccountNo }} <br>
                                        {{ props.item.CoaHutangDescription }} <br>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <strong>Akun Inventaris Beban Depresiasi: </strong> <br>
                                        {{ props.item.CoaBebanPenyusutanAccountNo }} <br>
                                        {{ props.item.CoaBebanPenyusutanDescription }} <br>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <strong>Akun Inventaris Akumulasi Depresiasi: </strong> <br>
                                        {{ props.item.CoaAkumulasiPenyusutanAccountNo }} <br>
                                        {{ props.item.CoaAkumulasiPenyusutanDescription }} <br>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <strong>Akun Inventaris Laba Pelepasan: </strong> <br>
                                        {{ props.item.CoaLabaPelepasanAccountNo }} <br>
                                        {{ props.item.CoaLabaPelepasanDescription }} <br>
                                    </v-flex>
                                    <v-flex xs4 pa-1>
                                        <strong>Akun Inventaris Rugi Pelepasan: </strong> <br>
                                        {{ props.item.CoaRugiPelepasanAccountNo }} <br>
                                        {{ props.item.CoaRugiPelepasanDescription }} <br>
                                    </v-flex>
                                </v-layout>
                            </td>
                            <td class="text-xs-center pa-1">
                                <v-tooltip bottom>
                                    <template v-slot:activator="{ on }">
                                        <v-btn color="info" dark v-on="on"
                                            @click="editAcc(props.item)" small
                                            style="min-width: 40px; margin: 0;"
                                        >
                                            <v-icon small>edit</v-icon>
                                        </v-btn>
                                    </template>
                                    <span>Edit</span>
                                </v-tooltip>
                                <v-tooltip bottom>
                                    <template v-slot:activator="{ on }">
                                        <v-btn color="error" dark v-on="on"
                                            @click="deleteAcc(props.item)" small
                                            style="min-width: 40px; margin: 0;"
                                        >
                                            <v-icon small>delete</v-icon>
                                        </v-btn>
                                    </template>
                                    <span>Delete</span>
                                </v-tooltip>
                            </td>
                        </tr>
                    </template>
                </v-data-table>
            </div>
        </v-card>
    </div>
</template>

<style scoped>
.right-layout-container {
    display: flex;
    flex-direction: column;
}

.table-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
</style>

<script>
module.exports = {
    components: {

    },
    data() {
        return {
            pagination: {},
            headers: [
                {
                    text: "NO", align: "center", sortable: false, value: "nomor",
                    width: "5%", class: "pa-1 blue lighten-3 white--text",
                },
                {
                    text: "ITEM INVENTARIS", align: "center", sortable: false, value: "nomor",
                    width: "25%", class: "pa-1 blue lighten-3 white--text",
                },
                {
                    text: "ACCOUNT KHUSUS", align: "center", sortable: false, value: "nomor",
                    width: "60%", class: "pa-1 blue lighten-3 white--text",
                },
                {
                    text: "AKSI", align: "center", sortable: false, value: "nomor",
                    width: "10%", class: "pa-1 blue lighten-3 white--text",
                },
            ]
        }
    },
    computed: {
        list_item_inventaris: {
            get() {
                return this.$store.state.invItemMap.list_item_inventaris
            },
            set(val) {
                this.$store.commit("invItemMap/update_list_item_inventaris", val)
            }
        },
        selected_inventaris_gol() {
            return this.$store.state.invMap.selected_inventaris_gol;
        }
    },
    methods: {
        editAcc(item) {
            this.hidrateCoaAutocomplete(item);
            const form = {
                invCoaID: item.M_InventarisItemCoaMappingCoaInventarisID,
                debtCoaID: item.M_InventarisItemCoaMappingCoaHutangID,
                bebanCoaID: item.M_InventarisItemCoaMappingCoaBebanPenyusutanID,
                accumCoaID: item.M_InventarisItemCoaMappingCoaAkumulasiPenyusutanID,
                labaCoaID: item.M_InventarisItemCoaMappingCoaLabaPelepasanID,
                rugiCoaID: item.M_InventarisItemCoaMappingCoaRugiPelepasanID
            }

            this.$store.commit("invItemMap/update_form", form);
            this.$store.commit("invItemMap/update_selected_inventaris_item", item)
            this.$store.commit("invItemMap/update_dialog_add_mapping_item", true)
        },
        deleteAcc(item) {
            this.$store.commit("invItemMap/update_selected_inventaris_item", item);
            this.$store.commit("invItemMap/update_dialog_confirm_item", true);
        },
        hidrateCoaAutocomplete(item) {
            this.$store.dispatch("datacoa/getListCoa", { 
                keyword: item.CoaInventarisAccountNo ?? "", key: "invCoa" 
            });
            this.$store.dispatch("datacoa/getListCoa", { 
                keyword: item.CoaHutangAccountNo ?? "", key: "debtCoa" 
            });
            this.$store.dispatch("datacoa/getListCoa", { 
                keyword: item.CoaBebanPenyusutanAccountNo ?? "", key: "bebanCoa" 
            });
            this.$store.dispatch("datacoa/getListCoa", { 
                keyword: item.CoaAkumulasiPenyusutanAccountNo ?? "", key: "accumCoa" 
            });
            this.$store.dispatch("datacoa/getListCoa", { 
                keyword: item.CoaLabaPelepasanAccountNo ?? "", key: "labaCoa" 
            });
            this.$store.dispatch("datacoa/getListCoa", {
                 keyword: item.CoaRugiPelepasanAccountNo ?? "", key: "rugiCoa" 
            });
        }
    }
}
</script>
