<template>
<aside class="app-sidebar" :class="{ 'is-mobile-open': props.mobileOpen }">
<div class="sidebar-header">
<div class="sidebar-logo">
<img src="/images/logo.svg" alt="Navi" />
<span>Navi</span>
<button class="btn-icon sidebar-close-btn" title="Close" @click="emit('close')">
<i class="ph ph-x"></i>
</button>
</div>
<div class="sidebar-controls-row">
<div class="sidebar-profile-select">
<select
:value="profilesStore.selectedProfileId"
@change="profilesStore.selectedProfileId = $event.target.value"
>
<option
v-for="p in profilesStore.profiles"
:key="p.id"
:value="p.id"
>{{ p.name }}</option>
</select>
</div>
<button class="btn btn-primary with-icon" @click="handleNewSession">
<i class="ph ph-plus"></i>
New Chat
</button>
</div>
</div>
<div class="sidebar-sessions">
<div class="sessions-label">Conversations</div>
<SessionList @select="handleSelect" />
</div>
<div class="sidebar-footer">
<template v-if="authStore.isAuthenticated">
<span class="user-name">{{ authStore.user?.display_name || authStore.user?.email }}</span>
<button class="btn btn-primary with-icon" @click="authStore.logout">
<i class="ph ph-sign-out"></i>
Logout
</button>
</template>
<template v-else>
<button class="btn btn-primary with-icon" @click="authStore.login">
<i class="ph ph-sign-in"></i>
Login
</button>
</template>
</div>
</aside>
</template>
<script setup>
import { watch } from 'vue'
import { useProfilesStore } from '@/stores/profiles.js'
import { useSessionsStore } from '@/stores/sessions.js'
import { useChatStore } from '@/stores/chat.js'
import { useAuthStore } from '@/stores/auth.js'
import SessionList from './SessionList.vue'
const props = defineProps({
mobileOpen: Boolean
})
const emit = defineEmits(['close'])
const profilesStore = useProfilesStore()
const sessionsStore = useSessionsStore()
const chatStore = useChatStore()
const authStore = useAuthStore()
// Keep selector in sync with the active session's profile
watch(
() => chatStore.currentProfileId,
(id) => { if (id) profilesStore.selectedProfileId = id }
)
async function handleNewSession() {
const session = await sessionsStore.createSession(profilesStore.selectedProfileId)
await chatStore.loadSession(session.session_id)
emit('close')
}
function handleSelect() {
emit('close')
}
</script>
<style scoped>
.sidebar-close-btn {
display: none;
@media (max-width: 1280px) {
display: flex;
margin-left: auto;
}
}
.sidebar-footer {
padding: 12px 16px;
border-top: 1px solid var(--color-border);
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.user-name {
font-size: 13px;
color: var(--color-text-secondary);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>