<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>
</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 SessionList from './SessionList.vue'
const props = defineProps({
mobileOpen: Boolean
})
const emit = defineEmits(['close'])
const profilesStore = useProfilesStore()
const sessionsStore = useSessionsStore()
const chatStore = useChatStore()
// 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: 768px) {
display: flex;
margin-left: auto;
}
}
</style>