{"version":3,"file":"LikeSection-BUY3_ffV.mjs","names":[],"sources":["../src/components/display/comments/like/LikeSection.vue","../src/components/display/comments/like/LikeSection.vue"],"sourcesContent":["<template>\n  <div class=\"d-flex align-items-center mt-1\">\n    <CheckIdentityModal\n      v-if=\"isCheckIdentityActions\"\n      :title=\"t('Welcome, thanks for your interaction')\"\n      @validate=\"likeActions(isCheckIdentityActions)\"\n      @close=\"isCheckIdentityActions = undefined\"\n    />\n    <template v-for=\"section in feelingSection\" :key=\"section.name\">\n      <template v-if=\"section.condition\">\n        <LikeButton\n          :like=\"'like' === section.name\"\n          :is-active=\"section.name === userFeeling\"\n          :can-interact=\"canLikeOrDislike\"\n          @like-action=\"initiateLikeActions\"\n        />\n        <span v-if=\"section.counter\" class=\"ms-1 me-2\">{{\n          transformInThousands(section.counter)\n        }}</span>\n      </template>\n    </template>\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { defineAsyncComponent, Ref, ref, computed, onBeforeMount } from \"vue\";\nimport classicApi from \"../../../../api/classicApi\";\nimport { useCommentStore } from \"../../../../stores/CommentStore\";\nimport { useAuthStore } from \"../../../../stores/AuthStore\";\nimport {\n  CommentFeelings,\n  CommentPodcast,\n} from \"@/stores/class/general/comment\";\nimport { CommentsConfig } from \"@/stores/class/config/commentsConfig\";\nimport { Podcast } from \"@/stores/class/general/podcast\";\nimport { useI18n } from \"vue-i18n\";\nconst CheckIdentityModal = defineAsyncComponent(\n  () => import(\"../modal/CheckIdentityModal.vue\"),\n);\nconst LikeButton = defineAsyncComponent(() => import(\"./LikeButton.vue\"));\n\n//Props \nconst props = defineProps({\n  comment: { default: () => undefined, type: Object as () => CommentPodcast },\n  editRight: { default: false, type: Boolean },\n  podcast: { default: undefined, type: Object as () => Podcast },\n})\n\n//Emits\nconst emit = defineEmits([\"deleteComment\", \"update:comment\"]);\n\n//Data \nconst isCheckIdentityActions: Ref<string | undefined> = ref(undefined);\nconst userFeeling: Ref<string | undefined> = ref(undefined);\nconst config: Ref<CommentsConfig | undefined> = ref(undefined);\nconst podcastFeeling: Ref<CommentFeelings | undefined> = ref(undefined);\n\n\n//Composables\nconst { t } = useI18n();\nconst authStore = useAuthStore();\nconst commentStore = useCommentStore();\n\n//Computed\nconst configToApply = computed(() => {\n  if (props.comment) {\n    return config.value?.commentLikes;\n  }\n  return config.value?.podcastLikes;\n});\nconst podcastId = computed(() =>  props.podcast?.podcastId ?? 0);\nconst feelingSection = computed(() => {\n  return [\n    {\n      name: \"like\",\n      counter: props.comment?.likes ?? podcastFeeling.value?.likesCount,\n      condition: configToApply.value?.likeEnabled ?? false,\n    },\n    {\n      name: \"dislike\",\n      counter: props.editRight\n        ? (props.comment?.dislikes ?? podcastFeeling.value?.dislikesCount)\n        : 0,\n      condition: configToApply.value?.dislikeEnabled ?? false,\n    },\n  ];\n});\nconst canLikeOrDislike = computed(() => {\n  return (\n    !configToApply.value?.authRequired ||\n    (configToApply.value.authRequired && undefined !== authStore.authOrgaId)\n  );\n});\n\nonBeforeMount(()=>initLikeConfig())\n\n\n//Methods\nasync function initLikeConfig() {\n  if (!props.podcast) {\n    return;\n  }\n  config.value = await commentStore.getCommentsConfig(props.podcast);\n  if (\n    props.comment ||\n    (!config.value.podcastLikes.likeEnabled &&\n      !config.value.podcastLikes.dislikeEnabled)\n  ) {\n    return;\n  }\n  await fetchPodcastCounters();\n}\nasync function fetchPodcastCounters() {\n  const data = await classicApi.fetchData<{\n    [key: number]: CommentFeelings;\n  }>({\n    api: 2,\n    path: \"podcast/status\",\n    parameters: {\n      podcastId: [podcastId.value],\n      uuid: commentStore.commentUser?.uuid,\n    },\n    isNotAuth: true,\n  });\n  podcastFeeling.value = data[podcastId.value];\n  if (\"LIKED\" === podcastFeeling.value.feeling) {\n    userFeeling.value = \"like\";\n  } else if (\"DISLIKED\" === podcastFeeling.value.feeling) {\n    userFeeling.value = \"dislike\";\n  }\n}\nfunction transformInThousands(nb: number) {\n  if (nb >= 1000) {\n    return Math.round(nb / 100) / 10 + \"k\";\n  }\n  return nb.toString();\n}\nasync function initiateLikeActions(actionName: string) {\n  if (!commentStore.commentUser?.name) {\n    isCheckIdentityActions.value = actionName;\n    return;\n  }\n  likeActions(actionName);\n}\nasync function likeActions(actionName: string) {\n  const prefix = props.comment ? \"comment/\" : \"podcast/\";\n  const data = await classicApi.putData<{\n    [key: number]: CommentFeelings;\n  }>({\n    api: 2,\n    path: prefix + actionName,\n    dataToSend: {\n      ids: [props.comment?.commentId ?? podcastId.value],\n      name: commentStore.commentUser?.name,\n      uuid: commentStore.commentUser?.uuid,\n    },\n    isNotAuth: true,\n  });\n  if (props.comment) {\n    emit(\"update:comment\", {\n      ...props.comment,\n      ...{\n        likes: data[props.comment.commentId].likesCount,\n        dislikes: data[props.comment.commentId].dislikesCount,\n      },\n    });\n  } else {\n    podcastFeeling.value = data[podcastId.value];\n  }\n  userFeeling.value = userFeeling.value ? undefined : actionName;\n  isCheckIdentityActions.value = undefined;\n}\n</script>\n","<template>\n  <div class=\"d-flex align-items-center mt-1\">\n    <CheckIdentityModal\n      v-if=\"isCheckIdentityActions\"\n      :title=\"t('Welcome, thanks for your interaction')\"\n      @validate=\"likeActions(isCheckIdentityActions)\"\n      @close=\"isCheckIdentityActions = undefined\"\n    />\n    <template v-for=\"section in feelingSection\" :key=\"section.name\">\n      <template v-if=\"section.condition\">\n        <LikeButton\n          :like=\"'like' === section.name\"\n          :is-active=\"section.name === userFeeling\"\n          :can-interact=\"canLikeOrDislike\"\n          @like-action=\"initiateLikeActions\"\n        />\n        <span v-if=\"section.counter\" class=\"ms-1 me-2\">{{\n          transformInThousands(section.counter)\n        }}</span>\n      </template>\n    </template>\n  </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { defineAsyncComponent, Ref, ref, computed, onBeforeMount } from \"vue\";\nimport classicApi from \"../../../../api/classicApi\";\nimport { useCommentStore } from \"../../../../stores/CommentStore\";\nimport { useAuthStore } from \"../../../../stores/AuthStore\";\nimport {\n  CommentFeelings,\n  CommentPodcast,\n} from \"@/stores/class/general/comment\";\nimport { CommentsConfig } from \"@/stores/class/config/commentsConfig\";\nimport { Podcast } from \"@/stores/class/general/podcast\";\nimport { useI18n } from \"vue-i18n\";\nconst CheckIdentityModal = defineAsyncComponent(\n  () => import(\"../modal/CheckIdentityModal.vue\"),\n);\nconst LikeButton = defineAsyncComponent(() => import(\"./LikeButton.vue\"));\n\n//Props \nconst props = defineProps({\n  comment: { default: () => undefined, type: Object as () => CommentPodcast },\n  editRight: { default: false, type: Boolean },\n  podcast: { default: undefined, type: Object as () => Podcast },\n})\n\n//Emits\nconst emit = defineEmits([\"deleteComment\", \"update:comment\"]);\n\n//Data \nconst isCheckIdentityActions: Ref<string | undefined> = ref(undefined);\nconst userFeeling: Ref<string | undefined> = ref(undefined);\nconst config: Ref<CommentsConfig | undefined> = ref(undefined);\nconst podcastFeeling: Ref<CommentFeelings | undefined> = ref(undefined);\n\n\n//Composables\nconst { t } = useI18n();\nconst authStore = useAuthStore();\nconst commentStore = useCommentStore();\n\n//Computed\nconst configToApply = computed(() => {\n  if (props.comment) {\n    return config.value?.commentLikes;\n  }\n  return config.value?.podcastLikes;\n});\nconst podcastId = computed(() =>  props.podcast?.podcastId ?? 0);\nconst feelingSection = computed(() => {\n  return [\n    {\n      name: \"like\",\n      counter: props.comment?.likes ?? podcastFeeling.value?.likesCount,\n      condition: configToApply.value?.likeEnabled ?? false,\n    },\n    {\n      name: \"dislike\",\n      counter: props.editRight\n        ? (props.comment?.dislikes ?? podcastFeeling.value?.dislikesCount)\n        : 0,\n      condition: configToApply.value?.dislikeEnabled ?? false,\n    },\n  ];\n});\nconst canLikeOrDislike = computed(() => {\n  return (\n    !configToApply.value?.authRequired ||\n    (configToApply.value.authRequired && undefined !== authStore.authOrgaId)\n  );\n});\n\nonBeforeMount(()=>initLikeConfig())\n\n\n//Methods\nasync function initLikeConfig() {\n  if (!props.podcast) {\n    return;\n  }\n  config.value = await commentStore.getCommentsConfig(props.podcast);\n  if (\n    props.comment ||\n    (!config.value.podcastLikes.likeEnabled &&\n      !config.value.podcastLikes.dislikeEnabled)\n  ) {\n    return;\n  }\n  await fetchPodcastCounters();\n}\nasync function fetchPodcastCounters() {\n  const data = await classicApi.fetchData<{\n    [key: number]: CommentFeelings;\n  }>({\n    api: 2,\n    path: \"podcast/status\",\n    parameters: {\n      podcastId: [podcastId.value],\n      uuid: commentStore.commentUser?.uuid,\n    },\n    isNotAuth: true,\n  });\n  podcastFeeling.value = data[podcastId.value];\n  if (\"LIKED\" === podcastFeeling.value.feeling) {\n    userFeeling.value = \"like\";\n  } else if (\"DISLIKED\" === podcastFeeling.value.feeling) {\n    userFeeling.value = \"dislike\";\n  }\n}\nfunction transformInThousands(nb: number) {\n  if (nb >= 1000) {\n    return Math.round(nb / 100) / 10 + \"k\";\n  }\n  return nb.toString();\n}\nasync function initiateLikeActions(actionName: string) {\n  if (!commentStore.commentUser?.name) {\n    isCheckIdentityActions.value = actionName;\n    return;\n  }\n  likeActions(actionName);\n}\nasync function likeActions(actionName: string) {\n  const prefix = props.comment ? \"comment/\" : \"podcast/\";\n  const data = await classicApi.putData<{\n    [key: number]: CommentFeelings;\n  }>({\n    api: 2,\n    path: prefix + actionName,\n    dataToSend: {\n      ids: [props.comment?.commentId ?? podcastId.value],\n      name: commentStore.commentUser?.name,\n      uuid: commentStore.commentUser?.uuid,\n    },\n    isNotAuth: true,\n  });\n  if (props.comment) {\n    emit(\"update:comment\", {\n      ...props.comment,\n      ...{\n        likes: data[props.comment.commentId].likesCount,\n        dislikes: data[props.comment.commentId].dislikesCount,\n      },\n    });\n  } else {\n    podcastFeeling.value = data[podcastId.value];\n  }\n  userFeeling.value = userFeeling.value ? undefined : actionName;\n  isCheckIdentityActions.value = undefined;\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;EAoCA,MAAM,qBAAqB,2BACnB,OAAO,oCACf;EACA,MAAM,aAAa,2BAA2B,OAAO,4BAAmB;EAGxE,MAAM,QAAQ;EAOd,MAAM,OAA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