<template>
  <div class="shadow-classic rounded-md bg-indigo-200 p-3 md:px-5 md:py-7">
    <feed-header :entity="entity" :feed_id="feed_id"
                 :created_at="entity.created_at_humans" :user="user"
                 @onRemoveFeed="onRemoveFeed"
    />

    <div class="mt-3 md:mt-6 feed-body">
      <div class="mb-3 md:mb-6 text-gray text-sm md:text-base" @click.stop="">
        <div>
          <feed-tags v-if="entity.tags.length" class="mb-1"
                     :tags="entity.tags"
          />
          {{ entity.body }}
        </div>
        <feed-paid-block
          :is_paid="entity.is_paid"
          :user_id="user.id"
          :price="entity.price"
          :feed_id="feed_id"
          :paid_open="entity.paid_open"
          @onReplaceFeed="onReplaceFeed"
        />
      </div>
      <feed-music-body
        :feed_id="feed_id"
        :title="entity.title"
        :preview="entity.preview"
        :medias="entity.collection_medias"
        @trackClick="addViewShow"
      />
    </div>
    <feed-footer
      :likes="entity.likes"
      :liked="entity.liked"
      :comments="entity.comments"
      :count="entity.views_count"
      :ads="entity.is_ads"
      @likeFeed="likeFeed"
    />
  </div>
</template>

<script>
import FeedHeader from '@/Shared/FeedList/FeedHeader.vue'
import FeedFooter from '@/Shared/FeedList/FeedFooter.vue'
import FeedMusicBody from '@/Shared/FeedList/FeedMusicBody.vue'
import FeedPaidBlock from '@/Shared/FeedList/FeedPaidBlock.vue'
import FeedTags from '@/Shared/Misc/FeedTags.vue'
import axios from 'axios'

export default {
    components: {
        FeedHeader,
        FeedFooter,
        FeedMusicBody,
        FeedPaidBlock,
        FeedTags,
    },
    props: {
        entity: Object,
        user: Object,
        feed_id: Number,
    },
    emits: ['likeFeed', 'onRemoveFeed'],

    methods: {
        addViewShow() {
            axios
                .post(route('add.view.feed', this.feed_id))
                .then(({ data }) => {
                    data && this.entity.views_count++
                })
        },
        onReplaceFeed(data) {
            this.entity.collection_medias = data.collection
            this.entity.preview = data.preview
            this.entity.paid_open = 1
        },

        onRemoveFeed() {
            this.$emit('onRemoveFeed', this.feed_id)
        },

        likeFeed() {
            this.$emit('likeFeed')
        },
    },
}
</script>
