<template>
  <aside class="sidebar">
    <h2>🗂️ Chats</h2>
    <button class="new-chat-btn" @click="$emit('create-chat')">
      ➕ Nuevo chat
    </button>
    <ul class="chat-list">
      <li
        v-for="chat in chats"
        :key="chat.conversationId"
        :class="{ active: chat.conversationId === currentChatId }"
        @click="$emit('select-chat', chat.conversationId)"
      >
        {{ chat.title }}
      </li>
    </ul>
  </aside>
</template>

<script setup>
defineProps({
  chats: {
    type: Array,
    required: true
  },
  currentChatId: {
    type: String,
    default: ''
  }
})

defineEmits(['select-chat', 'create-chat'])
</script>

<style scoped>
.sidebar {
  width: 25%;
  min-width: 200px;
  background-color: #1b1d23;
  color: #ffffff;
  padding: 1.5rem 1rem;
  box-sizing: border-box;
  border-right: 1px solid #2c2e34;
  display: flex;
  flex-direction: column;
}

.sidebar h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: #5a90ff;
}

.new-chat-btn {
  margin-bottom: 10px;
  padding: 8px;
  font-size: 14px;
  cursor: pointer;
  background-color: #5a90ff;
  color: white;
  border: none;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

.new-chat-btn:hover {
  background-color: #4076e0;
}

.chat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex-grow: 1;
}

.chat-list li {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 0.2s ease;
  font-size: 0.95rem;
}

.chat-list li:hover {
  background-color: #2c2f3a;
}

.chat-list li.active {
  background-color: #3451d1;
  color: white;
  font-weight: bold;
}
</style>
