import { defineComponent, unref, ref, mergeProps, computed, withAsyncContext, watch, useSSRContext } from 'vue'; import { ssrRenderComponent, ssrRenderAttrs, ssrRenderList, ssrInterpolate, ssrRenderStyle } from 'vue/server-renderer'; import { a as useConfigStore, u as useRouter$1, b as useUserStore, p as useCartStore, _ as __nuxt_component_0, q as useState, t as useRequestEvent, n as useIntersectionObserver, w as getProducts, o as getToken, d as api$1 } from './server.mjs'; import { P as Post, _ as _sfc_main$5 } from './PostCardSkeleton-1I8ZExkN.mjs'; import { C as CommentAddEdit, _ as _sfc_main$6, d as deletePostLike, c as createPostLike } from './moreOptionProduct-COId1EJx.mjs'; import { d as deleteSave, c as createSave } from './save-BM_TzM80.mjs'; import { u as useProductStore } from './product-C6Biv0TJ.mjs'; import { u as useAsyncData } from './asyncData-DGiCewbG.mjs'; import { _ as _export_sfc } from './_plugin-vue_export-helper-1tPrXgE0.mjs'; import { _ as _sfc_main$4 } from './FullScreenStories-BYW2TGy5.mjs'; import { u as useMediaStore } from './media-fadondUH.mjs'; import { U as UserProfilePic } from './UserProfilePic-CBi3ttKR.mjs'; import { _ as __nuxt_component_1 } from './index-CgIEYqpX.mjs'; import '../_/nitro.mjs'; import 'node:http'; import 'node:https'; import 'node:events'; import 'node:buffer'; import 'node:fs'; import 'node:url'; import 'consola'; import 'ipx'; import 'node:path'; import 'node:crypto'; import 'pinia'; import '@supabase/supabase-js'; import '@babel/runtime/helpers/esm/extends'; import '@babel/runtime/helpers/esm/objectSpread2'; import '@ant-design/colors'; import '@ctrl/tinycolor'; import 'stylis'; import 'vue-types'; import 'lodash-es'; import 'axios'; import '@ant-design/icons-vue'; import '../routes/renderer.mjs'; import 'vue-bundle-renderer/runtime'; import 'unhead/server'; import 'devalue'; import 'unhead/utils'; import './empty_user-BaUNCdgf.mjs'; import './useDateTime-D8RCoGwW.mjs'; import 'moment'; import 'moment-timezone'; import 'moment-jalaali'; import 'date-fns'; import 'date-fns/locale'; import 'swiper/vue'; import 'swiper/modules'; import './post_loading-BiySI7bp.mjs'; import './BasicIconOld-93vAWohq.mjs'; import './like-BhIOg3YL.mjs'; import 'vue-content-loader'; import './index-DN7-byVZ.mjs'; import '@vueuse/gesture'; import '@headlessui/vue'; import 'framesync'; import 'popmotion'; import 'style-value-types'; import './BasicButton-BY5Qzukq.mjs'; import './index-DWwHo7-N.mjs'; import 'throttle-debounce'; import './index-xM0P2tPp.mjs'; import 'dom-align'; import './index-DEYBOQNk.mjs'; import './shallowequal-NTdzjvNX.mjs'; import 'lodash-es/uniq.js'; import './index-D4GLYzaN.mjs'; import './FormItemContext-2mj5AJzl.mjs'; import './index-atBrDcKY.mjs'; import 'lodash-es/isPlainObject.js'; import 'resize-observer-polyfill'; import './collapseMotion-cQ2SGjCA.mjs'; import './handle-CbilF0ny.mjs'; import './BasicInput-BLgnaBLz.mjs'; import './usePrice-B-5-jXKQ.mjs'; import './media-TZzDk-n-.mjs'; import '../_/CheckOutlined.mjs'; import './useRefs-BHKrVg4I.mjs'; const _sfc_main$3 = /* @__PURE__ */ defineComponent({ __name: "Posts", __ssrInlineRender: true, props: { userPostScroll: {}, scrollSave: {} }, async setup(__props) { let __temp, __restore; const router = useRouter$1(); const config = useConfigStore(); const posts = ref([]); const total = ref(100); const currentPage = ref(0); const limit = ref(10); const endPage = ref(false); const loading = ref(false); const addLikeLoading = ref(false); const commentPostId = ref(); const commentVisible = ref(false); const optionVisible = ref(false); const optionPostId = ref(); const props = __props; const user = useUserStore(); computed(() => props.userPostScroll === "userPostScroll"); const percent = useProductStore(); ref(null); const reset = () => { endPage.value = false; posts.value = []; total.value = 0; }; function handleLike(isLiked, id) { try { addLikeLoading.value = true; if (getToken()) { if (isLiked) { deletePostLike(id); const index = posts.value.findIndex((x) => x.id === id); posts.value[index]?.likes.splice(posts.value[index].likes?.findIndex((y) => y.user_id === user.user.id)); } else { createPostLike(id); const index = posts.value.findIndex((x) => x.id === id); posts.value[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) { posts.value[posts.value.findIndex((x) => x.id === commentPostId.value)].comments.push({ id }); } function handleSave(isSaved, id) { if (getToken()) { if (isSaved) { deleteSave(id); const index = posts.value.findIndex((x) => x.id === id); posts.value[index]?.saved.splice(posts.value[index].saved?.findIndex((y) => y.user_id === user.user.id)); } else { createSave(id); const index = posts.value.findIndex((x) => x.id === id); posts.value[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) { commentPostId.value = id; commentVisible.value = true; } const request = async (page = 1) => { try { loading.value = true; return await getProducts(page, limit.value); } catch (e) { console.error(e); return { data: [], count: 0 }; } finally { loading.value = false; } }; const isBot = useState("isBot", () => { const event = useRequestEvent(); const ua = event?.node.req.headers["user-agent"] || ""; const bots = ["googlebot", "bingbot", "yandex", "duckduckbot", "baiduspider", "facebot", "slurp"]; console.log(ua.toLowerCase()); return bots.some((bot) => ua.toLowerCase().includes(bot)); }); if (isBot) { const { data } = ([__temp, __restore] = withAsyncContext(() => useAsyncData("posts", async () => { return request(1); })), __temp = await __temp, __restore(), __temp); } else { console.log("real"); } const observer = ref(); useIntersectionObserver(observer, async ([{ isIntersecting }]) => { if (isIntersecting && !loading.value && !endPage.value) { const nextPage = currentPage.value + 1; const res = await request(nextPage); if (res.data?.length) { posts.value.push(...res.data); currentPage.value = nextPage; } if (res.data?.length < limit.value) { endPage.value = true; } } }); computed(() => router.currentRoute.value.query.target || null); const present = computed(() => percent.percentUpload); watch(present, () => { if (present.value == 100) { currentPage.value = 0; reset(); request(); } }); return (_ctx, _push, _parent, _attrs) => { _push(`