<template>
  <user-dashboard-container page-class="announcements" panel-title="اطلاعیه های نمایندگان">
    <div v-for="item in agentAnnouncements" :key="item._id" class="item" :class="!item.seen && 'unread'">
      <el-collapse :key="item._id + 'co_parent'" accordion @change="seeAnnouncement">
        <el-collapse-item :key="item._id + 'co_item'" :name="item._id">
          <template slot="title">
            <h3>{{ item.title }}</h3>
          </template>
          <div>
            <p>{{ item.caption }}</p>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
    <h3 v-if="!agentAnnouncements.length" style="text-align: center; margin-top: 50px">هیچ اطلاعیه ای موجود نیست</h3>
  </user-dashboard-container>
</template>

<script>
export default {
  name: 'AccountAgentAnnouncements',
  layout: 'user',
  data() {
    return {}
  },
  computed: {
    agentAnnouncements() {
      return this.$store.state.front.agentAnnouncements
    }
  },
  methods: {
    seeAnnouncement(id) {
      if (!id) return
      const item = this.agentAnnouncements.find(item => item._id === id)
      if (!item.seen) this.$agentSocket.emit('agent:updateAnnouncement', id)
    }
  }
}
</script>
