<template>
    <div class="timeline-item-wrapper">
        <div class="timeline-item-description">
            <i class="avatar | small">
                <font-awesome-icon icon="user"/>
            </i>
            <span><!--a href="#">$USER</a--> linked item <span class="badge badge-secondary">#{{
                    item.item.id
                }} </span> on <time
                :datetime="timestamp">{{ timestamp }}</time> as <span class="badge badge-primary">{{
                    item.status
                }}</span>
            </span>
        </div>
        <div class="card bg-dark">
            <div class="row">
                <div class="col" style="flex-grow: 0;">
                    <AuthenticatedImage v-if="item.item.file" cached
                                        :src="`/media/2/256/${item.item.file}/`"
                                        class="d-block card-img-left"
                                        @click="openLightboxModalWith(item.item.file)"
                    />
                </div>
                <div class="col">
                    <div class="card-body">
                        <h6 class="card-subtitle text-secondary">id: {{ item.item.id }} box: {{ item.item.box }}</h6>
                        <router-link :to="{name: 'item', params: {id: item.item.id}}">
                            <h6 class="card-title">{{ item.item.description }}</h6>
                        </router-link>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

import AuthenticatedImage from "@/components/AuthenticatedImage.vue";
import AuthenticatedDataLink from "@/components/AuthenticatedDataLink.vue";
import {mapMutations} from "vuex";

export default {
    name: 'TimelineRelatedItem',
    components: {AuthenticatedImage, AuthenticatedDataLink},
    props: {
        'item': {
            type: Object,
            required: true
        }
    },
    computed: {
        'timestamp': function () {
            return new Date(this.item.timestamp).toLocaleString();
        },
        'body': function () {
            return this.item.body.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br/>');
        }

    },
    methods: {
        ...mapMutations(['openLightboxModalWith'])
    }
};
</script>

<style scoped>

a {
    color: inherit;
}

.card-img-left {
    border-top-left-radius: calc(.25rem - 1px);
    border-bottom-left-radius: calc(.25rem - 1px);
}

/*img {
    display: block;
    max-width: 100%;
}*/


.timeline-item-description {
    display: flex;
    padding-top: 6px;
    gap: 8px;
    color: var(--gray);

    img {
        flex-shrink: 0;
    }

    a {
        /*color: var(--c-grey-500);*/
        font-weight: 500;
        text-decoration: none;

        &:hover,
        &:focus {
            outline: 0; /* Don't actually do this */
            color: var(--info);
        }
    }
}


.card {
    border: 1px solid var(--gray);
}

.avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    width: 40px;
    height: 40px;

    &.small {
        width: 28px;
        height: 28px;
    }

    img {
        object-fit: cover;
    }
}

.button {
    border: 0;
    display: inline-flex;
    vertical-align: middle;
    margin-right: 4px;
    margin-top: 12px;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    height: 32px;
    padding: 0 8px;
    background-color: var(--gray);
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 99em;

    &:hover {
        background-color: var(--info);
    }

    &.square {
        border-radius: 50%;
        color: var(--gray);
        background-color: var(--dark);
        width: 32px;
        height: 32px;
        padding: 0;

        svg {
            width: 24px;
            height: 24px;
        }

        &:hover {
            color: var(--info);
        }
    }
}

.show-replies {
    color: var(--gray);
    background-color: transparent;
    border: 0;
    padding: 0;
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 1rem;
    cursor: pointer;

    svg {
        flex-shrink: 0;
        width: 24px;
        height: 24px;
    }

    &:hover,
    &:focus {
        color: var(--info);
    }
}

.avatar-list {
    display: flex;
    align-items: center;

    & > * {
        position: relative;
        box-shadow: 0 0 0 2px #fff;
        background: var(--dark);
        margin-right: -8px;
    }
}

</style>