<template>
    <BaseLayout>
        <main class="content">
            <div class="row">
                <div class="col">
                    <div class="card">
                        <div class="card-header">{{ item.name }}</div>
                        <div class="card-body">
                            <div class="mb-3">
                                <label for="owner" class="form-label">Owner</label>
                                {{ item.owner }}
                            </div>
                            <div class="mb-3">
                                <label for="description" class="form-label">Description</label>
                                {{ item.description }}
                            </div>
                            <div class="mb-3">
                                <label for="tags" class="form-label">Tags</label>
                                <span class="badge bg-dark" v-for="(tag, index) in item.tags" :key="index">
                                    {{ getNameFromHandle(tag) }}
                                </span>
                            </div>
                            <div class="mb-3">
                                <label for="property" class="form-label">Properties</label>
                                <span class="badge bg-dark" v-for="(property, index) in item.properties" :key="index">
                                    {{ property.name }}={{ property.value }}
                                </span>
                            </div>
                            <div class="mb-3">
                                <label for="quantity" class="form-label">Quantity</label>
                                {{ item.owned_quantity }}
                            </div>
                            <div class="mb-3">
                                <label for="image" class="form-label">Image</label>
                                <div>
                                    <authenticated-image v-for="file in item.files" :key="file.id" :src="file.name"
                                                         :owner="file.owner" class="img-thumbnail border-info"></authenticated-image>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </BaseLayout>
</template>

<script>
import * as BIcons from "bootstrap-icons-vue";
import BaseLayout from "@/components/BaseLayout.vue";
import {mapActions, mapGetters} from "vuex";
import AuthenticatedImage from "@/components/AuthenticatedImage.vue";

export default {
    name: "InventoryDetailForeign",
    components: {
        AuthenticatedImage,
        BaseLayout,
        ...BIcons
    },
    props: {
        user: {
            type: String,
            required: true
        },
        id: {
            type: String,
            required: true
        }
    },
    data() {
        return {
            item: {}
        }
    },
    computed: {
        ...mapGetters(["getNameFromHandle"]),
    },
    methods: {
        ...mapActions(["fetchForeignItem"]),
        async loadItem() {
            this.item = await this.fetchForeignItem({owner: this.user, id: this.id}) || {}
        }
    },
    watch: {
        user: 'loadItem',
        id: 'loadItem'
    },
    mounted() {
        this.loadItem()
    }
}
</script>

<style scoped>
img {
    width: 190px;
    height: 107px;
    object-fit: contain;
}
</style>
