import{h as t,H as s}from"./p-cdf3f581.js";import{f as i,a as e,b as n,g as r}from"./p-fb698d64.js";import{g as a}from"./p-933b240c.js";import{C as o}from"./p-2152cae9.js";import{d as c}from"./p-fc8feabd.js";function l(){this.setUpItems(),this.setUpFilter()}const h=["ArrowUp","ArrowDown"];function f(){this.setUpItems(),this.setUpFilter(),this.emitCalciteListChange=c(j.bind(this),0)}function u(){this.observer.observe(this.el,{childList:!0,subtree:!0})}function d(){this.observer.disconnect()}function m(t){const{selectedValues:s}=this,{item:i,value:e,selected:n,shiftPressed:r}=t.detail;n?(this.multiple||this.deselectSiblingItems(i),this.multiple&&r&&this.selectSiblings(i),s.set(e,i)):(s.delete(e),this.multiple&&r&&this.selectSiblings(i,!0)),this.multiple||g(i,n),this.lastSelectedItem=i,this.emitCalciteListChange()}function p(t){t.stopPropagation();const s=t.detail.oldValue,i=this.selectedValues;if(i.has(s)){const e=i.get(s);i.delete(s),i.set(t.detail.newValue,e)}}function b(t){const{key:s,target:e}=t;if(!function(t){return!!h.find(s=>s===t)}(s))return;const{items:n,multiple:r}=this,{length:o}=n,c=n.indexOf(e);if(!o||-1===c)return;t.preventDefault();const l=n[a(c+("ArrowUp"===s?-1:1),o)];g(l,!0),i(l),r||(l.selected=!0)}function j(){this.calciteListChange.emit(this.selectedValues)}function g(t,s){s?t.removeAttribute("tabindex"):t.setAttribute("tabindex","-1")}function v(){const{multiple:t,items:s}=this;if(0===s.length)return;if(t)return s[0].setFocus();return(s.find(t=>t.selected)||s[0]).setFocus()}function w(t){this.items=Array.from(this.el.querySelectorAll(t));let s=!1;const{items:i}=this;i.forEach(t=>{t.icon=this.getIconType(),this.multiple||(t.disableDeselect=!0,g(t,!1)),t.selected&&(s=!0,g(t,!0),this.selectedValues.set(t.value,t))});const[e]=i;!s&&e&&g(e,!0)}function y(t){this.items.forEach(s=>{s.value!==t.value&&(s.toggleSelected(!1),this.selectedValues.has(s.value)&&this.selectedValues.delete(s.value))})}function A(t,s=!1){if(!this.lastSelectedItem)return;const{items:i}=this,e=i.findIndex(t=>t.value===this.lastSelectedItem.value),n=i.findIndex(s=>s.value===t.value);i.slice(Math.min(e,n),Math.max(e,n)).forEach(t=>{t.toggleSelected(!s),s?this.selectedValues.delete(t.value):this.selectedValues.set(t.value,t)})}let F;function O(t){const s=t.detail.map(t=>t.value);F||(F=new Set);const i=this.items.filter(t=>{const i=t.parentElement;i.matches("calcite-pick-list-group")&&F.add(i);const e=s.includes(t.value);return t.hidden=!e,e});F.forEach(t=>{const s=i.some(s=>t.contains(s));if(t.hidden=!s,!s)return;const n=e(t,"parent-item");n&&(n.hidden=!1,i.includes(n)&&Array.from(t.children).forEach(t=>t.hidden=!1))}),F.clear()}function x(){return this.items.map(t=>({label:t.label||t.textLabel,description:t.description||t.textDescription,metadata:t.metadata,value:t.value}))}const k=i=>{var{props:e}=i,a=function(t,s){var i={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&s.indexOf(e)<0&&(i[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(e=Object.getOwnPropertySymbols(t);n<e.length;n++)s.indexOf(e[n])<0&&Object.prototype.propertyIsEnumerable.call(t,e[n])&&(i[e[n]]=t[e[n]])}return i}(i,["props"]);const{disabled:c,loading:l,filterEnabled:h,dataForFilter:f,handleFilter:u,filterPlaceholder:d,textFilterPlaceholder:m,el:p}=e,b=t("slot",null),j=d||m;return t(s,Object.assign({role:"menu","aria-disabled":c.toString(),"aria-busy":l.toString()},a),t("section",null,t("header",{class:{[o.sticky]:!0}},h?t("calcite-filter",{data:f,dir:n(p),placeholder:j,"aria-label":j,onCalciteFilterChange:u}):null,t("slot",{name:"menu-actions"})),l||c?t("calcite-scrim",{theme:r(p),loading:l},b):b))};export{k as L,u as a,m as b,d as c,y as d,p as e,w as f,x as g,O as h,f as i,v as j,b as k,l as m,A as s}