import{k as I,b as Y,aq as he,y as pe,r as V,Q as Z,j as e,bA as S,aw as xe,aU as J,M as Ee,O as Le,bv as z,bw as O,d as ye,a1 as je,bB as Pe,h as Ce,bC as G,ax as se,a3 as Ge,N as fe,ai as Ie,l as ee,g as Fe,a7 as Ue,a8 as _e,a9 as qe,x as He,m as j,v as R,$ as Ye,aE as $e,n as y,aH as Oe,a6 as ne,aI as Ve,t as B,bD as oe,Z as Ae,au as Se,V as K,av as X,ay as be,X as ce,aC as re,Y as Re,p as Ne,bE as We,bF as Qe,bG as ze,aG as we,U as Ke,bH as le,bI as ue,G as Xe,u as Ze,bh as Je}from"./index-E0AVXOTn.js";import{P as De}from"./index-Dq8xrBOI.js";import{F as de}from"./index.styled-FontnL1c.js";import{u as et,P as tt,a as nt}from"./useBoardConfig-Ce0hVxtU.js";const st=({reply:s,boardNo:r,memberNo:o,categoryNo:u})=>{const{t:n}=I(),{openDialog:c,openAsyncDialog:C}=Y(),{articleNo:g}=he(),{update:i,delete:a}=Te({articleNo:Number(g)||0}),d=o!==void 0&&s.registerNo===o,m=pe(s.registerYmdt).format("YYYY.MM.DD HH:mm:ss"),[l,t]=V.useState(!1),{register:T,handleSubmit:N,watch:h,formState:b}=Z({defaultValues:{content:s.content}}),v=h("content"),p=()=>{t(w=>!w)},F=async w=>{var E;try{const _={articleTitle:w.content.length>50?w.content.slice(0,50):w.content,articleContent:w.content,secreted:s.secreted??!1,postSearchTags:((E=s.tags)==null?void 0:E.filter(q=>typeof q=="string"))||[],...u&&{boardCategoryNo:u}};await i.mutateAsync({boardNo:r,articleNo:s.articleNo,data:_}),c({message:n("댓글이 수정되었습니다.")}),t(!1)}catch{}},U=async()=>{if(await C({type:"confirm",message:n("댓글을 삭제하시겠습니까?"),onConfirmReturnValue:!0,onCloseReturnValue:!1}))try{await a.mutateAsync({boardNo:r,articleNo:s.articleNo}),c({message:n("댓글이 삭제되었습니다.")})}catch{}};return e.jsxs(S.CommentListItem,{children:[e.jsxs(S.Header,{children:[e.jsx(S.AuthorInfo,{children:e.jsx(S.AuthorName,{children:s.memberNickname||s.registerName})}),e.jsx(S.HeaderRight,{children:d&&!l&&e.jsxs(S.ActionButtons,{children:[e.jsx(S.ActionButton,{onClick:p,children:n("수정")}),e.jsx(S.ActionButton,{onClick:U,children:n("삭제")})]})})]}),l?e.jsx(S.EditForm,{onSubmit:N(F),children:e.jsxs(xe,{children:[e.jsx(J,{...T("content",{required:n("댓글 내용을 입력해주세요."),maxLength:{value:500,message:n("댓글은 500자 이하로 입력해주세요.")}}),disabled:b.isSubmitting,maxLength:500,style:{flexGrow:1,height:"80px",maxHeight:"80px",overflowY:"auto",lineHeight:"normal"}}),e.jsxs(S.ButtonContainer,{children:[e.jsx(S.EditButton,{type:"submit",disabled:b.isSubmitting||!v.trim(),children:n("저장")}),e.jsx(S.CancelButton,{type:"button",onClick:p,disabled:b.isSubmitting,children:n("취소")})]})]})}):e.jsx(S.Content,{dangerouslySetInnerHTML:{__html:s.content.replace(/\n/g,"
")}}),e.jsx(S.Date,{children:m})]})},ot=({boardNo:s,articleNo:r,params:o,options:u})=>Ee({queryKey:z.reply(s,r,o),queryFn:async()=>{const{data:n}=await O.getRepliesByBoardNo(s,r,o);return n},placeholderData:Le,...u}),Q={pageSize:10,direction:"DESC"},rt=({boardNo:s,articleNo:r,categoryNo:o})=>{const{t:u}=I(),n=ye(),{openDialog:c,openLoginDialog:C}=Y(),{data:g}=je(),{data:i}=Pe(),[a,d]=Ce(),m=Number(a.get("pageNumber")||1),l={page:m,...Q},{data:t,isLoading:T}=ot({boardNo:s,articleNo:r,params:l}),N=(t==null?void 0:t.items)||[],h=(t==null?void 0:t.totalCount)||0,{register:b}=Te({articleNo:r}),v=V.useMemo(()=>i!=null&&i.boardConfigs?i.boardConfigs.find(f=>f.boardNo===Number(s)):null,[i,s]),p=(v==null?void 0:v.guestPostingUsed)??!1,{handleSubmit:F,reset:U,control:w,formState:E}=Z({defaultValues:{content:""}}),_=async f=>{if(!n&&!p){C();return}try{await b.mutateAsync({boardNo:s,data:{articleTitle:f.content.slice(0,50),articleContent:f.content,parentBoardArticleNo:r,secreted:!1,postSearchTags:[],...o&&{boardCategoryNo:o}}}),c({message:u("댓글이 등록되었습니다.")}),U()}catch{}},q=V.useRef(null);return e.jsxs(G.Container,{children:[e.jsxs(G.CommentContainer,{children:[e.jsx(G.CommentForm,{onSubmit:F(_),children:e.jsx(se,{name:"content",control:w,render:({field:f})=>{var k;return e.jsxs(xe,{children:[e.jsx(J,{placeholder:u("댓글을 입력하세요."),disabled:E.isSubmitting,maxLength:500,style:{flexGrow:1,height:"80px",maxHeight:"80px",overflowY:"auto",lineHeight:"normal"},...f}),e.jsx(G.SubmitButton,{type:"submit",disabled:E.isSubmitting||!((k=f.value)!=null&&k.trim()),children:u("등록")})]})}})}),e.jsxs(G.Title,{ref:q,children:[u("총 댓글")," ",e.jsx("span",{children:h})]}),e.jsx(Ge,{isLoading:T,children:N.length===0?e.jsx(fe,{text:"댓글이 없습니다.",icon:e.jsx(e.Fragment,{}),style:{height:"80px"}}):e.jsx(G.CommentList,{children:N.map(f=>e.jsx(st,{reply:f,boardNo:s,memberNo:g==null?void 0:g.memberNo,categoryNo:o},f.articleNo))})})]}),t&&h>Q.pageSize&&e.jsx(G.PaginationContainer,{children:e.jsx(De,{totalCount:h,currentPage:m,onPageClick:f=>{var k;d(D=>{const A=new URLSearchParams(D);return A.set("pageNumber",f.toString()),A}),(k=q.current)==null||k.scrollIntoView({block:"center"})},pageSize:Q.pageSize})})]})},Te=({articleNo:s})=>{const{t:r}=I(),{openDialog:o}=Y(),u=Ie(),[n]=Ce(),c=i=>{u.invalidateQueries({queryKey:Ue(z.reply(i,s),qe,_e),refetchType:"all"})},C=i=>{u.invalidateQueries({queryKey:z.reply(i,s,{page:Number(n.get("pageNumber"))||1,...Q}),refetchType:"all"})},g=i=>{var a,d;o({message:r(Fe(i)?(d=(a=i.response)==null?void 0:a.data)==null?void 0:d.message:r("알 수 없는 오류가 발생했습니다."))})};return{register:ee({mutationFn:async({boardNo:i,data:a})=>{await O.writeArticle(i,a)},onSuccess:(i,{boardNo:a})=>{c(a)},onError:g}),update:ee({mutationFn:async({boardNo:i,articleNo:a,data:d})=>{await O.updateArticle(i,a,d)},onSuccess:(i,{boardNo:a})=>{C(a)},onError:g}),delete:ee({mutationFn:async({boardNo:i,articleNo:a,data:d})=>{await O.deleteArticle(i,a,d)},onSuccess:(i,{boardNo:a})=>{c(a)},onError:g})}},at=({boardNo:s,articleNo:r,searchParams:o,options:u})=>He({queryKey:z.detail(s,r,o),queryFn:async()=>{const{data:n}=await O.getArticle(s,r,o);return n},...u}),it=j.div(["width:100%;margin:0 auto;","{padding:0 16px;}"],R.SM),ct=j(Ye.div)(["width:100%;overflow:hidden;"]),lt=j.div(["width:100%;",";"," min-height:30vh;line-height:1.4;img{width:100%;line-height:0;object-fit:contain;vertical-align:top;}.contents_pc_on{display:none;}.contents_m_on{display:block;}","{"," .contents_pc_on{display:block;}.contents_m_on{display:none;}}"],$e,y(14),R.SM,y(16)),te={Content:lt,ContentWrapper:ct,Container:it},ut=({contents:s,attachments:r})=>{const{t:o}=I(),u=n=>{ne.open(c=>e.jsx(Ve,{...c,imageUrl:n}))};return e.jsx(te.Container,{children:e.jsx(te.ContentWrapper,{initial:{opacity:0},animate:{opacity:1},transition:{duration:.2},children:s?e.jsxs(e.Fragment,{children:[e.jsx(te.Content,{dangerouslySetInnerHTML:{__html:s.replace(/\n/g,"
")}}),e.jsx(de.ImageList,{children:r.map(n=>e.jsx(de.ImageListItem,{children:e.jsx("button",{onClick:()=>u(n.downloadFileUrl),style:{width:"100%",height:"100%"},children:e.jsx(Oe,{src:n.downloadFileUrl})})},n.downloadFileUrl))})]}):e.jsx(fe,{text:o("상세 내용이 없습니다.")})})})},dt=j.p(["",";line-height:1.5;color:",";","{","}"],y(12),B.darkGray,R.SM,y(14)),mt=j.p(["margin-top:12px;",";line-height:1.5;color:",";","{","}"],y(10),B.darkGray,R.SM,y(12)),gt=j.span(["position:absolute;bottom:8px;right:12px;",";color:",";","{","}"],y(10),B.darkGray,R.SM,y(12)),ht=j.div(["position:relative;"]),P={GuideText:dt,WarningText:mt,CharacterCount:gt,TextAreaContainer:ht},me=[{value:"COPYRIGHT",label:"저작권 침해"},{value:"SLANDER",label:"비방"},{value:"ETC",label:"기타사유"}],pt=({close:s,boardNo:r,articleNo:o,...u})=>{const{t:n}=I(),{openDialog:c}=Y(),{report:C}=oe(),{register:g,control:i,handleSubmit:a,watch:d,formState:{errors:m}}=Z({defaultValues:{reportReasonType:void 0,content:""}}),l=d("content"),t=(l==null?void 0:l.length)||0,T=1e3,N=a(h=>{if(!r||!o){c({message:n("신고할 게시글 정보를 찾을 수 없습니다.")});return}C.mutate({boardNo:r,articleNo:o,data:h},{onSuccess:()=>{s(),c({message:n("신고가 접수되었습니다.")})},onError:()=>{c({message:n("신고 처리에 실패했습니다.")})}})});return e.jsx(Ae,{...u,close:s,width:"500px",title:n("신고하기"),isDeskTopUsable:!0,footerButtonList:[e.jsx(re,{type:"button",onClick:s,children:e.jsx("span",{children:n("취소")})},"cancel"),e.jsx(Re,{type:"submit",onClick:N,children:e.jsx("span",{children:n("등록")})},"submit")],children:e.jsxs(Se.Form,{onSubmit:N,children:[e.jsxs(P.GuideText,{children:[n("신고 사유를 선택해주세요."),e.jsx("br",{}),n("신고 내용은 이용약관 및 정책에 의하여 처리됩니다.")]}),e.jsxs(K,{children:[e.jsx(X,{isRequired:!0,children:n("신고 사유")}),e.jsx(se,{name:"reportReasonType",control:i,rules:{required:n("신고 사유를 선택해 주세요.")},render:({field:{onChange:h,value:b,...v}})=>e.jsx(be,{...v,placeholder:n("사유를 선택해 주세요."),options:me,value:me.find(p=>p.value===b)??null,onChange:p=>{p&&h(p.value)}})}),e.jsx(ce,{name:"reportReasonType",errors:m})]}),e.jsxs(K,{children:[e.jsx(X,{isRequired:!0,children:n("상세 사유")}),e.jsxs(P.TextAreaContainer,{children:[e.jsx(J,{placeholder:n("상세 사유를 입력해 주세요."),...g("content",{required:n("상세 사유를 입력해 주세요.")}),maxLength:T,style:{height:"120px",paddingBottom:"30px"}}),e.jsxs(P.CharacterCount,{children:[t," / ",T]})]}),e.jsx(ce,{name:"content",errors:m})]}),e.jsx(P.WarningText,{children:n("※ 허위 신고일 경우, 신고자의 서비스 활동이 제한될 수 있으니 유의하시어 신중하게 신고해주세요.")})]})})},xt=j(Qe)(["gap:20px;width:100%;padding:20px 20px 0;b{color:",";}","{margin:50px auto 0;gap:50px;padding:0;}"],B.black,R.SM),yt=j(ze)(["display:flex;flex-direction:column;gap:12px;margin:0;padding:16px 0 12px;width:100%;border-bottom:1px solid ",";border-top:2px solid ",";","{padding:20px 0;}"],B.gray,B.black,R.SM),jt=j.h1(["",";",";","{",";}"],y(14),Ne.bold,R.SM,y(18)),Ct=j.p(["",";color:",";> span{line-height:1.6;}","{",";> span{line-height:1.8;}}"],y(12),B.darkGray,R.SM,y(14)),ft=j.div(["min-height:30vh;"]),St=j(re)(["margin:24px auto 0;width:100%;max-width:210px;","{margin:40px auto 0;}"],R.MD),bt=j.div(["display:flex;gap:8px;padding-top:8px;justify-content:flex-end;border-top:1px solid ",";","{gap:12px;padding-top:12px;}"],B.gray,R.SM),Rt=j(we)(["width:auto;padding:5px 0 0 3px;height:fit-content;",";color:",";","{padding:7px 0 0 5px;",";}"],y(12),B.darkGray,R.SM,y(14)),Nt=j(we)(["width:auto;padding:5px 0 0 3px;height:fit-content;",";color:",";"," ","{padding:7px 0 0 5px;",";}"],y(12),({$isRecommended:s})=>s?B.black:B.darkGray,({$isRecommended:s})=>s&&We(["",""],Ne.medium),R.SM,y(14)),M={Container:xt,TitleContainer:yt,Title:jt,Description:Ct,ContentsContainer:ft,BackButton:St,ActionButtonContainer:bt,ActionButton:Rt,RecommendButton:Nt},ge=[{value:"COPYRIGHT",label:"저작권 침해"},{value:"SLANDER",label:"비방"},{value:"ETC",label:"기타사유"}],wt=({...s})=>{const{close:r,boardNo:o,articleNo:u}=s,{t:n}=I(),{openDialog:c}=Y(),{report:C}=oe(),{register:g,control:i,handleSubmit:a,watch:d,formState:{errors:m}}=Z({defaultValues:{reportReasonType:void 0,content:""}}),l=d("content"),t=(l==null?void 0:l.length)||0,T=1e3,N=a(h=>{if(!o||!u){c({message:n("신고할 게시글 정보를 찾을 수 없습니다.")});return}C.mutate({boardNo:o,articleNo:u,data:h},{onSuccess:()=>{r(),c({message:n("신고가 접수되었습니다.")})},onError:()=>{c({message:n("신고 처리에 실패했습니다.")})}})});return e.jsx(Ke,{...s,type:"fullscreen",title:n("신고하기"),children:e.jsxs(le.Container,{children:[e.jsxs(Se.Form,{onSubmit:N,children:[e.jsxs(P.GuideText,{children:[n("신고 사유를 선택해주세요."),e.jsx("br",{}),n("신고 내용은 이용약관 및 정책에 의하여 처리됩니다.")]}),e.jsxs(K,{children:[e.jsx(X,{isRequired:!0,children:n("신고 사유")}),e.jsx(se,{name:"reportReasonType",control:i,rules:{required:n("신고 사유를 선택해 주세요.")},render:({field:{onChange:h,value:b,...v}})=>e.jsx(be,{...v,placeholder:n("사유를 선택해 주세요."),options:ge,value:ge.find(p=>p.value===b)??null,onChange:p=>{p&&h(p.value)}})}),e.jsx(ue,{name:"reportReasonType",errors:m})]}),e.jsxs(K,{children:[e.jsx(X,{isRequired:!0,children:n("상세 사유")}),e.jsxs(P.TextAreaContainer,{children:[e.jsx(J,{placeholder:n("상세 사유를 입력해 주세요."),...g("content",{required:n("상세 사유를 입력해 주세요.")}),maxLength:T,style:{height:"120px",paddingBottom:"30px"}}),e.jsxs(P.CharacterCount,{children:[t," / ",T]})]}),e.jsx(ue,{name:"content",errors:m})]}),e.jsx(P.WarningText,{children:n("※ 허위 신고일 경우, 신고자의 서비스 활동이 제한될 수 있으니 유의하시어 신중하게 신고해주세요.")})]}),e.jsxs(le.ButtonContainer,{children:[e.jsx(re,{type:"button",onClick:r,children:e.jsx("span",{children:n("취소")})},"cancel"),e.jsx(Re,{type:"submit",onClick:N,children:e.jsx("span",{children:n("등록")})},"submit")]})]})})},Et=()=>{var ae;const{boardId:s,articleNo:r}=he(),{t:o}=I(),{isMobile:u}=Xe(),n=Ze(),{openDialog:c,openAsyncDialog:C,openLoginDialog:g}=Y(),{state:i}=Je(),{data:a}=je(),{data:d}=et(),m=V.useMemo(()=>d!=null&&d.boardConfigs?d.boardConfigs.find(x=>x.boardId===s):null,[d,s]),l=m!=null&&m.boardNo?m.boardNo.toString():"",{data:t}=at({boardNo:l,articleNo:Number(r??0),searchParams:{password:(i==null?void 0:i.password)??""}}),T=(m==null?void 0:m.replyUsed)===!0,N=((ae=t==null?void 0:t.registerType)==null?void 0:ae.toString().toUpperCase())==="GUEST",h=V.useMemo(()=>{var x;return((x=t==null?void 0:t.registerType)==null?void 0:x.toString().toUpperCase())==="GUEST"||!(a!=null&&a.memberNo)||!(t!=null&&t.registerNo)?!1:a.memberNo===t.registerNo},[a==null?void 0:a.memberNo,t==null?void 0:t.registerNo,t==null?void 0:t.registerType]),b=ye(),p=!((t==null?void 0:t.recommendable)??!1),F=(t==null?void 0:t.reported)??!1,U=(t==null?void 0:t.recommendCount)??0,{delete:w,recommend:E,cancelRecommend:_,cancelReport:q,checkEditable:f}=oe(),k=(x,H)=>{const W={boardNo:l,articleNo:H},ie=async(L,$)=>{if((t==null?void 0:t.registerType)!=="GUEST")return c({message:o("회원이 작성한 게시글은 비밀번호로 수정/삭제할 수 없습니다.")}),!1;try{return await f.mutateAsync({boardNo:l,articleNo:Number(H),data:{password:L}})?x==="edit"?(n({pathname:`/boards/${s}/${H}/modify`},{state:{password:L}}),!0):x==="delete"?(w.mutate({boardNo:l,articleNo:Number(H),data:{password:L}},{onSuccess:async()=>{$.close(),await C({message:o("게시글이 삭제되었습니다.")}),n(`/boards/${s}`)}}),!1):!0:!1}catch{return!1}};ne.open(L=>u?e.jsx(tt,{...L,boardData:W,onConfirm:$=>ie($,L)}):e.jsx(nt,{...L,boardData:{boardNo:l,articleNo:H},onConfirm:$=>ie($,L)}))},D=()=>{var W;const x=((W=t==null?void 0:t.registerType)==null?void 0:W.toString().toUpperCase())??"";if(x!=="GUEST"&&!!(a!=null&&a.memberNo)&&!!(t!=null&&t.registerNo)&&a.memberNo===t.registerNo){n({pathname:`/boards/${s}/${r}/modify`});return}if(x==="GUEST"){k("edit",Number(r));return}c({message:o("수정 권한이 없습니다.")})},A=async()=>{if(await C({message:o("게시글을 삭제하시겠습니까?"),iconType:"warning",onConfirmReturnValue:!0,onCloseReturnValue:!1})){if(h){w.mutate({boardNo:l,articleNo:Number(r)},{onSuccess:async()=>{await C({message:o("게시글이 삭제되었습니다.")}),n(`/boards/${s}`,{replace:!0})}});return}if((t==null?void 0:t.registerType)==="GUEST"){k("delete",Number(r));return}c({message:o("삭제 권한이 없습니다.")})}},Me=()=>{if(!b){g();return}!!(t!=null&&t.recommendable)?E.mutate({boardNo:l,articleNo:Number(r)},{onSuccess:()=>{c({message:o("추천되었습니다.")})},onError:()=>{c({message:o("추천에 실패했습니다.")})}}):_.mutate({boardNo:l,articleNo:Number(r)},{onSuccess:()=>{c({message:o("추천이 취소되었습니다.")})},onError:()=>{c({message:o("추천 취소에 실패했습니다.")})}})},Be=async()=>{if(!b){g();return}if(F){if(!await C({message:o("신고를 취소하시겠습니까?"),iconType:"warning",onConfirmReturnValue:!0,onCloseReturnValue:!1}))return;q.mutate({boardNo:l,articleNo:Number(r)},{onSuccess:()=>c({message:o("신고가 취소되었습니다.")})})}else ne.open(x=>u?e.jsx(wt,{...x,boardNo:l,articleNo:Number(r)}):e.jsx(pt,{...x,boardNo:l,articleNo:Number(r)}))},ve=h||N&&!b;return e.jsxs(M.Container,{children:[e.jsxs(M.TitleContainer,{children:[e.jsx(M.Title,{children:t==null?void 0:t.title}),e.jsxs(M.Description,{children:[e.jsx("span",{children:t==null?void 0:t.registerName}),e.jsx("br",{}),e.jsx("span",{children:pe(t==null?void 0:t.registerYmdt).format("YYYY.MM.DD")})]})]}),e.jsx(M.ContentsContainer,{children:e.jsx(ut,{contents:(t==null?void 0:t.content)??"",attachments:t.attachments})}),e.jsx(M.ActionButtonContainer,{children:ve?e.jsxs(e.Fragment,{children:[e.jsx(M.ActionButton,{onClick:D,children:o("수정")}),e.jsx(M.ActionButton,{onClick:A,children:o("삭제")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(M.RecommendButton,{onClick:Me,$isRecommended:p,children:[o("추천")," ",U>0&&`${U}`]}),e.jsx(M.ActionButton,{onClick:Be,children:o(F?"신고 취소":"신고")})]})}),T&&e.jsx(rt,{boardNo:l,articleNo:Number(r),categoryNo:(t==null?void 0:t.categoryNo)??void 0}),e.jsx(M.BackButton,{onClick:()=>{n(`/boards/${s}`)},children:e.jsx("p",{children:o("목록으로")})})]})};export{Et as default};