import{p as t,H as e,c as i,h as s,a as o}from"./index.js";import{g as n,t as r}from"./p-DKo9A5gq.js";import{c}from"./p-vN03FcXN.js";import{B as a}from"./p-CNqoJU2V.js";const h={triggerEvents:"click",exclude:""};function d(t,e,i,s=h){const o=u(s);f(s).forEach((s=>{window.addEventListener(s,(s=>{l(s,t,e,i,o)}),false)}))}function l(t,e,i,s,o){const n=t.target;if(!i.contains(n)&&!p(n,o)){s.call(e)}}function f(t){if(t.triggerEvents){return t.triggerEvents.split(",").map((t=>t.trim()))}return["click"]}function u(t){if(t.exclude){try{return Array.from(document.querySelectorAll(t.exclude))}catch(e){console.warn(`@ClickOutside: Exclude: '${t.exclude}' will not be evaluated. Check your exclude selector syntax.`,e)}}return}function p(t,e){if(t&&e){for(let i of e){if(i.contains(t)){return true}}}return false}var g;(function(t){t["LEFT"]="left";t["RIGHT"]="right"})(g||(g={}));const v={root:"gov-dropdown",list:"gov-dropdown__list"};const m=t(class t extends e{constructor(){super();this.__registerHost();this.govChange=i(this,"gov-change");this.open=false;this.position=g.LEFT;this.h=n(this.host);this.listId=c("GovDropdownList");this.controlId=c("GovDropdownControl")}watchOpen(){var t;(t=this.trigger)===null||t===void 0?void 0:t.setAttribute("aria-expanded",r(this.open))}get trigger(){return this.host.querySelector(`* > ${a.root}`)}get list(){return this.h.getSlot("list")}componentWillLoad(){var t;if(!this.trigger)return;this.trigger.setAttribute("aria-controls",this.listId);this.trigger.setAttribute("aria-haspopup",r(!!this.list));this.trigger.setAttribute("aria-expanded",r(this.open));this.trigger.setAttribute("identifier",(t=this.identifier)!==null&&t!==void 0?t:this.controlId);this.trigger.addEventListener("gov-click",(t=>{t.preventDefault();t.stopPropagation();this.open=!this.open;this.govChange.emit({component:v.root,originalEvent:t,open:this.open})}))}render(){return s(o,{key:"24e596043840ec3b4e2ae0c59cecd1ec5425f5b5",class:this.h.classes([v.root]),open:this.open,position:this.position},s("slot",{key:"5c9c344162c6842585b134b327e9d45e4c1df19e"}),s("div",{key:"b424408e77eaebc2eedfe5ac1c7a916808af21f7",ref:t=>d(this,t,(()=>this.open=false)),class:v.list,id:this.listId,"aria-labelledby":this.controlId,"aria-hidden":r(!this.open),hidden:!this.open},s("slot",{key:"b39d21fd27642fd5e7ece4b9d68de2e8468b93ae",name:"list"})))}async getState(){return this.open}async toggle(){this.open=!this.open}get host(){return this}static get watchers(){return{open:["watchOpen"]}}},[4,"gov-dropdown",{identifier:[1],open:[1028],position:[1],getState:[64],toggle:[64]},undefined,{open:["watchOpen"]}]);function w(){if(typeof customElements==="undefined"){return}const t=["gov-dropdown"];t.forEach((t=>{switch(t){case"gov-dropdown":if(!customElements.get(t)){customElements.define(t,m)}break}}))}w();const b=m;const y=w;export{b as GovDropdown,y as defineCustomElement};
//# sourceMappingURL=gov-dropdown.js.map