import{p as se,a as r,s as g,b as le,f as d,h as c,e as l,i as b,j as ie,g as a,t as _,l as F,m as h,n as o,o as ne,c as re,r as ce,d as v,w as oe,x as ve}from"./index-DUEdOLeb.js";var de=d('<p class="svelte-hx6wcr"> </p>'),ue=d('<input class="search svelte-hx6wcr" placeholder="Search..."/>'),_e=d('<span class="icon"> </span>'),he=d('<div class="option-desc svelte-hx6wcr"> </div>'),fe=d('<button><div class="option-title"><!> <span> </span></div> <!></button>'),xe=d('<div class="error svelte-hx6wcr"> </div>'),be=d('<div class="select-option svelte-hx6wcr"><div class="header svelte-hx6wcr"><h3 class="svelte-hx6wcr"> </h3> <!></div> <!> <div></div> <div class="actions svelte-hx6wcr"><!> <button class="btn-cancel svelte-hx6wcr">Cancel</button> <button class="btn-submit svelte-hx6wcr">Submit</button></div></div>');function me(G,i){se(i,!0);let H=r(i,"title",3,"Choose an option"),C=r(i,"description",3,""),I=r(i,"options",19,()=>[]),k=r(i,"multiple",3,!1),m=r(i,"minSelections",3,1),y=r(i,"maxSelections",3,void 0),J=r(i,"layout",3,"list"),L=r(i,"searchable",3,!1),R=r(i,"onResult",3,void 0),w=g(""),f=g(le(new Set)),u=g(null);const K=re(()=>I().filter(t=>{if(!L()||!a(w).trim())return!0;const e=a(w).toLowerCase();return t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)}));function M(t){if(!k()){v(f,new Set([t]),!0),v(u,null);return}const e=new Set(a(f));if(e.has(t))e.delete(t);else{if(y()&&e.size>=y())return;e.add(t)}v(f,e,!0),v(u,null)}function N(){const t=Array.from(a(f));if(t.length<m()){v(u,`Select at least ${m()} option${m()>1?"s":""}.`);return}v(u,null),R()?.({selection:k()?t:t[0]})}function P(){R()?.({selection:null,cancelled:!0})}var j=be(),q=l(j),z=l(q),Q=l(z),T=c(z,2);{var U=t=>{var e=de(),s=l(e);_(()=>h(s,C())),o(t,e)};b(T,t=>{C()&&t(U)})}var A=c(q,2);{var V=t=>{var e=ue();oe(e,()=>a(w),s=>v(w,s)),o(t,e)};b(A,t=>{L()&&t(V)})}var p=c(A,2);ie(p,21,()=>a(K),ne,(t,e)=>{var s=fe();s.__click=()=>M(a(e).value);var D=l(s),E=l(D);{var Z=n=>{var x=_e(),S=l(x);_(()=>h(S,a(e).icon)),o(n,x)};b(E,n=>{a(e).icon&&n(Z)})}var $=c(E,2),ee=l($),te=c(D,2);{var ae=n=>{var x=he(),S=l(x);_(()=>h(S,a(e).description)),o(n,x)};b(te,n=>{a(e).description&&n(ae)})}_(n=>{F(s,1,n,"svelte-hx6wcr"),s.disabled=a(e).disabled,h(ee,a(e).label)},[()=>`option ${a(f).has(a(e).value)?"active":""}`]),o(t,s)});var W=c(p,2),O=l(W);{var X=t=>{var e=xe(),s=l(e);_(()=>h(s,a(u))),o(t,e)};b(O,t=>{a(u)&&t(X)})}var B=c(O,2);B.__click=P;var Y=c(B,2);Y.__click=N,_(()=>{h(Q,H()),F(p,1,`options ${J()}`,"svelte-hx6wcr")}),o(G,j),ce()}ve(["click"]);export{me as default};
