1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exportThreadDocx-DV7UI23-.js","assets/index-BRuSZtGQ.js","assets/FileSaver.min-CENiJ7oA.js","assets/index-MoAbC8_9.js","assets/index-sPIAqQPc.css"])))=>i.map(i=>d[i]); 2import{c as nn,o as Bt,t as Rt,r as m,s as f,u as Jt,j as e,w as vt,x as bt,I as an,B as H,k as ye,X as Vt,y as De,m as et,l as rn,p as on,z as ms,L as us,_ as ln}from"./index-MoAbC8_9.js";import{O as fs}from"./OwnersLayout-Cd0M3dw8.js";import{A as ps,a as hs,f as gs}from"./avatar-Bl5f64JA.js";import{R as xs,F as cn,T as _s,L as ys,a as vs,n as he}from"./ForumCategoryRow-od0t3MBP.js";import{D as dn,a as mn,b as un,c as fn,d as pn,e as hn}from"./dialog-DrI7Oddz.js";import{S as Me}from"./switch-BHj3-8MN.js";import{C as gn}from"./confirm-dialog-DHYtbMdr.js";import{F as xn}from"./ForumNewPostCard-B-1VK3ho.js";import{T as _n,a as yn,b as bs}from"./tabs-5EVsfllK.js";import{S as vn,a as bn,b as wn,c as jn,d as kn}from"./select-ChAxOmxm.js";import{C as Es}from"./Header-CnJGZ8vQ.js";import{S as ws}from"./send-DIVN8qsp.js";import{V as Nn}from"./video-DFpZvpEd.js";import{P as As}from"./paperclip-I8ctU5eK.js";import{L as Sn}from"./upload-BH1HltYO.js";import{A as Cn}from"./arrow-up-down-D7o6PKMM.js";import{U as Tn}from"./user-Cvsz7Lm_.js";import{C as zn}from"./calendar-days-DbjuOaGz.js";import{S as js}from"./search-_fcwEKN-.js";import{P as wt}from"./plus-CkJQv7GY.js";import{S as In}from"./star-CU0yRqe0.js";import{B as En}from"./badge-BHbYeRgi.js";import{S as ks}from"./skeleton-ClxqB572.js";import{L as An}from"./unlink-CxCPpy3W.js";import{C as Pn}from"./chevron-down-BDe4YKQW.js";import{U as xt}from"./users-xui-UtA1.js";import{M as _t}from"./collapsible-BIxz44zB.js";import{C as Ns}from"./circle-help-BFmb_2uk.js";import{A as Ss}from"./arrow-left-CZKmX_Y-.js";import{F as Dn}from"./file-down-D9u4xV4V.js";import"./separator-CQ84aZ0V.js";import"./breadcrumb-CmKLwRya.js";import"./house-DjS1WMqx.js";import"./receipt-DnGXta2k.js";import"./building-crte1H4H.js";import"./file-text-Bif0RP8Y.js";import"./chart-column-Bo5i9GGE.js";import"./piggy-bank-DP-A2O0m.js";import"./landmark-C0TkBs1l.js";import"./flame-wMx8KIS8.js";import"./trending-up-Cg9WFJWB.js";import"./euro-Cc6O9qjZ.js";import"./eye-DKrvAixa.js";import"./textarea-4z16PwID.js";import"./mountain-BHfTfCFy.js";import"./purify.es-dhnUglUx.js";import"./chevron-left-BrISfdwW.js";import"./index-Dh4i1-J3.js";import"./popover-BsQ559UC.js";import"./filter-DtRxSZ25.js";import"./image-zcTlJhLM.js";import"./minus-Dry52jGc.js";import"./table-BYzMA2MF.js";import"./trash-2-DRJ_nWSl.js";import"./printer-Bb7W1Pva.js";import"./ellipsis-BEOtFA2b.js";import"./globe-DTZBS0aY.js";import"./pencil-C_0Cp3wi.js";import"./thumbs-up-jDPlFMTx.js";import"./settings-BUFFH3UG.js";import"./languages-DJ80weRR.js";import"./download-DXQgHLv7.js";import"./sparkles-OdPvYVOS.js";import"./pen-line-3TShWx6o.js";import"./index-D9-GACGG.js";import"./index-BdQq_4o_.js";import"./chevron-up-JyGCcpt9.js";/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const Cs=nn("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]),Mn=()=>{const{user:c}=Bt(),{toast:g}
7=Rt(),I=m.useRef(new Set);return m.useEffect(()=>{if(!c)return;(async()=>{const{data:p,error:T}=await f.from("forum_posts").select("id").eq("user_id",c.id);!T&&p&&(I.current=new Set(p.map(j=>j.id)))})();const se=f.channel("reaction-notifications").on("postgres_changes",{event:"INSERT",schema:"public",table:"forum_post_reactions"},async p=>{const T=p.new;if(T.user_id===c.id)return;if(!I.current.has(T.post_id)){const{data:b}=await f.from("forum_posts").select("id, user_id").eq("id",T.post_id).maybeSingle();if(!b||b.user_id!==c.id)return;I.current.add(T.post_id)}const{data:j}=await f.from("profiles_public").select("first_name, last_name, full_name").eq("user_id",T.user_id).maybeSingle(),L=j!=null&&j.first_name?`${j.first_name} ${j.last_name||""}`.trim():(j==null?void 0:j.full_name)||"Someone";g({title:`${T.emoji} New Reaction`,description:`${L} reacted to your post`})}).subscribe();return()=>{f.removeChannel(se)}},[c,g]),{trackPost:K=>{I.current.add(K)}}},Fn=({onCreatePost:c,isCreating:g=!1,isAdmin:I=!1,categories:i=[],defaultExpanded:K=!1,onCancel:se})=>{var nt;const{language:p}=Jt(),{user:T}=Bt(),{toast:j}=Rt();m.useRef(null);const[L,b]=m.useState(K),[S,M]=m.useState(()=>{const x=sessionStorage.getItem("forum_draft_active_tab");return x==="de"||x==="en"?x:p==="en"?"en":"de"}),[_,d]=m.useState(()=>sessionStorage.getItem("forum_draft_title_de")||""),[C,V]=m.useState(()=>sessionStorage.getItem("forum_draft_title_en")||""),[Y,oe]=m.useState(()=>sessionStorage.getItem("forum_draft_content_de")||""),[$,le]=m.useState(()=>sessionStorage.getItem("forum_draft_content_en")||""),[te,Ie]=m.useState(!0),[ne,U]=m.useState(()=>sessionStorage.getItem("forum_draft_category")||""),[Ee,ce]=m.useState([]),[y,Fe]=m.useState(!1),[Le,ve]=m.useState(!1),[tt,Oe]=m.useState(!1),[de,Be]=m.useState(!0),[A,Ze]=m.useState(!1),[ge,w]=m.useState("");m.useEffect(()=>{sessionStorage.setItem("forum_draft_title_de",_)},[_]),m.useEffect(()=>{sessionStorage.setItem("forum_draft_title_en",C)},[C]),m.useEffect(()=>{sessionStorage.setItem("forum_draft_content_de",Y)},[Y]),m.useEffect(()=>{sessionStorage.setItem("forum_draft_content_en",$)},[$]),m.useEffect(()=>{sessionStorage.setItem("forum_draft_active_tab",S)},[S]),m.useEffect(()=>{T&&f.from("profiles").select("first_name, last_name, full_name").eq("user_id",T.id).maybeSingle().then(({data:x})=>{if(x){const R=[x.first_name,x.last_name].filter(Boolean).join(" ")||x.full_name||"";w(R)}})},[T]);const Q=x=>{ce(R=>R.filter((me,we)=>we!==x))},z=x=>{var me;const R=document.createElement("div");return R.innerHTML=x,!!((me=R.textContent)!=null&&me.trim().length)},Re=()=>{sessionStorage.removeItem("forum_draft_title_de"),sessionStorage.removeItem("forum_draft_title_en"),sessionStorage.removeItem("forum_draft_content_de"),sessionStorage.removeItem("forum_draft_content_en"),sessionStorage.removeItem("forum_draft_active_tab"),sessionStorage.removeItem("forum_draft_category"),sessionStorage.removeItem("forum_composer_open")},Ye=async(x=!1)=>{const R=!!_.trim(),me=!!C.trim(),we=z(Y),Ve=z($),ae=R&&we,We=me&&Ve;if(x?!(R||me||we||Ve):!ae&&!We){j({variant:"destructive",title:p==="cs"?"ChybÄjÃcà údaje":p==="de"?"Fehlende Angaben":"Missing Information",description:x?p==="cs"?"Pro uloženà konceptu vyplÅte název nebo obsah.":p==="de"?"Geben Sie zum Speichern des Entwurfs einen Titel oder Inhalt ein.":"Enter a title or content to save the draft.":p==="cs"?"VyplÅte prosÃm název a obsah alespoÅ v jednom jazyce.":p==="de"?"Bitte Titel und Inhalt in mindestens einer Sprache ausfüllen.":"Please fill in title and content in at least one language."});return}if(!x&&i.length>0&&!ne){j({variant:"destructive",title:p==="cs"?"Vyberte kategorii":p==="de"?"Kategorie wählen":"Select Category",description:p==="cs"?"Pro odeslánà pÅÃspÄvku je nutné vybrat kategorii.":p==="de"?"Bitte wählen Sie eine Kategorie.":"Please select a category before posting."});return}let ue=S;!(S==="de"?x?R||we:ae:x?me||Ve:We)&&(S==="de"?x?me||Ve:We:x?R||we:ae)&&(ue=S==="de"?"en":"de");const it=ue==="de"?_:C,rt=ue==="de"?Y:$,ot=ue==="de"?C:_,Ue=ue==="de"?$:Y,qe=ae&&We,je={titleTranslated:qe?ot:"",contentTranslated:qe?Ue:"",translationSource:qe?"manual":null,autoTranslate:te,originalLanguage:ue};await c(it,rt,ne,ue,Ee.map(Ae=>Ae.url),tt,x,je,!de,A)&&(Re(),d(""),V(""),oe(""),le(""),U(""),ce([]),Oe(!1),Be(!0),b(!1))},jt={cs:{sharePlaceholder:"SdÃlet nÄco...",createPost:"VytvoÅit pÅÃspÄvek",newPost:"Nový pÅÃspÄvek",title:"Název",titlePlaceholder:"Název pÅÃspÄvku",content:"Obsah",contentPlaceholder:"Co chcete sdÃlet?",cancel:"ZruÅ¡it",post:"Odeslat",saveDraft:"Uložit koncept",category:"Kategorie",selectCategory:"Vyberte kategorii"},de:{sharePlaceholder:"Etwas teilen...",createPost:"Beitrag erstellen",newPost:"Neuer Beitrag",title:"Titel",titlePlaceholder:"Beitragstitel",content:"Inhalt",contentPlaceholder:"Was möchten Sie teilen?",cancel:"Abbrechen",post:"Posten",saveDraft:"Entwurf speichern",category:"Kategorie",selectCategory:"Kategorie wählen"},en:{sharePlaceholder:"Share something...",createPost:"Create a Post",newPost:"New Post",title:"Title",titlePlaceholder:"Post title",content:"Content",contentPlaceholder:"What would you like to share?",cancel:"Cancel",post:"Post",saveDraft:"Save Draft",category:"Category",selectCategory:"Select category"}},xe=jt[p]||jt.en,be=!!_.trim()&&z(Y),st=!!C.trim()&&z($),Je=be||st,$e=!!_.trim()||!!C.trim()||z(Y)||z($),kt=Je&&!g&&!y&&!Le,Nt=$e&&!g&&!y&&!Le;return L?e.jsx(vt,{className:"mb-4 border-border/50",children:e.jsxs(bt,{className:"p-4 sm:p-6 space-y-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-0 pb-4 border-b border-border/50",children:[e.jsx(ps,{className:"h-8 w-8 ring-2 ring-primary/10",children:e.jsx(hs,{className:"bg-primary/10 text-primary font-medium text-xs",children:ge?ge.split(" ").map(x=>x[0]).join("").substring(0,2).toUpperCase():"You"})}),e.jsx("span",{className:"text-sm text-muted-foreground",children:ge}),i.length>0&&e.jsxs(vn,{value:ne,onValueChange:U,children:[e.jsx(bn,{className:"h-9 w-auto min-w-[300px] max-w-[400px] ml-6",children:e.jsx(wn,{placeholder:xe.selectCategory,children:ne?(nt=i.find(x=>x.id===ne))==null?void 0:nt.name:xe.selectCategory})}),e.jsx(jn,{className:"min-w-[320px]",children:i.map(x=>e.jsx(kn,{value:x.id,className:"py-2.5 focus:bg-primary/10 focus:text-primary data-[highlighted]:bg-primary/10 data-[highlighted]:text-primary",children:e.jsxs("div",{className:"flex flex-col items-start gap-0.5",children:[e.jsx("span",{className:"font-medium text-sm",children:x.name}),x.description&&e.jsx("span",{className:"text-xs text-muted-foreground leading-tight",children:x.description})]})},x.id))})]}),e.jsxs("div",{className:"flex items-center ml-auto border border-border rounded-lg overflow-hidden h-9",children:[e.jsxs("button",{type:"button",onClick:()=>M("de"),className:ye("px-3.5 h-full text-sm font-semibold transition-colors relative",S==="de"?"bg-primary text-primary-foreground":"bg-background text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:["DE",_.trim()&&z(Y)&&e.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full bg-emerald-400"})]}),e.jsxs("button",{type:"button",onClick:()=>M("en"),className:ye("px-3.5 h-full text-sm font-semibold transition-colors relative border-l border-border",S==="en"?"bg-primary text-primary-foreground":"bg-background text-muted-foreground hover:text-foreground hover:bg-muted/50"),children:["EN",C.trim()&&z($)&&e.jsx("span",{className:"absolute top-1 right-1 w-1.5 h-1.5 rounded-full bg-emerald-400"})]})]})]}),e.jsxs(_n,{value:S,onValueChange:x=>M(x),className:"pt-0",children:[e.jsx(yn,{className:"hidden"}),e.jsxs(bs,{value:"de",children:[e.jsxs("div",{className:"relative mb-1 pl-10 sm:pl-12 pr-3",children:[e.jsx("input",{value:_,onCh
7ange:x=>{x.target.value.length<=120&&d(x.target.value)},maxLength:120,placeholder:p==="de"?"Beitragstitel (Deutsch)":p==="cs"?"Název pÅÃspÄvku (nÄmecky)":"Post title (German)",className:"w-full text-2xl font-semibold bg-transparent border-none outline-none placeholder:text-muted-foreground/50 text-foreground",autoFocus:S==="de"}),e.jsx("span",{className:`absolute right-0 top-1/2 -translate-y-1/2 text-xs ${_.length>100?"text-destructive":"text-muted-foreground/50"}`,children:120-_.length})]}),e.jsx("div",{className:"min-h-[250px]",children:e.jsx(xs,{content:Y,onChange:oe,placeholder:p==="de"?"Was möchten Sie teilen? (Deutsch)":p==="cs"?"Co chcete sdÃlet? (nÄmecky)":"What would you like to share? (German)",onFileAttached:x=>ce(R=>[...R,x]),onUploadingChange:ve})})]}),e.jsxs(bs,{value:"en",children:[e.jsxs("div",{className:"relative mb-1 pl-10 sm:pl-12 pr-3",children:[e.jsx("input",{value:C,onChange:x=>{x.target.value.length<=120&&V(x.target.value)},maxLength:120,placeholder:p==="de"?"Beitragstitel (Englisch)":p==="cs"?"Název pÅÃspÄvku (anglicky)":"Post title (English)",className:"w-full text-2xl font-semibold bg-transparent border-none outline-none placeholder:text-muted-foreground/50 text-foreground",autoFocus:S==="en"}),e.jsx("span",{className:`absolute right-0 top-1/2 -translate-y-1/2 text-xs ${C.length>100?"text-destructive":"text-muted-foreground/50"}`,children:120-C.length})]}),e.jsx("div",{className:"min-h-[250px]",children:e.jsx(xs,{content:$,onChange:le,placeholder:p==="de"?"Was möchten Sie teilen? (Englisch)":p==="cs"?"Co chcete sdÃlet? (anglicky)":"What would you like to share? (English)",onFileAttached:x=>ce(R=>[...R,x]),onUploadingChange:ve})})]})]}),Ee.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-3",children:Ee.map((x,R)=>e.jsxs("div",{className:"relative group",children:[x.type.startsWith("image/")?e.jsx("img",{src:x.url,alt:x.name,className:"h-20 w-20 object-cover rounded-lg border"}):x.type.startsWith("video/")?e.jsxs("div",{className:"h-20 w-28 bg-muted rounded-lg border flex items-center justify-center",children:[e.jsx(Nn,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("span",{className:"text-xs truncate max-w-[60px] ml-1",children:x.name})]}):e.jsxs("div",{className:"h-20 px-3 flex items-center gap-2 bg-muted rounded-lg border",children:[e.jsx(As,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs truncate max-w-[80px]",children:x.name})]}),e.jsx("button",{onClick:()=>Q(R),className:"absolute -top-2 -right-2 h-5 w-5 bg-destructive text-destructive-foreground rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(Vt,{className:"h-3 w-3"})})]},R))}),e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsx(Me,{id:"auto-translate",checked:te,onCheckedChange:Ie}),e.jsx(De,{htmlFor:"auto-translate",className:"text-sm text-muted-foreground cursor-pointer",children:p==="cs"?"Automaticky pÅeložit pÅi publikaci":p==="de"?"Beim Veröffentlichen automatisch übersetzen":"Auto-translate on publish"})]}),e.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[e.jsx(Me,{id:"notify-by-email",checked:de,onCheckedChange:Be}),e.jsx(De,{htmlFor:"notify-by-email",className:"text-sm text-muted-foreground cursor-pointer",children:p==="cs"?"Odeslat e-mailové upozornÄnà vlastnÃkům":p==="de"?"E-Mail-Benachrichtigung an Eigentümer senden":"Send email notification to owners"})]}),!de&&e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:p==="cs"?"PÅÃspÄvek bude publikován bez e-mailového upozornÄnÃ.":p==="de"?"Der Beitrag wird ohne E-Mail-Benachrichtigung veröffentlicht.":"The post will be published without an email notification."}),de&&e.jsxs("div",{className:"mb-2 rounded-md border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Me,{id:"email-full-content",checked:A,onCheckedChange:Ze}),e.jsx(De,{htmlFor:"email-full-content",className:"text-sm text-muted-foreground cursor-pointer",children:p==="cs"?"Poslat e-mailem celý text pÅÃspÄvku":p==="de"?"Vollständigen Beitragstext per E-Mail senden":"Send the full post text by email"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:A?p==="cs"?"E-mail obsahuje celý pÅÃspÄvek. TlaÄÃtko â
7Zobrazit ve fóruâ zůstává.":p==="de"?"Die E-Mail enthält den gesamten Beitrag. Der Button zum Forum bleibt erhalten.":"The email contains the full post. The forum button remains.":p==="cs"?"E-mail obsahuje jen zkrácený úryvek s odkazem do fóra.":p==="de"?"Die E-Mail enthält nur einen kurzen Auszug mit Link zum Forum.":"The email contains only a short teaser with a forum link."})]}),!(be&&st)&&e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:p==="cs"?"Pokud vyplnÃte jen jeden jazyk, systém může pÅi publikaci automaticky vytvoÅit pÅeklad.":p==="de"?"Wenn Sie nur eine Sprache ausfüllen, kann das System beim Veröffentlichen automatisch eine Ãbersetzung erstellen.":"If you fill in only one language, the system can automatically create a translation on publish."}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3",children:[e.jsx("div",{className:"flex items-center gap-3 flex-1"}),e.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[e.jsx(H,{variant:"ghost",size:"sm",onClick:()=>{Re(),d(""),V(""),oe(""),le(""),U(""),ce([]),Oe(!1),b(!1),se==null||se()},disabled:g,children:xe.cancel}),e.jsx(H,{variant:"outline",size:"sm",onClick:()=>Ye(!0),disabled:!Nt,children:xe.saveDraft}),e.jsxs(H,{size:"sm",onClick:()=>Ye(!1),disabled:!kt,children:[g?e.jsx(et,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ws,{className:"mr-2 h-4 w-4"}),xe.post]})]})]})]})}):e.jsx(vt,{className:"mb-4 border-border/50",children:e.jsx(bt,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ps,{className:"h-8 w-8 sm:h-10 sm:w-10 shrink-0",children:e.jsx(hs,{className:"bg-primary/10 text-primary text-xs",children:"You"})}),e.jsx(an,{placeholder:xe.sharePlaceholder,className:"flex-1 bg-muted/50 border-0 cursor-pointer text-sm",onClick:()=>b(!0),readOnly:!0}),e.jsx(H,{onClick:()=>b(!0),size:"sm",className:"shrink-0 hidden sm:inline-flex",children:xe.createPost}),e.jsx(H,{onClick:()=>b(!0),size:"icon",className:"shrink-0 sm:hidden h-9 w-9",children:e.jsx(ws,{className:"h-4 w-4"})})]})})})},Ts=({searchQuery:c,onSearchChange:g,isSearching:I=!1,sortBy:i,onSortChange:K,authors:se,selectedAuthor:p,onAuthorChange:T,timePeriod:j,onTimePeriodChange:L,contentType:b,onContentTypeChange:S,categories:M=[],selectedCategoryId:_=null,onCategoryChange:d,showImportant:C=!1,onShowImportantChange:V,filteredCount:Y})=>{const{language:oe}=Jt(),[$,le]=m.useState(!0),[te,Ie]=m.useState(!1),[ne,U]=m.useState(null),Ee=m.useRef(null),ce=m.useRef(null),y={cs:{searchPlaceholder:"Hledat v diskuzi...",category:"Kategorie",sort:"ÅazenÃ",author:"Autor",timePeriod:"ObdobÃ",contentType:"Typ obsahu",clearFilters:"Vymazat filtry",all:"VÅ¡e",important:"Důležité",newest:"NejnovÄjÅ¡Ã",activity:"Poslednà aktivita",popular:"NejpopulárnÄjÅ¡Ã",allAuthors:"VÅ¡ichni autoÅi",allTime:"VÅ¡e",today:"Dnes",thisWeek:"Tento týden",thisMonth:"Tento mÄsÃc",thisYear:"Tento rok",allContent:"VÅ¡e",withAttachments:"S pÅÃlohami",textOnly:"Pouze text"},de:{searchPlaceholder:"In Diskussion suchen...",category:"Kategorie",sort:"Sortierung",author:"Autor",timePeriod:"Zeitraum",contentType:"Inhaltstyp",clearFilters:"Filter löschen",all:"Alle",important:"Wichtig",newest:"Neueste",activity:"Letzte Aktivität",popular:"Beliebteste",allAuthors:"Alle Autoren",allTime:"Alle",today:"Heute",thisWeek:"Diese Woche",thisMonth:"Diesen Monat",thisYear:"Dieses Jahr",allContent:"Alle",withAttachments:"Mit Anhängen",textOnly:"Nur Text"},en:{searchPlaceholder:"Search discussions...",category:"Category",sort:"Sort",author:"Author",timePeriod:"Time period",contentType:"Content type",clearFilters:"Clear filters",all:"All",important:"Important",newest:"Newest",activity:"Recent activity",popular:"Most popular",allAuthors:"All authors",allTime:"All time",today:"Today",thisWeek:"This week",thisMonth:"This month",thisYear:"This year",allContent:"All",withAttachments:"With attachments",textOnly:"Text only"}}[oe]||{searchPlaceholder:"Search discussions...",category:"Category",sort:"Sort",author:"Author",timePeriod:"Time period",contentType:"Content type",clearFilters:"Clear filters",all:"All",important:"Important",newest:"Newest",activity:"Recent activity",popular:"Most popular",allAuthors:"All authors",allTime:"All time",today:"Today",thisWeek:"This week",thisMonth:"This month",thisYear:"This year",allContent:"All",withAttachments:"With attachments",textOnly:"Text only"},Fe=!!(p||j!=="all"||b!=="all"||_||C),Le=Fe||!!c,ve=()=>{const w=[];if(Y!==void 0&&w.push(String(Y)),C&&w.push(y.important),_){const Q=M.find(z=>z.id===_);Q&&w.push(Q.name)}if(p){const Q=se.find(z=>z.id===p);Q&&w.push(Q.name)}return w.length>0?w.join(" · "):y.searchPlaceholder};m.useEffect(()=>{$&&setTimeout(()=>{var w;return(w=ce.current)==null?void 0:w.focus()},200)},[$]);const tt=()=>{var w;return C?y.important:_&&((w=M.find(Q=>Q.id===_))==null?void 0:w.name)||y.all},Oe=()=>i==="activity"?y.activity:i==="date"?y.newest:y.popular,de=()=>{var w;return p&&((w=se.find(Q=>Q.id===p))==null?void 0:w.name)||y.allAuthors},Be=()=>({all:y.allTime,today:y.today,week:y.thisWeek,month:y.thisMonth,year:y.thisYear})[j]||y.allTime,A=()=>
7({all:y.allContent,with_attachments:y.withAttachments,text_only:y.textOnly})[b]||y.allContent,Ze=()=>{g(""),T(null),L("all"),S("all"),d==null||d(null),V==null||V(!1)},ge=[{key:"category",label:y.category,icon:e.jsx(Sn,{className:"h-4 w-4"}),value:tt(),isActive:!!(_||C)},{key:"sort",label:y.sort,icon:e.jsx(Cn,{className:"h-4 w-4"}),value:Oe(),isActive:i!=="activity"},{key:"author",label:y.author,icon:e.jsx(Tn,{className:"h-4 w-4"}),value:de(),isActive:!!p},{key:"time",label:y.timePeriod,icon:e.jsx(zn,{className:"h-4 w-4"}),value:Be(),isActive:j!=="all"},{key:"content",label:y.contentType,icon:e.jsx(As,{className:"h-4 w-4"}),value:A(),isActive:b!=="all"}];return e.jsxs("div",{className:"relative w-full max-w-full",ref:Ee,children:[te&&e.jsx("div",{className:"fixed inset-0 z-[39]",onClick:()=>{Ie(!1),U(null)}}),e.jsx("div",{className:"flex w-full items-center justify-end",children:$?e.jsxs("div",{className:"relative z-[40] w-full min-w-0 max-w-full lg:w-[480px] lg:flex-none",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-card border border-primary/40 rounded-xl shadow-sm px-3 h-11 transition-all duration-200",children:[e.jsx(js,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("input",{ref:ce,type:"text",value:c,onChange:w=>g(w.target.value),placeholder:ve(),className:"flex-1 min-w-0 bg-transparent border-none outline-none text-sm text-foreground placeholder:text-muted-foreground"}),I&&e.jsx(et,{className:"h-4 w-4 text-muted-foreground animate-spin shrink-0"}),e.jsx("button",{onClick:()=>{Ie(!te),te&&U(null)},className:ye("h-7 w-7 rounded-full flex items-center justify-center shrink-0 transition-all duration-200",te||Fe?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"),children:e.jsx(wt,{className:ye("h-3.5 w-3.5 transition-transform duration-200",te&&"rotate-45")})}),e.jsx("button",{onClick:()=>{le(!1),Ie(!1),U(null)},className:"h-7 w-7 rounded-full flex items-center justify-center shrink-0 bg-muted text-muted-foreground hover:bg-muted/80 transition-colors",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]}),te&&e.jsxs("div",{className:"absolute inset-x-0 top-full mt-2 w-full max-w-full bg-card border border-border rounded-xl shadow-lg z-[41] overflow-hidden sm:left-auto sm:right-0 sm:w-72 sm:max-w-72",children:[ge.map((w,Q)=>e.jsxs("div",{children:[Q>0&&e.jsx("div",{className:"h-px bg-border"}),e.jsxs("button",{onClick:()=>U(ne===w.key?null:w.key),className:"w-full flex items-center gap-3 px-4 py-3 text-sm hover:bg-muted/50 transition-colors",children:[e.jsx("span",{className:"text-muted-foreground",children:w.icon}),e.jsx("span",{className:"font-medium text-foreground",children:w.label}),e.jsx("span",{className:ye("ml-auto text-xs",w.isActive?"text-primary font-semibold":"text-muted-foreground"),children:w.value}),e.jsx(Es,{className:ye("h-3.5 w-3.5 text-muted-foreground transition-transform duration-200",ne===w.key&&"rotate-90")})]}),ne===w.key&&e.jsxs("div",{className:"bg-muted/30 pb-1",children:[w.key==="category"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{label:y.all,active:!_&&!C,onClick:()=>{d==null||d(null),V==null||V(!1)}}),e.jsx(X,{label:y.important,icon:e.jsx(In,{className:"h-3.5 w-3.5"}),active:C,onClick:()=>{V==null||V(!C),C||d==null||d(null)}}),M.map(z=>e.jsx(X,{label:z.name,active:_===z.id,onClick:()=>{d==null||d(_===z.id?null:z.id),V==null||V(!1)}},z.id))]}),w.key==="sort"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{label:y.activity,active:i==="activity",onClick:()=>K("activity")}),e.jsx(X,{label:y.newest,active:i==="date",onClick:()=>K("date")}),e.jsx(X,{label:y.popular,active:i==="popularity",onClick:()=>K("popularity")})]}),w.key==="author"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{label:y.allAuthors,active:!p,onClick:()=>T(null)}),se.map(z=>e.jsx(X,{label:z.name,active:p===z.id,onClick:()=>T(z.id)},z.id))]}),w.key==="time"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{label:y.allTime,active:j==="all",onClick:()=>L("all")}),e.jsx(X,{label:y.today,active:j==="today",onClick:()=>L("today")}),e.jsx(X,{label:y.thisWeek,active:j==="week",onClick:()=>L("week")}),e.jsx(X,{label:y.thisMonth,active:j==="month",onClick:()=>L("month")}),e.jsx(X,{label:y.thisYear,active:j==="year",onClick:()=>L("year")})]}),w.key==="content"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{label:y.allC
7ontent,active:b==="all",onClick:()=>S("all")}),e.jsx(X,{label:y.withAttachments,active:b==="with_attachments",onClick:()=>S("with_attachments")}),e.jsx(X,{label:y.textOnly,active:b==="text_only",onClick:()=>S("text_only")})]})]})]},w.key)),Fe&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-px bg-border"}),e.jsx("button",{onClick:Ze,className:"w-full px-4 py-3 text-sm text-destructive hover:bg-destructive/5 transition-colors text-left font-medium",children:y.clearFilters})]})]})]}):e.jsx("button",{onClick:()=>le(!0),className:ye("h-11 w-11 rounded-full flex items-center justify-center transition-all duration-200 shadow-md ring-2 ring-primary/20",Le?"bg-primary text-primary-foreground ring-primary/40":"bg-primary text-primary-foreground hover:bg-primary/90"),children:e.jsx(js,{className:"h-[18px] w-[18px]"})})})]})},X=({label:c,icon:g,active:I,onClick:i})=>e.jsxs("button",{onClick:i,className:ye("w-full flex items-center gap-2 px-6 py-2 text-sm transition-colors text-left",I?"bg-primary/10 text-primary font-semibold":"text-foreground hover:bg-muted/50"),children:[g,c]}),zs={cs:{title:"SouvisejÃcà pÅÃspÄvky",subtitle:"Propojeno s tÃmto pÅÃspÄvkem",link:"Propojit",showMore:"Zobrazit dalÅ¡Ã",showLess:"Zobrazit ménÄ",removeLink:"Odstranit propojenÃ",empty:"ZatÃm nejsou pÅidané žádné souvisejÃcà pÅÃspÄvky."},de:{title:"Verwandte Beiträge",subtitle:"Mit diesem Beitrag verknüpft",link:"Verknüpfen",showMore:"Mehr anzeigen",showLess:"Weniger anzeigen",removeLink:"Verknüpfung entfernen",empty:"Noch keine verwandten Beiträge."},en:{title:"Related Posts",subtitle:"Linked to this post",link:"Link",showMore:"Show more",showLess:"Show less",removeLink:"Remove link",empty:"No related posts yet."}},Is=({threads:c,isLoading:g,canManage:I,onLinkClick:i,onRemoveLink:K,onThreadClick:se,language:p})=>{const[T,j]=m.useState(!0),L=zs[p]||zs.en,b=3;if(!g&&c.length===0&&!I)return null;const S=T?c:c.slice(0,b),M=c.length>b;return e.jsxs("div",{className:"relative rounded-lg border border-primary/20 bg-primary/[0.04] p-4 my-6 text-sm overflow-hidden",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 bg-primary/30","aria-hidden":"true"}),e.jsx("div",{className:"absolute left-[-5px] top-6 h-2.5 w-2.5 rounded-full bg-primary ring-4 ring-primary/10","aria-hidden":"true"}),e.jsxs("button",{type:"button",onClick:()=>j(!T),className:"relative w-full flex items-center justify-between gap-3 group","aria-expanded":T,children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"flex items-center justify-center h-7 w-7 rounded-full bg-primary/10 text-primary flex-shrink-0",children:e.jsx(An,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex flex-col items-start min-w-0",children:[e.jsx("h3",{className:"font-medium text-foreground text-sm truncate",children:L.title}),e.jsx("span",{className:"text-[11px] text-primary/80 font-medium truncate",children:L.subtitle})]}),!g&&c.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:["(",c.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[I&&e.jsxs(H,{variant:"ghost",size:"sm",className:"h-7 text-xs px-2 gap-1 opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity",onClick:_=>{_.stopPropagation(),i()},children:[e.jsx(wt,{className:"h-3 w-3"}),L.link]}),T?e.jsx(Pn,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Es,{className:"h-4 w-4 text-muted-foreground"})]})]}),T&&e.jsxs("div",{className:"mt-2 pl-6 space-y-1",children:[g&&e.jsx("div",{className:"space-y-2",children:[1,2].map(_=>e.jsxs("div",{className:"flex items-center gap-3 py-2",children:[e.jsx(ks,{className:"h-4 w-4/6"}),e.jsx(ks,{className:"h-4 w-16"})]},_))}),!g&&c.length===0&&I&&e.jsx("p",{className:"text-sm text-muted-foreground italic py-2",children:L.empty}),!g&&c.length>0&&e.jsxs("div",{className:"relative space-y-1 mt-3",children:[e.jsx("div",{className:"absolute left-[13px] top-0 bottom-0 w-px bg-primary/20","aria-hidden":"true"}),S.map(_=>e.jsxs("div",{className:"group relative flex items-start gap-3 py-2 pl-7 pr-2 roun
7ded-md hover:bg-primary/10 cursor-pointer transition-colors",onClick:()=>se(_.id),children:[e.jsx("div",{className:"absolute left-[9px] top-1/2 -translate-y-1/2 h-2 w-2 rounded-full bg-primary/60 ring-2 ring-primary/10","aria-hidden":"true"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:_.title}),_.category_name&&e.jsx(En,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4 w-fit shrink-0",children:_.category_name}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:new Date(_.created_at).toLocaleDateString(p==="cs"?"cs-CZ":p==="de"?"de-DE":"en-US")})]}),_.title_translated&&e.jsx("span",{className:"text-xs text-muted-foreground italic block truncate",children:_.title_translated})]}),I&&e.jsx("button",{className:"p-1.5 rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors shrink-0",title:L.removeLink,"aria-label":L.removeLink,onClick:d=>{d.stopPropagation(),K(_.link_id)},children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]},_.id))]}),!g&&M&&e.jsx("button",{className:"mt-1 text-xs text-primary hover:underline flex items-center gap-1",onClick:()=>j(!T),children:T?L.showLess:`${L.showMore} (${c.length-b})`})]})]})},Ln={hausverwaltung:{cs:{name:"Správa domu",description:"Komunikace se správcem, smlouvy, reklamace"},en:{name:"Property Management",description:"Communication with management, contracts, complaints"}},betriebskosten:{cs:{name:"Provoznà náklady a vyúÄtovánÃ",description:"RoÄnà vyúÄtovánÃ, zálohy, pÅehled nákladů"},en:{name:"Operating Costs & Billing",description:"Annual statements, advances, cost overview"}},instandhaltung:{cs:{name:"Ãdržba a opravy",description:"Hlášenà závad, údržba, domovnà technika"},en:{name:"Maintenance & Repairs",description:"Report defects, maintenance, building systems"}},gemeinschaftsraeume:{cs:{name:"SpoleÄné prostory",description:"UžÃvánà spoleÄných prostor, pravidla, rezervace"},en:{name:"Common Areas",description:"Use of shared spaces, rules, bookings"}},eigentuemerversammlung:{cs:{name:"ShromáždÄnà vlastnÃků",description:"Zápisy, usnesenÃ, program jednánÃ"},en:{name:"Owners' Meeting",description:"Minutes, resolutions, agenda"}},hausordnung:{cs:{name:"Domovnà Åád",description:"Klid, parkovánÃ, odvoz odpadu"},en:{name:"House Rules",description:"Quiet hours, parking, waste disposal"}},ruecklage:{cs:{name:"Fond oprav a investice",description:"Fond oprav, plánované investice, mimoÅádné pÅÃspÄvky"},en:{name:"Reserve Fund & Investments",description:"Repair fund, planned investments, special contributions"}},nachbarschaft:{cs:{name:"SousedstvÃ",description:"Sousedské vztahy, spoleÄné akce, oznámenÃ"},en:{name:"Neighborhood",description:"Community relations, joint events, announcements"}},general:{cs:{name:"Obecná diskuze",description:"Obecná témata a komunitnà chat"},en:{name:"General Discussion",description:"General topics and community chat"}}},yt=(c,g,I,i)=>!g||i===I?c:i==="en"&&I==="de"||i==="de"&&I==="en"?g:I==="en"?c:I==="de"&&g?g:c,Ka=()=>{const{user:c}=Bt(),{toast:g}
7=Rt(),{t:I,language:i}=Jt(),[K,se]=rn();Mn();const{isAdmin:p,simulateOwner:T}=on(),[j,L]=m.useState([]),[b,S]=m.useState([]),[M,_]=m.useState([]),[d,C]=m.useState(null),[V,Y]=m.useState(!0),[oe,$]=m.useState(null),[le,te]=m.useState(!1),[Ie,ne]=m.useState(!1),U=(p||Ie)&&!T,[Ee,ce]=m.useState(!1),[y,Fe]=m.useState(null),[Le,ve]=m.useState({}),[tt,Oe]=m.useState(!1),[de,Be]=m.useState(()=>sessionStorage.getItem("forum_composer_open")==="true"),[A,Ze]=m.useState(()=>sessionStorage.getItem("forum_auto_draft_id")||null),ge=t=>{Ze(t),t?sessionStorage.setItem("forum_auto_draft_id",t):sessionStorage.removeItem("forum_auto_draft_id")},w=t=>{Be(t),t?sessionStorage.setItem("forum_composer_open","true"):sessionStorage.removeItem("forum_composer_open")},Q=async()=>{w(!0)},z=async()=>{w(!1),await Js()},[Re,Ye]=m.useState("why"),[jt,xe]=m.useState(!1),[be,st]=m.useState(()=>localStorage.getItem("forum_view_mode")==="cards"?"cards":"list"),Je=t=>{st(t),localStorage.setItem("forum_view_mode",t),q(1)},[$e,kt]=m.useState(0),[Nt,nt]=m.useState(""),[x,R]=m.useState(""),[me,we]=m.useState(""),[Ve,ae]=m.useState(!1),[We,St]=m.useState(!1),[ue,at]=m.useState(!1),[Ct,it]=m.useState(!1),[rt,ot]=m.useState(null),[Ue,qe]=m.useState("activity"),[je,Tt]=m.useState(""),[Ae,Ut]=m.useState(null),[lt,qt]=m.useState("all"),[He,Zt]=m.useState("all"),[ke,q]=m.useState(1),[ct,Ps]=m.useState(4),Ds=[4,8,16],[Yt,$t]=m.useState({}),[Wt,Ne]=m.useState([]),[zt,dt]=m.useState(!1),[Ht,mt]=m.useState(!1),Qe=t=>{const n=Ln[t.slug];if(!n||i==="de")return{name:t.name,description:t.description};const r=i==="cs"?"cs":"en";return{name:n[r].name,description:n[r].description}},[_e,Ms]=m.useState({}),[Fs,It]=m.useState(null),[Ls,Qt]=m.useState(null),[Et,ut]=m.useState(null),[fe,Xe]=m.useState({notify:!0,autoTranslate:!0,fullContent:!1,testSingle:!1}),[At,Xt]=m.useState(!1),[Pt,Dt]=m.useState({}),[Kt,Gt]=m.useState(null),Os=async t=>{if(!t.length||!c)return;const{data:n}=await f.from("forum_thread_subscriptions").select("thread_id, notify_comments").eq("user_id",c.id).in("thread_id",t);if(n){const r={};n.forEach(a=>{r[a.thread_id]=a.notify_comments}),Dt(a=>({...a,...r}))}},es=async t=>{if(c){Gt(t);try{const n=!Pt[t],{data:r}=await f.from("forum_thread_subscriptions").select("id").eq("user_id",c.id).eq("thread_id",t).maybeSingle();r?await f.from("forum_thread_subscriptions").update({notify_comments:n,updated_at:new Date().toISOString()}).eq("id",r.id):await f.from("forum_thread_subscriptions").insert({user_id:c.id,thread_id:t,notify_comments:n}),Dt(a=>({...a,[t]:n}))}catch(n){console.error("Failed to toggle subscription",n)}finally{Gt(null)}}},Mt=async t=>{if(c)try{await f.from("forum_thread_subscriptions").upsert({user_id:c.id,thread_id:t,notify_comments:!0},{onConflict:"user_id,thread_id",ignoreDuplicates:!0}),Dt(n=>n[t]===void 0?{...n,[t]:!0}:n)}catch(n){console.error("Auto-subscribe failed (non-blocking):",n)}},ft=async t=>{if(!t.length)return;const{data:n}=await f.from("email_history").select("related_entity_id, sent_at, status, notification_run_id").eq("related_entity_type","forum").eq("template_type","forum_new_post").in("related_entity_id",t).order("sent_at",{ascending:!1});if(n){const r={};n.forEach(a=>{const l=a.related_entity_id;l&&(r[l]||(r[l]={sent_at:a.sent_at||"",sent:0,failed:0,skipped:0,total:0,notification_run_id:a.notification_run_id??null}),a.status==="sent"?r[l].sent+=1:a.status==="failed"?r[l].failed+=1:a.status==="skipped"&&(r[l].skipped+=1),r[l].total+=1)}),Ms(a=>({...a,...r}))}},Ft=async t=>{try{const n=await fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:t.substring(0,500),detectLanguage:!0})});if(n.ok){const{detectedLanguage:r}=await n.json();return r||"de"}}catch(n){console.error("Language detection failed:",n)}return"de"};m.useEffect(()=>{Vs(),ht(),f.from("profiles_public").select("id",{count:"exact",head:!0}).eq("approval_status","approved").then(({count:t})=>kt(t||0))},[]),m.useEffect(()=>{const t=K.get("thread");if(t&&b.length>0&&!d){const n=b.find(r=>r.id===t);n&&(Se(n),K.delete("thread"),se(K,{replace:!0}))}},[b,K]),m.useEffect(()=>{const t=async()=>
7{if(!c){ne(!1);return}const{data:r}=await f.rpc("has_role",{_user_id:c.id,_role:"admin"});ne(r===!0)},n=async()=>{if(!c)return;const{data:r}=await f.from("profiles").select("language, auto_translate").eq("user_id",c.id).single();r&&(ce(r.auto_translate??!1),Fe(r.language||i))};t(),n()},[c,i]),m.useEffect(()=>{if(!je.trim()){ot(null);return}const t=setTimeout(async()=>{it(!0);const n=je.trim().toLowerCase(),{data:r}=await f.from("forum_threads").select("id").or(`title.ilike.%${n}%,title_translated.ilike.%${n}%`),{data:a}=await f.from("forum_posts").select("thread_id").or(`content.ilike.%${n}%,content_translated.ilike.%${n}%`),l=new Set;r==null||r.forEach(s=>l.add(s.id)),a==null||a.forEach(s=>l.add(s.thread_id));const o=b.filter(s=>l.has(s.id));ot(o),it(!1)},300);return()=>clearTimeout(t)},[je,b]);const ts=()=>{C(null),_([]),Ne([])},Se=t=>{C(t),Us(t.id)},ss=async t=>{if(!c)return;const n=t.first_post_id;if(!n)return;const{data:r}=await f.from("forum_post_reactions").select("id").eq("post_id",n).eq("user_id",c.id).eq("emoji","ð").maybeSingle(),{data:a}=await f.from("profiles").select("full_name").eq("user_id",c.id).maybeSingle(),l=(a==null?void 0:a.full_name)||"Anonymous";r?(await f.from("forum_post_reactions").delete().eq("id",r.id),S(o=>o.map(s=>s.id===t.id?{...s,like_count:Math.max(0,(s.like_count||1)-1),user_liked:!1,like_users:(s.like_users||[]).filter(u=>u!==l)}:s))):(await f.from("forum_post_reactions").insert({post_id:n,user_id:c.id,emoji:"ð"}),S(o=>o.map(s=>s.id===t.id?{...s,like_count:(s.like_count||0)+1,user_liked:!0,like_users:[...s.like_users||[],l]}:s)))},ns=()=>{const t=new Map;return b.forEach(n=>{var r;n.user_id&&((r=n.profiles)!=null&&r.full_name)&&t.set(n.user_id,n.profiles.full_name)}),Array.from(t.entries()).map(([n,r])=>({id:n,name:r}))},Bs=t=>{const n=new Date;switch(t){case"today":return new Date(n.getFullYear(),n.getMonth(),n.getDate());case"week":const r=new Date(n);return r.setDate(r.getDate()-7),r;case"month":const a=new Date(n);return a.setMonth(a.getMonth()-1),a;case"year":const l=new Date(n);return l.setFullYear(l.getFullYear()-1),l;default:return null}},Ke=async t=>{dt(!0);try{const{data:n}=await f.from("thread_links").select("id, thread_a_id, thread_b_id").or(`thread_a_id.eq.${t},thread_b_id.eq.${t}`);if(!n||n.length===0){Ne([]),dt(!1);return}const r=n.map(o=>o.thread_a_id===t?o.thread_b_id:o.thread_a_id),a=new Map(n.map(o=>[o.thread_a_id===t?o.thread_b_id:o.thread_a_id,o.id])),{data:l}=await f.from("forum_threads").select("id, title, title_translated, category_id, created_at").in("id",r).eq("is_draft",!1);if(!l){Ne([]),dt(!1);return}Ne(l.map(o=>({id:o.id,title:o.title,title_translated:o.title_translated||null,category_id:o.category_id,created_at:o.created_at,excerpt:null,link_id:a.get(o.id)||""})))}catch(n){console.error("Failed to fetch related threads:",n),Ne([])}dt(!1)},as=async(t,n)=>{const r=n??(d==null?void 0:d.id);if(!c||!r)return;const a=r<t?r:t,l=r<t?t:r,{error:o}=await f.from("thread_links").insert({thread_a_id:a,thread_b_id:l,created_by:c.id});if(o){g({title:"Error",description:o.message,variant:"destructive"});return}g({title:i==="cs"?"Propojenà bylo pÅidáno":i==="de"?"Verknüpfung hinzugefügt":"Link added"}),Ke(r)},is=async(t,n)=>{const{error:r}=await f.from("thread_links").delete().eq("id",t);if(r){g({title:"Error",description:r.message,variant:"destructive"});return}g({title:i==="cs"?"Propojenà bylo odstranÄno":i==="de"?"Verknüpfung entfernt":"Link removed"});const a=n??(d==null?void 0:d.id);a&&Ke(a)};m.useEffect(()=>{d&&(os(d.id),Ke(d.id))},[d]);const pt=m.useRef(null),Rs=m.useCallback(async()=>{if(!c)return null;const t=A||sessionStorage.getItem("forum_auto_draft_id");if(t)return t;if(pt.current)return pt.current;const n=(async()=>{const{data:r,error:a}=await f.from("forum_threads").insert({title:"",user_id:c.id,language:i==="en"?"en":"de",is_draft:!0}).select().single();return a||!r?(console.error("Auto-draft creation error:",a),null):(await f.from("forum_posts").insert({thread_id:r.id,content:"",user_id:c.id,language:i==="en"?"en":"de"}),ge(r.id),Ke(r.id),r.id)})();pt.current=n;try{return await n}finally{pt.current=null}},[c,A,i]),Js=m.useCallback(async()=>
7{if(!A)return;const{data:t}=await f.from("forum_threads").select("title, is_draft").eq("id",A).maybeSingle();if(t&&t.is_draft&&!(t.title||"").trim()){const{data:n}=await f.from("forum_posts").select("content").eq("thread_id",A).order("created_at",{ascending:!0}).limit(1).maybeSingle();(!n||!(n.content||"").replace(/<[^>]*>/g,"").trim())&&await f.from("forum_threads").delete().eq("id",A)}ge(null),Ne([])},[A]),rs=t=>{if(!t.is_draft||t.user_id!==(c==null?void 0:c.id))return!1;const n=(t.title||"").trim().length>0,r=(t.first_post_content||"").replace(/<[^>]*>/g,"").trim().length>0;return n||r};m.useEffect(()=>{c&&de&&A&&Ke(A)},[c,de]),m.useEffect(()=>{if(!c)return;(async()=>{const{data:n}=await f.from("forum_threads").select("id, title").eq("user_id",c.id).eq("is_draft",!0);if(!(n!=null&&n.length))return;const r=sessionStorage.getItem("forum_auto_draft_id");for(const a of n){if(a.id===r||(a.title||"").trim())continue;const{data:l}=await f.from("forum_posts").select("content").eq("thread_id",a.id);(l||[]).some(s=>(s.content||"").replace(/<[^>]*>/g,"").trim().length>0)||await f.from("forum_threads").delete().eq("id",a.id)}ht()})()},[c]),m.useEffect(()=>{ue&&M.length>0&&d&&(at(!1),setTimeout(()=>{const t=document.getElementById("forum-comment-input");if(t){t.scrollIntoView({behavior:"smooth",block:"center"});const n=t.querySelector("input");n&&n.focus()}},300))},[ue,M,d]);const Vs=async()=>{const{data:t,error:n}=await f.from("forum_categories").select("*").order("sort_order");if(t){const{data:r}=await f.from("forum_threads").select("category_id, updated_at"),a=new Map,l=new Map;(r||[]).forEach(o=>{if(!o.category_id)return;a.set(o.category_id,(a.get(o.category_id)||0)+1);const s=l.get(o.category_id);(!s||o.updated_at&&o.updated_at>s)&&l.set(o.category_id,o.updated_at)}),L(t.map(o=>({...o,thread_count:a.get(o.id)||0,last_activity:l.get(o.id)||null})))}},ht=async()=>{Y(!0);let t=f.from("forum_threads").select("*").order("is_pinned",{ascending:!1}).order("updated_at",{ascending:!1});c?t=t.or(`is_draft.eq.false,and(is_draft.eq.true,user_id.eq.${c.id})`):t=t.eq("is_draft",!1);const{data:n}=await t;if(n){const r=n.map(h=>h.id);if(r.length===0){S([]),Y(!1);return}const[{data:a},{data:l},{data:o}]=await Promise.all([f.from("forum_posts").select("id, thread_id, user_id, created_at, attachments, content, content_translated, translation_source, translation_outdated").in("thread_id",r).order("created_at",{ascending:!0}),f.from("forum_thread_views").select("thread_id, view_count").in("thread_id",r),f.from("forum_post_reactions").select("post_id, user_id, forum_posts!inner(thread_id)").eq("emoji","ð").in("forum_posts.thread_id",r)]),s=new Map;(a||[]).forEach(h=>{s.has(h.thread_id)||s.set(h.thread_id,[]),s.get(h.thread_id).push(h)});const u=new Map;(l||[]).forEach(h=>{u.set(h.thread_id,(u.get(h.thread_id)||0)+(h.view_count||1))});const v=new Set(r.map(h=>{var O,F;return(F=(O=s.get(h))==null?void 0:O[0])==null?void 0:F.id}).filter(Boolean)),N=(o||[]).filter(h=>v.has(h.post_id)),k=new Map;(N||[]).forEach(h=>{k.has(h.post_id)||k.set(h.post_id,[]),k.get(h.post_id).push(h.user_id
7)});const E=[...new Set([...n.map(h=>h.user_id),...(N||[]).map(h=>h.user_id)].filter(Boolean))],[{data:P},G]=await Promise.all([f.from("profiles_public").select("user_id, full_name, first_name, last_name").in("user_id",E),gs(E)]),J=new Map;(P||[]).forEach(h=>J.set(h.user_id,h));const Z=h=>{const O=J.get(h);return O&&([O.first_name,O.last_name].filter(Boolean).join(" ")||O.full_name)||"Anonymous"},pe=n.map(h=>{const O=s.get(h.id)||[],F=O[0],D=F||null,ze=O.some(re=>re.attachments&&Array.isArray(re.attachments)&&re.attachments.length>0),B=F?k.get(F.id)||[]:[],ee=B.map(re=>{const gt=G.get(re);return(gt!=null&>.length?gt.join(", ")+" â ":"")+Z(re)}),W=O[O.length-1],ie=[h.created_at,W==null?void 0:W.created_at].filter(Boolean).sort().pop();return{...h,last_activity_at:ie,post_count:O.length,view_count:u.get(h.id)||0,has_attachments:ze,first_post_content:(D==null?void 0:D.content)||"",first_post_content_translated:(D==null?void 0:D.content_translated)||null,first_post_translation_source:(D==null?void 0:D.translation_source)||null,first_post_translation_outdated:(D==null?void 0:D.translation_outdated)||!1,first_post_id:(F==null?void 0:F.id)||void 0,first_post_attachments:(D==null?void 0:D.attachments)||[],like_count:B.length,like_users:ee,user_liked:c?B.includes(c.id):!1,profiles:J.get(h.user_id)?{full_name:J.get(h.user_id).full_name}:{full_name:null}}});S(pe);const Te=pe.map(h=>h.id);ft(Te),Os(Te)}Y(!1)},Us=async t=>{c&&(await f.rpc("record_forum_thread_view",{_thread_id:t}),S(n=>n.map(r=>r.id===t?{...r,view_count:(r.view_count||0)+1}:r)))},qs=async t=>{let n=M.find(a=>a.id===t);if(!n&&d){const a=Le[d.id];a&&(n=a.comments.find(l=>l.id===t))}if(!n)return;let r=i;i==="cs"&&(r=y==="de"?"de":"en");try{const a=await fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:n.content,sourceLanguage:n.language||"auto",targetLanguage:r})});if(!a.ok)throw new Error("Translation failed");const{translatedText:l}=await a.json();if(!l)throw new Error("No translation returned");await f.from("forum_posts").update({content_translated:l,translation_source:"ai"}).eq("id",t),_(o=>o.map(s=>s.id===t?{...s,content_translated:l,translation_source:"ai"}:s)),d&&ve(o=>{const s=d.id;return o[s]?{...o,[s]:{...o[s],comments:o[s].comments.map(u=>u.id===t?{...u,content_translated:l,translation_source:"ai"}:u)}}:o})}catch(a){console.error("Comment translation error:",a),g({variant:"destructive",title:i==="cs"?"Chyba pÅekladu":i==="de"?"Ãbersetzungsfehler":"Translation error",description:a instanceof Error?a.message:"Unknown error"})}},Zs=async t=>{await f.from("forum_posts").delete().eq("thread_id",t);const{error:n}=await f.from("forum_threads").delete().eq("id",t);if(n)throw n;S(r=>r.filter(a=>a.id!==t))},Ys=async(t,n,r,a,l)=>{const o={content:he(n),updated_at:new Date().toISOString()};a!==void 0?(o.content_translated=a&&he(a),o.translation_outdated=!1,o.translation_source="manual"):o.translation_outdated=!0;const{error:s}=await f.from("forum_posts").update(o).eq("id",t);if(s)throw s;if(r!==void 0&&d){const u={title:r,updated_at:new Date().toISOString()};l!==void 0?(u.title_translated=l,u.translation_outdated=!1,u.translation_source="manual"):d.title_translated&&(u.translation_outdated=!0),await f.from("forum_threads").update(u).eq("id",d.id),C(v=>v?{...v,title:r,...l!==void 0?{title_translated:l,translation_outdated:!1}:{}}:null)}_(u=>u.map(v=>v.id===t?{...v,content:n,...a!==void 0?{content_translated:a,translation_outdated:!1}:{}}:v)),await ht()},$s=async t=>{if(M.findIndex(a=>a.id===t)===0&&d){await Zs(d.id),C(null),_([]);return}const{error:r}=await f.from("forum_posts").delete().eq("id",t);if(r)throw r;_(a=>a.filter(l=>l.id!==t))},Ws=async(t,n)=>{const r=he(n),{data:a,error:l}=await f.from("forum_posts").update({content:r,updated_at:new Date().toISOString()}).eq("id",t).select("id, content, updated_at").maybeSingle();if(l)throw l;if(!a)throw new Error(i==="cs"?"ZmÄnu nebylo možné uložit (chybà oprávnÄnà k úpravÄ).":i==="de"?"Ãnderung konnte nicht gespeichert werden (keine Bearbeitungsberechtigung).":"The change could not be saved (no permission to edit).");_(o=>o.map(s=>s.id===t?{...s,content:a.content,updated_at:a.updated_at}:s)),ve(o=>{const s={...o};for(const u in s)s[u]={...s[u],comments:s[u].comments.map(v=>v.id===t?{...v,content:a.content,updated_at:a.updated_at}:v)};return s})},Hs=async t=>{const{error:n}=await f.from("forum_posts").delete().eq("id",t);if(n)throw n;ve(r=>{const a={...r};for(const l in a)a[l]={...a[l],comments:a[l].comments.filter(o=>o.id!==t)};return a}),_(r=>r.filter(a=>a.id!==t)),S(r=>r.map(a=>({...a,post_count:Math.max(0,(a.post_count||0)-1)})))},os=async t=>{Y(!0);const{data:n}=await f.from("forum_posts").select("*").eq("thread_id",t).order("created_at",{ascending:!0});if(n){const r=[...new Set(n.map(u=>u.user_id))],[{data:a},l]=await Promise.all([f.from("profiles_public").select("user_id, full_name, first_name, last_name").in("user_id",r),gs(r)]),o=new Map;
7(a||[]).forEach(u=>{const v=[u.first_name,u.last_name].filter(Boolean).join(" ")||u.full_name||"Anonymous";o.set(u.user_id,v)});const s=n.map(u=>({...u,profiles:{full_name:o.get(u.user_id)||"Anonymous"},_apt_codes:l.get(u.user_id)||[]}));_(s)}Y(!1)},Lt=async(t,n,r,a,l,o,s,u)=>{try{await f.functions.invoke("notify-forum-post",{body:{thread_title:t,thread_title_translated:(s==null?void 0:s.titleTranslated)||void 0,category_name:n,post_content:r,post_content_translated:(s==null?void 0:s.contentTranslated)||void 0,author_user_id:c==null?void 0:c.id,test_single_recipient:a||!1,thread_id:l||void 0,is_comment:o||!1,original_language:(s==null?void 0:s.originalLanguage)||void 0,translation_source:(s==null?void 0:s.translationSource)||void 0,full_content:u===!0}}),l&&ft([l])}catch(v){console.error("Forum notification failed (non-blocking):",v)}},Qs=async t=>{if(Fs)return;It(t),Qt(null);const n=b.find(a=>a.id===t);if(!n){It(null);return}const r=j.find(a=>a.id===n.category_id);try{await f.functions.invoke("notify-forum-post",{body:{thread_title:n.title,category_name:(r==null?void 0:r.name)||"",post_content:n.first_post_content||"",author_user_id:n.user_id,thread_id:t,resend_failed:!0,sent_by:c==null?void 0:c.id}}),await ft([t]),g({title:i==="cs"?"Odesláno znovu":i==="de"?"Erneut gesendet":"Resent",description:i==="cs"?"NeúspÄÅ¡né notifikace byly odeslány znovu.":i==="de"?"Fehlgeschlagene Benachrichtigungen erneut gesendet.":"Failed notifications have been resent."})}catch(a){console.error("Resend failed:",a),g({variant:"destructive",title:"Error",description:"Resend failed."})}It(null)},Xs=async t=>{var l;if(!d)return;const n=M.find(o=>o.id===t);if(!n)throw new Error("Comment not found");const r=((l=j.find(o=>o.id===d.category_id))==null?void 0:l.name)||"",{error:a}=await f.functions.invoke("notify-forum-post",{body:{thread_title:d.title,category_name:r,post_content:n.content,author_user_id:n.user_id,thread_id:d.id,is_comment:!0,force_all_recipients:!0,sent_by:c==null?void 0:c.id}});if(a)throw new Error(a.message||"Failed to send");await ft([d.id])},Ks=async(t,n,r,a,l,o,s,u,v,N)=>{const k=t??Nt,E=n??x,P=r??me,G=l??[],J=o??!1,Z=s??!1,pe=!!k.trim(),Te=!!E.replace(/<[^>]*>/g,"").trim();if(Z?!pe&&!Te:!pe||!Te)return g({variant:"destructive",title:"Missing Information",description:Z?"Please enter a title or content.":"Please fill in title and content."}),!1;if(!Z&&!P)return g({variant:"destructive",title:"Missing Information",description:"Please select a category."}),!1;ae(!0);const h=(u==null?void 0:u.originalLanguage)??a??await Ft(E);if(u&&!Z){const B=await Ft(E);if(B!==h&&!window.confirm(i==="cs"?`Detekovaný jazyk (${B}) nesouhlasà se zvolenou záložkou (${h}). Chcete pÅesto publikovat?`:i==="de"?`Erkannte Sprache (${B}) stimmt nicht mit dem gewählten Tab (${h}) überein. Trotzdem veröffentlichen?`:`Detected language (${B}) doesn't match selected tab (${h}). Publish anyway?`))return ae(!1),!1}let O=null,F=null,D=null;if(u&&!Z){if(u.translationSource==="manual")O=u.titleTranslated,F=u.contentTranslated,D="manual";else if(u.autoTranslate){const B=h==="de"?"en":"de";try{const[ee,W]=await Promise.all([fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:k,sourceLanguage:h,targetLanguage:B})}),fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:E,sourceLanguage:h,targetLanguage:B})})]);if(ee.ok&&W.ok){const ie=await ee.json(),re=await W.json();O=ie.translatedText||null,F=re.translatedText||null,D="ai"}else g({title:i==="cs"?"PÅeklad se nepodaÅilo dokonÄit":i==="de"?"Ãbersetzung fehlgeschlagen":"Translation could not be completed"})}catch(ee){console.error("Auto-translation failed:",ee),g({title:i==="cs"?"PÅeklad se nepodaÅilo dokonÄit":i==="de"?"Ãbersetzung fehlgeschlagen":"Translation could not be completed"})}}}let ze=null;if(A){const B={title:k,title_translated:O,language:h,is_draft:Z,translation_source:D,translation_outdated:!1,updated_at:new Date().toISOString()};P&&(B.category_id=P);const{data:ee,error:W}=await f.from("forum_threads").update(B).eq("id",A).select().single();if(W||!ee)return console.error("Auto-draft update error:",W),g({variant:"destructive",title:I("common.error"),description:`Failed to save thread: ${(W==null?void 0:W.message)||"Unknown error"}`}),ae(!1),!1;ze=ee;const{data:ie}=await f.from("forum_posts").select("id").eq("thread_id",A).order("created_at",{ascending:!0}).limit(1).maybeSingle();if(ie){const{error:re}=await f.from("forum_posts").update({content:he(E),content_translated:F&&he(F),language:h,attachments:G,translation_source:D,translation_outdated:!1,updated_at:new Date().toISOString()}).eq("id",ie.id);if(re)return console.error("Post update error:",re),g({variant:"destructive",title:"Error",description:`Failed to save post: ${re.message}`}),ae(!1),!1}else await f.from("forum_posts").insert({thread_id:A,content:he(E),content_translated:F&&he(F),user_id:c==null?void 0:c.id,language:h,attachments:G,translation_source:D,translation_outdated:!1})}else{const B={title:k,title_translated:O,user_id:c==null?void 0:c.id,language:h,is_draft:Z,translation_source:D,translation_outdated:!1};P&&(B.category_id=P);const{data:ee,error:W}=await f.from("forum_threads").insert(B).select().single();if(W||!ee)return console.error("Thread creation error:",W),g({variant:"destructive",title:I("common.error"),description:`Failed to create thread: ${(W==null?void 0:W.message)||"Unknown error"}`}),ae(!1),!1;ze=ee;const{error:ie}=await f.from("forum_posts").insert({thread_id:ze.id,content:he(E),content_translated:F&&he(F),user_id:c==null?void 0:c.id,language:h,attachments:G,translation_source:D,translation_outdated:!1});if(ie)return console.error("Post creation error:",ie),g({variant:"destructive",title:"Error",description:`Failed to create post: ${(ie==null?void 0:ie.message)||"Unknown error"}`}),ae(!1),!1}if(ae(!1),Z)g({title:i==="cs"?"Koncept uložen":i==="de"?"Entwurf gespeichert":"Draft Saved",description:i==="cs"?"PÅÃspÄvek byl uložen jako koncept.":i==="de"?"Beitrag als Entwurf gespeichert.":"Post saved as draft."});else{g({title:"Thread Created",description:v?"Your new thread has been created. No email notification was sent.":"Your new thread has been created. Subscribers will be notified."});const B=j.find(ee=>ee.id===P);
7ze&&(await Mt(ze.id),v||Lt(k,(B==null?void 0:B.name)||"",E,J,ze.id,!1,{titleTranslated:O,contentTranslated:F,originalLanguage:h,translationSource:D},N===!0))}return ge(null),Ne([]),Oe(!1),nt(""),R(""),we(""),await ht(),!0},ls=async(t,n=!1,r)=>{const a=(r==null?void 0:r.notify)!==!1,l=(r==null?void 0:r.autoTranslate)!==!1,o=b.find(J=>J.id===t)||((d==null?void 0:d.id)===t?d:void 0),s=(d==null?void 0:d.id)===t?M.find(J=>!J.parent_id):void 0,u=(o==null?void 0:o.title)||"",v=(s==null?void 0:s.content)||(o==null?void 0:o.first_post_content)||"";let N=(o==null?void 0:o.title_translated)||null,k=(s==null?void 0:s.content_translated)||(o==null?void 0:o.first_post_content_translated)||null,E=(o==null?void 0:o.translation_source)||null;if(l&&(!N||!k)&&u&&v){const J=(o==null?void 0:o.language)==="en"?"en":"de",Z=J==="de"?"en":"de";try{const[pe,Te]=await Promise.all([fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:u,sourceLanguage:J,targetLanguage:Z})}),fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:v,sourceLanguage:J,targetLanguage:Z})})]);if(pe.ok&&Te.ok){const h=await pe.json(),O=await Te.json();N=h.translatedText||N,k=O.translatedText||k,E="ai",s!=null&&s.id&&k&&await f.from("forum_posts").update({content_translated:k,translation_source:"ai",translation_outdated:!1}).eq("id",s.id)}else g({title:i==="cs"?"PÅeklad se nepodaÅilo dokonÄit":i==="de"?"Ãbersetzung fehlgeschlagen":"Translation could not be completed"})}catch(pe){console.error("Auto-translation failed:",pe),g({title:i==="cs"?"PÅeklad se nepodaÅilo dokonÄit":i==="de"?"Ãbersetzung fehlgeschlagen":"Translation could not be completed"})}}const P={is_draft:!1,updated_at:new Date().toISOString()};N&&(P.title_translated=N,P.translation_source=E,P.translation_outdated=!1);const{error:G}=await f.from("forum_threads").update(P).eq("id",t);if(G){g({variant:"destructive",title:"Error",description:"Failed to publish."});return}if(o&&a){await Mt(t);const J=j.find(Z=>Z.id===o.category_id);Lt(u,(J==null?void 0:J.name)||"",v,n,t,!1,{titleTranslated:N,contentTranslated:k,originalLanguage:o.language||"de",translationSource:E},(r==null?void 0:r.fullContent)===!0)}S(J=>J.map(Z=>Z.id===t?{...Z,is_draft:!1}:Z)),C(null),_([]),Ne([]),g({title:i==="cs"?"Publikováno":i==="de"?"Veröffentlicht":"Published",description:n?i==="cs"?"PÅÃspÄvek publikován. E-mail odeslán pouze vám.":i==="de"?"Veröffentlicht. E-Mail nur an Sie.":"Published. Email sent only to you.":i==="cs"?"PÅÃspÄvek byl publikován.":i==="de"?"Beitrag veröffentlicht.":"Post has been published."})},Gs=async(t,n)=>{const{error:r}=await f.from("forum_threads").update({category_id:n,updated_at:new Date().toISOString()}).eq("id",t);if(r){g({variant:"destructive",title:"Error",description:"Failed to move thread."});return}S(l=>l.map(o=>o.id===t?{...o,category_id:n}:o));const a=j.find(l=>l.id===n);g({title:i==="cs"?"PÅesunuto":i==="de"?"Verschoben":"Moved",description:i==="cs"?`PÅÃspÄvek pÅesunut do "${a==null?void 0:a.name}"`:`Thread moved to "${a==null?void 0:a.name}"`})},en=async(t,n)=>{var o;if(!t.trim()||!d)return;St(!0);const r=await Ft(t),{error:a}=await f.from("forum_posts").insert({thread_id:d.id,content:he(t),user_id:c==null?void 0:c.id,language:r,parent_id:n||null});if(St(!1),a){g({variant:"destructive",title:I("common.error"),description:"Failed to post reply. Please try again."});return}await f.from("forum_threads").update({updated_at:new Date().toISOString()}).eq("id",d.id),os(d.id),await Mt(d.id),g({title:I("forum.reply"),description:n?i==="cs"?"VaÅ¡e odpovÄÄ byla pÅidána.":i==="de"?"Ihre Antwort wurde hinzugefügt.":"Your reply has been added.":i==="cs"?"Váš komentáŠbyl pÅidán.":i==="de"?"Ihr Kommentar wurde hinzugefügt.":"Your comment has been added."});const l=((o=j.find(s=>s.id===d.category_id))==null?void 0:o.name)||"";Lt(d.title,l,t,!1,d.id,!0)},tn=async(t,n)=>{const r=M.find(a=>a.id===t);if(r)try{const a=await fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:r.content,sourceLanguage:r.language||void 0,targetLanguage:n})});if(!a.ok){const s=await a.json();throw new Error(s.error||"Translation failed")}
7const{translatedText:l,skipped:o}=await a.json();if(o)return;$t(s=>({...s,[t]:{content:l}})),_(s=>s.map(u=>u.id===t?{...u,content_translated:l}:u))}catch(a){throw console.error("Translation error:",a),a}},sn=async(t,n)=>{const r=b.find(s=>s.id===t),a=M.find(s=>s.id===n);if(!r||!a)return;const l=a.language||r.language||"de",o=l==="de"?"en":"de";try{const[s,u]=await Promise.all([fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:r.title,sourceLanguage:l,targetLanguage:o})}),fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/translate",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Indhc2xkem5ld2ljdHRvc2xwbW54Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc2MDcyNzgsImV4cCI6MjA4MzE4MzI3OH0.FE0Nk3VJ2ibEoUW3QEL3joKY1pM0TQhXZSygVQyuyvY"},body:JSON.stringify({text:a.content,sourceLanguage:l,targetLanguage:o})})]);if(!s.ok||!u.ok)throw new Error("Translation failed");const v=await s.json(),N=await u.json(),k=v.translatedText||null,E=N.translatedText||null;await Promise.all([f.from("forum_threads").update({title_translated:k,translation_source:"ai",translation_outdated:!1,updated_at:new Date().toISOString()}).eq("id",t),f.from("forum_posts").update({content_translated:E,translation_source:"ai",translation_outdated:!1,updated_at:new Date().toISOString()}).eq("id",n)]),S(P=>P.map(G=>G.id===t?{...G,title_translated:k,translation_source:"ai",translation_outdated:!1}:G)),_(P=>P.map(G=>G.id===n?{...G,content_translated:E,translation_source:"ai",translation_outdated:!1}:G)),$t(P=>({...P,[t]:{...P[t],title:k},[n]:{...P[n],content:E}})),(d==null?void 0:d.id)===t&&C(P=>P?{...P,title_translated:k,translation_source:"ai",translation_outdated:!1}:null),g({title:i==="cs"?"PÅeklad aktualizován":i==="de"?"Ãbersetzung aktualisiert":"Translation updated"})}catch(s){console.error("Retranslation error:",s),g({variant:"destructive",title:i==="cs"?"PÅeklad se nezdaÅil":i==="de"?"Ãbersetzung fehlgeschlagen":"Translation failed"})}},Ce=t=>{const n=j.find(r=>r.id===t);return n?Qe(n).name:""},Ot=t=>{const n=j.find(r=>r.id===t);return(n==null?void 0:n.image_url)||null},Ge=ms.useMemo(()=>Wt.map(t=>({...t,category_name:t.category_id?Ce(t.category_id):null})),[Wt,j,i]),cs={de:{title:"Diskussion der Eigentümer",subtitle:"Pinnwand des Hauses",description:"Diskutieren Sie mit anderen Eigentümern",backToForum:"Zurück zum Forum",startDiscussion:"Neue Diskussion starten",createThread:"Thema erstellen",selectCategory:"Kategorie wählen",threadTitle:"Titel",threadContent:"Inhalt",whatToDiscuss:"Was möchten Sie besprechen?"},en:{title:"Owners Discussion",subtitle:"Community bulletin board",description:"Discuss topics with fellow apartment owners",backToForum:"Back to Forum",startDiscussion:"Start New Discussion",createThread:"Create Thread",selectCategory:"Select a category",threadTitle:"Title",threadContent:"Content",whatToDiscuss:"What would you like to discuss?"},cs:{title:"Diskuse vlastnÃků",subtitle:"NástÄnka dÄnà v domÄ",description:"Diskutujte s ostatnÃmi vlastnÃky",backToForum:"ZpÄt na fórum",startDiscussion:"Založit novou diskuzi",createThread:"VytvoÅit téma",selectCategory:"Vyberte kategorii",threadTitle:"Název",threadContent:"Obsah",whatToDiscuss:"O Äem chcete diskutovat?"}},Pe=cs[i]||cs.en,ds=()=>e.jsx(vt,{children:e.jsxs(bt,{className:"p-0",children:[e.jsxs("div",{className:"flex border-b",children:[e.jsx("button",{onClick:()=>Ye("why"),className:`flex-1 px-4 py-2.5 text-xs font-medium transition-colors ${Re==="why"?"text-primary border-b-2 border-primary bg-primary/5":"text-muted-foreground hover:text-foreground"}`,children:i==="cs"?"ProÄ se zapojit":i==="de"?"Warum mitmachen":"Why participate"}),e.jsx("button",{onClick:()=>Ye("stats"),className:`flex-1 px-4 py-2.5 text-xs font-medium transition-colors ${Re==="stats"?"text-primary border-b-2 border-primary bg-primary/5":"text-muted-foreground hover:text-foreground"}`,children:i==="cs"?"Statistiky":i==="de"?"Statistiken":"Statistics"})]}),e.jsx("div",{className:"p-4 sm:p-5",children:Re==="stats"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center gap-1.5",children:[e.jsx(xt,{className:"h-3.5 w-3.5"}),i==="cs"?"Celkový poÄet Älenů":i==="de"?"Mitglieder gesamt":"Total members"]}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:$e})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center gap-1.5",children:[e.jsx(xt,{className:"h-3.5 w-3.5"}),i==="cs"?"AktivnÃch Älenů":i==="de"?"Aktive Mitglieder":"Active members"]}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:new Set(b.map(t=>t.user_id)).size})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center gap-1.5",children:[e.jsx(_t,{className:"h-3.5 w-3.5"}),i==="cs"?"PÅÃspÄvků celkem":i==="de"?"Beiträge gesamt":"Total posts"]}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:b.length})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center gap-1.5",children:[e.jsx(_t,{className:"h-3.5 w-3.5"}),i==="cs"?"Za poslednà rok":i==="de"?"Letztes Jahr":"Last year"]}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:b.filter(t=>{const n=new Date;return n.setFullYear(n.getFullYear()-1),new Date(t.created_at)>=n}).length})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:i==="cs"?"KomentáÅů":i==="de"?"Kommentare":"Comments"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:b.reduce((t,n)=>t+Math.max(0,(n.post_count||1)-1),0)})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:i==="cs"?"ZobrazenÃ":i==="de"?"Aufrufe":"Views"}),e.jsx("span",{className:"text-sm font-semibold text-foreground",children:b.reduce((t,n)=>t+(n.view_count||0),0)})]})]}):e.jsxs("div",{className:"space-y-3.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:i==="cs"?"Na vaÅ¡em názoru záležÃ":i==="de"?"Ihre Meinung zählt":"Your opinion matters"}),e.jsx("p",{className:"text-[13px] leading-relaxed text-muted-foreground",children:i==="cs"?"I krátký komentáŠmůže upozornit na problém, podpoÅit návrh nebo pomoci ostatnÃm pÅi rozhodovánÃ.":i==="de"?"Auch ein kurzer Kommentar kann auf ein Problem aufmerksam machen, einen Vorschlag unterstützen oder anderen bei der Entscheidung helfen.":"Even a short comment can highlight a problem, support a proposal or help others make decisions."})]}),e.jsxs("div",{className:"-mx-4 border-l-4 border-amber-400 bg-amber-50/50 dark:bg-amber-950/15 pl-4 pr-4 py-2.5",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:i==="cs"?"Bez zapojenà vlastnÃků se vÄci neposunou":i==="de"?"Ohne Beteiligung der Eigentümer bewegt sich nichts":"Nothing moves without owner participation"}),e.jsx("p",{className:"text-[13px] leading-relaxed text-muted-foreground mt-1",children:i==="cs"?"SpoleÄné ÅeÅ¡enà i dalšà kroky vznikajà jen tehdy, když se vlastnÃci zapojà do diskuse.":i==="de"?"Gemeinsame Lösungen und nächste Schritte entstehen nur, wenn sich die Eigentümer an der Diskussion beteiligen.":"Shared solutions and next steps only happen when owners join the discussion."})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:i==="cs"?"VÅ¡e na jednom mÃstÄ":i==="de"?"Alles an einem Ort":"Everything in one place"}),e.jsx("p",{className:"text-[13px] leading-relaxed text-muted-foreground",children:i==="cs"?"Fórum sloužà jako spoleÄný prostor pro témata domu a podnÄty, které mohou být dále pÅedány správci nemovitosti.":i==="de"?"Das Forum dient als gemeinsamer Raum für Hausthemen und Anregungen, die an die Hausverwaltung weitergeleitet werden können.":"The forum serves as a shared space for building topics and suggestions that can be forwarded to the property manager."})]})]})})]})});
7return d?e.jsx(fs,{title:Pe.title,description:Pe.subtitle,headerContent:e.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-4 text-xs sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(xt,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}),e.jsxs("span",{children:[$e," ",i==="cs"?"Älenů":i==="de"?"Mitglieder":"members"]})]}),e.jsx("span",{className:"text-border",children:"â¢"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(_t,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}),e.jsxs("span",{children:[b.length," ",i==="cs"?"pÅÃspÄvků":i==="de"?"Beiträge":"posts"]})]}),e.jsx("span",{className:"text-border",children:"â¢"}),e.jsxs(us,{to:"/owners/forum/faq",className:"flex items-center gap-1.5 hover:text-primary transition-colors",children:[e.jsx(Ns,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}),e.jsx("span",{children:"FAQ"})]})]}),breadcrumbs:[{label:Pe.title,onClick:ts}],children:e.jsx("div",{className:"flex flex-col lg:flex-row gap-6 items-start forum-reader",children:e.jsxs("div",{className:"flex-1 min-w-0
7w-full max-w-[1100px] mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs(H,{variant:"ghost",size:"sm",onClick:ts,className:"-ml-2 text-muted-foreground hover:text-primary-foreground hover:bg-primary",children:[e.jsx(Ss,{className:"mr-2 h-4 w-4"}),Pe.backToForum]}),e.jsxs(H,{variant:"outline",size:"sm",onClick:async()=>{const{exportThreadAsDocx:t}=await ln(async()=>{const{exportThreadAsDocx:n}=await import("./exportThreadDocx-DV7UI23-.js");return{exportThreadAsDocx:n}},__vite__mapDeps([0,1,2,3,4]));t({title:d.title,categoryName:Ce(d.category_id),posts:M.map(n=>{var r;return{authorName:((r=n.profiles)==null?void 0:r.full_name)||"Anonymous",createdAt:n.created_at,content:n.content}})})},className:"gap-1.5",children:[e.jsx(Dn,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:i==="cs"?"Stáhnout DOCX":i==="de"?"Als DOCX":"Download DOCX"})]})]}),e.jsx(gn,{open:Ls===d.id,onOpenChange:t=>{t||Qt(null)},title:i==="cs"?"Odeslat znovu neúspÄÅ¡né?":i==="de"?"Fehlgeschlagene erneut senden?":"Retry failed notifications?",description:i==="cs"?"Znovu se pokusÃme odeslat notifikace pouze aktuálnÄ neúspÄÅ¡ným pÅÃjemcům.":i==="de"?"Wir versuchen erneut, Benachrichtigungen nur an derzeit fehlgeschlagene Empfänger zu senden.":"We will retry sending notifications only to currently failed recipients.",confirmText:i==="cs"?"Odeslat znovu":i==="de"?"Erneut senden":"Retry",cancelText:i==="cs"?"ZruÅ¡it":i==="de"?"Abbrechen":"Cancel",variant:"default",onConfirm:()=>Qs(d.id)}),(Ge.length>0||zt||U||d.user_id===(c==null?void 0:c.id))&&e.jsx("div",{className:"w-full",children:e.jsx(Is,{threads:Ge,isLoading:zt,canManage:U||d.user_id===(c==null?void 0:c.id),onLinkClick:()=>mt(!0),onRemoveLink:is,onThreadClick:t=>{const n=b.find(r=>r.id===t);n&&Se(n)},language:i})}),V?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(et,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsx("div",{className:"space-y-4",children:(()=>{const t=M.filter(a=>!a.parent_id),n=M.filter(a=>!!a.parent_id),r=a=>n.filter(l=>{const o=u=>{if(!u)return null;const v=M.find(N=>N.id===u);return v?v.parent_id?o(v.parent_id):v.id:u};return o(l.parent_id)===a}).map(l=>{var o;return{id:l.id,content:l.content,content_translated:l.content_translated||null,translation_source:l.translation_source||null,created_at:l.created_at,authorName:((o=l.profiles)==null?void 0:o.full_name)||"Anonymous",language:l.language||"de",user_id:l.user_id,parent_id:l.parent_id||null}});return t.map((a,l)=>{var s,u,v;const o=r(a.id);return e.jsx(ms.Fragment,{children:e.jsx("div",{id:l===t.length-1?"forum-post-last":void 0,className:ye(l>0?"sm:ml-6":""),children:e.jsx(cn,{id:a.id,threadId:d.id,authorName:((s=a.profiles)==null?void 0:s.full_name)||"Anonymous",createdAt:a.created_at,userId:a.user_id,title:l===0?d.title:void 0,titleTranslated:l===0?((u=Yt[d.id])==null?void 0:u.title)||d.title_translated:void 0,content:a.content,contentTranslated:((v=Yt[a.id])==null?void 0:v.content)||a.content_translated,language:a.language||"de",translationSource:l===0?a.translation_source||d.translation_source:a.translation_source,translationOutdated:l===0?a.translation_outdated||d.translation_outdated:a.translation_outdated,attachments:a.attachments||[],isFirstPost:l===0,viewCount:l===0&&d.view_count||0,replyCount:o.length+1,comments:o,onReply:d.is_locked?void 0:en,onTranslate:tn,onRetranslate:l===0?sn:void 0,onEdit:a.user_id===(c==null?void 0:c.id)||U?Ys:void 0,onDelete:a.user_id===(c==null?void 0:c.id)||U?$s:void 0,onEditComment:Ws,onDeleteComment:Hs,onSendCommentNotification:U?Xs:void 0,isAdmin:U,onTranslateComment:qs,autoTranslate:Ee,userPreferredLanguage:y||void 0,categoryName:Ce(d.category_id),onMoveThread:l===0&&(a.user_id===(c==null?void 0:c.id)||U)?N=>Gs(d.id,N):void 0,availableCategories:l===0?j.map(N=>{const k=Qe(N);return{id:N.id,name:k.name,description:k.description}}):[],currentCategoryId:d.category_id||void 0,notificationStats:l===0&&_e[d.id]?{sent:_e[d.id].sent,failed:_e[d.id].failed,total:_e[d.id].total,sent_at:_e[d.id].sent_at}:void 0,onEditingChange:l===0?xe:void 0,isDraft:l===0?d.is_draft:!1,onPublishDraft:l===0&&d.is_draft&&(a.user_id===(c==null?void 0:c.id)||U)?N=>{N?ls(d.id,N.testSingle,{notify:N.notify,autoTranslate:N.autoTranslate,fullContent:N.fullContent}):(Xe({notify:!0,autoTranslate:!0,fullContent:!1,testSingle:!1}),ut(d.id))}:void 0})})},a.id)})})()}
7),e.jsx(_s,{open:Ht,onOpenChange:mt,currentThreadId:d.id,excludeIds:Ge.map(t=>t.id),language:i,onLink:as,getCategoryName:Ce}),e.jsx(dn,{open:!!Et,onOpenChange:t=>{t||ut(null)},children:e.jsxs(mn,{className:"sm:max-w-md",children:[e.jsxs(un,{children:[e.jsx(fn,{children:i==="cs"?"Publikovat pÅÃspÄvek":i==="de"?"Beitrag veröffentlichen":"Publish post"}),e.jsx(pn,{children:i==="cs"?"Nastavte, jak se pÅÃspÄvek publikuje a rozeÅ¡le.":i==="de"?"Legen Sie fest, wie der Beitrag veröffentlicht und versendet wird.":"Choose how the post is published and sent."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx(De,{htmlFor:"pub-notify",className:"text-sm font-normal cursor-pointer",children:i==="cs"?"Odeslat e-mailové upozornÄnà vlastnÃkům":i==="de"?"E-Mail-Benachrichtigung an Eigentümer senden":"Send email notification to owners"}),e.jsx(Me,{id:"pub-notify",checked:fe.notify,onCheckedChange:t=>Xe(n=>({...n,notify:t}))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx(De,{htmlFor:"pub-translate",className:"text-sm font-normal cursor-pointer",children:i==="cs"?"Automaticky pÅeložit chybÄjÃcà jazyk":i==="de"?"Fehlende Sprache automatisch übersetzen":"Auto-translate the missing language"}),e.jsx(Me,{id:"pub-translate",checked:fe.autoTranslate,onCheckedChange:t=>Xe(n=>({...n,autoTranslate:t}))})]}),fe.notify&&e.jsxs("div",{className:"rounded-md border p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx(De,{htmlFor:"pub-full",className:"text-sm font-normal cursor-pointer",children:i==="cs"?"Poslat e-mailem celý text pÅÃspÄvku":i==="de"?"Vollständigen Beitragstext per E-Mail senden":"Send the full post text by email"}),e.jsx(Me,{id:"pub-full",checked:fe.fullContent,onCheckedChange:t=>Xe(n=>({...n,fullContent:t}))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:fe.fullContent?i==="cs"?"E-mail obsahuje celý pÅÃspÄvek. TlaÄÃtko âZobrazit ve fóruâ zůstává.":i==="de"?"Die E-Mail enthält den gesamten Beitrag. Der Button zum Forum bleibt erhalten.":"The email contains the full post. The forum button remains.":i==="cs"?"E-mail obsahuje pouze zkrácený úryvek s odkazem do fóra.":i==="de"?"Die E-Mail enthält nur einen kurzen Auszug mit Link zum Forum.":"The email contains only a short teaser with a forum link."}),U&&e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx(De,{htmlFor:"pub-test",className:"text-sm font-normal cursor-pointer",children:i==="cs"?"Testovacà odeslánà pouze mnÄ":i==="de"?"Testversand nur an mich":"Test send to me only"}),e.jsx(Me,{id:"pub-test",checked:fe.testSingle,onCheckedChange:t=>Xe(n=>({...n,testSingle:t}))})]})]})]}),e.jsxs(hn,{children:[e.jsx(H,{variant:"ghost",onClick:()=>ut(null),disabled:At,children:i==="cs"?"ZruÅ¡it":i==="de"?"Abbrechen":"Cancel"}),e.jsxs(H,{disabled:At,onClick:async()=>{if(Et){Xt(!0);try{await ls(Et,fe.testSingle,{notify:fe.notify,autoTranslate:fe.autoTranslate,fullContent:fe.fullContent})}finally{Xt(!1),ut(null)}}},children:[At&&e.jsx(et,{className:"mr-2 h-4 w-4 animate-spin"}),i==="cs"?"Publikovat":i==="de"?"Veröffentlichen":"Publish"]})]})]})})]})})}):e.jsx(fs,{title:Pe.title,description:Pe.subtitle,headerContent:e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-4 text-[11px] sm:text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(xt,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsxs("span",{children:[$e," ",i==="cs"?"Älenů":i==="de"?"Mitglieder":"members"]})]}),e.jsx("span",{className:"text-border",children:"â¢"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(_t,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsxs("span",{children:[b.length," ",i==="cs"?"pÅÃspÄvků":i==="de"?"Beiträge":"posts"]})]}),e.jsx("span",{className:"text-border",children:"â¢"}),e.jsxs(us,{to:"/owners/forum/faq",className:"flex items-center gap-1 hover:text-primary transition-colors",children:[e.jsx(Ns,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.jsx("span",{children:"FAQ"})]})]}),breadcrumbs:[{label:Pe.title}],children:de?e.jsxs("div",{className:"space-y-4",children:[e.jsxs(H,{variant:"ghost",onClick:()=>z(),className:"gap-2",children:[e.jsx(Ss,{className:"h-4 w-4"}),i==="cs"?"ZpÄt na fórum":i==="de"?"Zurück zum Forum":"Back to forum"]}),e.jsx(Is,{threads:Ge,isLoading:zt,canManage:!0,onLinkClick:async()=>{await Rs(),mt(!0)},onRemoveLink:t=>A&&is(t,A),onThreadClick:t=>{const n=b.find(r=>r.id===t);n&&Se(n)},language:i}),e.jsx(Fn,{onCreatePost:async(t,n,r,a,l,o,s,u,v,N)=>{const k=await Ks(t,n,r,a,l,o,s,u,v,N);return k&&w(!1),k},isCreating:Ve,isAdmin:U,categories:j.map(t=>{const n=Qe(t);return{id:t.id,name:n.name,description:n.description}}),defaultExpanded:!0,onCancel:()=>z()}
7),A&&e.jsx(_s,{open:Ht,onOpenChange:mt,currentThreadId:A,excludeIds:Ge.map(t=>t.id),language:i,onLink:t=>as(t,A),getCategoryName:Ce})]}):e.jsxs(e.Fragment,{children:[e.jsxs(H,{onClick:()=>Q(),className:"mb-4 flex w-full items-center justify-center gap-2 lg:hidden h-12 text-base font-semibold shadow-md ring-1 ring-primary/20",size:"lg",children:[e.jsx(wt,{className:"h-5 w-5"}),i==="cs"?"Nový pÅÃspÄvek":i==="de"?"Neuer Beitrag":"New Post"]}),e.jsxs("div",{className:"hidden lg:flex items-center gap-6 mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-foreground shrink-0",children:i==="cs"?"Nové pÅÃspÄvky":i==="de"?"Neue Beiträge":"New Posts"}),e.jsx("div",{className:"flex-1"}),e.jsx("div",{className:"w-96 min-w-0 shrink-0",children:e.jsx(Ts,{searchQuery:je,onSearchChange:t=>{Tt(t),q(1)},isSearching:Ct,sortBy:Ue,onSortChange:t=>{qe(t),q(1)},authors:ns(),selectedAuthor:Ae,onAuthorChange:t=>{Ut(t),q(1)},timePeriod:lt,onTimePeriodChange:t=>{qt(t),q(1)},contentType:He,onContentTypeChange:t=>{Zt(t),q(1)},categories:j.map(t=>{const n=Qe(t);return{id:t.id,name:n.name}}),selectedCategoryId:oe,onCategoryChange:t=>{$(t),te(!1),q(1)},showImportant:le,onShowImportantChange:t=>{te(t),t&&$(null),q(1)}})}),e.jsxs("div",{className:"flex items-center rounded-lg border border-border p-0.5 shrink-0",children:[e.jsx("button",{onClick:()=>Je("list"),className:`p-1.5 rounded transition-colors ${be==="list"?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground"}`,title:i==="cs"?"Seznam":i==="de"?"Liste":"List",children:e.jsx(ys,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>Je("cards"),className:`p-1.5 rounded transition-colors ${be==="cards"?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground"}`,title:i==="cs"?"Karty":i==="de"?"Karten":"Cards",children:e.jsx(Cs,{className:"h-4 w-4"})})]}),e.jsxs(H,{onClick:()=>Q(),className:"gap-2 shrink-0 w-80 h-11 text-base font-semibold shadow-md ring-1 ring-primary/20",size:"lg",children:[e.jsx(wt,{className:"h-5 w-5"}),i==="cs"?"Nový pÅÃspÄvek":i==="de"?"Neuer Beitrag":"New Post"]})]}),e.jsx("div",{className:"lg:hidden mb-6 max-w-full overflow-hidden",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(Ts,{searchQuery:je,onSearchChange:t=>{Tt(t),q(1)},isSearching:Ct,sortBy:Ue,onSortChange:t=>{qe(t),q(1)},authors:ns(),selectedAuthor:Ae,onAuthorChange:t=>{Ut(t),q(1)},timePeriod:lt,onTimePeriodChange:t=>{qt(t),q(1)},contentType:He,onContentTypeChange:t=>{Zt(t),q(1)},categories:j.map(t=>{const n=Qe(t);return{id:t.id,name:n.name}}),selectedCategoryId:oe,onCategoryChange:t=>{$(t),te(!1),q(1)},showImportant:le,onShowImportantChange:t=>{te(t),t&&$(null),q(1)}})}),e.jsxs("div",{className:"flex items-center rounded-lg border border-border p-0.5 shrink-0",children:[e.jsx("button",{onClick:()=>Je("list"),className:`p-1 rounded transition-colors ${be==="list"?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground"}`,children:e.jsx(ys,{className:"h-4.5 w-4.5"})}),e.jsx("button",{onClick:()=>Je("cards"),className:`p-1 rounded transition-colors ${be==="cards"?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground"}`,children:e.jsx(Cs,{className:"h-4.5 w-4.5"})})]})]})}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-3 lg:gap-6 items-start",children:[e.jsxs("div",{className:"flex-1 min-w-0
7w-full pb-4 lg:pb-0",children:[e.jsx("div",{className:"mb-6 space-y-2 overflow-hidden",children:V?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(et,{className:"h-8 w-8 animate-spin text-primary"})}):(()=>{let t=(rt!==null?rt:b).filter(s=>!s.is_draft);oe&&(t=t.filter(s=>s.category_id===oe)),le&&(t=t.filter(s=>s.is_pinned)),Ae&&(t=t.filter(s=>s.user_id===Ae));const n=Bs(lt);n&&(t=t.filter(s=>new Date(s.created_at)>=n)),He==="with_attachments"?t=t.filter(s=>s.has_attachments===!0):He==="text_only"&&(t=t.filter(s=>s.has_attachments!==!0));const r=[...t].sort((s,u)=>{if(s.is_pinned&&!u.is_pinned)return-1;if(!s.is_pinned&&u.is_pinned)return 1;if(Ue==="popularity")return(u.post_count||0)-(s.post_count||0);if(Ue==="activity"){const v=new Date(s.last_activity_at||s.created_at).getTime();return new Date(u.last_activity_at||u.created_at).getTime()-v}return new Date(u.created_at).getTime()-new Date(s.created_at).getTime()});if(r.length===0)return e.jsx(vt,{className:"border-dashed",children:e.jsx(bt,{className:"py-8 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:je.trim()||Ae||lt!=="all"||He!=="all"||oe||le?i==="cs"?"Žádné výsledky pro zadané filtry":i==="de"?"Keine Ergebnisse für die Filter":"No results for the selected filters":i==="cs"?"ZatÃm žádné pÅÃspÄvky":i==="de"?"Noch keine Beiträge":"No posts yet"})})});const a=Math.ceil(r.length/ct),l=(ke-1)*ct,o=r.slice(l,l+ct);return e.jsxs(e.Fragment,{children:[be==="cards"?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-4",children:o.map(s=>{var u,v;return e.jsx(xn,{title:yt(s.title,s.title_translated,s.language,i),authorName:((u=s.profiles)==null?void 0:u.full_name)||"Anonymous",createdAt:s.created_at,lastActivityAt:s.last_activity_at,categoryName:Ce(s.category_id),previewText:yt(s.first_post_content||"",s.first_post_content_translated,s.language,i),replyCount:Math.max(0,(s.post_count||1)-1),viewCount:s.view_count||0,likeCount:s.like_count||0,likeUsers:s.like_users||[],userLiked:s.user_liked||!1,onLike:()=>ss(s),onClick:()=>Se(s),imageUrl:((v=s.first_post_attachments)==null?void 0:v.find(N=>/\.(jpg|jpeg|png|gif|webp)/i.test(N)))||(()=>{var k;const N=(k=s.first_post_content)==null?void 0:k.match(/<img[^>]+src="([^"]+)"/);return N?N[1]:null})()||Ot(s.category_id),isPinned:s.is_pinned,onCommentClick:()=>{at(!0),Se(s)},commentNotify:!!Pt[s.id],isTogglingNotify:Kt===s.id,onToggleCommentNotify:c?()=>es(s.id):void 0},s.id)})}):e.jsx("div",{className:"space-y-2",children:o.map((s,u)=>{var v,N;return e.jsx(vs,{isLatest:ke===1&&u===0,className:void 0,id:s.id,name:yt(s.title,s.title_translated,s.language,i),authorName:((v=s.profiles)==null?void 0:v.full_name)||"Anonymous",categoryName:Ce(s.category_id),createdAt:s.created_at,lastActivityAt:s.last_activity_at,description:(()=>{const k=yt(s.first_post_content||"",s.first_post_content_translated,s.language,i),E=document.createElement("div");return E.innerHTML=k,E.textContent||""})(),imageUrl:((N=s.first_post_attachments)==null?void 0:N.find(k=>/\.(jpg|jpeg|png|gif|webp)/i.test(k)))||(()=>{var E;const k=(E=s.first_post_content)==null?void 0:E.match(/<img[^>]+src="([^"]+)"/);return k?k[1]:null})()||Ot(s.category_id),threadCount:Math.max(0,(s.post_count||1)-1),viewCount:s.view_count||0,likeCount:s.like_count||0,likeUsers:s.like_users||[],isPrivate:s.is_pinned,onClick:()=>Se(s),onCommentClick:()=>{at(!0),Se(s)},userLiked:s.user_liked||!1,onLike:()=>ss(s),notificationStats:_e[s.id]?{sent:_e[s.id].sent,failed:_e[s.id].failed,total:_e[s.id].total}:void 0,commentNotify:!!Pt[s.id],isTogglingNotify:Kt===s.id,onToggleCommentNotify:c?()=>es(s.id):void 0},s.id)})}),a>1&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 pt-4 sm:justify-end",children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[e.jsx(H,{variant:"outline",size:"sm",className:"h-8 px-2 sm:px-3 text-xs sm:text-sm",onClick:()=>q(s=>Math.max(1,s-1)),disabled:ke===1,children:"â"}),e.jsx("div",{className:"flex items-center gap-0.5 sm:gap-1",children:Array.from({length:a},(s,u)=>u+1).map(s=>s===1||s===a||Math.abs(s-ke)<=1?e.jsx(H,{variant:ke===s?"default":"outline",size:"sm",className:"h-8 w-8 sm:w-9 text-xs sm:text-sm",onClick:()=>q(s),children:s},s):s===2&&ke>3||s===a-1&&ke<a-2?e.jsx("span",{className:"px-0.5 text-muted-foreground text-xs",children:"â¦"},s):null)}),e.jsx(H,{variant:"outline",size:"sm",className:"h-8 px-2 sm:px-3 text-xs sm:text-sm",onClick:()=>q(s=>Math.min(a,s+1)),disabled:ke===a,children:"â"})]}),e.jsx("div",{className:"flex w-full items-center justify-end gap-1 border-border pt-1 sm:ml-3 sm:w-auto
7sm:border-l sm:pl-3 sm:pt-0",children:Ds.map(s=>e.jsx(H,{variant:ct===s?"default":"ghost",size:"sm",className:"h-7 w-7 sm:w-8 text-[10px] sm:text-xs p-0",onClick:()=>{Ps(s),q(1)},children:s},s))})]}),e.jsx("div",{className:"mt-4 lg:hidden",children:ds()})]})})()}),b.filter(rs).length>0&&e.jsxs("div",{className:"mb-8",children:[e.jsx("h2",{className:"text-base sm:text-lg font-semibold text-foreground mb-3 sm:mb-4",children:i==="cs"?"Moje koncepty":i==="de"?"Meine Entwürfe":"My Drafts"}),e.jsx("div",{className:"space-y-2",children:b.filter(rs).sort((t,n)=>new Date(n.updated_at).getTime()-new Date(t.updated_at).getTime()).map(t=>{var n,r;return e.jsx(vs,{id:t.id,name:t.title||(i==="cs"?"Bez názvu":"Untitled"),authorName:((n=t.profiles)==null?void 0:n.full_name)||"Anonymous",categoryName:Ce(t.category_id),createdAt:t.updated_at,description:(()=>{const a=document.createElement("div");return a.innerHTML=t.first_post_content||"",a.textContent||""})(),imageUrl:((r=t.first_post_attachments)==null?void 0:r.find(a=>/\.(jpg|jpeg|png|gif|webp)/i.test(a)))||(()=>{var l;const a=(l=t.first_post_content)==null?void 0:l.match(/<img[^>]+src="([^"]+)"/);return a?a[1]:null})()||Ot(t.category_id),threadCount:0,viewCount:0,likeCount:0,onClick:()=>Se(t),className:"border-dashed border-amber-400/50"},`draft-${t.id}`)})})]})]}),e.jsx("div",{className:"hidden lg:block w-80 shrink-0 self-start sticky top-24",children:ds()})]})]})})};export{Ka as default};
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.