import { u as useRouter$1, a as useConfigStore, b as useUserStore, m as useIntersectionObserver, _ as __nuxt_component_0, n as getToken, d as api$1 } from './server.mjs'; import { defineComponent, computed, ref, withAsyncContext, provide, unref, useSSRContext } from 'vue'; import { ssrRenderAttrs, ssrRenderClass, ssrRenderComponent, ssrInterpolate, ssrRenderList, ssrRenderStyle } from 'vue/server-renderer'; import { P as Post, _ as _sfc_main$1 } from './PostCardSkeleton-BfG9M_Aj.mjs'; import { u as useUserPostStore } from './userPostsStore-CAxMlK-n.mjs'; import { C as CommentAddEdit, _ as _sfc_main$2, d as deletePostLike, c as createPostLike } from './moreOptionProduct-DGhUOthE.mjs'; import { d as deleteSave, c as createSave } from './save-6qQTYFWc.mjs'; import { u as useAsyncData } from './asyncData-CZ9BKXPA.mjs'; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "index", __ssrInlineRender: true, async setup(__props) { let __temp, __restore; const router = useRouter$1(); const config = useConfigStore(); const user = useUserStore(); const userId = computed(() => router.currentRoute.value.query.userId); const commentPostId = ref(); const commentVisible = ref(false); const optionVisible = ref(false); const optionPostId = ref(); const ownerPostId = ref(); const addLikeLoading = ref(false); const userPostStore = useUserPostStore(); computed(() => router.currentRoute.value.query.target || null); function handleLike(isLiked, id) { try { addLikeLoading.value = true; if (getToken()) { if (isLiked) { deletePostLike(id); const index = userPostStore.posts?.findIndex((x) => x.id === id); userPostStore.posts[index]?.likes.splice(userPostStore.posts[index]?.likes?.findIndex((y) => y.user_id === user.user.id)); } else { createPostLike(id); const index = userPostStore.posts?.findIndex((x) => x.id === id); userPostStore.posts[index]?.likes.push({ product_id: id, user_id: user.user.id }); } } else { router.push({ name: "auth-login" }); api$1.warn(config.useString("pleaseLoginOrRegister")); } } catch (e) { console.log(e); } finally { addLikeLoading.value = false; } } function addCommentId(id) { userPostStore.posts[userPostStore.posts.findIndex((x) => x.id === commentPostId.value)]?.comments.push({ id }); } function deleteCommentId() { userPostStore.posts[userPostStore.posts.findIndex((x) => x.id === commentPostId.value)]?.comments.splice(0, 1); } const observer = ref(); useIntersectionObserver(observer, async ([{ isIntersecting }]) => { if (isIntersecting && !userPostStore.loading && !userPostStore.endPage) { const nextPage = userPostStore.currentPage + 1; const data2 = await userPostStore.loadPosts(userId.value, nextPage); userPostStore.loadStateNextPage(data2); } }); const { data } = ([__temp, __restore] = withAsyncContext(async () => useAsyncData("productPostMainSeller", async () => { if (userPostStore.posts.length === 0) { return await userPostStore.loadPosts(userId.value, 1); } else { return null; } })), __temp = await __temp, __restore(), __temp); function handleSave(isSaved, id) { if (getToken()) { if (isSaved) { deleteSave(id); const index = userPostStore.posts?.findIndex((x) => x.id === id); userPostStore.posts[index]?.saved.splice(userPostStore.posts[index]?.saved?.findIndex((y) => y.user_id === user.user.id)); } else { createSave(id); const index = userPostStore.posts?.findIndex((x) => x.id === id); userPostStore.posts[index]?.saved.push({ product_id: id, user_id: user.user.id }); } } else { router.push({ name: "auth-login" }); api$1.warn(config.useString("pleaseLoginOrRegister")); } } function openOption(id) { optionPostId.value = id; optionVisible.value = true; } function openComment(id, owner_id) { commentPostId.value = id; commentVisible.value = true; ownerPostId.value = owner_id; } provide("ownerPostId", ownerPostId); return (_ctx, _push, _parent, _attrs) => { const _component_ClientOnly = __nuxt_component_0; _push(`
`); _push(ssrRenderComponent(_component_ClientOnly, null, {}, _parent)); _push(`
${ssrInterpolate(unref(config).sellerConfig?.store?.username)}
`); ssrRenderList(unref(userPostStore).posts, (post, index) => { _push(`
`); _push(ssrRenderComponent(Post, { index, post, onOpenOption: openOption, onOpenComment: openComment, onHandleLike: handleLike, onHandleSave: handleSave, "scroll-save": "scrollPositionSeller", "add-like-loading": addLikeLoading.value }, null, _parent)); _push(`
`); }); _push(``); if (unref(userPostStore).loading) { _push(ssrRenderComponent(_sfc_main$1, null, null, _parent)); } else { _push(``); } _push(`
load
`); _push(ssrRenderComponent(CommentAddEdit, { id: commentPostId.value, open: commentVisible.value, "onUpdate:open": ($event) => commentVisible.value = $event, onAddCommentId: addCommentId, onDeleteCommentId: deleteCommentId }, null, _parent)); _push(ssrRenderComponent(_sfc_main$2, { id: optionPostId.value, open: optionVisible.value, "onUpdate:open": ($event) => optionVisible.value = $event }, null, _parent)); _push(``); }; } }); const _sfc_setup = _sfc_main.setup; _sfc_main.setup = (props, ctx) => { const ssrContext = useSSRContext(); (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("views/base/pages/user/userMain/posts/index.vue"); return _sfc_setup ? _sfc_setup(props, ctx) : void 0; }; export { _sfc_main as _ };