<template>
  <div class="q-pa-sm ui-gap-y-sm flex column">
    <search-messages-item
      @click="showThread(message.threadId)"
      v-for="message in messages"
      :key="message.id"
      :message="message"
    />
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import { FoundMessage } from '@/widgets/messages/types/Message'
import { RouteNames } from '@/widgets/messages/router/routeNames'
import SearchMessagesItem from '@/widgets/messages/components/search/SearchMessagesItem.vue'

@Component({
  components: { SearchMessagesItem },
})
export default class SearchMessages extends Vue {
  @Prop({ type: Array, required: true })
  messages!: FoundMessage[]

  showThread(threadId: number) {
    this.$router.push({
      name: RouteNames.thread,
      params: { threadId: threadId.toString() },
    })
  }
}
</script>
