<script setup lang="ts">
import { useRouter } from 'vue-router'
import { store } from '../store'


const router = useRouter()

defineProps<{
    data: []
}>()
</script>

<template>
    <div class="incident_list">
        <div
            v-for="item in data"
            :key="item.id"
            class="incident_item"
            :class="`sev_${item.severity}`"
            @click="router.push(`/incidents/${item.id}`)"
        >
            <div class="incident_header">
                <span
                    class="incident_site"
                    @click.stop="router.push(`/cellsites/${item.site_id}`)"
                >Site {{ item.site_id }}</span>
                <span
                    class="incident_assignee"
                    @click.stop="() => { const r = store.robots.find(r => r.name === item.assigned_to); if (r) router.push(`/robots/${r.id}`) }"
                >{{ item.assigned_to }}</span>

                <span class="incident_status" :class="item.status">{{ item.status }}</span>
            </div>
            <div class="incident_text">{{ item.text }}</div>
            <div class="incident_meta">{{ item.created }}</div>
            <div class="incident_meta">{{ item.created_by }}</div>
        </div>
        <p v-if="data.length === 0">No tickets here... for now.</p>
    </div>
</template>

<style scoped>
.incident_list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.incident_item {
    background: rgba(20, 20, 20, 0.9);
    border-left: 4px solid transparent;
    border-radius: 3px;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
}

.incident_item:hover {
    background: rgba(40, 40, 40, 0.9);
}

.incident_header {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.3rem;
}

.incident_site {
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 0 0.3rem;
}


.incident_site:hover {
    color: var(--theme, rgba(255, 100, 0, 1));
    text-decoration: underline;
    text-underline-offset: 3px;
}

.incident_item:hover .incident_site {
    border-color: var(--theme, rgba(255, 100, 0, 0.5));
    color: var(--theme, rgba(255, 100, 0, 1));
}

.incident_status { margin-left: auto; font-size: 0.75rem; }
.incident_status.closed { color: rgba(100, 200, 100, 0.7); }
.incident_status.active { color: rgba(220, 30, 30, 0.9); }

.incident_text { color: rgba(255, 255, 255, 0.6); margin-bottom: 0.2rem; }
.incident_meta { font-size: 0.75rem; color: rgba(255, 255, 255, 0.3); }

.sev_1 { border-left-color: rgb(220, 30, 30); }
.sev_2 { border-left-color: rgb(220, 120, 30); }
.sev_3 { border-left-color: rgb(200, 180, 30); }
.sev_4 { border-left-color: rgb(60, 140, 200); }
.sev_5 { border-left-color: rgb(80, 160, 180); }

.incident_assignee {
    color: rgba(255, 100, 0, 0.7);
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 0 0.3rem;
    transition: color 0.15s, border-color 0.15s;
}

.incident_assignee:hover {
    color: rgba(255, 255, 255, 1);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.incident_item:hover .incident_assignee {
    border-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.9);
}

</style>
