import{r as t,c as i,h as s}from"./p-BIwHMk6j.js";import{L as e,b as o}from"./p-D5qhls4G.js";import{g as r,a as n}from"./p-CQUZjrU4.js";import{g as h}from"./p-CI7dwT4T.js";const l=class{constructor(s){t(this,s),this.change=i(this,"change"),this.label="Property",this.required=!1,this.isOpen=!1,this.navigationPath="",this.menuItems=[],this.handleChipSetWrapperClick=t=>{t.stopPropagation()},this.handleChipSetFocus=()=>{this.isOpen||(this.navigationPath=this.value||"",this.loadMenuItems(),this.isOpen=!0)},this.handleSelect=t=>{t.stopPropagation();const i=t.detail.value;if(!i)return;const s=r(this.limetypes,this.limetype,i);(null==s?void 0:s.relation)?this.navigationPath=i:(this.change.emit(i),this.isOpen=!1,this.navigationPath="")},this.handleNavigateMenu=t=>{var i;t.stopPropagation(),(null===(i=t.detail)||void 0===i?void 0:i.value)&&(this.navigationPath=t.detail.value)},this.handleCancel=()=>{this.isOpen=!1,this.navigationPath=""},this.handleChipSetChange=t=>{t.stopPropagation();const i=t.detail;if(!i)return this.change.emit(""),void(this.navigationPath="");const s=Array.isArray(i)?i:[i];if(0===s.length)this.change.emit(""),this.navigationPath="";else{const t=s.at(-1);t&&this.change.emit(t.value),this.navigationPath=""}}}componentWillLoad(){const t=this.platform.get(o.Application).getLanguage();this.collator=new Intl.Collator(t,{numeric:!0,sensitivity:"base"})}render(){if(!this.limetype||!this.limetypes)return null;const t=this.getChipsForPath(this.navigationPath||this.value||"");return s("limel-menu",{items:this.menuItems,open:this.isOpen,emptyResultMessage:"No available properties",surfaceWidth:"inherit-from-trigger",openDirection:"bottom-end",onSelect:this.handleSelect,onNavigateMenu:this.handleNavigateMenu,onCancel:this.handleCancel},s("div",{slot:"trigger"},s("div",{onClick:this.handleChipSetWrapperClick},s("limel-chip-set",{type:"input",label:this.label,value:t,required:this.required,helperText:this.helperText,delimiter:"›",maxItems:1,onChange:this.handleChipSetChange,onFocus:this.handleChipSetFocus}))))}loadMenuItems(){const t=this.getCurrentLimetype();this.menuItems=t?this.createMenuItems(t,""):[]}getCurrentLimetype(){if(!this.navigationPath)return this.limetypes[this.limetype];const t=r(this.limetypes,this.limetype,this.navigationPath);return(null==t?void 0:t.relation)?t.relation.getLimetype():this.limetypes[this.limetype]}createMenuItems(t,i){const s=[];if(!t)return s;const e=n(t);for(const[t,o]of Object.entries(e)){if("hasmany"===o.type||"hasandbelongstomany"===o.type)continue;const e=i?`${i}.${t}`:t;let r;if(o.relation&&o.relation){const t=o.relation.getLimetype();t&&(r=async()=>this.createMenuItems(t,e))}s.push({text:o.localname||t,secondaryText:this.getSecondaryText(o),icon:this.getIconForProperty(o),value:e,items:r})}return s.sort(((t,i)=>{var s,e;return this.collator.compare(null!==(s=t.text)&&void 0!==s?s:"",null!==(e=i.text)&&void 0!==e?e:"")})),0===s.length?[{text:"No available properties",value:"",disabled:!0}]:s}getSecondaryText(t){var i;if(t.relation){const s=t.relation.getLimetype();return(null===(i=null==s?void 0:s.localname)||void 0===i?void 0:i.singular)||"Object"}return t.type.charAt(0).toUpperCase()+t.type.slice(1)}getIconForProperty(t){return t.relation?h(t.relation.getLimetype()):{name:"dot_circle",color:"rgb(var(--color-gray-default))"}}getChipsForPath(t){if(!t)return[];const i=t.split("."),s=[];let e=this.limetypes[this.limetype],o="";for(const t of i){o=o?`${o}.${t}`:t;const i=n(e)[t];i&&(s.push({id:o,text:i.localname||t,icon:this.getIconForProperty(i),value:o}),i.relation&&(e=i.relation.getLimetype()))}return s}};(function(t,i,s,e){var o,r=arguments.length,n=r<3?i:null===e?e=Object.getOwnPropertyDescriptor(i,s):e;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,i,s,e);else for(var h=t.length-1;h>=0;h--)(o=t[h])&&(n=(r<3?o(n):r>3?o(i,s,n):o(i,s))||n);r>3&&n&&Object.defineProperty(i,s,n)})([e()],l.prototype,"limetypes",void 0),l.style=":host(limebb-property-selector){display:block}limel-menu{display:block;width:100%}";export{l as limebb_property_selector}