<template>
  <div class="chat-container">
    <aside class="sidebar">
      <header class="app-title">应用标题</header>
      <ul class="contact-list">
        <li v-for="contact in contacts" :key="contact.id" @click="selectContact(contact)">
          {{ contact.name }}
        </li>
      </ul>
    </aside>
    <main class="chat-area">
      <div class="messages">
        <div v-for="message in messages" :key="message.id" :class="{ 'user-message': message.sender === 'user', 'bot-message': message.sender === 'bot' }">
          {{ message.text }}
        </div>
      </div>
      <footer>
        <input type="file" class="file-upload" @change="handleFileUpload" />
        <input type="text" v-model="messageText" @keyup.enter="sendMessage" class="message-input" />
        <button @click="sendMessage" class="send-button">发送</button>
      </footer>
    </main>
  </div>
</template>

<script>
export default {
  data() {
    return {
      contacts: [
        { id: 1, name: '联系人1' },
        { id: 2, name: '联系人2' },
        // Add more contacts as needed
      ],
      selectedContact: null,
      messages: [],
      messageText: ''
    };
  },
  methods: {
    selectContact(contact) {
      this.selectedContact = contact;
      // Fetch and display messages for the selected contact
      this.messages = [
        { id: 1, sender: 'bot', text: '你好！' },
        { id: 2, sender: 'user', text: '这是我的消息。' },
        // Add more messages as needed
      ];
    },
    sendMessage() {
      if (this.messageText.trim()) {
        this.messages.push({ id: this.messages.length + 1, sender: 'user', text: this.messageText });
        this.messageText = '';
      }
    },
    handleFileUpload(event) {
      // Handle file upload logic here
    }
  }
};
</script>

<style scoped>
.chat-container {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 250px;
  background-color: #f0f2f5;
  padding: 1rem;
}

.app-title {
  font-size: 18px;
  font-weight: bold;
  background-color: darkslateblue;
  color: white;
  text-align: center;
  padding: 0.5rem;
}

.contact-list {
  list-style-type: none;
  padding: 0;
}

.contact-list li {
  cursor: pointer;
  padding: 0.5rem;
  border-bottom: 1px solid #ddd;
}

.contact-list li:hover {
  background-color: #e0e0e0;
}

.chat-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
}

.message-input {
  flex-grow: 1;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0.5rem;
  margin-right: 0.5rem;
}

.send-button {
  background-color: darkslateblue;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

.file-upload {
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0.5rem;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.file-upload:hover {
  background-color: #e0e0e0;
}

.user-message {
  background-color: #72a0c1;
  color: white;
  align-self: flex-end;
  border-radius: 10px;
  padding: 0.5rem;
  max-width: 75%;
  word-wrap: break-word;
}

.bot-message {
  background-color: #f9f9f9;
  color: black;
  align-self: flex-start;
  border-radius: 10px;
  padding: 0.5rem;
  max-width: 75%;
  word-wrap: break-word;
}
</style>
