1import{r as n,j as e,es as _}from"./main-Bo0oayNO.js";import{d as q,e as U,h as Y}from"./ui-utils-CNoARbDA.js";function P({postId:t,parentId:s,currentUserId:c,onSubmit:m,isSubmitting:u=!1,isReply:l=!1,turnstileEnabled:b=!1,turnstileSiteKey:d=""}){const[x,N]=n.useState(""),[h,f]=n.useState(""),[p,C]=n.useState(""),[g,a]=n.useState(""),[i,r]=n.useState(null),[A,S]=n.useState(!1),[w,k]=n.useState(null),[I,$]=n.useState(!1),y=n.useRef(null),E=n.useRef(null),R=!c,j=!!(b&&d);n.useEffect(()=>{if(!j)return;if(window.turnstile){$(!0);return}if(document.querySelector('script[src*="turnstile"]')){const F=setInterval(()=>{window.turnstile&&($(!0),clearInterval(F))},100);return()=>clearInterval(F)}const v=document.createElement("script");return v.src="https://challenges.cloudflare.com/turnstile/v0/api.js",v.async=!0,v.onload=()=>{$(!0)},document.head.appendChild(v),()=>{}},[j]),n.useEffect(()=>{if(!(!j||!I||!E.current)&&window.turnstile){if(y.current)try{window.turnstile.remove(y.current)}catch{}return y.current=window.turnstile.render(E.current,{sitekey:d,callback:o=>{k(o)},"expired-callback":()=>{k(null)},"error-callback":()=>{k(null),r("Security check failed. Please refresh and try again.")},theme:"auto"}),()=>{if(y.current&&window.turnstile){try{window.turnstile.remove(y.current)}catch{}y.current=null}}}},[j,I,d]);const T=()=>{y.current&&window.turnstile&&(window.turnstile.reset(y.current),k(null))},W=async o=>{if(o.preventDefault(),r(null),S(!1),!x.trim()){r("Please enter a comment.");return}if(R){if(!h.trim()){r("Please enter your name.");return}if(!p.trim()){r("Please enter your email.");return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p)){r("Please enter a valid email address.");return}}if(j&&!w){r("Please complete the security check.");return}const v=await m({content:x.trim(),...R&&{authorName:h.trim(),authorEmail:p.trim(),authorUrl:g.trim()||void 0},...j&&w&&{turnstileToken:w}});v.success?(N(""),S(!0),T()):(r(v.error||"Failed to submit comment."),T())};return e.jsxs("form",{onSubmit:W,className:"space-y-4",children:[i&&e.jsx("div",{className:"p-3 bg-red-50 border border-red-200 text-red-700 text-sm rounded-lg",children:i}),A&&e.jsxs("div",{className:"p-3 bg-green-50 border border-green-200 text-green-700 text-sm rounded-lg",children:[l?"Reply":"Comment"," submitted successfully! It will appear after moderation."]}),R&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:`name-${s||"root"}`,className:"block text-sm font-medium text-gray-700 mb-1",children:["Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",id:`name-${s||"root"}`,value:h,onChange:o=>f(o.target.value),className:"input w-full",placeholder:"Your name",required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:`email-${s||"root"}`,className:"block text-sm font-medium text-gray-700 mb-1",children:["Email ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"email",id:`email-${s||"root"}`,value:p,onChange:o=>C(o.target.value),className:"input w-full",placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsxs("label",{htmlFor:`url-${s||"root"}`,className:"block text-sm font-medium text-gray-700 mb-1",children:["Website ",e.jsx("span",{className:"text-gray-400",children:"(optional)"})]}),e.jsx("input",{type:"url",id:`url-${s||"root"}`,value:g,onChange:o=>a(o.target.value),className:"input w-full",placeholder:"https://your-website.com"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:`comment-${s||"root"}`,className:"block text-sm font-medium text-gray-700 mb-1",children:[l?"Your Reply":"Your Comment"," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("textarea",{id:`comment-${s||"root"}`,value:x,onChange:o=>N(o.target.value),rows:l?3:5,className:"input w-full resize-y",placeholder:l?"Write your reply...":"Write your comment...",required:!0})]}),j&&e.jsx("div",{ref:E,className:"flex justify-start"}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"submit",disabled:u||j&&!w,className:"btn-primary",children:u?"Submitting...":l?"Post Reply":"Post Comment"})}),e.jsx("p",{className:"text-xs text-gray-500",children:"All comments are moderated and will appear after approval."})]})}function z(t){return t.replace(/<\/?(?!(?:a|br|strong|em|b|i|p|code)\b)[^>]*>/gi,"")}function L({comment:t,depth:s=0,maxDepth:c=3,currentUserId:m,onReplySubmit:u,turnstileEnabled:l=!1,turnstileSiteKey:b=""}){const[d,x]=n.useState(!1),[N,h]=n.useState(!1),f=q(t),p=t.authorEmail==="[email protected]",C=()=>p?e.jsx("img",{src:"/uploads/jeff-harvie-migration-agent-150x150.jpg",alt:"Jeff Harvie",className:"w-full h-full object-cover"}):t.author?.avatarUrl?e.jsx("img",{src:t.author.avatarUrl,alt:f,className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-sm font-medium text-gray-600",children:Y(f)}),g=async i=>{h(!0);const r=await u({...i,parentId:t.id});return h(!1),r.success&&x(!1),r},a=s<c;return e.jsxs("div",{className:`${s>0?"ml-8 border-l-2 border-gray-100 pl-4":""}`,children:[e.jsxs("div",{className:"flex gap-3 py-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"w-10 h-10 rounded-full bg-gray-200 flex items-center justify-center overflow-hidden",children:C()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-gray-900",children:f}),t.author&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-sm text-xs font-medium bg-primary-100 text-primary-800",children:"Member"}),e.jsx("span",{className:"text-gray-500 text-sm",children:U(t.createdAt)})]}),e.jsx("div",{className:"mt-2 text-gray-700 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:z(t.content)}}),a&&e.jsx("div",{className:"mt-3",children:e.jsx("button",{type:"button",onClick:()=>x(!d),className:"text-sm text-primary-600 hover:text-primary-700 font-medium",children:d?"Cancel":"Reply"})}),d&&e.jsx("div",{className:"mt-4",children:e.jsx(P,{postId:t.postId,parentId:t.id,currentUserId:m,onSubmit:g,isSubmitting:N,isReply:!0,turnstileEnabled:l,turnstileSiteKey:b})})]})]}),t.replies.length>0&&e.jsx("div",{className:"space-y-0",children:t.replies.map(i=>e.jsx(L,{comment:i,depth:s+1,maxDepth:c,currentUserId:m,onReplySubmit:u,turnstileEnabled:l,turnstileSiteKey:b},i.id))})]})}function H({comments:t,currentUserId:s,onReplySubmit:c,turnstileEnabled:m=!1,turnstileSiteKey:u=""}){return t.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500",children:e.jsx("p",{children:"No comments yet. Be the first to comment!"})}):e.jsx("div",{className:"divide-y divide-gray-100",children:t.map(l=>e.jsx(L,{comment:l,currentUserId:s,onReplySubmit:c,turnstileEnabled:m,turnstileSiteKey:u},l.id))})}function B({postId:t,comments:s,currentUserId:c,commentsEnabled:m=!0,turnstileEnabled:u=!1,turnstileSiteKey:l=""}){const[b,d]=n.useState(s),[x,N]=n.useState(!1),h=()=>({userAgent:typeof navigator<"u"?navigator.userAgent:null}),f=async a=>{N(!0);try{const i=h(),r=await _({data:{postId:t,content:a.content,parentId:a.parentId||null,authorId:c||null,authorName:a.authorName||null,authorEmail:a.authorEmail||null,authorUrl:a.authorUrl||null,userAgent:i.userAgent,turnstileToken:a.turnstileToken}});return r.success?{success:!0}:{success:!1,error:r.error}}catch{return{success:!1,error:"An error occurred while submitting your comment."}}finally{N(!1)}},p=async a=>f(a),C=async a=>f(a);if(!m)return e.jsxs("section",{className:"mt-12 border-t border-gray-200 pt-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Comments"}),e.jsx("p",{className:"text-gray-500",children:"Comments are disabled for this post."})]});const g=b.reduce((a,i)=>{const r=A=>1+A.replies.reduce((S,w)=>S+r(w),0);return a+r(i)},0);return e.jsxs("section",{className:"mt-12 border-t border-gray-200 pt-8",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-6",children:g===0?"Comments":`${g} Comment${g===1?"":"s"}`}),e.jsx(H,{comments:b,currentUserId:c,onReplySubmit:C,turnstileEnabled:u,turnstileSiteKey:l}),e.jsxs("div",{className:"mt-8 border-t border-gray-200 pt-8",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Leave a Comment"}),e.jsx(P,{postId:t,currentUserId:c,onSubmit:p,isSubmitting:x,turnstileEnabled:u,turnstileSiteKey:l})]})]})}export{B as C};
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.