import{e as w,A as D}from"./AppLayout-0a5a7f0f.js";import{_ as U}from"./SearchForm-e48ef6c3.js";import{Z as z}from"./inertia-11bf9011.js";import{a as V,s as R}from"./arrow-up-a-z-solid-68a9dbc8.js";import{F as q}from"./@inertiajs/core-9c117dfe.js";import{r as L,a as x,p as P,ad as Z,b as G,M as C,w as k,q as f,u as y,v as c,x as O,F as _,E,y as K,D as M,A as $,B as N,$ as d,C as Q}from"./vue-0d7ee8e8.js";import{a as X}from"./axios-dd1c8fc2.js";import"./inertia-d4e795d3.js";import"./preload-helper-f61836a9.js";import"./userActivity-e849d9de.js";import"./fingerprint-374ab551.js";import"./recaptcha-v3-f0e7cd4f.js";import"./qs-0fed5bc1.js";import"./get-intrinsic-20bd36cc.js";import"./object-inspect-747fc63f.js";import"./nprogress-f6c1521f.js";import"./lodash.isequal-390c7467.js";import"./_plugin-vue_export-helper-b15b4a05.js";import"./PrimaryButton-ea293497.js";const Y={key:0,class:"mb-8 w-full"},ee={class:"index-table-head index-table-head-cell flex items-center justify-between !sticky z-[1000]"},te=["src"],oe=["onClick"],W={__name:"Results",props:["letters","buttons","favoriteShow","showOptionsList","getMenuIcon","title"],emits:["update:filter"],setup(a,{emit:e}){const n=e,l=L([]),g=x({down:V,up:R}),{filter:S,words:i}=P(Z()),h=G(()=>S.value==="desc"?g.down:g.up);C(()=>{l.value=i.value,q.on("success",()=>{l.value=i.value})});const u=()=>{const p=S.value==="asc"?"desc":"asc";n("update:filter",p)};return k(i,p=>{l.value=i.value}),(p,v)=>l.value.length?(f(),y("div",Y,[c("div",ee,[c("h2",null,O(a.title),1),c("button",{type:"button",class:"ml-auto",onClick:u,"aria-label":"sort"},[c("img",{src:h.value,width:"23.63",height:"20.8",alt:"sort"},null,8,te)])]),(f(!0),y(_,null,E(l.value,s=>(f(),y("div",{key:s,class:"index-table-row index-table-cell flex items-center justify-between relative"},[c("span",null,O(s==null?void 0:s.word.toUpperCase()),1),a.favoriteShow?(f(),y("div",{key:0,role:"button",class:K(a.getMenuIcon(s==null?void 0:s.word)),onClick:o=>a.showOptionsList(o,s==null?void 0:s.word,"right z-[2000]")},null,10,oe)):M("",!0)]))),128))])):M("",!0)}};function se(a){const e=L({}),n=L(0),l=L(null),g=L(window.innerWidth>1022),S=()=>{localStorage.words&&(e.value=JSON.parse(localStorage.words),n.value=Object.keys(e.value).length)},i=(o,t,r,b)=>{var I,j,T,H,A,B;const m=document.querySelector(`.option[data-value='${t}']`);for(let[F,J]of Object.entries(e.value))if(J.word===t){h(F),m&&(m.innerHTML=`<div class="icon icon-heart me-2"></div>${a[0]}`),(I=document.querySelector(`.menu-box2[data-word="${t}"]`))==null||I.remove(),(j=l.value)==null||j.setAttribute("class","show-options-list icon icon-heart"),(T=l.value)==null||T.classList.remove("index-table-wildcard");return}e.value[n.value]={topic:o,word:t,category:b,hasLink:r},n.value++,w.emit("savedWords",e.value),w.emit("savedWordsCount",n.value),localStorage.setItem("words",JSON.stringify(e.value)),document.cookie=`countSavedWord=${n.value}`,m&&(m.innerHTML=`<div class="icon icon-trash me-2"></div>${a[2]}`),(H=document.querySelector(`.menu-box2[data-word="${t}"]`))==null||H.remove(),(A=l.value)==null||A.setAttribute("class","show-options-list icon icon-heart-solid"),(B=l.value)==null||B.classList.add("index-table-wildcard")},h=o=>{const t={};for(let[r,b]of Object.entries(e.value))r!==o&&(t[Object.keys(t).length]=b);e.value=t,n.value--,w.emit("savedWords",e.value),w.emit("savedWordsCount",n.value),localStorage.setItem("words",JSON.stringify(e.value)),document.cookie=`countSavedWord=${n.value}`},u=(o,t,r="right")=>{l.value=o.target;const b=o.target;if(document.querySelectorAll(".menu-box2").forEach(m=>{m.dataset.word!==t&&m.remove()}),document.querySelector(`.menu-box2[data-word="${t}"]`)===null){const m=`<div class="menu-box2 ${r}" data-word="${t}"> <div class="${s(t)}"> <div class="option js-save-word" data-value="${t}"> ${p(t)} </div> <div class="option"> <a href="${route("saved.words")}"> <div class="icon icon-list-ul me-2"></div>${a[1]} </a> </div> </div> </div>`;b.insertAdjacentHTML("afterEnd",m)}else document.querySelector(`.menu-box2[data-word="${t}"]`).remove()},p=o=>{for(let t of Object.values(e.value))if(t.word===o)return`<div class="icon icon-trash me-2"></div>${a[2]}`;return`<div class="icon icon-heart me-2"></div>${a[0]}`},v=o=>{for(let t of Object.values(e.value))if(t.word===o)return"show-options-list icon icon-heart-solid index-table-wildcard";return"show-options-list icon icon-heart"},s=o=>{for(let t of Object.values(e.value))if(t.word===o)return"options-list flex flex-wrap-reverse";return"options-list"};return C(()=>{w.on("savedWords",o=>{e.value=o}),w.on("savedWordsCount",o=>{n.value=o;const t=document.getElementById("savedWordsCounter");t&&(t.innerHTML=`(${n.value})`);const r=document.getElementById("wordCounter");r&&(r.innerHTML=`(${n.value})`)}),X.post("/saved-words",{_token:document.querySelector('meta[name="csrf-token"]').getAttribute("content"),data:JSON.stringify(localStorage.words?JSON.parse(localStorage.words):{})}).then(({data:o})=>{localStorage.setItem("words",JSON.stringify(o)),document.cookie=`countSavedWord=${Object.entries(o).length}`,w.emit("savedWords",o),w.emit("savedWordsCount",Object.entries(o).length)}).catch(()=>{S()})}),{savedWords:e,savedWordsCount:n,menuIcon:l,favoriteShow:g,saveWord:i,removeWord:h,showOptionsList:u,getMenuIcon:v,getListStyle:s}}const ne=["content"],ae={class:"section"},le={class:"mb-6"},re=["innerHTML"],ie=["innerHTML"],ce=["innerHTML"],ue=["innerHTML"],Ie={__name:"Index",props:["placeholders","letters","words","buttons","pangrams"],setup(a){const e=a,{favoriteShow:n,showOptionsList:l,getMenuIcon:g,saveWord:S}=se(e.buttons);let i=x({...e.words}),h=x([...e.pangrams]);const u=L("asc");k(u,v=>{const s=new Intl.Collator(void 0,{sensitivity:"base"});for(const o in i)i[o]=[...i[o]].sort((t,r)=>v==="asc"?s.compare(t.word,r.word):s.compare(r.word,t.word));h.sort((o,t)=>v==="asc"?s.compare(o.word,t.word):s.compare(t.word,o.word))}),k(()=>e.words,()=>{i=x({...e.words}),h=x([...e.pangrams])}),C(()=>{q.on("success",()=>u.value="asc"),document.body.removeEventListener("click",p),document.body.addEventListener("click",p)});const p=function(v){if(v.target.classList.contains("js-save-word")){const s=v.target.dataset.value;S(e.placeholders["spelling-bee-topic"].replace("<letters>",s==null?void 0:s.length).replace("<length>",s==null?void 0:s.length),s,!1,"spelling-bee")}};return(v,s)=>(f(),y(_,null,[$(d(z),null,{default:N(()=>[c("title",null,O(e.placeholders.metaTitle),1),c("meta",{name:"description",content:e.placeholders.metaDescription},null,8,ne)]),_:1}),$(D,null,{default:N(()=>{var o;return[c("section",ae,[c("div",le,[c("h1",{class:"heading !border-y-0 mb-[3px]",innerHTML:e.placeholders.heading},null,8,re),c("p",{class:"subheading",innerHTML:e.placeholders.subheading},null,8,ie)]),$(U,{placeholders:e.placeholders,defLetters:e.letters},null,8,["placeholders","defLetters"]),$(W,{words:d(h),letters:e.letters,class:"mt-8",filter:u.value,buttons:e==null?void 0:e.buttons,"onUpdate:filter":s[0]||(s[0]=t=>u.value=t),favoriteShow:d(n),showOptionsList:d(l),getMenuIcon:d(g),title:a.placeholders.pangramsWords},null,8,["words","letters","filter","buttons","favoriteShow","showOptionsList","getMenuIcon","title"]),(f(!0),y(_,null,E(d(i),(t,r)=>(f(),Q(W,{key:r,words:t,letters:e.letters,class:"mt-8",filter:u.value,buttons:e==null?void 0:e.buttons,"onUpdate:filter":s[1]||(s[1]=b=>u.value=b),favoriteShow:d(n),showOptionsList:d(l),getMenuIcon:d(g),title:r.replace("_","")+" "+a.placeholders.wordsFound},null,8,["words","letters","filter","buttons","favoriteShow","showOptionsList","getMenuIcon","title"]))),128)),!Object.keys(d(i)).length&&((o=a.letters)==null?void 0:o.length)>6?(f(),y("p",{key:0,innerHTML:e.placeholders.resultsNotFound,class:"mt-8 text-center"},null,8,ce)):M("",!0),c("p",{innerHTML:e.placeholders.description,class:"mt-8"},null,8,ue)])]}),_:1})],64))}};export{Ie as default};