1import{a as $}from"./chunk-IUTJLVK4.js";import"./chunk-OYOXAY44.js";import"./chunk-IO44HIO6.js";import"./chunk-FDN33MRG.js";import{m as O,n as E,y as F}from"./chunk-F45KP72J.js";import{Cc as p,Dc as c,Ec as l,Lb as s,Mc as I,Pa as y,Qa as w,Qd as M,Sc as V,Vc as f,Xb as m,bd as v,cc as _,cd as D,d as S,fd as d,gd as x,hc as b,hd as q,jb as k,sa as g}from"./chunk-Z5YOIIAC.js";import{l as t,t as C}from"./chunk-ATLPHYUF.js";function T(r,n){if(r&1&&(c(0,"div",7),d(1),l()),r&2){let a=f();s(),x(a.sublabel)}}function z(r,n){if(r&1){let a=I();c(0,"button",8),V("click",function(o){let i=y(a).$implicit,u=f();return w(u.onButtonClick(o,i))}),d(1),l()}if(r&2){let a=n.$implicit,e=f();D("active",e.isSelected(a)),p("disabled",e.isDisabled||!e.connected),s(),q(" ",a.label," ")}}function N(r,n){r&1&&(c(0,"div",9),d(1," Verbindung wird hergestellt... "),l())}var J="mqtt-selector",Q=["url","user","password","broker","topic","label","sublabel","options","disabled"],U=(()=>{let n=class n{constructor(e,o,i){t(this,"elementRef");t(this,"cdr");t(this,"mqttService");t(this,"url");t(this,"user","");t(this,"password","");t(this,"broker","");t(this,"topic");t(this,"label","");t(this,"sublabel","");t(this,"options","[]");t(this,"disabled","false");t(this,"currentValue",null);t(this,"selectedLabel","--");t(this,"selectedColor","#2185d0");t(this,"connected",!1);t(this,"isDisabled",!1);t(this,"parsedOptions",[]);t(this,"destroy$",new S);t(this,"connectionConfig");this.elementRef=e,this.cdr=o,this.mqttService=i}ngOnInit(){return C(this,null,function*(){this.elementRef.nativeElement.removeAttribute("ng-version"),this.isDisabled=this.disabled==="true";try{this.parsedOptions=JSON.parse(this.options)}catch(e){console.error("[mqtt-selector] Failed to parse options:",e)}try{this.connectionConfig=yield this.mqttService.resolveConfig({url:this.url,username:this.user||void 0,password:this.password||void 0,broker:this.broker||void 0})}catch(e){console.error("[mqtt-selector] Failed to resolve MQTT auth:",e);return}this.mqttService.connect(this.connectionConfig,this.topic).pipe(g(this.destroy$)).subscribe({next:e=>{this.processValue(e.payload),this.cdr.markForCheck()},error:e=>{console.error("[mqtt-selector] Connection error:",e)}}),this.mqttService.connectionStatus$(this.connectionConfig).pipe(g(this.destroy$)).subscribe(e=>{this.connected=e,this.cdr.markForCheck()})})}processValue(e){var u;let o=parseFloat(e);this.currentValue=isNaN(o)?e:o;let i=this.parsedOptions.find(h=>typeof h.value=="number"?h.value===o:String(h.value)===e);i?(this.selectedLabel=i.label,this.selectedColor=this.getColor((u=i.color)!=null?u:"blue")):(this.selectedLabel=e,this.selectedColor="#767676")}isSelected(e){return this.currentValue===null?!1:typeof e.value=="number"?e.value===this.currentValue:String(e.value)===String(this.currentValue)}onButtonClick(e,o){e.stopPropagation(),e.preventDefault(),this.select(o)}select(e){if(this.isDisabled||!this.connected)return;let o=String(e.value);this.mqttService.publish(this.connectionConfig,this.topic,o).then(()=>{console.log("[mqtt-selector] Published ".concat(o," to ").concat(this.topic))}).catch(i=>{console.error("[mqtt-selector] Publish error:",i)})}getColor(e){return{red:"#db2828",green:"#21ba45",orange:"#f2711c",yellow:"#fbbd08",blue:"#2185d0",grey:"#767676",gray:"#767676"}[e.toLowerCase()]||e}ngOnDestroy(){this.destroy$.next(),this.destroy$.complete(),this.connectionConfig&&this.mqttService.disconnect(this.connectionConfig,this.topic)}};t(n,"\u0275fac",function(o){return new(o||n)(m(k),m(M),m($))}),t(n,"\u0275cmp",_({type:n,selectors:[["hz-mqtt-selector"]],inputs:{url:"url",user:"user",password:"password",broker:"broker",topic:"topic",label:"label",sublabel:"sublabel",options:"options",disabled:"disabled"},decls:9,vars:9,consts:[[1,"mqtt-selector-card"],[1,"mqtt-selector-label"],["class","mqtt-selector-sublabel",4,"ngIf"],[1,"mqtt-selector-value"],[1,"mqtt-selector-buttons"],["class","mqtt-selector-button",3,"active","disabled","click",4,"ngFor","ngForOf"],["class","mqtt-selector-disconnected",4,"ngIf"],[1,"mqtt-selector-sublabel"],[1,"mqtt-selector-button",3,"click","disabled"],[1,"mqtt-selector-disconnected"]],template:function(o,i){o&1&&(c(0,"div",0)(1,"div",1),d(2),l(),b(3,T,2,1,"div",2),c(4,"div",3),d(5),l(),c(6,"div",4),b(7,z,2,4,"button",5),l(),b(8,N,2,0,"div",6),l()),o&2&&(v("border-left-color",i.selectedColor),s(2),x(i.label),s(),p("ngIf",i.sublabel),s(),v("color",i.selectedColor),s(),q(" ",i.selectedLabel," "),s(2),p("ngForOf",i.parsedOptions),s(),p("ngIf",!i.connected))},dependencies:[F,O,E],styles:[":host{display:block}.mqtt-selector-card{background:#f8f9fa;border-radius:8px;padding:16px;
1min-width:200px;border-left:4px solid #2185d0}.mqtt-selector-label{color:#666;font-size:12px;text-transform:uppercase;letter-spacing:.5px;margin-bottom:4px}.mqtt-selector-sublabel{font-size:11px;color:#888;margin-bottom:4px}.mqtt-selector-value{font-size:24px;font-weight:700;margin-bottom:12px;color:#2185d0}.mqtt-selector-buttons{display:flex;gap:8px;flex-wrap:wrap}.mqtt-selector-button{padding:8px 16px;border:1px solid #e0e0e0;border-radius:4px;background:#fff;color:#333;font-size:12px;cursor:pointer;transition:all .2s}.mqtt-selector-button:hover:not(:disabled){background:#e8e8e8;border-color:#ccc}.mqtt-selector-button.active{background:#2185d0;border-color:#2185d0;color:#fff}.mqtt-selector-button:disabled{opacity:.5;cursor:not-allowed}.mqtt-selector-disconnected{font-size:11px;color:#999;font-style:italic;margin-top:8px}\n"],encapsulation:3,changeDetection:0}));let r=n;return r})();export{U as MqttSelectorComponent,Q as webComponentAttributes,J as webComponentName};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.