<template>
  <InsideRouterLink
    v-if="redirection"
    :to="redirection"
    class="custom-item-solr-searches"
  >
    <div class="custom-item-solr-searches__main df-center-y">
      <img
        v-if="getCheckedData(resultData, 'main_taxo.0.image')"
        :src="$_getContentImage(resultData.main_taxo[0].image)"
      />

      <div>
        <Title
          tag="h4"
          class="custom-item-solr-searches__title"
          v-html="resultData.title"
        />

        <BaseText
          class="custom-item-solr-searches__extract"
          v-html="resultData.body"
        />
      </div>
    </div>

    <div class="custom-item-solr-searches__infos df-center-y">
      <div class="df-center-y">
        <date-ui :date="resultData.date" tag="p" />

        <BaseText :tiny="true">
          {{ resultData.type_title[$_currentLang] }}
        </BaseText>

        <BaseText
          v-for="taxo in resultData.main_taxo"
          :key="taxo.uuid"
          :tiny="true"
        >
          {{ taxo.title }}
        </BaseText>
      </div>

      <div class="custom-item-solr-searches__brands df-center-y">
        <template v-for="brand in resultData.secondary_taxo">
          <img
            v-if="getCheckedData(brand, 'menu_icon.main')"
            :key="brand.uuid"
            :src="$_getContentImage(brand.menu_icon)"
          />
        </template>
      </div>
    </div>
  </InsideRouterLink>
</template>

<script>
import InsideRouterLink from '@inside-links/components/lib/InsideRouterLink'
import { Title, BaseText } from 'inside-collection/atoms'

export default {
  name: 'SolrSearchItem',
  components: {
    InsideRouterLink,
    Title,
    BaseText
  },
  props: {
    resultUuid: {
      type: String,
      required: true
    },
    resultData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      redirection: null,
      method: this.$_getRedirectionMethod(this.resultData.content_type)
    }
  },
  async beforeMount() {
    this.$store.commit(
      'setCurrentModalContentType',
      this.resultData.content_type
    )

    this.redirection = await this.method({ data: this.resultData })
  }
}
</script>

<style scoped lang="scss">
@use '../../../styles/modules/inside-customs/searches/solr-item.scss' as *;
</style>
