1import{u as w,b as G,r as c,j as t,T as x,G as f,a5 as P,l as d,t as p}from"./app-YI4vRmAj.js";import{C as H}from"./confirm-dialog-BKlSuO4r.js";import{PostAuthorAvatar as q}from"./Avatar-D1WzsYUG.js";import{CommentThread as B}from"./CommentThread-DvKaCrbD.js";import{ImageLightbox as J}from"./ImageLightbox-DiF_6RXR.js";import{PostEditor as K}from"./PostEditor-7MpXqV4D.js";import{g as Q}from"./routes-BoX--Bko.js";import{f as W}from"./CommentItem-C472JAMH.js";import{P as S,a as X}from"./pin-Cp2lYxsv.js";import{P as Y}from"./pencil-BlF7qnxq.js";import{T as Z}from"./trash-2-CseZ6fmJ.js";import{M as U,r as I}from"./index-BnJIWtcL.js";import{H as ee}from"./heart-C4T4HVR0.js";import{M as te}from"./message-circle-DTQWTzDe.js";/* empty css */import"./dialog-CLERLtaA.js";import"./index-M0e1w8uf.js";import"./index-BRraZams.js";import"./CommentComposer-Bl07bd7d.js";import"./file-upload-DDPGxr9b.js";import"./popover-_-U4HIEO.js";import"./input-Beo_GdVg.js";import"./switch-vY9jX7TO.js";import"./index-SsixNrS0.js";import"./spinner-BbIBb2jV.js";import"./video-kOOaMhNc.js";import"./sortable.esm-BrjVDNU6.js";import"./modifiers.esm-CkFkXmzQ.js";import"./tiny-invariant-CopsF_GD.js";import"./fieldset-Bn07QR3Z.js";import"./skeleton-BAcwO16Q.js";import"./tabs-INlGWDZx.js";import"./index-CN8IXT_E.js";import"./lightweight-confirm-dialog-H0BCd8Wg.js";import"./download-B5lrRegq.js";import"./play-DV1k8Blz.js";import"./file-CIFQrLUk.js";import"./image-DolMJVIY.js";import"./search-CrP0_A7-.js";import"./film-CcFClu40.js";import"./reply-CQxYWC_l.js";function Je({post:e,creatorUsername:n,communityId:a,currentCustomerId:s,isPreview:m=!1,onPostUpdated:i,onPostDeleted:g}){const{t:r}=w(),L=G(["language"]).getLanguage()??"de",[N,E]=c.useState(!1),[v,h]=c.useState(!1),[C,T]=c.useState(!1),y=c.useRef(!1),_=c.useRef(!1),b=c.useRef(!1),u=c.useMemo(()=>Q(m),[m]),j=m?e.author.is_creator&&s!==null&&e.author.id===s:s!==null&&!e.author.is_creator&&e.author.id===s,k=m;async function D(){if(y.current)return;y.current=!0;const o=e.liked_by_me;i({...e,liked_by_me:!o,like_count:Math.max(0,e.like_count+(o?-1:1))});try{const l={creator:n,community:a,post:e.id},R=o?u.postsLikeDestroy(l):u.postsLikeStore(l),{data:M}=await(o?d.delete(R):d.post(R));i({...e,liked_by_me:M.liked,like_count:M.like_count})}catch{i(e),p.error(r("customer.community.post.like_error","Could not update like."))}finally{y.current=!1}}async function V(o){if(!C){T(!0);try{const{data:l}=await d.put(u.postsUpdate({creator:n,community:a,post:e.id}),{body:o.body,media:o.media,remove_media:o.removeMedia});i(l.post),h(!1),p.success(r("customer.community.post.update_success","Post updated"))}catch{p.error(r("customer.community.post.update_error","Could not update post."))}finally{T(!1)}}}async function z(){if(_.current)return;const o=e.is_pinned?u.postsUnpin({creator:n,community:a,post:e.id}):u.postsPin({creator:n,community:a,post:e.id});if(o!==null){_.current=!0;try{const{data:l}=await(e.is_pinned?d.delete(o):d.post(o));i(l.post),p.success(e.is_pinned?r("customer.community.post.unpin_success","Post unpinned"):r("customer.community.post.pin_success","Post pinned"))}catch{p.error(r("customer.community.post.pin_error","Could not update pin state."))}finally{_.current=!1}}}function F(o){i({...e,comment_count:Math.max(0,e.comment_count+o)})}function O(){if(m||!e.has_unread_comments||b.current)return;const o=u.postsMarkRead({creator:n,community:a,post:e.id});o!==null&&(b.current=!0,i({...e,has_unread_comments:!1}),d.post(o).catch(()=>{b.current=!1}))}function $(){E(o=>{const l=!o;return l&&O(),l})}async function A(){try{await d.delete(u.postsDestroy({creator:n,community:a,post:e.id})),g(e.id),p.success(r("customer.community.post.delete_success","Post deleted"))}catch{p.error(r("customer.community.post.delete_error","Could not delete post."))}}return t.jsxs("article",{id:`post-${e.id}`,className:"flex scroll-mt-20 items-start gap-3",children:[t.jsx(q,{displayName:e.author.display_name,initials:e.author.initials,profilePicture:e.author.profile_picture,colorIndex:e.author.color_index,isCreator:e.author.is_creator,isFormer:e.author.is_former,size:40}),t.jsxs("div",{className:"min-w-0 flex-1 rounded-xl border border-gray-100 bg-white p-4 shadow-[0px_1px_2px_0px_hsla(0,0%,0%,0.04)] sm:p-5",children:[t.jsxs("header",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[t.jsx("span",{className:f("font-semibold",e.author.is_former?"italic text-muted-foreground":"text-gray-900"),children:e.author.is_former?t.jsx(x,{keyName:"customer.community.former_member",defaultValue:"Former member"}):e.author.display_name||t.jsx(x,{keyName:"customer.community.post.unknown_author",defaultValue:"Unknown member"})}),e.author.is_creator&&t.jsx(P,{variant:"secondary",className:"text-xs",children:t.jsx(x,{keyName:"customer.community.post.creator_badge",defaultValue:"Creator"})}),e.is_pinned&&t.jsxs(P,{variant:"outline",className:"border-amber-200 bg-amber-50 text-[11px] text-amber-700",children:[t.jsx(S,{className:"mr-1 h-3 w-3 fill-current"}),t.jsx(x,{keyName:"customer.community.post.pinned_badge",defaultValue:"Pinned"})]}),t.jsx("span",{className:"text-xs text-muted-foreground",children:e.created_at?`· ${W(e.created_at,r,L)}`:""}),e.edited_at&&t.jsxs("span",{className:"text-xs text-muted-foreground",children:["·"," ",t.jsx(x,{keyName:"customer.community.post.edited",defaultValue:"edited"})]}),!v&&(j||k)&&t.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[k&&t.jsx("button",{type:"button",onClick:z,"aria-label":e.is_pinned?r("customer.community.post.unpin","Unpin"):r("customer.community.post.pin","Pin"),title:e.is_pinned?r("customer.community.post.unpin","Unpin"):r("customer.community.post.pin","Pin"),className:f("rounded-full p-1.5 transition",e.is_pinned?"text-amber-600 hover:bg-amber-50":"text-muted-foreground hover:bg-gray-100 hover:text-gray-900"),children:e.is_pinned?t.jsx(X,{className:"h-4 w-4"}):t.jsx(S,{className:"h-4 w-4"})}),j&&t.jsx("button",{type:"button",onClick:()=>h(!0),"aria-label":r("customer.community.post.edit","Edit"),className:"rounded-full p-1.5 text-muted-foreground transition hover:bg-gray-100 hover:text-gray-900",children:t.jsx(Y,{className:"h-4 w-4"})}),(j||k)&&t.jsx(H,{title:r("customer.community.post.delete_title","Delete post?"),description:r("customer.community.post.delete_confirm","This post and all of its comments will be permanently removed."),confirmText:r("customer.community.post.delete","Delete"),onConfirm:A,trigger:t.jsx("button",{type:"button","aria-label":r("customer.community.post.delete","Delete"),className:"rounded-full p-1.5 text-muted-foreground transition hover:bg-gray-100 hover:text-red-600",children:t.jsx(Z,{className:"h-4 w-4"})})})]})]}),v?t.jsx(K,{initialBody:e.body,existingMedia:e.media,creatorUsername:n,communityId:a,saving:C,isPreview:m,onCancel:()=>h(!1),onSave:V}):e.body!==""&&t.jsx("div",{className:"prose prose-sm mt-2 max-w-none break-words text-gray-800 [&_a]:break-words [&_a]:text-blue-600 [&_a]:underline [&_a:hover]:text-blue-700 [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-gray-900 [&_pre]:p-3 [&_pre]:text-gray-100 [&_code]:rounded [&_code]:bg-gray-100 [&_code]:px-1 [&_code]:py-0.5",children:t.jsx(U,{remarkPlugins:[I],children:e.body})}),e.media&&t.jsx(oe,{media:e.media}),t.jsx(re,{likedByMe:e.liked_by_me,likeCount:e.like_count,commentCount:e.comment_count,hasUnreadComments:e.has_unread_comments,showComments:N,onToggleLike:D,onToggleComments:$}),N&&t.jsx(B,{postId:e.id,creatorUsername:n,communityId:a,currentCustomerId:s,isPreview:m,onCountChange:F})]})]})}function re({likedByMe:e,likeCount:n,commentCount:a,hasUnreadComments:s,showComments:m,onToggleLike:i,onToggleComments:g}){const{t:r}=w();return t.jsxs("div",{className:"mt-3 flex items-center gap-1",children:[t.jsxs("button",{type:"button",onClick:i,"aria-pressed":e,"aria-label":e?r("customer.community.post.unlike","Unlike"):r("customer.community.post.like","Like"),className:f("inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium transition",e?"text-rose-600 hover:bg-rose-50":"text-muted-foreground hover:bg-gray-100 hover:text-gray-900"),children:[t.jsx(ee,{className:f("h-3.5 w-3.5",e&&"fill-current")}),t.jsx("span",{children:n})]}),t.jsxs("button",{type:"button",onClick:g,"aria-expanded":m,className:f("relative inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium transition",s?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground hover:bg-gray-100 hover:text-gray-900"),children:[t.jsx("span",{className:"relative inline-flex","aria-label":s?r("customer.community.post.unread_comments","New comments"):void 0,children:t.jsx(te,{className:"h-3.5 w-3.5"})}),t.jsx("span",{children:a}),s&&t.jsx("span",{className:"sr-only",children:t.jsx(x,{keyName:"customer.community.post.unread_comments",defaultValue:"New comments"})})]})]})}function oe({media:e}){const{t:n}=w(),[a,s]=c.useState(!1);if(e.type==="image"){const m=e.srcset.map(i=>`${i.url} ${i.width}w`).join(", ");return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>s(!0),"aria-label":n("customer.community.post.open_image","Open image full size"),className:"mt-4 block w-full overflow-hidden rounded-lg border border-gray-100 bg-gray-50 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2",children:t.jsx("img",{src:e.url,srcSet:m,sizes:"(max-width: 640px) 100v
1w, (max-width: 1024px) 640px, 720px",alt:"",loading:"lazy",className:"mx-auto block max-h-[520px] w-auto max-w-full object-contain"})}),t.jsx(J,{open:a,onOpenChange:s,src:e.full_url})]})}return t.jsx("div",{className:"mt-4 aspect-video overflow-hidden rounded-lg border border-gray-100 bg-black",children:t.jsx("iframe",{src:e.url,title:"Video",loading:"lazy",sandbox:"allow-scripts allow-same-origin allow-presentation allow-popups",allow:"accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture",allowFullScreen:!0,className:"h-full w-full"})})}export{Je as PostCard};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.