1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9585],{19585:function(e,t,n){n.r(t),n.d(t,{TripCommentSection:function(){return m}});var o=n(57437),r=n(1312),a=n(2265),i=n(72903);n(46652);var c=n(45922),l=n(13089),s=n(3663),d=n(5925),u=n(1296);function m(e){var t,n,m,p;let{tripId:f,className:y="",embedded:g=!1,onCountChange:h}=e,{user:b}=(0,l.a)(),[v,x]=(0,a.useState)([]),[S,w]=(0,a.useState)(!0);(0,c.BA)();let _=(0,u.l)(g);(0,a.useEffect)(()=>{null==h||h(S?null:v.reduce((e,t)=>e+1+t.replies.length,0))},[v,S,h]);let C=(0,a.useCallback)(async()=>{try{let e=await fetch("/api/trips/".concat(f,"/comments")),t=await e.json();if(e.ok){let e=t.comments.map(e=>{var t,n,o,r,a;return{userId:e.user_id,comId:e.id,fullName:(null===(t=e.user)||void 0===t?void 0:t.full_name)||"Anonymous",avatarUrl:(null===(n=e.user)||void 0===n?void 0:n.avatar_url)||"https://ui-avatars.com/api/?name=".concat(encodeURIComponent((null===(o=e.user)||void 0===o?void 0:o.full_name)||"User"),"&background=random"),userProfile:"/u/".concat(null===(r=e.user)||void 0===r?void 0:r.username),text:e.content,timestamp:e.created_at,replies:(null===(a=e.replies)||void 0===a?void 0:a.map(e=>{var t,n,o,r;return{userId:e.user_id,comId:e.id,fullName:(null===(t=e.user)||void 0===t?void 0:t.full_name)||"Anonymous",avatarUrl:(null===(n=e.user)||void 0===n?void 0:n.avatar_url)||"https://ui-avatars.com/api/?name=".concat(encodeURIComponent((null===(o=e.user)||void 0===o?void 0:o.full_name)||"User"),"&background=random"),userProfile:"/u/".concat(null===(r=e.user)||void 0===r?void 0:r.username),text:e.content,timestamp:e.created_at,replies:[]}}))||[]}});x(e)}}catch(e){console.error("Error fetching comments:",e),d.default.error("Failed to load comments")}finally{w(!1)}},[f]);(0,a.useEffect)(()=>{C()},[C,f]),(0,s.q)({type:"trip",entityId:f,onCommentAdded:async()=>{await C()},onCommentUpdated:async()=>{await C()},onCommentDeleted:async()=>{await C()},showToasts:!0});let E=async e=>{try{if(e.commentId){d.default.error("Replies are not available for trip comments yet");return}let t=await fetch("/api/trips/".concat(f,"/comments"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e.text})}),n=await t.json();if(!t.ok)throw Error(n.error||"Failed to post comment");d.default.success("Comment posted!"),await C()}catch(e){console.error("Error posting comment:",e),d.default.error(e instanceof Error?e.message:"Failed to post comment")}},k=async e=>{try{if(!(await fetch("/api/trips/comments/".concat(e),{method:"DELETE"})).ok)throw Error("Failed to delete comment");d.default.success("Comment deleted"),await C()}catch(e){console.error("Error deleting comment:",e),d.default.error("Failed to delete comment")}},I=async e=>{try{if(!(await fetch("/api/trips/comments/".concat(e.comId),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e.text})})).ok)throw Error("Failed to edit comment");d.default.success("Comment updated"),await C()}catch(e){console.error("Error editing comment:",e),d.default.error("Failed to edit comment")}};return S?g?(0,o.jsx)("div",{className:"tb-skeleton h-20 rounded-xl",role:"status","aria-label":"Loading comments"}):(0,o.jsx)("div",{className:"flex items-center justify-center py-8 ".concat(y),children:(0,o.jsx)(r.ModernLoader,{size:20})}):(0,o.jsx)("div",{className:"".concat(u.w," ").concat(y).trim(),children:(0,o.jsx)(i.F,{currentUser:b?{currentUserId:b.id,currentUserImg:(null===(t=b.user_metadata)||void 0===t?void 0:t.avatar_url)||"https://ui-avatars.com/api/?name=".concat(encodeURIComponent((null===(n=b.user_metadata)||void 0===n?void 0:n.full_name)||"User"),"&background=random"),currentUserProfile:"/u/".concat(null===(m=b.user_metadata)||void 0===m?void 0:m.username),currentUserFullName:(null===(p=b.user_metadata)||void 0===p?void 0:p.full_name)||"User"}:null,logIn:{onLogin:()=>{window.location.href="/auth/signin?redirect="+encodeURIComponent(window.location.pathname)},signUpLink:"/auth/signup"},commentData:v,onSubmitAction:E,onDeleteAction:e=>k(e.comIdToDelete),onEditAction:I,currentData:e=>{},placeHolder:"Write your comment...",overlayStyle:_.overlayStyle,titleStyle:_.titleStyle,hrStyle:_.hrStyle,formStyle:g?{..._.formStyle,boxShadow:"none"}:_.formStyle,inputStyle:_.inputStyle,replyInputStyle:_.replyInputStyle,submitBtnStyle:g?{..._.submitBtnStyle,background:"#25232C",boxShadow:"none"}:_.submitBtnStyle,cancelBtnStyle:_.cancelBtnStyle,imgStyle:_.imgStyle,customNoComment:()=>g?(0,o.jsx)("p",{className:"py-3 text-sm",style:{color:"rgba(11,31,42,0.65)",textTransform:"none"},children:"No comments yet"}):(0,o.jsx)("div",{className:"text-center py-8 text-gray-500",children:(0,o.jsx)("p",{className:"text-base font-medium",children:"No comments yet"})})})})}},1296:function(e,t,n){n.d(t,{l:function(){return r},w:function(){return o}});let o="travelblogr-comments";function r(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return{overlayStyle:{padding:0,margin:0,background:"transparent",fontFamily:"var(--font-inter), system-ui, sans-serif",color:"#0f172a"},titleStyle:{display:"none"},hrStyle:{display:"none"},formStyle:{display:"flex",alignItems:"center",gap:"12px",background:"#ffffff",border:"1px solid rgba(148, 163,
1184, 0.22)",borderRadius:"20px",padding:"".concat(e?12:14,"px ").concat(e?14:16,"px"),boxShadow:"0 1px 2px rgba(15, 23, 42, 0.04)"},inputStyle:{width:"100%",border:"none",background:"transparent",color:"#0f172a",fontSize:"14px",lineHeight:1.5,padding:0,marginLeft:0,minHeight:"44px",outline:"none"},replyInputStyle:{width:"100%",border:"none",background:"transparent",color:"#0f172a",fontSize:"14px",lineHeight:1.5,padding:0,marginLeft:0,minHeight:"42px",outline:"none"},submitBtnStyle:{borderRadius:"9999px",border:"1px solid #111827",background:"#111827",color:"#ffffff",fontWeight:600,fontSize:"14px",padding:"10px 18px",boxShadow:"0 8px 20px rgba(15, 23, 42, 0.08)"},cancelBtnStyle:{borderRadius:"9999px",border:"1px solid rgba(148, 163, 184, 0.35)",background:"#ffffff",color:"#0f172a",fontWeight:600,fontSize:"14px",padding:"10px 18px"},imgStyle:{width:"40px",height:"40px",borderRadius:"9999px",objectFit:"cover",background:"#e2e8f0"}}}},3663:function(e,t,n){n.d(t,{q:function(){return i}});var o=n(2265),r=n(45922),a=n(5925);function i(e){let{type:t,entityId:n,onCommentAdded:i,onCommentUpdated:c,onCommentDeleted:l,enabled:s=!0,showToasts:d=!0}=e,u=(0,r.getBrowserSupabase)(),m=(0,o.useCallback)(()=>{switch(t){case"trip":return{table:"comments",filterColumn:"trip_id"};case"post":return{table:"comments",filterColumn:"post_id"};case"activity":return{table:"activity_comments",filterColumn:"activity_id"};case"location":return{table:"location_comments",filterColumn:"location_id"};case"blog":return{table:"cms_comments",filterColumn:"post_id"};default:throw Error("Unknown comment type: ".concat(t))}},[t]);(0,o.useEffect)(()=>{if(!s)return;let{table:e,filterColumn:o}=m(),r="".concat(t,":").concat(n,":comments"),p=u.channel(r).on("postgres_changes",{event:"INSERT",schema:"public",table:e,filter:"".concat(o,"=eq.").concat(n)},e=>{i&&i(e.new),d&&a.default.success("New comment added!",{icon:"\uD83D\uDCAC",duration:3e3})}).on("postgres_changes",{event:"UPDATE",schema:"public",table:e,filter:"".concat(o,"=eq.").concat(n)},e=>{c&&c(e.new),d&&a.default.success("Comment updated!",{icon:"âï¸",duration:2e3})}).on("postgres_changes",{event:"DELETE",schema:"public",table:e,filter:"".concat(o,"=eq.").concat(n)},e=>{l&&l(e.old.id),d&&a.default.success("Comment deleted!",{icon:"\uD83D\uDDD1ï¸",duration:2e3})}).subscribe(e=>{"SUBSCRIBED"===e||"CHANNEL_ERROR"===e&&console.error("â Error subscribing to ".concat(r))});return()=>{u.removeChannel(p)}},[t,n,i,c,l,s,d,u,m])}}}]);
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.