import{q as D,r as V,a as m,F as j,b as x,y as n,z as u,S as h,U as f,I as p,L as w,A as d,J as q,K as L,a4 as z,n as M,D as a}from"./EchoChannel-Bg1-kez_.js";import{_ as N}from"./_plugin-vue_export-helper-DlAUqK2U.js";const R={class:"uppercase text-qorus-grey-dark tracking-widest text-xs mb-2"},T={key:0,class:"no-underline",title:"required"},E={class:"relative"},I={class:"h-6 w-8 text-qorus-grey-mid hover:text-qorus-purple absolute bottom-2 right-2"},Z=["onClick"],A={key:0,class:"text-qorus-purple h-4 w-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor"},H={class:"flex flex-col gap-2 mt-2"},J={class:"text-qorus-red"},K=D({__name:"FormSelect",props:{focus:{type:Boolean},search:{type:Boolean},multiple:{type:Boolean},nullable:{type:Boolean},label:{},value:{},required:{type:Boolean},errors:{},options:{},defaultLabel:{}},emits:["change"],setup(k,{emit:_}){const o=k,e=V({value:o.value||(o.multiple?[]:""),open:!1,dropUp:!1,searchQuery:""}),v=m(null);j(v,()=>B());const c=m(),g=m(),b=_,C=()=>{const t=c.value.getBoundingClientRect();e.dropUp=t.top>window.innerHeight/2,e.open=!e.open,o.search&&M(()=>{g.value.focus()})},B=()=>{e.open===!0&&(e.searchQuery="",e.open=!1,c.value.focus())},U=t=>{o.multiple&&typeof e.value=="object"?e.value.indexOf(t)===-1?e.value.push(t):e.value=e.value.filter(r=>r!==t):e.value=t,b("change",e.value),e.open=!1,c.value.focus()},S=()=>{e.value=o.multiple?[]:null,e.searchQuery="",b("change",e.value),e.open=!1},i=t=>o.multiple&&typeof e.value=="object"&&e.value.indexOf(t)!==-1||e.value===t,F={mounted:(t,l)=>{l.value&&t.focus()}},O=x(()=>{let t,l=Object.keys(o.options);return o.multiple&&(l=l.sort((r,s)=>i(r)&&i(s)?0:i(r)&&!i(s)?-1:!i(r)&&i(s)?1:0)),t=l.reduce((r,s)=>{if(o.search&&e.searchQuery!==""){const y=new RegExp(e.searchQuery,"gi");o.options[s].match(y)&&(r[s]=o.options[s])}else r[s]=o.options[s];return r},{}),t}),Q=x(()=>{let t="";return o.multiple&&typeof e.value=="object"?t=e.value.reduce((l,r)=>l===""?o.options[r]:l+", "+o.options[r],""):(typeof e.value=="string"||typeof e.value=="number")&&(t=o.options[e.value]),t||o.defaultLabel});return(t,l)=>(a(),n("div",{ref_key:"targetFormSelect",ref:v,class:"flex flex-col"},[u("label",R,[h(f(t.label)+" ",1),t.required?(a(),n("abbr",T,"*")):p("",!0)]),u("div",E,[w((a(),n("div",{ref_key:"input",ref:c,tabindex:"0",class:d(["overflow-hidden text-ellipsis whitespace-nowrap cursor-pointer relative w-full border border-qorus-grey-light border-solid py-2 pl-4 pr-12 outline-0 focus:border-qorus-purple h-[42px]",{"border-qorus-purple":e.open,"border-qorus-red":t.errors.length,"text-qorus-grey-mid":t.multiple?!e.value.length:!e.value}]),onClick:C},[h(f(Q.value)+" ",1),u("div",I,[(a(),n("svg",{class:d({"rotate-180":e.open}),xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor"},l[1]||(l[1]=[u("path",{d:"M12.8772 17.0712L21.5 8.02551L20.4433 7L12 14.5752L3.55666 7L2.5 8.02551L11.1228 17.0712L12 18L12.8772 17.0712Z"},null,-1)]),2))])],2)),[[F,t.focus||!1]]),u("div",{class:d([{"md:bottom-full md:top-auto":e.dropUp,"md:top-full md:bottom-auto":!e.dropUp,hidden:!e.open,"flex flex-col":e.open},"bg-white shadow-sm z-10 w-full md:my-1 items-center justify-center bg-black/5 fixed md:absolute top-0 left-0 right-0 bottom-0 md:left-auto md:right-auto border border-qorus-grey-light border-solid"])},[u("ul",{class:d([{"order-2":!e.dropUp,"order-1":e.dropUp},"overflow-y-auto h-screen md:h-auto max-h-96 md:max-h-60 flex flex-col bg-white w-full"])},[(a(!0),n(q,null,L(O.value,(r,s)=>(a(),n("li",{class:"items-center flex gap-2 cursor-pointer py-2 px-4 leading-normal hover:text-qorus-purple hover:bg-qorus-purple/5",onClick:y=>U(s)},[i(s)?(a(),n("svg",A,l[2]||(l[2]=[u("path",{d:"M21.443 4L7.98148 16.54L2.55698 11.8192L1.5 12.8552C2.02849 13.4319 7.64245 19.6286 7.98148 20L8.88889 19.0617L22.5 5.03604L21.443 4Z"},null,-1)]))):p("",!0),h(" "+f(r),1)],8,Z))),256))],2),t.nullable||t.search?(a(),n("div",{key:0,class:d([{"order-1 border-b":!e.dropUp,"order-2 border-t":e.dropUp},"w-full flex border-qorus-grey-light items-center justify-end"])},[t.search?w((a(),n("input",{key:0,"onUpdate:modelValue":l[0]||(l[0]=r=>e.searchQuery=r),ref_key:"inputSearch",ref:g,class:"grow flex outline-0 border-O px-4 py-2 font-light text-qorus-grey-dark",type:"text",placeholder:"Search..."},null,512)),[[z,e.searchQuery]]):p("",!0),t.nullable?(a(),n("button",{key:1,onClick:S,class:"font-light text-xs grow-0 hover:underline hover:text-qorus-purple py-2 px-4"}," clear ")):p("",!0)],2)):p("",!0)],2)]),u("div",H,[(a(!0),n(q,null,L(t.errors,r=>(a(),n("div",J,f(r),1))),256))])],512))}}),P=N(K,[["__scopeId","data-v-548f58a3"]]);export{P as default};