<script setup>
//Fix v-if riga 20
import ChatPreview from "@/components/ChatPreview.vue";
import ChatView from "@/components/single_chat/ChatView.vue";
</script>

<template>
  <div id="background chat-list">
    <ChatPreview
      v-for="chat in $options.demo_chats.history"
      :key="chat.id"
      :chat-picture="chat.picture"
      :chat-name="chat.name"
      :chat-last-message="chat.last_message"
      :chat-seen="chat.seen"
      :chat-date="chat.date"
      :chat-new-messages="chat.new_messages"
      @click="showChat(chat)"
    />
    <ChatView v-if="selectedChat" />
  </div>
</template>

<script>
import demo_chats_json from "../assets/demo_chats.json";
export default {
  demo_chats: demo_chats_json,
  selectedChat: false,
  chatId: Number,
  methods: {
    showChat(chat) {
      console.log(chat);
      this.$emit("change-header", [chat.picture, chat.name]);
      this.selectedChat = true;
      this.chatId = chat.id;
    },
  },
};
</script>

<style scoped></style>
