@riddix/hamh 2.1.0-alpha.603 → 2.1.0-alpha.604
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -486,7 +486,7 @@ ${n.comment}`:n.comment}this.doc.range[2]=n.offset;break}default:this.errors.pus
|
|
|
486
486
|
`)+1;for(;n!==0;)this.onNewLine(this.offset+n),n=this.source.indexOf(`
|
|
487
487
|
`,n)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(t){const n=t.items[t.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,n.value){const r="end"in n.value?n.value.end:void 0;(Array.isArray(r)?r[r.length-1]:void 0)?.type==="comment"?r?.push(this.sourceToken):t.items.push({start:[this.sourceToken]})}else n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"space":case"comment":if(n.value)t.items.push({start:[this.sourceToken]});else if(n.sep)n.sep.push(this.sourceToken);else{if(this.atIndentedComment(n.start,t.indent)){const i=t.items[t.items.length-2]?.value?.end;if(Array.isArray(i)){Array.prototype.push.apply(i,n.start),i.push(this.sourceToken),t.items.pop();return}}n.start.push(this.sourceToken)}return}if(this.indent>=t.indent){const r=!this.onKeyLine&&this.indent===t.indent,i=r&&(n.sep||n.explicitKey)&&this.type!=="seq-item-ind";let o=[];if(i&&n.sep&&!n.value){const s=[];for(let a=0;a<n.sep.length;++a){const l=n.sep[a];switch(l.type){case"newline":s.push(a);break;case"space":break;case"comment":l.indent>t.indent&&(s.length=0);break;default:s.length=0}}s.length>=2&&(o=n.sep.splice(s[1]))}switch(this.type){case"anchor":case"tag":i||n.value?(o.push(this.sourceToken),t.items.push({start:o}),this.onKeyLine=!0):n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"explicit-key-ind":!n.sep&&!n.explicitKey?(n.start.push(this.sourceToken),n.explicitKey=!0):i||n.value?(o.push(this.sourceToken),t.items.push({start:o,explicitKey:!0})):this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case"map-value-ind":if(n.explicitKey)if(n.sep)if(n.value)t.items.push({start:[],key:null,sep:[this.sourceToken]});else if($d(n.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:null,sep:[this.sourceToken]}]});else if(gle(n.key)&&!$d(n.sep,"newline")){const s=wm(n.start),a=n.key,l=n.sep;l.push(this.sourceToken),delete n.key,delete n.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:a,sep:l}]})}else o.length>0?n.sep=n.sep.concat(o,this.sourceToken):n.sep.push(this.sourceToken);else if($d(n.start,"newline"))Object.assign(n,{key:null,sep:[this.sourceToken]});else{const s=wm(n.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:null,sep:[this.sourceToken]}]})}else n.sep?n.value||i?t.items.push({start:o,key:null,sep:[this.sourceToken]}):$d(n.sep,"map-value-ind")?this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):n.sep.push(this.sourceToken):Object.assign(n,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{const s=this.flowScalar(this.type);i||n.value?(t.items.push({start:o,key:s,sep:[]}),this.onKeyLine=!0):n.sep?this.stack.push(s):(Object.assign(n,{key:s,sep:[]}),this.onKeyLine=!0);return}default:{const s=this.startBlockValue(t);if(s){if(s.type==="block-seq"){if(!n.explicitKey&&n.sep&&!$d(n.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else r&&t.items.push({start:o});this.stack.push(s);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(t){const n=t.items[t.items.length-1];switch(this.type){case"newline":if(n.value){const r="end"in n.value?n.value.end:void 0;(Array.isArray(r)?r[r.length-1]:void 0)?.type==="comment"?r?.push(this.sourceToken):t.items.push({start:[this.sourceToken]})}else n.start.push(this.sourceToken);return;case"space":case"comment":if(n.value)t.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(n.start,t.indent)){const i=t.items[t.items.length-2]?.value?.end;if(Array.isArray(i)){Array.prototype.push.apply(i,n.start),i.push(this.sourceToken),t.items.pop();return}}n.start.push(this.sourceToken)}return;case"anchor":case"tag":if(n.value||this.indent<=t.indent)break;n.start.push(this.sourceToken);return;case"seq-item-ind":if(this.indent!==t.indent)break;n.value||$d(n.start,"seq-item-ind")?t.items.push({start:[this.sourceToken]}):n.start.push(this.sourceToken);return}if(this.indent>t.indent){const r=this.startBlockValue(t);if(r){this.stack.push(r);return}}yield*this.pop(),yield*this.step()}*flowCollection(t){const n=t.items[t.items.length-1];if(this.type==="flow-error-end"){let r;do yield*this.pop(),r=this.peek(1);while(r?.type==="flow-collection")}else if(t.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":!n||n.sep?t.items.push({start:[this.sourceToken]}):n.start.push(this.sourceToken);return;case"map-value-ind":!n||n.value?t.items.push({start:[],key:null,sep:[this.sourceToken]}):n.sep?n.sep.push(this.sourceToken):Object.assign(n,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":!n||n.value?t.items.push({start:[this.sourceToken]}):n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{const i=this.flowScalar(this.type);!n||n.value?t.items.push({start:[],key:i,sep:[]}):n.sep?this.stack.push(i):Object.assign(n,{key:i,sep:[]});return}case"flow-map-end":case"flow-seq-end":t.end.push(this.sourceToken);return}const r=this.startBlockValue(t);r?this.stack.push(r):(yield*this.pop(),yield*this.step())}else{const r=this.peek(2);if(r.type==="block-map"&&(this.type==="map-value-ind"&&r.indent===t.indent||this.type==="newline"&&!r.items[r.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&r.type!=="flow-collection"){const i=V5(r),o=wm(i);MG(t);const s=t.end.splice(1,t.end.length);s.push(this.sourceToken);const a={type:"block-map",offset:t.offset,indent:t.indent,items:[{start:o,key:t,sep:s}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=a}else yield*this.lineEnd(t)}}flowScalar(t){if(this.onNewLine){let n=this.source.indexOf(`
|
|
488
488
|
`)+1;for(;n!==0;)this.onNewLine(this.offset+n),n=this.source.indexOf(`
|
|
489
|
-
`,n)+1}return{type:t,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(t){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;const n=V5(t),r=wm(n);return r.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:r,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;const n=V5(t),r=wm(n);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:r,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(t,n){return this.type!=="comment"||this.indent<=n?!1:t.every(r=>r.type==="newline"||r.type==="space")}*documentEnd(t){this.type!=="doc-mode"&&(t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()))}*lineEnd(t){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop())}}}function yle(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new mle||null,prettyErrors:t}}function vat(e,t={}){const{lineCounter:n,prettyErrors:r}=yle(t),i=new eI(n?.addNewLine),o=new QR(t),s=Array.from(o.compose(i.parse(e)));if(r&&n)for(const a of s)a.errors.forEach(Gw(e,n)),a.warnings.forEach(Gw(e,n));return s.length>0?s:Object.assign([],{empty:!0},o.streamInfo())}function ble(e,t={}){const{lineCounter:n,prettyErrors:r}=yle(t),i=new eI(n?.addNewLine),o=new QR(t);let s=null;for(const a of o.compose(i.parse(e),!0,e.length))if(!s)s=a;else if(s.options.logLevel!=="silent"){s.errors.push(new zh(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return r&&n&&(s.errors.forEach(Gw(e,n)),s.warnings.forEach(Gw(e,n))),s}function xat(e,t,n){let r;typeof t=="function"?r=t:n===void 0&&t&&typeof t=="object"&&(n=t);const i=ble(e,n);if(!i)return null;if(i.warnings.forEach(o=>Lae(i.options.logLevel,o)),i.errors.length>0){if(i.options.logLevel!=="silent")throw i.errors[0];i.errors=[]}return i.toJS(Object.assign({reviver:r},n))}function Sat(e,t,n){let r=null;if(typeof t=="function"||Array.isArray(t)?r=t:n===void 0&&t&&(n=t),typeof n=="string"&&(n=n.length),typeof n=="number"){const i=Math.round(n);n=i<1?void 0:i>8?{indent:8}:{indent:i}}if(e===void 0){const{keepUndefined:i}=n??t??{};if(!i)return}return Ep(e)&&!r?e.toString(n):new R0(e,r,n).toString(n)}const wat=Object.freeze(Object.defineProperty({__proto__:null,Alias:a8,CST:gat,Composer:QR,Document:R0,Lexer:ple,LineCounter:mle,Pair:zo,Parser:eI,Scalar:sn,Schema:g8,YAMLError:ZR,YAMLMap:Qs,YAMLParseError:zh,YAMLSeq:Of,YAMLWarning:rle,isAlias:zf,isCollection:ii,isDocument:Ep,isMap:T0,isNode:oi,isPair:Xr,isScalar:Ir,isSeq:O0,parse:xat,parseAllDocuments:vat,parseDocument:ble,stringify:Sat,visit:Ap,visitAsync:s8},Symbol.toStringTag,{value:"Module"}));function Cat(e){let t=null;try{t=wat.parse(e.doc.toString())}catch{}const n=pR(e,Jr.YAML);return{data:t,pointers:n}}const vle=e=>{switch(e){case Jr.JSON:return est;case Jr.JSON5:return hst;case Jr.YAML:return Cat}};function kat(e){return Object.entries(e)}function Sy(e,t){if(typeof e=="string"||typeof e!="object"||e===null)return e;if(Array.isArray(e))return e.map(i=>Sy(i,t));if(e instanceof Map){const i=new Map;for(const[o,s]of e){const a=o,l=Sy(s,t);i.set(a,l)}return i}if(e instanceof Set){const i=new Set;for(const o of e){const s=Sy(o,t);i.add(s)}return i}const n={};function r(i,o,s,a){s===i&&a===o?n[s]=Sy(o,t):n[s]=a}for(const[i,o]of kat(e)){const s=t(i,o);if(s.length===2&&typeof s[0]=="string")r(i,o,s[0],s[1]);else for(const[a,l]of s)r(i,o,a,l)}return n}var Eat=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};class Aat{constructor(){this.completions=new Map,this.reservedKeys=new Set}reserve(t){this.reservedKeys.add(t)}add(t){this.reservedKeys.has(t.label)||this.completions.set(t.label,t)}}function rb(e){return!(!e||Ho(e)||e.name==="UnknownPropertyError"||e.type==="undefined")}class Dat{constructor(t){var n,r,i;this.opts=t,this.originalSchema=null,this.schema=null,this.laxSchema=null,this.mode=Jr.JSON,this.mode=(n=t.mode)!==null&&n!==void 0?n:Jr.JSON,this.parser=(i=(r=this.opts)===null||r===void 0?void 0:r.jsonParser)!==null&&i!==void 0?i:vle(this.mode)}doComplete(t){var n;const r=mR(t.state);if(this.originalSchema!==r&&(this.schema=(n=wh(r,r))!==null&&n!==void 0?n:r,this.laxSchema=Tat(this.schema)),!this.schema||!this.laxSchema)return[];ni.log("xxx","trying with original schema");const i=this.doCompleteForSchema(t,this.schema);return i.options.length!==0?i:(ni.log("xxx","no completions with original schema, trying with lax schema"),this.doCompleteForSchema(t,this.laxSchema))}doCompleteForSchema(t,n){var r,i;const o={from:t.pos,to:t.pos,options:[],filter:!1},s=t.state.doc.sliceString(0);let a=Q7(t.state,t.pos),l=t.state.sliceDoc(a.from,t.pos).replace(/^(["'])/,"");if(ni.log("xxx","node",a,"prefix",l,"ctx",t),!(VS(a,this.mode)||_5(a,this.mode))&&!t.explicit)return ni.log("xxx","no completions for non-word/primitive",a),o;const c=Pm(t.state.doc,a),u=Pm(t.state.doc,a,!1);if(a&&(VS(a,this.mode)||_5(a,this.mode)))o.from=a.from,o.to=a.to;else{const y=t.matchBefore(/[A-Za-z0-9._]*/),b=t.pos-c.length;ni.log("xxx","overwriteStart after",b,"ctx.pos",t.pos,"word",y,"currentWord",c,"=>",s[b-1],"..",s[b],"..",s),o.from=a.name===un.INVALID?(r=y?.from)!==null&&r!==void 0?r:t.pos:b,o.to=t.pos}const d=new Aat;let p=!0;const g=oK(a,un.PROPERTY_NAME,this.mode);if(g&&(ni.log("xxx","closestPropertyNameNode",g,"node",a),a=g),_5(a,this.mode)){ni.log("xxx","isPropertyNameNode",a);const y=a.parent;if(y){const b=iK(y,this.mode);p=!b||b.name===un.INVALID&&b.from-b.to===0||(b.parent?yv(b.parent).length<=1:!1),ni.log("xxx","addValue",p,iK(y,this.mode),a),a=(i=oK(y,un.OBJECT,this.mode))!==null&&i!==void 0?i:null}}if(ni.log("xxx",a,c,t,"node at pos",Q7(t.state,t.pos)),a&&[un.OBJECT,un.JSON_TEXT].includes(wi(a.name,this.mode))&&(_5(Q7(t.state,t.pos),this.mode)||g)){if(a.from===t.pos)return ni.log("xxx","no completions for just before opening brace"),o;this.getPropertyCompletions(n,t,a,d,p,u)}else{const y={},b=this.getValueCompletions(n,t,y,d);ni.log("xxx","getValueCompletions res",b)}return o.options=Array.from(d.completions.values()).filter(y=>US(y.label).startsWith(l)),ni.log("xxx","result",o,"prefix",l,"collector.completions",d.completions,"reservedKeys",d.reservedKeys),o}applySnippetCompletion(t){return GJe(typeof t.apply!="string"?t.label:t.apply,t)}getPropertyCompletions(t,n,r,i,o,s){const a=NZe(r,un.PROPERTY,this.mode);ni.log("xxx","getPropertyCompletions",r,n,a),a.forEach(c=>{const u=Pm(n.state.doc,aT(c,un.PROPERTY_NAME,this.mode));i.reserve(US(u))});const l=this.getSchemas(t,n);ni.log("xxx","propertyCompletion schemas",l),l.forEach(c=>{if(typeof c!="object")return;const u=c.properties;u&&Object.entries(u).forEach(([p,g])=>{var y,b;if(typeof g=="object"){const v=(y=g.description)!==null&&y!==void 0?y:"",S=(b=g.type)!==null&&b!==void 0?b:"",C=Array.isArray(S)?S.toString():S,w={label:p,apply:this.getInsertTextForProperty(p,o,s,t,g),type:"property",detail:C,info:()=>Yl("div",{inner:bg(v)})};i.add(this.applySnippetCompletion(w))}});const d=c.propertyNames;if(typeof d=="object"&&(d.enum&&d.enum.forEach(p=>{const g=p?.toString();if(g){const y={label:g,apply:this.getInsertTextForProperty(g,o,s,t),type:"property"};i.add(this.applySnippetCompletion(y))}}),d.const)){const p=d.const.toString(),g={label:p,apply:this.getInsertTextForProperty(p,o,s,t),type:"property"};i.add(this.applySnippetCompletion(g))}})}getInsertTextForProperty(t,n,r,i,o){o=o&&wh(o,i);let s=this.getInsertTextForPropertyName(t,r);if(!n)return s;s+=": ";let a,l=0;if(typeof o=="object"){if(typeof o.default<"u")a||(a=this.getInsertTextForGuessedValue(o.default,"")),l++;else if(o.enum&&(!a&&o.enum.length===1&&(a=this.getInsertTextForGuessedValue(o.enum[0],"")),l+=o.enum.length),typeof o.const<"u"&&(a||(a=this.getInsertTextForGuessedValue(o.const,"")),l++),Array.isArray(o.examples)&&o.examples.length&&(a||(a=this.getInsertTextForGuessedValue(o.examples[0],"")),l+=o.examples.length),a===void 0&&l===0){let c=Array.isArray(o.type)?o.type[0]:o.type;switch(c||(o.properties?c="object":o.items&&(c="array")),c){case"boolean":a="#{}";break;case"string":a=this.getInsertTextForString("");break;case"object":switch(this.mode){case Jr.JSON5:a="{#{}}";break;case Jr.YAML:a="#{}";break;default:a="{#{}}";break}break;case"array":a="[#{}]";break;case"number":case"integer":a="#{0}";break;case"null":a="#{null}";break;default:a="#{}";break}}}return(!a||l>1)&&(ni.log("xxx","value",a,"nValueProposals",l,o),a="#{}"),s+a}getInsertTextForPropertyName(t,n){switch(this.mode){case Jr.JSON5:case Jr.YAML:return n.startsWith('"')?`"${t}"`:n.startsWith("'")?`'${t}'`:t;default:return`"${t}"`}}getInsertTextForString(t,n="#"){switch(this.mode){case Jr.JSON5:return`'${n}{${t}}'`;case Jr.YAML:return`${n}{${t}}`;default:return`"${n}{${t}}"`}}getInsertTextForGuessedValue(t,n=""){switch(typeof t){case"object":return t===null?"${null}"+n:this.getInsertTextForValue(t,n);case"string":{let r=JSON.stringify(t);return r=r.substr(1,r.length-2),r=this.getInsertTextForPlainText(r),this.getInsertTextForString(r,"$")+n}case"number":case"boolean":return"${"+JSON.stringify(t)+"}"+n}return this.getInsertTextForValue(t,n)}getInsertTextForPlainText(t){return t.replace(/[\\$}]/g,"\\$&")}getInsertTextForValue(t,n){const r=JSON.stringify(t,null," ");return r==="{}"?"{#{}}"+n:r==="[]"?"[#{}]"+n:this.getInsertTextForPlainText(r+n)}getValueCompletions(t,n,r,i){let o=$i(n.state).resolveInner(n.pos,-1),s=null,a;if(ni.log("xxx","getValueCompletions",o,n),o&&VS(o,this.mode)&&(s=o,o=o.parent),!o){this.addSchemaValueCompletions(t,r,i);return}if(wi(o.name,this.mode)===un.PROPERTY){const c=aT(o,un.PROPERTY_NAME,this.mode);c&&(a=Pm(n.state.doc,c),o=o.parent)}if(ni.log("xxx","node",o,"parentKey",a),o&&(a!==void 0||wi(o.name,this.mode)===un.ARRAY)){const c=this.getSchemas(t,n);for(const u of c){if(typeof u!="object")return;if(wi(o.name,this.mode)===un.ARRAY&&u.items){let d=i;if(u.uniqueItems&&(d=Object.assign(Object.assign({},d),{add(p){d.completions.has(p.label)||i.add(p)},reserve(p){i.reserve(p)}})),Array.isArray(u.items)){let p=0;if(s){const y=_oe(o,s,this.mode);y>=0&&(p=y)}const g=u.items[p];g&&this.addSchemaValueCompletions(g,r,d)}else this.addSchemaValueCompletions(u.items,r,d)}if((u.type==null||u.type!=="object")&&this.addSchemaValueCompletions(u,r,i),a!==void 0){let d=!1;if(u.properties){const p=u.properties[a];p&&(d=!0,this.addSchemaValueCompletions(p,r,i))}if(u.patternProperties&&!d)for(const p of Object.keys(u.patternProperties)){const g=this.extendedRegExp(p);if(g?.test(a)){d=!0;const y=u.patternProperties[p];y&&this.addSchemaValueCompletions(y,r,i)}}if(u.additionalProperties&&!d){const p=u.additionalProperties;this.addSchemaValueCompletions(p,r,i)}}r.boolean&&(this.addBooleanValueCompletion(!0,i),this.addBooleanValueCompletion(!1,i)),r.null&&this.addNullValueCompletion(i)}}return{valuePrefix:s?Pm(n.state.doc,s,!0,!1):""}}addSchemaValueCompletions(t,n,r){typeof t=="object"&&(this.addEnumValueCompletions(t,r),this.addDefaultValueCompletions(t,r),this.collectTypes(t,n),Array.isArray(t.allOf)&&t.allOf.forEach(i=>this.addSchemaValueCompletions(i,n,r)),Array.isArray(t.anyOf)&&t.anyOf.forEach(i=>this.addSchemaValueCompletions(i,n,r)),Array.isArray(t.oneOf)&&t.oneOf.forEach(i=>this.addSchemaValueCompletions(i,n,r)))}addDefaultValueCompletions(t,n,r=0){let i=!1;if(typeof t.default<"u"){let o=t.type,s=t.default;for(let l=r;l>0;l--)s=[s],o="array";const a=Object.assign(Object.assign({type:o?.toString()},this.getAppliedValue(s)),{detail:"Default value"});n.add(a),i=!0}Array.isArray(t.examples)&&t.examples.forEach(o=>{let s=t.type,a=o;for(let l=r;l>0;l--)a=[a],s="array";n.add(Object.assign({type:s?.toString()},this.getAppliedValue(a))),i=!0}),!i&&typeof t.items=="object"&&!Array.isArray(t.items)&&r<5&&this.addDefaultValueCompletions(t.items,n,r+1)}addEnumValueCompletions(t,n){var r,i;if(typeof t.const<"u"&&n.add(Object.assign(Object.assign({type:(r=t.type)===null||r===void 0?void 0:r.toString()},this.getAppliedValue(t.const)),{info:t.description})),Array.isArray(t.enum))for(let o=0,s=t.enum.length;o<s;o++){const a=t.enum[o];n.add(Object.assign(Object.assign({type:(i=t.type)===null||i===void 0?void 0:i.toString()},this.getAppliedValue(a)),{info:t.description}))}}addBooleanValueCompletion(t,n){n.add({type:"boolean",label:t?"true":"false"})}addNullValueCompletion(t){t.add({type:"null",label:"null"})}collectTypes(t,n){if(Array.isArray(t.enum)||typeof t.const<"u")return;const r=t.type;Array.isArray(r)?r.forEach(i=>n[i]=!0):r&&(n[r]=!0)}getSchemas(t,n){var r,i,o;const{data:s}=this.parser(n.state),a=new pse(t);let l=Aoe(n.state,n.pos,-1,this.mode);if(l===""&&(l=void 0),l!=null&&l.endsWith("/")){l=l.substring(0,l.length-1);const y=jG(t,s,l);if(y!=null)return[y]}let c=l?.replace(/\/[^/]*$/,"");c===""&&(c=void 0);const u=jG(t,s,c),d=l?.split("/").pop(),p=d==null||d in((r=u?.properties)!==null&&r!==void 0?r:{});let g=a.getSchema({pointer:l,data:s??void 0});return!p&&g?.type==="null"&&this.mode==="yaml"&&(g=void 0),ni.log("xxxx","draft.getSchema",g,"data",s,"pointer",l,"pointerPointsToKnownProperty",p),Ho(g)&&(g=(i=g.data)===null||i===void 0?void 0:i.schema),!rb(g)&&u?[u]:(rb(g)||(g=a.getSchema({pointer:c}),l=c),ni.log("xxx","pointer..",JSON.stringify(l)),!rb(g)&&(!l||l==="/")&&(g=(o=wh(t,t))!==null&&o!==void 0?o:t),ni.log("xxx","subSchema..",g),g?Array.isArray(g.allOf)?[g,...g.allOf.map(y=>wh(y,t))]:Array.isArray(g.oneOf)?[g,...g.oneOf.map(y=>wh(y,t))]:Array.isArray(g.anyOf)?[g,...g.anyOf.map(y=>wh(y,t))]:[g]:[])}getAppliedValue(t){const n=US(JSON.stringify(t));switch(this.mode){case Jr.JSON5:return{label:n,apply:IZe(JSON.stringify(t))};case Jr.YAML:return{label:n,apply:n};default:return{label:n,apply:JSON.stringify(t)}}}getValueFromLabel(t){return JSON.parse(t)}extendedRegExp(t){let n="";t.startsWith("(?i)")&&(t=t.substring(4),n="i");try{return new RegExp(t,n+"u")}catch{try{return new RegExp(t,n)}catch{return}}}}function _at(e={}){const t=new Dat(e);return function(r){return t.doComplete(r)}}function Tat(e){return Sy(e,(t,n)=>t==="additionalProperties"&&n===!1?[]:t==="required"&&Array.isArray(n)?[]:t==="unevaluatedProperties"&&n===!1?[]:t==="unevaluatedItems"&&n===!1?[]:[t,n])}function jG(e,t,n){const r=new pse(e),i=r.getSchema({pointer:n,data:t??void 0});if(!rb(i))return;const o=xle(r,i),s={};for(let p of o){let g=Mat(n,p);const y=r.getSchema({pointer:g,data:t??void 0});rb(y)&&Object.assign(s,{[p]:y})}if(o.length===0||Object.keys(s).length===0)return;const a=i,{allOf:l,anyOf:c,oneOf:u}=a,d=Eat(a,["allOf","anyOf","oneOf"]);return Object.assign(Object.assign({},d),{properties:s})}function xle(e,t){if(t=wh(t,e.rootSchema),typeof t!="object"||t==null)return[];const n=[];function r(i){const o=xle(e,i);n.push(...o)}if(typeof t.properties=="object"&&t.properties!=null&&n.push(...Object.keys(t.properties)),typeof t.then=="object"&&t.then!=null&&r(t.then),Array.isArray(t.allOf))for(const i of t.allOf)r(i);if(Array.isArray(t.anyOf))for(const i of t.anyOf)r(i);if(Array.isArray(t.oneOf))for(const i of t.oneOf)r(i);return n}function wh(e,t){if(typeof e=="object"&&e.$ref){const n=Oat(t,e.$ref);if(typeof n=="object"){const r=Object.assign(Object.assign({},e),n);return Reflect.deleteProperty(r,"$ref"),r}}return e}function Oat(e,t){const n=t.split("/");let r=e;return n.forEach(i=>{if(i){if(i==="#"){r=e;return}typeof r=="object"&&(r=r[i])}}),r}function Mat(e,t){return e===void 0?`/${t}`:`${e}/${t}`}const y2=(e,t)=>{const n=e.length>2;let r=e.map((i,o)=>{const s="`"+(t?t(i):i)+"`";return o===e.length-1?"or "+s:s});return n?r.join(", "):r.join(" ")},jat=e=>{var t,n,r;return!((t=e?.data)===null||t===void 0)&&t.pointer&&((n=e?.data)===null||n===void 0?void 0:n.pointer)!=="#"?e.data.pointer.slice(1):!((r=e?.data)===null||r===void 0)&&r.property?`/${e.data.property}`:""},Rat=e=>e.startState.field(kw)!==e.state.field(kw);function Iat(e){const t=new Nat(e);return n=>t.doValidation(n)}const Pat=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class Nat{constructor(t){var n,r,i,o;this.options=t,this.schema=null,this.mode=Jr.JSON,this.rewriteError=s=>{var a,l,c,u,d;const p=s?.data,g=p?.errors;return s.code==="one-of-error"&&g?.length?`Expected one of ${y2(g,b=>b.data.expected)}`:s.code==="type-error"?`Expected \`${!((a=s?.data)===null||a===void 0)&&a.expected&&Array.isArray((l=s?.data)===null||l===void 0?void 0:l.expected)?y2((c=s?.data)===null||c===void 0?void 0:c.expected):(u=s?.data)===null||u===void 0?void 0:u.expected}\` but received \`${(d=s?.data)===null||d===void 0?void 0:d.received}\``:s.message.replaceAll("in `#` ","").replaceAll("at `#`","").replaceAll("/",".").replaceAll("#.","")},this.mode=(r=(n=this.options)===null||n===void 0?void 0:n.mode)!==null&&r!==void 0?r:Jr.JSON,this.parser=(o=(i=this.options)===null||i===void 0?void 0:i.jsonParser)!==null&&o!==void 0?o:vle(this.mode)}get schemaTitle(){var t,n,r;return(r=(n=(t=this.schema)===null||t===void 0?void 0:t.getSchema())===null||n===void 0?void 0:n.title)!==null&&r!==void 0?r:"json-schema"}doValidation(t){const n=mR(t.state);if(!n)return[];if(this.schema=new fse(n),!this.schema)return[];const r=t.state.doc.toString();if(!r?.length)return[];const i=this.parser(t.state);if(i.data==null)return[];let o=[];try{o=this.schema.validate(i.data)}catch{}return ni.log("xxx","validation errors",o,i.data),o.length?o.reduce((s,a)=>{const l=()=>{const d=this.rewriteError(a);s.push({from:0,to:0,message:d,severity:"error",source:this.schemaTitle,renderMessage:()=>{const p=Yl("div",{});return p.innerHTML=bg(d),p}})},c=jat(a),u=i.pointers.get(c);if(a.name==="MaxPropertiesError"||a.name==="MinPropertiesError"||c==="")l();else if(u){const d=Pat.includes(a.name),p=this.rewriteError(a),g=d?u.keyFrom:u.valueFrom,y=d?u.keyTo:u.valueTo;y!==void 0&&g!==void 0&&s.push({from:g,to:y,message:p,renderMessage:()=>{const b=Yl("div",{});return b.innerHTML=bg(p),b},severity:"error",source:this.schemaTitle})}else l();return s},[]):[]}}function $at(e){const t=new Lat(e);return async function(r,i,o){return t.doHover(r,i,o)}}function RG(e){if(e.type)return e.$ref?`${e.$ref} (${e.type})`:e.type;if(e.$ref)return`${e.$ref}`}function MA(e,t,n){return`${t}: ${y2(e[t].map(r=>{try{const{data:i}=n.resolveRef({data:r,pointer:r.$ref});return RG(i||r)}catch{return r.type}}))}`}class Lat{constructor(t){var n,r;this.opts=t,this.schema=null,this.mode=Jr.JSON,this.opts=Object.assign({parser:JSON.parse},this.opts),this.mode=(r=(n=this.opts)===null||n===void 0?void 0:n.mode)!==null&&r!==void 0?r:Jr.JSON}getDataForCursor(t,n,r){const i=mR(t.state);if(!i)return null;this.schema=new fse(i);const o=Aoe(t.state,n,r,this.mode);let s;try{s=this.opts.parser(t.state.doc.toString())}catch{}if(!o)return null;let a=this.schema.getSchema({pointer:o,data:s,withSchemaWarning:!0});return Ho(a)&&(a?.data.schema.$ref?a=this.schema.resolveRef(a):a=a?.data.schema),{schema:a,pointer:o}}formatMessage(t){const{message:n,typeInfo:r}=t;return n?Yl("div",{class:"cm6-json-schema-hover"},[Yl("div",{class:"cm6-json-schema-hover--description",inner:bg(n,!1)}),Yl("div",{class:"cm6-json-schema-hover--code-wrapper"},[Yl("div",{class:"cm6-json-schema-hover--code",inner:bg(r,!1)})])]):Yl("div",{class:"cm6-json-schema-hover"},[Yl("div",{class:"cm6-json-schema-hover--code-wrapper"},[Yl("code",{class:"cm6-json-schema-hover--code",inner:bg(r,!1)})])])}getHoverTexts(t,n){let r="",i=null;const{schema:o}=t;return o.oneOf&&(r=MA(o,"oneOf",n)),o.anyOf&&(r=MA(o,"anyOf",n)),o.allOf&&(r=MA(o,"allOf",n)),o.type&&(r=Array.isArray(o.type)?y2(o.type):o.type),o.$ref&&(r=` Reference: ${o.$ref}`),o.enum&&(r=`\`enum\`: ${y2(o.enum)}`),o.format&&(r+=`\`format\`: ${o.format}`),o.pattern&&(r+=`\`pattern\`: ${o.pattern}`),o.description&&(i=o.description),{message:i,typeInfo:r}}async doHover(t,n,r){var i,o,s,a;const l=n,c=n;try{const u=this.getDataForCursor(t,n,r);if(ni.log("cursorData",u),!u?.schema)return null;const p=((o=(i=this.opts)===null||i===void 0?void 0:i.getHoverTexts)!==null&&o!==void 0?o:this.getHoverTexts)(u,this.schema),y=((a=(s=this.opts)===null||s===void 0?void 0:s.formatHover)!==null&&a!==void 0?a:this.formatMessage)(p);return{pos:l,end:c,arrow:!0,above:!0,create:b=>({dom:y})}}catch(u){return ni.log(u),null}}}const Fat=e=>h.jsx(Fo,{disablePadding:!0,children:e.validationErrors.map((t,n)=>h.jsx(Es,{disableGutters:!0,disablePadding:!0,children:h.jsxs(Wt,{direction:"row",spacing:1,children:[h.jsx(re,{variant:"body2",children:"•"}),h.jsx(re,{variant:"caption",children:t.instancePath.length===0?"/":t.instancePath}),h.jsx(re,{variant:"body2",children:t.message})]})},n.toString()))}),IG=e=>{let t;try{t=JSON.parse(e)}catch{t=void 0}return t};function zat({schema:e,customValidate:t}){const n=A.useMemo(()=>new bne({allErrors:!0}),[]);return A.useCallback(r=>{const i=[];return n.validate(e,r),i.push(...n.errors??[]),i.push(...t?.(r)??[]),i},[n,e,t])}const Bat=e=>{const t=Hat(),[n,r]=A.useState(()=>JSON.stringify(e.value,null,2)),i=zat(e),[o,s]=A.useState([]);A.useEffect(()=>{s(i(e.value))},[i,e.value]);const a=e.onChange,l=A.useCallback(u=>{const d=IG(u),p=i(d);a(d,p.length===0),r(u),s(p)},[i,a]),c=()=>{const u=IG(n);u&&r(JSON.stringify(u,null,2))};return h.jsxs(Wt,{spacing:2,children:[h.jsxs(se,{position:"relative",children:[h.jsx(woe,{value:n,onChange:u=>l(u),extensions:[tGe(),Aq(QKe(),{delay:100}),Aq(Iat(),{delay:100,needsRefresh:Rat}),gie.data.of({autocomplete:_at({mode:"json4"})}),Jre($at()),FZe(e.schema)],theme:t,height:"400px"}),h.jsx(Ue,{sx:{position:"absolute",right:"0",bottom:"0"},onClick:()=>c(),children:"Prettify"})]}),o.length>0&&h.jsx(zt,{severity:"error",variant:"outlined",children:h.jsx(Fat,{validationErrors:o})})]})};function Hat(){return Ki().palette.mode==="dark"?kGe:xGe}const Uat=[{value:"",label:"Auto (based on domain/name)"},{value:"light",label:"💡 Light"},{value:"switch",label:"🔌 Switch"},{value:"climate",label:"🌡️ Climate"},{value:"cover",label:"🪟 Cover"},{value:"fan",label:"🌀 Fan"},{value:"lock",label:"🔒 Lock"},{value:"sensor",label:"📊 Sensor"},{value:"media_player",label:"📺 Media Player"},{value:"vacuum",label:"🧹 Vacuum"},{value:"remote",label:"🎮 Remote"},{value:"humidifier",label:"💧 Humidifier"},{value:"speaker",label:"🔊 Speaker"},{value:"garage",label:"🚗 Garage"},{value:"door",label:"🚪 Door"},{value:"window",label:"🪟 Window"},{value:"motion",label:"🏃 Motion"},{value:"battery",label:"🔋 Battery"},{value:"power",label:"⚡ Power"},{value:"camera",label:"📷 Camera"},{value:"default",label:"🔗 Default"}],Vat=({bridgeId:e,selectedIcon:t,onIconChange:n})=>{const r=A.useRef(null),[i,o]=A.useState(!1),[s,a]=A.useState(null),[l,c]=A.useState(!1),[u,d]=A.useState(null);A.useEffect(()=>{e&&hC(e).then(b=>{o(b),b&&a(`${Db(e)}?t=${Date.now()}`)}).catch(()=>{o(!1)})},[e]);const p=A.useCallback(async b=>{const v=b.target.files?.[0];if(!(!v||!e)){d(null),c(!0);try{await ETe(e,v),o(!0),a(`${Db(e)}?t=${Date.now()}`),n(void 0)}catch(S){d(S instanceof Error?S.message:"Upload failed")}finally{c(!1),r.current&&(r.current.value="")}}},[e,n]),g=A.useCallback(async()=>{if(e){d(null);try{await ATe(e),o(!1),a(null)}catch(b){d(b instanceof Error?b.message:"Delete failed")}}},[e]),y=A.useCallback(b=>{n(b===""?void 0:b)},[n]);return h.jsxs(Wt,{spacing:2,children:[h.jsxs(rs,{fullWidth:!0,size:"small",children:[h.jsx(Ia,{id:"icon-select-label",children:"Bridge Icon"}),h.jsx(ts,{labelId:"icon-select-label",value:t??"",label:"Bridge Icon",onChange:b=>y(b.target.value),disabled:i,children:Uat.map(b=>h.jsx(Bn,{value:b.value,children:b.label},b.value))}),h.jsx(tC,{children:i?"Custom icon is set. Delete it to use preset icons.":"Select a preset icon or upload a custom image"})]}),e&&h.jsxs(se,{children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"Custom Icon"}),h.jsxs(Wt,{direction:"row",spacing:2,alignItems:"center",children:[i&&s&&h.jsx(se,{component:"img",src:s,alt:"Custom bridge icon",sx:{width:48,height:48,objectFit:"contain",borderRadius:1,border:"1px solid",borderColor:"divider"}}),h.jsx("input",{ref:r,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp,image/svg+xml",style:{display:"none"},onChange:p}),h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(B_e,{}),onClick:()=>r.current?.click(),disabled:l,children:l?"Uploading...":"Upload Image"}),i&&h.jsx(Ue,{variant:"outlined",size:"small",color:"error",startIcon:h.jsx(Pa,{}),onClick:g,children:"Delete"})]}),u&&h.jsx(re,{variant:"caption",color:"error",sx:{mt:1},children:u}),h.jsx(re,{variant:"caption",color:"text.secondary",sx:{mt:1,display:"block"},children:"Supported formats: PNG, JPG, GIF, WebP, SVG (max 5MB)"})]}),!e&&h.jsx(re,{variant:"body2",color:"text.secondary",children:"Save the bridge first to upload a custom icon."})]})},Cm={light:"Light",switch:"On/Off Plug-in Unit",lock:"Door Lock",fan:"Fan",binary_sensor:"Sensor",sensor:"Sensor",cover:"Window Covering",climate:"Thermostat",media_player:"Speaker / Video Player",vacuum:"Robot Vacuum Cleaner",humidifier:"Humidifier",valve:"Water Valve",alarm_control_panel:"On/Off Plug-in Unit",event:"Generic Switch",button:"Generic Switch",input_button:"Generic Switch",automation:"On/Off Switch",script:"On/Off Switch",scene:"On/Off Switch",remote:"On/Off",water_heater:"Water Heater",input_boolean:"On/Off Plug-in Unit"},PG=e=>{try{return JSON.parse(e)}catch{return}};function Wat({filter:e}){const[t,n]=A.useState(!1),[r,i]=A.useState(null),[o,s]=A.useState(null),[a,l]=A.useState(!1),c=A.useRef(null),u=A.useRef(""),d=A.useCallback(async()=>{n(!0),s(null);try{const y=await fetch("api/matter/filter-preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),b=await y.text(),v=PG(b);if(!y.ok){const C=typeof v=="object"&&v!==null&&"error"in v?String(v.error):b||"Failed to fetch preview";throw new Error(C)}const S=v??PG(b);i(S),l(!0)}catch(y){s(y instanceof Error?y.message:"Unknown error")}finally{n(!1)}},[e]);A.useEffect(()=>{if(!(e.include.length>0&&e.include.some(v=>v.type&&v.value))){i(null),l(!1);return}const b=JSON.stringify(e);if(b!==u.current)return u.current=b,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d()},800),()=>{c.current&&clearTimeout(c.current)}},[e,d]);const p=r?r.entities.reduce((y,b)=>(y[b.domain]=(y[b.domain]||0)+1,y),{}):{},g=[];if(r){r.entities.some(v=>v.domain==="vacuum")&&g.push("This filter includes a vacuum. Consider using Server Mode (single device per bridge) for Apple Home/Alexa compatibility."),r.total>50&&g.push(`${r.total} entities is a large number. Consider splitting across multiple bridges for better stability.`);const b=Object.keys(p).filter(v=>!Cm[v]);b.length>0&&g.push(`Unsupported domains will be skipped: ${b.join(", ")}`)}return h.jsxs(se,{sx:{mt:2},children:[h.jsx(Ue,{variant:"outlined",startIcon:t?h.jsx(Xn,{size:16}):h.jsx(aTe,{}),onClick:d,disabled:t,size:"small",children:t?"Loading...":"Preview Matching Entities"}),o&&h.jsx(zt,{severity:"error",sx:{mt:1},children:o}),h.jsx(is,{in:a&&r!==null,children:r&&h.jsxs(se,{sx:{mt:2},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsxs(re,{variant:"subtitle1",fontWeight:"bold",children:[r.total," entities match"]}),r.truncated&&h.jsx(ot,{label:"Showing first 100",size:"small",color:"warning",variant:"outlined"})]}),g.length>0&&h.jsx(Wt,{spacing:.5,sx:{mb:1.5},children:g.map(y=>h.jsx(zt,{severity:"warning",variant:"outlined",icon:y.includes("vacuum")?h.jsx(c0,{fontSize:"small"}):h.jsx(Hu,{fontSize:"small"}),sx:{py:0},children:h.jsx(re,{variant:"caption",children:y})},y))}),h.jsx(se,{display:"flex",gap:.5,flexWrap:"wrap",mb:2,children:Object.entries(p).sort((y,b)=>b[1]-y[1]).map(([y,b])=>h.jsx(ot,{label:`${y}: ${b}${Cm[y]?` → ${Cm[y]}`:""}`,size:"small",variant:"outlined",color:Cm[y]?"default":"warning"},y))}),h.jsx(Fo,{dense:!0,sx:{maxHeight:200,overflow:"auto",bgcolor:"background.paper",borderRadius:1,border:1,borderColor:"divider"},children:r.entities.map(y=>h.jsx(Es,{divider:!0,children:h.jsx(ao,{primary:y.friendly_name||y.entity_id,secondary:`${y.entity_id}${Cm[y.domain]?` → ${Cm[y.domain]}`:""}`,primaryTypographyProps:{variant:"body2"},secondaryTypographyProps:{variant:"caption",fontFamily:"monospace"}})},y.entity_id))}),h.jsx(Ue,{size:"small",onClick:()=>l(!1),sx:{mt:1},children:"Hide Preview"})]})})]})}const qat=xne(),Kat=qat.ObjectFieldTemplate;function Gat(e){return(e.fieldPathId?.$id??"")==="root_filter"?h.jsx(Yat,{...e}):h.jsx(Kat,{...e})}function Yat(e){const t=e.formData?.include?.length??0,n=e.formData?.exclude?.length??0,r=t+n,[i,o]=A.useState(r>0);return h.jsxs(Md,{expanded:i,onChange:(s,a)=>o(a),variant:"outlined",disableGutters:!0,sx:{borderRadius:2,"&::before":{display:"none"},overflow:"hidden"},children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),sx:{px:2,"& .MuiAccordionSummary-content":{alignItems:"center",gap:1.5}},children:[h.jsx(G6,{fontSize:"small",color:"action"}),h.jsx(re,{variant:"subtitle1",fontWeight:600,children:"Entity Filters"}),h.jsx(CQ,{badgeContent:r,color:"primary",sx:{ml:1},max:99,children:h.jsx(se,{})}),h.jsx(re,{variant:"caption",color:"text.secondary",sx:{ml:1},children:i?"Click to collapse":`${r} rule${r!==1?"s":""} configured`})]}),h.jsx(jd,{sx:{px:2,pb:2},children:e.properties.map(s=>h.jsx("div",{children:s.content},s.name))})]})}function Jat(e){const t=A.useRef(e),n=t.current;return t.current=e,n}function NG(e){const{items:t,canAdd:n,onAddClick:r,title:i,formData:o}=e,s=o??[],[a,l]=A.useState(()=>new Set),[c,u]=A.useState(""),d=Jat(s.length);A.useEffect(()=>{if(s.length>d){const b=s.length-1,v=s[b];!v?.type&&!v?.value&&l(S=>new Set([...S,b]))}},[s,d]);const p=A.useCallback(b=>{l(v=>{const S=new Set(v);return S.has(b)?S.delete(b):S.add(b),S})},[]),g=A.useMemo(()=>{if(!c.trim())return null;const b=c.toLowerCase(),v=[];for(let S=0;S<s.length;S++){const C=s[S],w=C?.type??"",E=C?.value??"";(w.toLowerCase().includes(b)||E.toLowerCase().includes(b))&&v.push(S)}return new Set(v)},[c,s]),y=A.useMemo(()=>{const b=Array.from({length:t.length},(v,S)=>S);return g?b.filter(v=>g.has(v)):b},[t.length,g]);return h.jsxs(se,{children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1,children:[h.jsx(re,{variant:"subtitle2",fontWeight:600,children:i}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(ot,{label:t.length,size:"small",color:"default",sx:{height:22,fontSize:"0.75rem"}}),n&&h.jsx(Ue,{size:"small",startIcon:h.jsx(Ts,{}),onClick:r,children:"Add"})]})]}),t.length>3&&h.jsx(zn,{size:"small",fullWidth:!0,placeholder:"Search rules...",value:c,onChange:b=>u(b.target.value),slotProps:{input:{startAdornment:h.jsx(PC,{position:"start",children:h.jsx(DM,{fontSize:"small",color:"action"})})}},sx:{mb:1}}),g&&y.length===0&&h.jsx(re,{variant:"body2",color:"text.secondary",textAlign:"center",py:2,children:"No matching rules"}),h.jsx(Wt,{spacing:.5,children:y.map(b=>{const v=s[b],S=v?.type??"",C=v?.value??"",w=a.has(b),E=S||C;return h.jsxs(se,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:[h.jsxs(se,{display:"flex",alignItems:"center",sx:{px:1.5,py:.75,cursor:"pointer","&:hover":{bgcolor:"action.hover"},bgcolor:w?"action.selected":"transparent"},onClick:()=>p(b),children:[w?h.jsx(M_e,{fontSize:"small",color:"action"}):h.jsx(R_e,{fontSize:"small",color:"action"}),E?h.jsxs(se,{display:"flex",alignItems:"center",gap:1,ml:.5,flex:1,minWidth:0,children:[h.jsx(ot,{label:S,size:"small",variant:"outlined",sx:{height:22,fontSize:"0.75rem",flexShrink:0}}),h.jsx(re,{variant:"body2",noWrap:!0,sx:{flex:1,minWidth:0},children:C})]}):h.jsx(re,{variant:"body2",color:"text.secondary",ml:.5,fontStyle:"italic",children:"New rule (click to configure)"})]}),h.jsx(is,{in:w,children:h.jsx(se,{sx:{px:2,pb:1.5,pt:.5},children:t[b]})})]},b)})})]})}function Zat(e){const{schema:t,formData:n={},onChange:r,disabled:i,readonly:o,fieldPathId:s}=e,a=t.properties??{},l=A.useCallback((c,u)=>{r({...n,[c]:u},s.path)},[n,r,s]);return h.jsxs(se,{children:[h.jsx(re,{variant:"h6",sx:{mb:2},children:"Feature Flags"}),h.jsx(ht,{container:!0,spacing:2,children:Object.entries(a).map(([c,u])=>{const d=n[c]??u.default??!1,p=u.title?.toLowerCase().includes("deprecated")??!1;return h.jsx(ht,{size:{xs:12,sm:6,lg:4},children:h.jsx(Mn,{variant:"outlined",sx:{height:"100%",opacity:p?.6:1,transition:"border-color 0.2s, box-shadow 0.2s",borderColor:d?"primary.main":"divider","&:hover":{transform:"none",boxShadow:"none"}},children:h.jsx(zu,{onClick:()=>{!i&&!o&&l(c,!d)},disabled:i||o,sx:{height:"100%"},children:h.jsxs(Qn,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:1,children:[h.jsxs(se,{sx:{flex:1,minWidth:0},children:[h.jsx(re,{variant:"subtitle2",fontWeight:600,sx:{lineHeight:1.3},children:u.title??c}),d&&h.jsx(ot,{label:"Active",size:"small",color:"primary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]}),h.jsx(Mu,{checked:d,size:"small",disabled:i||o,tabIndex:-1,onClick:g=>g.stopPropagation(),onChange:g=>l(c,g.target.checked)})]}),h.jsx(re,{variant:"caption",color:"text.secondary",sx:{mt:1,lineHeight:1.4,flex:1},children:u.description})]})})})},c)})})]})}const Sle=e=>{const{t}=en(),[n,r]=A.useState("FIELDS_EDITOR"),i=()=>{r(n==="FIELDS_EDITOR"?"JSON_EDITOR":"FIELDS_EDITOR")},[o,s]=A.useState(e.bridge),[a,l]=A.useState(!0),c=A.useCallback(y=>{const b=y;if(!b?.port)return[];const v=e.usedPorts[b.port];return v!==void 0&&v!==e.bridgeId?[{instancePath:"/port",message:`Port is already used by bridge with id ${v}`}]:[]},[e.bridgeId,e.usedPorts]),u=(y,b)=>{const v=S=>S?.icon;s(S=>{const C=v(S);return C!=null?{...y,icon:C}:{...y}}),l(b)},d=A.useCallback(y=>{s(b=>{if(y!=null)return{...b,icon:y};const{icon:v,...S}=b??{};return S})},[]),p=A.useMemo(()=>{const b=o?.featureFlags,v=[];return b?.serverMode&&v.push({severity:"warning",message:"Server Mode is enabled. Only ONE device should be in this bridge. Multiple devices will cause errors."}),b?.serverMode&&b?.vacuumOnOff===!1&&v.push({severity:"warning",message:"Server Mode with Vacuum OnOff disabled: Alexa REQUIRES the OnOff cluster (PowerController) for robotic vacuums. Without it, the vacuum commissions but never appears in Alexa. Only disable this for Apple Home."}),!b?.serverMode&&b?.vacuumOnOff&&v.push({severity:"warning",message:"Vacuum OnOff is enabled in bridge mode. This adds a non-standard cluster to the RVC device type which may cause issues with Apple Home and Google Home."}),b?.autoForceSync&&b?.autoComposedDevices&&v.push({severity:"warning",message:"Auto Force Sync with Auto Composed Devices increases network traffic. Composed devices have more clusters, so each sync cycle sends more data."}),v},[o]),g=async()=>{a&&await e.onSave(o)};return h.jsxs(h.Fragment,{children:[h.jsxs(zt,{severity:"warning",variant:"outlined",children:["Please consult"," ",h.jsx(V2,{href:Ot.faq.bridgeConfig,target:"_blank",children:"the documentation"})," ","for proper bridge configurations."," ",h.jsx("strong",{children:'Especially if you are using labels, see the "Labels" section.'})]}),h.jsxs(zt,{severity:"info",variant:"outlined",children:[h.jsx("strong",{children:"Community tip:"})," Users have reported that bridges with a large number of devices can become unstable depending on the controller. If you experience connectivity issues, consider splitting your devices across multiple bridges."]}),p.map(y=>h.jsx(zt,{severity:y.severity,variant:"outlined",children:y.message},y.message)),h.jsxs(Wt,{spacing:2,children:[h.jsx(se,{display:"flex",justifyContent:"flex-end",children:h.jsx(Ue,{onClick:()=>i(),title:t(n==="FIELDS_EDITOR"?"bridge.jsonEditor":"bridge.formEditor"),children:n==="FIELDS_EDITOR"?h.jsx(dTe,{}):h.jsx(eTe,{})})}),n==="FIELDS_EDITOR"&&h.jsx(EUe,{value:o??{},onChange:u,schema:My,uiSchema:{icon:{"ui:widget":"hidden"},featureFlags:{"ui:field":"featureFlags"},filter:{include:{"ui:options":{ArrayFieldTemplate:NG}},exclude:{"ui:options":{ArrayFieldTemplate:NG}}}},customValidate:c,templates:{ObjectFieldTemplate:Gat},fields:{featureFlags:Zat}}),n==="JSON_EDITOR"&&h.jsx(Bat,{value:o??{},onChange:u,schema:My,customValidate:c}),o?.filter&&h.jsx(Wat,{filter:o.filter}),h.jsx(Mn,{variant:"outlined",children:h.jsxs(Qn,{children:[h.jsx(re,{variant:"subtitle1",gutterBottom:!0,fontWeight:600,children:t("bridge.iconLabel")}),h.jsx(Vat,{bridgeId:e.bridgeId,selectedIcon:o?.icon,onIconChange:d})]})}),h.jsxs(ht,{container:!0,children:[h.jsx(ht,{size:{xs:6,sm:4,md:3},children:h.jsx(Ue,{fullWidth:!0,variant:"outlined",color:"error",onClick:e.onCancel,children:t("common.cancel")})}),h.jsx(ht,{size:{xs:0,sm:4,md:6},sx:{display:{xs:"none",sm:"block"}}}),h.jsx(ht,{size:{xs:6,sm:4,md:3},children:h.jsx(Ue,{fullWidth:!0,variant:"outlined",disabled:!a,onClick:g,children:t("common.save")})})]})]})]})},Xat={name:"",featureFlags:{},filter:{include:[],exclude:[]}};function Qat(e){let t=5540;for(;e[t];)t++;return t}const elt=()=>{const{t:e}=en(),t=Fc(),n=$c(),[r,i]=A.useState(),o=!!h0().content?.length,s=nee(),a=A.useCallback(p=>{i(p?.id)},[]),l=A.useMemo(()=>{if(!s)return;const p=Qat(s);if(r){const g=IX.find(y=>y.id===r);if(g)return{name:g.name,port:p,filter:{...g.filter},featureFlags:{...g.featureFlags},icon:g.icon}}return{...Xat,port:p}},[s,r]),c=c_e(),u=()=>{n(-1)},d=async p=>{await c({...p}).then(()=>t.show({message:e("bridge.saveSuccess"),severity:"success"})).then(()=>u()).catch(g=>t.show({message:g.message,severity:"error"}))};return!l||!s?e("common.loading"):h.jsxs(Wt,{spacing:4,children:[h.jsx(W2,{items:[{name:e("nav.bridges"),to:Ot.bridges},{name:e("common.create"),to:Ot.createBridge}]}),o&&h.jsx(zt,{severity:"info",variant:"outlined",children:h.jsxs(re,{children:["Did you know that you can connect the same bridge with multiple assistants?"," ",h.jsx(V2,{href:Ot.faq.multiFabric,target:"_blank",children:"Learn more."})]})}),h.jsx(hee,{selectedTemplate:r,onSelect:a}),h.jsx(Sle,{bridge:l,usedPorts:s,onSave:d,onCancel:u},r??"custom")]})},tlt=()=>{const{t:e}=en(),t=Fc(),n=$c(),{bridgeId:r}=FJ(),{content:i,isLoading:o}=ree(r),s=nee(),a=u_e(),l=A.useMemo(()=>{if(!(o||!i))return{name:i.name,port:i.port,filter:i.filter,...i.countryCode!=null&&{countryCode:i.countryCode},...i.featureFlags!=null&&{featureFlags:i.featureFlags},...i.icon!=null&&{icon:i.icon},...i.priority!=null&&{priority:i.priority}}},[o,i]),c=()=>{n(-1)},u=async d=>{await a({...d,id:r}).then(()=>t.show({message:e("bridge.updateSuccess"),severity:"success"})).then(()=>c()).catch(p=>t.show({message:p.message,severity:"error"}))};return o||!s?e("common.loading"):!i||!l?e("notFound.title"):h.jsxs(Wt,{spacing:4,children:[h.jsx(W2,{items:[{name:e("nav.bridges"),to:Ot.bridges},{name:i.name,to:Ot.bridge(r)},{name:e("common.edit"),to:Ot.editBridge(r)}]}),h.jsx(Sle,{bridgeId:r,bridge:l,usedPorts:s,onSave:u,onCancel:c})]})};async function nlt(){const e=await fetch("api/backup/snapshots");return await Rn(e,"Failed to fetch backups"),ar(e)}async function rlt(){const e=await fetch("api/backup/snapshots/create",{method:"POST"});return await Rn(e,"Failed to create backup"),ar(e)}async function ilt(e){const t=await fetch(`api/backup/snapshots/${encodeURIComponent(e)}/download`);if(!t.ok)throw new Error("Failed to download backup");const n=await t.blob(),r=window.URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(r),document.body.removeChild(i)}async function olt(e,t){const n=await fetch(`api/backup/snapshots/${encodeURIComponent(e)}/restore`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({overwriteExisting:!0,includeMappings:!0,restoreIdentity:!0,...t})});return await Rn(n,"Failed to restore backup"),ar(n)}async function slt(e){const t=await fetch(`api/backup/snapshots/${encodeURIComponent(e)}`,{method:"DELETE"});await Rn(t,"Failed to delete backup")}async function alt(){const e=await fetch("api/backup/settings");return await Rn(e,"Failed to fetch backup settings"),ar(e)}async function llt(e){const t=await fetch("api/backup/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return await Rn(t,"Failed to update backup settings"),ar(t)}function clt(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function wle(){const{t:e}=en(),[t,n]=A.useState(!1),[r,i]=A.useState(null),[o,s]=A.useState(null),[a,l]=A.useState(null),[c,u]=A.useState(new Set),[d,p]=A.useState(!1),[g,y]=A.useState(!0),[b,v]=A.useState(!0),[S,C]=A.useState(!1),[w,E]=A.useState(!1),[k,T]=A.useState(null),_=A.useRef(null),[O,R]=A.useState([]),[P,L]=A.useState(!0),[M,N]=A.useState(null),[$,B]=A.useState(null),[F,V]=A.useState(null),[W,q]=A.useState(!1),Z=A.useCallback(async()=>{try{L(!0);const[J,X]=await Promise.all([nlt(),alt()]);R(J),N(X)}catch(J){i(J instanceof Error?J.message:"Failed to load backups")}finally{L(!1)}},[]);A.useEffect(()=>{Z()},[Z]);const z=async()=>{q(!0),i(null);try{await rlt(),s(e("backup.snapshotCreated")),await Z()}catch(J){i(J instanceof Error?J.message:"Failed to create backup")}finally{q(!1)}},U=async J=>{try{await ilt(J)}catch(X){i(X instanceof Error?X.message:"Failed to download backup")}},Y=async J=>{n(!0),i(null);try{const X=await olt(J);X.errors.length>0?i(`Restored ${X.bridgesRestored} bridges with ${X.errors.length} errors`):s(e("backup.snapshotRestored",{bridges:X.bridgesRestored,mappings:X.mappingsRestored,identities:X.identitiesRestored})),B(null),X.restartRequired&&E(!0)}catch(X){i(X instanceof Error?X.message:"Failed to restore backup")}finally{n(!1)}},H=async J=>{try{await slt(J),V(null),await Z()}catch(X){i(X instanceof Error?X.message:"Failed to delete backup")}},K=async J=>{try{const X=await llt(J);N(X)}catch(X){i(X instanceof Error?X.message:"Failed to update settings")}},Q=async(J=!1)=>{n(!0),i(null);try{const oe=await fetch(J?"api/backup/download?includeIdentity=true":"api/backup/download");if(!oe.ok)throw new Error("Failed to create backup");const le=await oe.blob(),fe=window.URL.createObjectURL(le),ye=document.createElement("a");ye.href=fe,ye.download=oe.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]||"hamh-backup.zip",document.body.appendChild(ye),ye.click(),window.URL.revokeObjectURL(fe),document.body.removeChild(ye),s(e("backup.downloadSuccess"))}catch(X){i(X instanceof Error?X.message:"Unknown error")}finally{n(!1)}},ie=async J=>{const X=J.target.files?.[0];if(X){T(X),n(!0),i(null);try{const oe=new FormData;oe.append("file",X);const le=await fetch("api/backup/restore/preview",{method:"POST",body:oe});if(!le.ok){const ye=await le.text();let Me="Failed to parse backup";try{const ue=JSON.parse(ye);ue.error&&(Me=ue.error)}catch{ye&&(Me=`${Me} (HTTP ${le.status}: ${ye.slice(0,120)})`)}throw new Error(Me)}const fe=await le.json();l(fe),u(new Set(fe.bridges.map(ye=>ye.id))),C(!0)}catch(oe){i(oe instanceof Error?oe.message:"Unknown error")}finally{n(!1),_.current&&(_.current.value="")}}},te=async()=>{if(k){n(!0),i(null);try{const J=new FormData;J.append("file",k),J.append("options",JSON.stringify({bridgeIds:Array.from(c),overwriteExisting:d,includeMappings:g,restoreIdentity:b&&a?.includesIdentity}));const X=await fetch("api/backup/restore",{method:"POST",body:J});if(!X.ok){const le=await X.text();let fe="Failed to restore backup";try{const ye=JSON.parse(le);ye.error&&(fe=ye.error)}catch{le&&(fe=`${fe} (HTTP ${X.status}: ${le.slice(0,120)})`)}throw new Error(fe)}const oe=await X.json();if(oe.errors.length>0)i(`Restored ${oe.bridgesRestored} bridges with ${oe.errors.length} errors`);else{const le=[`Restored ${oe.bridgesRestored} bridges`];oe.mappingsRestored>0&&le.push(`${oe.mappingsRestored} entity mappings`),oe.identitiesRestored>0&&le.push(`${oe.identitiesRestored} identities`),s(`${le.join(", ")}!`)}C(!1),l(null),T(null),oe.restartRequired&&E(!0)}catch(J){i(J instanceof Error?J.message:"Unknown error")}finally{n(!1)}}},ce=J=>{const X=new Set(c);X.has(J)?X.delete(J):X.add(J),u(X)},ee=async()=>{n(!0);try{await fetch("api/backup/restart",{method:"POST"}),s("Application is restarting...")}catch(J){i(J instanceof Error?J.message:"Failed to restart")}finally{n(!1),E(!1)}};return h.jsxs(Mn,{children:[h.jsxs(Qn,{children:[h.jsxs(re,{variant:"h6",gutterBottom:!0,children:[h.jsx(pm,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.title")]}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:e("backup.description")}),r&&h.jsx(zt,{severity:"error",sx:{mb:2},onClose:()=>i(null),children:r}),o&&h.jsx(zt,{severity:"success",sx:{mb:2},onClose:()=>s(null),children:o}),h.jsxs(ht,{container:!0,spacing:2,children:[h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(pm,{color:"primary"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.configBackup")})]}),h.jsxs(se,{sx:{flexGrow:1},children:[h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.configBackupDesc")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.configBackupNote")})]}),h.jsx(Ue,{variant:"contained",startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):h.jsx(pm,{}),onClick:()=>Q(!1),disabled:t,fullWidth:!0,sx:{mt:2},children:e("backup.configBackup")})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(lee,{color:"warning"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.fullBackup")})]}),h.jsxs(se,{sx:{flexGrow:1},children:[h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.fullBackupDesc")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.fullBackupWarning")})]}),h.jsx(Ue,{variant:"contained",color:"warning",startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):h.jsx(pm,{}),onClick:()=>Q(!0),disabled:t,fullWidth:!0,sx:{mt:2},children:e("backup.fullBackup")})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(Mh,{color:"info"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.restoreFromBackup")})]}),h.jsx(se,{sx:{flexGrow:1},children:h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.restoreDesc")})}),h.jsxs(Ue,{variant:"outlined",color:"info",startIcon:h.jsx(Mh,{}),component:"label",disabled:t,fullWidth:!0,sx:{mt:2},children:[e("backup.restoreFromBackup"),h.jsx("input",{ref:_,type:"file",accept:".zip",hidden:!0,onChange:ie})]})]})})]}),h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(pm,{color:"primary"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.storedBackups")}),O.length>0&&h.jsx(ot,{label:O.length,size:"small",color:"primary",variant:"outlined"})]}),h.jsx(Ue,{variant:"outlined",size:"small",startIcon:W?h.jsx(Xn,{size:16,color:"inherit"}):h.jsx(Ts,{}),onClick:z,disabled:W,children:e("backup.createSnapshot")})]}),P?h.jsx(se,{display:"flex",justifyContent:"center",p:2,children:h.jsx(Xn,{size:24})}):O.length===0?h.jsx(re,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2},children:e("backup.noSnapshots")}):h.jsx(Fo,{dense:!0,children:O.map(J=>h.jsxs(Es,{secondaryAction:h.jsxs(se,{display:"flex",gap:.5,children:[h.jsx(Lt,{title:e("backup.downloadSnapshot"),children:h.jsx(qt,{size:"small",onClick:()=>U(J.filename),children:h.jsx(lC,{fontSize:"small"})})}),h.jsx(Lt,{title:e("backup.restoreSnapshot"),children:h.jsx(qt,{size:"small",color:"warning",onClick:()=>B(J.filename),children:h.jsx(Mh,{fontSize:"small"})})}),h.jsx(Lt,{title:e("common.delete"),children:h.jsx(qt,{size:"small",color:"error",onClick:()=>V(J.filename),children:h.jsx(Pa,{fontSize:"small"})})})]}),children:[h.jsx(Io,{sx:{minWidth:36},children:h.jsx(pm,{fontSize:"small",color:J.auto?"action":"primary"})}),h.jsx(ao,{primary:h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsxs(re,{variant:"body2",children:["v",J.version]}),h.jsx(ot,{label:J.auto?e("backup.auto"):e("backup.manual"),size:"small",variant:"outlined",color:J.auto?"default":"primary"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:clt(J.sizeBytes)})]}),secondary:new Date(J.createdAt).toLocaleString()})]},J.filename))}),h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:2,children:[h.jsx(f0,{color:"action"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.settings")})]}),M&&h.jsxs(se,{sx:{display:"flex",flexDirection:"column",gap:2,maxWidth:400},children:[h.jsx(Ro,{control:h.jsx(Mu,{checked:M.autoBackup,onChange:J=>K({autoBackup:J.target.checked})}),label:e("backup.autoBackupLabel")}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mt:-1},children:e("backup.autoBackupDesc")}),h.jsx(zn,{label:e("backup.retentionCount"),type:"number",size:"small",value:M.backupRetentionCount,onChange:J=>{const X=parseInt(J.target.value,10);X>=1&&X<=100&&K({backupRetentionCount:X})},inputProps:{min:1,max:100},helperText:e("backup.retentionCountDesc"),sx:{maxWidth:200}})]})]}),h.jsxs(Po,{open:S,onClose:()=>C(!1),maxWidth:"sm",fullWidth:!0,children:[h.jsx($o,{children:e("backup.restoreTitle")}),h.jsx(No,{children:a&&h.jsxs(h.Fragment,{children:[h.jsxs(re,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Backup created: ",new Date(a.createdAt).toLocaleString()]}),a.includesIdentity&&h.jsx(zt,{severity:"info",sx:{mt:1},children:"This backup includes Matter identity data (keypairs, fabric credentials). Restoring identities allows bridges to reconnect without re-commissioning."}),h.jsxs(re,{variant:"subtitle2",sx:{mt:2,mb:1},children:[e("backup.selectBridges"),":"]}),h.jsx(Fo,{dense:!0,children:a.bridges.map(J=>h.jsxs(Es,{onClick:()=>ce(J.id),sx:{cursor:"pointer"},children:[h.jsx(Io,{children:h.jsx(ws,{edge:"start",checked:c.has(J.id),tabIndex:-1,disableRipple:!0})}),h.jsx(ao,{primary:J.name,secondary:h.jsxs(h.Fragment,{children:["Port: ",J.port,J.hasMappings&&` • ${J.mappingCount} entity mappings`,J.exists&&h.jsx(re,{component:"span",color:"warning.main",sx:{ml:1},children:"(exists)"})]})})]},J.id))}),h.jsxs(se,{sx:{mt:2},children:[h.jsx(Ro,{control:h.jsx(ws,{checked:d,onChange:J=>p(J.target.checked)}),label:e("backup.overwriteExisting")}),h.jsx(Ro,{control:h.jsx(ws,{checked:g,onChange:J=>y(J.target.checked)}),label:e("backup.includeMappings")}),a?.includesIdentity&&h.jsx(Ro,{control:h.jsx(ws,{checked:b,onChange:J=>v(J.target.checked)}),label:e("backup.restoreIdentities")})]})]})}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>C(!1),children:e("common.cancel")}),h.jsx(Ue,{variant:"contained",onClick:te,disabled:t||c.size===0,startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):null,children:e("backup.restore")})]})]}),h.jsxs(Po,{open:w,onClose:()=>E(!1),children:[h.jsxs($o,{children:[h.jsx(jg,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.restartRequired")]}),h.jsxs(No,{children:[h.jsx(re,{children:e("backup.restartMessage")}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mt:1},children:e("backup.restartNote")})]}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>E(!1),children:e("common.later")}),h.jsx(Ue,{variant:"contained",color:"warning",onClick:ee,disabled:t,startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):h.jsx(jg,{}),children:e("backup.restartNow")})]})]}),h.jsxs(Po,{open:$!==null,onClose:()=>B(null),children:[h.jsxs($o,{children:[h.jsx(Mh,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.confirmRestore")]}),h.jsxs(No,{children:[h.jsx(re,{children:e("backup.confirmRestoreMessage",{filename:$})}),h.jsx(zt,{severity:"warning",sx:{mt:2},children:e("backup.restoreWarning")})]}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>B(null),children:e("common.cancel")}),h.jsx(Ue,{variant:"contained",color:"warning",onClick:()=>$&&Y($),disabled:t,startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):null,children:e("backup.restore")})]})]}),h.jsxs(Po,{open:F!==null,onClose:()=>V(null),children:[h.jsxs($o,{children:[h.jsx(Pa,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.confirmDelete")]}),h.jsx(No,{children:h.jsx(re,{children:e("backup.confirmDeleteMessage",{filename:F})})}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>V(null),children:e("common.cancel")}),h.jsx(Ue,{variant:"contained",color:"error",onClick:()=>F&&H(F),children:e("common.delete")})]})]})]})}const ult=e=>{const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`};function dlt(e={}){const{t}=en(),[n,r]=A.useState(null),[i,o]=A.useState(!0),[s,a]=A.useState(null),[l,c]=A.useState("name"),[u,d]=A.useState("asc"),p=e.sortField??l,g=e.sortDirection??u,y=e.onSortFieldChange??c,b=e.onSortDirectionChange??d,v=A.useCallback(async()=>{try{const E=await fetch("api/health/detailed");if(E.ok){const k=await E.json();r(k),a(null)}else a(t("health.fetchFailed"))}catch{a(t("health.connectionError"))}finally{o(!1)}},[t]);A.useEffect(()=>{v();const E=setInterval(v,1e4);return()=>clearInterval(E)},[v]);const S=A.useCallback(async()=>{try{const E=await fetch("api/diagnostic/export");if(E.ok){const k=await E.blob(),T=URL.createObjectURL(k),_=document.createElement("a");_.href=T;const R=E.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]??`hamh-diagnostic-${new Date().toISOString().replace(/[:.]/g,"-")}.json`;_.download=R,document.body.appendChild(_),_.click(),document.body.removeChild(_),URL.revokeObjectURL(T)}}catch{a(t("health.exportFailed"))}},[t]),C=async E=>{try{await fetch(`api/matter/bridges/${E}/actions/restart`,{method:"POST"}),v()}catch{a(t("health.restartFailed"))}};if(i)return h.jsx(se,{display:"flex",justifyContent:"center",p:4,children:h.jsx(Xn,{})});if(s||!n)return h.jsx(zt,{severity:"error",sx:{m:2},children:s??t("health.unableToLoad")});const w=n.status==="healthy"?h.jsx(Za,{color:"success"}):n.status==="degraded"?h.jsx(u0,{color:"warning"}):h.jsx(Nf,{color:"error"});return h.jsxs(se,{sx:{p:2},children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[w,h.jsx(re,{variant:"h5",children:t("health.systemHealth")}),h.jsx(ot,{label:n.status.toUpperCase(),color:n.status==="healthy"?"success":n.status==="degraded"?"warning":"error",size:"small"})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(dC,{}),onClick:S,children:t("health.exportDiagnostic")}),h.jsx(Lt,{title:t("common.refresh"),children:h.jsx(qt,{onClick:v,"aria-label":"Refresh health data",children:h.jsx(Z2,{})})})]})]}),h.jsxs(ht,{container:!0,spacing:2,children:[h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2},children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:t("health.version")}),h.jsx(re,{variant:"h6",children:n.version})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2},children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:t("health.uptime")}),h.jsx(re,{variant:"h6",children:ult(n.uptime)})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2},children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:t("health.homeAssistant")}),h.jsx(ot,{label:n.services.homeAssistant.connected?t("health.connected"):t("health.disconnected"),color:n.services.homeAssistant.connected?"success":"error",size:"small"})]})})]}),h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,flexWrap:"wrap",gap:1,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(ZD,{}),h.jsx(re,{variant:"h6",children:t("health.bridgeStatus")}),h.jsx(ot,{label:`${n.services.bridges.running}/${n.services.bridges.total} ${t("common.running")}`,size:"small",variant:"outlined"})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(wQ,{fontSize:"small",color:"action"}),h.jsxs(rs,{size:"small",sx:{minWidth:120},children:[h.jsx(Ia,{children:t("health.sortBy")}),h.jsxs(ts,{value:p,label:t("health.sortBy"),onChange:E=>y(E.target.value),children:[h.jsx(Bn,{value:"name",children:t("common.name")}),h.jsx(Bn,{value:"created",children:t("health.created")})]})]}),h.jsx(Lt,{title:t(g==="asc"?"health.ascending":"health.descending"),children:h.jsx(qt,{size:"small",onClick:()=>b(g==="asc"?"desc":"asc"),"aria-label":`Sort ${g==="asc"?"descending":"ascending"}`,children:g==="asc"?h.jsx(uC,{fontSize:"small"}):h.jsx(cC,{fontSize:"small"})})})]})]}),h.jsx(ht,{container:!0,spacing:2,alignItems:"stretch",children:[...n.bridgeDetails].sort((E,k)=>{let T=0;return p==="name"?T=E.name.localeCompare(k.name):T=E.id.localeCompare(k.id),g==="asc"?T:-T}).map(E=>h.jsx(ht,{size:{xs:12,sm:6,md:6,lg:4,xl:3},sx:{display:"flex"},children:h.jsx(Mn,{variant:"outlined",sx:{width:"100%",height:"100%",minWidth:280,maxWidth:480,display:"flex",flexDirection:"column",borderColor:E.status==="running"?"success.main":E.status==="failed"?"error.main":"warning.main"},children:h.jsxs(Qn,{sx:{flex:1,display:"flex",flexDirection:"column",p:2,"&:last-child":{pb:2}},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",flexShrink:0,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,minWidth:0,children:[h.jsx(aa,{}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",noWrap:!0,sx:{maxWidth:140},children:E.name})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:.5,flexShrink:0,children:[h.jsx(ot,{label:E.status.toUpperCase(),color:E.status==="running"?"success":E.status==="failed"?"error":"warning",size:"small"}),E.status==="failed"&&h.jsx(Lt,{title:t("bridge.restart"),children:h.jsx(qt,{size:"small",onClick:()=>C(E.id),children:h.jsx(eH,{})})})]})]}),E.statusReason&&h.jsx(re,{variant:"body2",color:"error",sx:{mt:1,flexShrink:0},children:E.statusReason}),h.jsx(se,{sx:{mt:"auto",pt:1,flexShrink:0},children:h.jsxs(se,{display:"flex",flexWrap:"wrap",gap:.5,alignItems:"center",children:[h.jsx(ot,{label:`${t("common.port")} ${E.port}`,size:"small",variant:"outlined",color:"default"}),h.jsx(ot,{label:`${E.deviceCount} ${t("common.devices")}`,size:"small",variant:"outlined",color:"default"}),h.jsx(ot,{label:`${E.fabricCount} ${t("common.fabrics")}`,size:"small",variant:"outlined",color:"default"}),E.failedEntityCount>0&&h.jsx(ot,{label:`${E.failedEntityCount} failed`,color:"error",size:"small"})]})}),E.connectivity&&E.status==="running"&&h.jsx(se,{sx:{mt:1,flexShrink:0},children:h.jsxs(re,{variant:"caption",color:"text.secondary",children:[t("health.sessions"),":"," ",E.connectivity.totalSessions," |"," ",t("health.subscriptions"),":"," ",E.connectivity.totalSubscriptions,E.connectivity.fabricSummary&&E.connectivity.fabricSummary.length>1&&` (${E.connectivity.fabricSummary.length} ${t("health.fabrics")})`]})}),E.fabrics.length>0&&h.jsxs(se,{sx:{mt:1,flexShrink:0},children:[h.jsxs(re,{variant:"caption",color:"text.secondary",children:[t("health.connectedTo"),":"]}),h.jsx(se,{display:"flex",gap:.5,flexWrap:"wrap",mt:.5,children:E.fabrics.map(k=>h.jsx(Lt,{title:h.jsxs(se,{sx:{fontSize:"0.75rem"},children:[h.jsxs("div",{children:["Fabric #",k.fabricIndex]}),h.jsxs("div",{children:["Vendor: ",Mg(k.rootVendorId)," ","(0x",k.rootVendorId.toString(16).toUpperCase().padStart(4,"0"),")"]}),h.jsxs("div",{children:["Fabric ID: ",k.fabricId]}),h.jsxs("div",{children:["Node ID: ",k.nodeId]}),h.jsxs("div",{children:["Root Node ID: ",k.rootNodeId]})]}),children:h.jsx(ot,{icon:h.jsx(yQ,{fabric:k}),label:k.label||Mg(k.rootVendorId),size:"small",variant:"outlined"})},k.fabricIndex))})]})]})})},E.id))}),n.recovery.enabled&&h.jsxs(h.Fragment,{children:[h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(eH,{}),h.jsx(re,{variant:"h6",children:t("health.autoRecovery")}),h.jsx(ot,{label:t("common.enabled"),color:"success",size:"small"})]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[t("health.recoveryAttempts"),": ",n.recovery.recoveryCount,n.recovery.lastRecoveryAttempt&&` | Last attempt: ${new Date(n.recovery.lastRecoveryAttempt).toLocaleString()}`]})]}),h.jsx(Dr,{sx:{my:3}}),h.jsx(wle,{})]})}const $G=e=>e==="pass"?"success":e==="warn"?"warning":"error";function flt(){const{t:e}=en(),[t,n]=A.useState(null),[r,i]=A.useState(!1),[o,s]=A.useState(null),[a,l]=A.useState(!1),c=A.useCallback(async()=>{i(!0),s(null);try{const g=await fetch("api/network");g.ok?n(await g.json()):s(e("health.fetchFailed"))}catch{s(e("health.connectionError"))}finally{i(!1)}},[e]);A.useEffect(()=>{c()},[c]);const u=t?.checks.filter(g=>g.status==="pass").length??0,d=t?.checks.filter(g=>g.status==="warn").length??0,p=t?.checks.filter(g=>g.status==="fail").length??0;return h.jsxs(zr,{variant:"outlined",sx:{p:2},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1,children:[h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("health.networkDiagnostics")}),h.jsx(Ue,{size:"small",onClick:c,disabled:r,children:r?h.jsx(Xn,{size:16}):e("health.refresh")})]}),o&&h.jsx(zt,{severity:"error",sx:{mb:1},children:o}),t&&h.jsxs(h.Fragment,{children:[h.jsxs(se,{display:"flex",gap:1,mb:1.5,flexWrap:"wrap",children:[u>0&&h.jsx(ot,{label:`${u} ${e("health.checksPassed")}`,color:"success",size:"small",variant:"outlined"}),d>0&&h.jsx(ot,{label:`${d} ${e("health.checksWarning")}`,color:"warning",size:"small",variant:"outlined"}),p>0&&h.jsx(ot,{label:`${p} ${e("health.checksFailed")}`,color:"error",size:"small",variant:"outlined"}),h.jsx(ot,{label:t.matterConfig.boundInterface?`mDNS: ${t.matterConfig.boundInterface}`:"mDNS: all interfaces",size:"small",variant:"outlined"}),h.jsx(ot,{label:`IPv4: ${t.matterConfig.ipv4Enabled?"on":"off"}`,size:"small",variant:"outlined"})]}),t.checks.filter(g=>g.status!=="pass").map(g=>h.jsxs(zt,{severity:$G(g.status),sx:{mb:1},children:[h.jsx("strong",{children:g.message}),g.detail&&h.jsx(re,{variant:"body2",sx:{mt:.5},children:g.detail})]},g.name)),h.jsx(Ue,{size:"small",onClick:()=>l(!a),sx:{mt:.5},children:e(a?"health.hideDetails":"health.showDetails")}),h.jsxs(is,{in:a,children:[h.jsx(re,{variant:"subtitle2",sx:{mt:1,mb:.5},children:e("health.allChecks")}),h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{children:e("health.check")}),h.jsx(Tt,{children:e("health.statusLabel")}),h.jsx(Tt,{children:e("health.message")})]})}),h.jsx(Ec,{children:t.checks.map(g=>h.jsxs(xi,{children:[h.jsx(Tt,{children:h.jsx(re,{variant:"body2",children:g.name})}),h.jsx(Tt,{children:h.jsx(ot,{label:g.status,color:$G(g.status),size:"small"})}),h.jsxs(Tt,{children:[h.jsx(re,{variant:"body2",children:g.message}),g.detail&&h.jsx(re,{variant:"caption",color:"text.secondary",display:"block",children:g.detail})]})]},g.name))})]}),h.jsx(re,{variant:"subtitle2",sx:{mt:2,mb:.5},children:e("health.networkInterfaces")}),h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{children:e("health.interfaceName")}),h.jsx(Tt,{children:"IPv4"}),h.jsx(Tt,{children:"IPv6"}),h.jsx(Tt,{children:"MAC"})]})}),h.jsx(Ec,{children:t.interfaces.filter(g=>!g.internal).map(g=>h.jsxs(xi,{children:[h.jsx(Tt,{children:g.name}),h.jsx(Tt,{children:g.ipv4.join(", ")||"-"}),h.jsx(Tt,{children:h.jsx(re,{variant:"body2",sx:{wordBreak:"break-all",maxWidth:240},children:g.ipv6.join(", ")||"-"})}),h.jsx(Tt,{children:g.mac})]},g.name))})]})]})]})]})}const PT="hamh-translation-overrides";function wy(e,t=""){const n={};for(const[r,i]of Object.entries(e)){const o=t?`${t}.${r}`:r;typeof i=="object"&&i!==null&&!Array.isArray(i)?Object.assign(n,wy(i,o)):n[o]=String(i??"")}return n}function jA(e){const t={};for(const[n,r]of Object.entries(e)){const i=n.split(".");let o=t;for(let s=0;s<i.length-1;s++)i[s]in o||(o[i[s]]={}),o=o[i[s]];o[i[i.length-1]]=r}return t}function LG(e){try{const t=localStorage.getItem(PT);return t?JSON.parse(t)[e]??{}:{}}catch{return{}}}function FG(e,t){try{const n=localStorage.getItem(PT),r=n?JSON.parse(n):{};Object.keys(t).length===0?delete r[e]:r[e]=t,localStorage.setItem(PT,JSON.stringify(r))}catch{}}const Cle="hamh-custom-languages";function hlt(){try{const e=localStorage.getItem(Cle);return e?JSON.parse(e):[]}catch{return[]}}function zG(e){localStorage.setItem(Cle,JSON.stringify(e))}const W5=[{code:"de",name:"Deutsch"},{code:"fr",name:"Français"},{code:"es",name:"Español"},{code:"it",name:"Italiano"},{code:"zh",name:"中文"},{code:"zh-TW",name:"繁體中文"},{code:"th",name:"ไทย"},{code:"sv",name:"Svenska"},{code:"tr",name:"Türkçe"},{code:"ru",name:"Русский"}];function plt(){const{t:e,i18n:t}=en(),n=t.language??"en",r=W5.some(ee=>ee.code===n)?n:n.split("-")[0]??"en",[i,o]=A.useState(()=>r==="en"?"de":r),[s,a]=A.useState(""),[l,c]=A.useState(()=>LG(i)),[u,d]=A.useState(!1),[p,g]=A.useState("all"),[y,b]=A.useState(hlt),[v,S]=A.useState(!1),[C,w]=A.useState(""),[E,k]=A.useState(""),[T,_]=A.useState(""),[O,R]=A.useState(""),P=A.useMemo(()=>[...W5,...y],[y]),L=A.useCallback(ee=>y.some(J=>J.code===ee),[y]),M=A.useMemo(()=>wy(oZ),[]),N=A.useMemo(()=>{const ee=t.getResourceBundle(i,"translation");return ee?wy(ee):{}},[i,t]),$=A.useMemo(()=>Object.keys(M).map(J=>({key:J,section:J.split(".")[0],enValue:M[J],currentValue:l[J]??N[J]??"",isOverridden:J in l})),[M,N,l]),B=A.useMemo(()=>{let ee=$;if(s){const J=s.toLowerCase();ee=ee.filter(X=>X.key.toLowerCase().includes(J)||X.enValue.toLowerCase().includes(J)||X.currentValue.toLowerCase().includes(J))}return p==="missing"?ee=ee.filter(J=>!J.currentValue):p==="edited"&&(ee=ee.filter(J=>J.isOverridden)),ee},[$,s,p]),F=A.useMemo(()=>[...new Set(B.map(ee=>ee.section))],[B]),V=Object.keys(M).length,W=$.filter(ee=>ee.currentValue).length,q=Object.keys(l).length,Z=V>0?W/V*100:0;A.useEffect(()=>{c(LG(i))},[i]);const z=A.useCallback(ee=>{c(ee),FG(i,ee);const J=t.getResourceBundle(i,"translation"),X=J?wy(J):{},oe={};for(const[le,fe]of Object.entries(ee))fe&&fe!==X[le]&&(oe[le]=fe);if(Object.keys(oe).length>0){const le=jA({...X,...oe});t.addResourceBundle(i,"translation",le,!0,!0)}},[i,t]),U=A.useCallback((ee,J)=>{const X={...l,[ee]:J};J||delete X[ee],z(X)},[l,z]),Y=A.useCallback(ee=>{const J={...l};delete J[ee],z(J)},[l,z]),H=A.useCallback(()=>{z({})},[z]),K=A.useCallback(()=>{const ee={};for(const ye of Object.keys(M))ee[ye]=l[ye]??N[ye]??"";const J=jA(ee),X=JSON.stringify(J,null,2),oe=new Blob([X],{type:"application/json"}),le=URL.createObjectURL(oe),fe=document.createElement("a");fe.href=le,fe.download=`${i}.json`,document.body.appendChild(fe),fe.click(),document.body.removeChild(fe),URL.revokeObjectURL(le)},[M,N,l,i]),Q=A.useCallback(()=>{const ee={};for(const X of Object.keys(M))ee[X]=l[X]??N[X]??"";const J=jA(ee);navigator.clipboard.writeText(JSON.stringify(J,null,2)),d(!0),setTimeout(()=>d(!1),2e3)},[M,N,l]),ie=A.useCallback(()=>{const ee=C.trim().toLowerCase(),J=E.trim();if(!ee){_(e("translationEditor.codeRequired"));return}if(!J){_(e("translationEditor.nameRequired"));return}if(W5.some(oe=>oe.code===ee)||y.some(oe=>oe.code===ee)||ee==="en"){_(e("translationEditor.languageExists"));return}const X=[...y,{code:ee,name:J}];b(X),zG(X),t.addResourceBundle(ee,"translation",{},!0,!0),o(ee),S(!1),w(""),k(""),_("")},[C,E,y,t,e]),te=A.useCallback(()=>{if(!L(i))return;const ee=y.filter(J=>J.code!==i);b(ee),zG(ee),FG(i,{}),o(W5[0].code)},[i,y,L]),ce=A.useCallback(()=>{const ee=document.createElement("input");ee.type="file",ee.accept=".json",ee.onchange=()=>{const J=ee.files?.[0];if(!J)return;const X=new FileReader;X.onload=()=>{try{const oe=JSON.parse(X.result);if(typeof oe!="object"||oe===null)throw new Error;const le=wy(oe),fe=new Set(Object.keys(M)),ye={};let Me=0;for(const[ue,we]of Object.entries(le))fe.has(ue)&&we&&(ye[ue]=we,Me++);z({...l,...ye}),R(e("translationEditor.importSuccess",{count:Me}))}catch{R(e("translationEditor.importFailed"))}},X.readAsText(J)},ee.click()},[M,l,z,e]);return h.jsxs(se,{sx:{p:2},children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,flexWrap:"wrap",gap:1,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(hTe,{}),h.jsx(re,{variant:"h5",children:e("translationEditor.title")})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsxs(rs,{size:"small",sx:{minWidth:140},children:[h.jsx(Ia,{children:e("translationEditor.editLanguage")}),h.jsx(ts,{value:i,label:e("translationEditor.editLanguage"),onChange:ee=>o(ee.target.value),children:P.map(ee=>h.jsxs(Bn,{value:ee.code,children:[h.jsx(ao,{primary:ee.name}),L(ee.code)&&h.jsx(Io,{sx:{minWidth:"auto",ml:1},children:h.jsx(nH,{fontSize:"small",color:"disabled"})})]},ee.code))})]}),h.jsx(Lt,{title:e("translationEditor.addLanguage"),children:h.jsx(qt,{size:"small",onClick:()=>S(ee=>!ee),children:h.jsx(Ts,{fontSize:"small"})})}),L(i)&&h.jsx(Lt,{title:e("translationEditor.removeLanguage"),children:h.jsx(qt,{size:"small",color:"error",onClick:te,children:h.jsx(nH,{fontSize:"small"})})})]})]}),h.jsx(is,{in:v,children:h.jsxs(se,{display:"flex",gap:1,mb:2,alignItems:"flex-start",flexWrap:"wrap",children:[h.jsx(zn,{size:"small",label:e("translationEditor.newLanguageCode"),value:C,onChange:ee=>w(ee.target.value),error:!!T,sx:{width:180}}),h.jsx(zn,{size:"small",label:e("translationEditor.newLanguageName"),value:E,onChange:ee=>k(ee.target.value),sx:{width:220}}),h.jsx(Ue,{variant:"contained",size:"small",onClick:ie,children:e("translationEditor.addLanguageButton")}),T&&h.jsx(re,{variant:"caption",color:"error",sx:{mt:.5},children:T})]})}),h.jsx(zt,{severity:"info",sx:{mb:2},children:e("translationEditor.info")}),h.jsxs(se,{display:"flex",alignItems:"center",gap:2,mb:2,flexWrap:"wrap",children:[h.jsxs(se,{sx:{flexGrow:1,minWidth:200},children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5,children:[h.jsx(re,{variant:"body2",color:"text.secondary",children:e("translationEditor.progress",{translated:W,total:V})}),h.jsxs(re,{variant:"body2",fontWeight:600,children:[Math.round(Z),"%"]})]}),h.jsx(UO,{variant:"determinate",value:Z,sx:{height:8,borderRadius:4}})]}),q>0&&h.jsx(ot,{label:e("translationEditor.localEdits",{count:q}),color:"primary",size:"small"})]}),h.jsxs(se,{display:"flex",gap:1,mb:2,flexWrap:"wrap",children:[h.jsx(zn,{size:"small",placeholder:e("translationEditor.searchPlaceholder"),value:s,onChange:ee=>a(ee.target.value),sx:{flexGrow:1,minWidth:200},slotProps:{input:{startAdornment:h.jsx(PC,{position:"start",children:h.jsx(DM,{fontSize:"small"})})}}}),h.jsx(rs,{size:"small",sx:{minWidth:130},children:h.jsxs(ts,{value:p,onChange:ee=>g(ee.target.value),children:[h.jsx(Bn,{value:"all",children:e("translationEditor.filterAll")}),h.jsx(Bn,{value:"missing",children:e("translationEditor.filterMissing")}),h.jsx(Bn,{value:"edited",children:e("translationEditor.filterEdited")})]})})]}),h.jsxs(se,{display:"flex",gap:1,mb:3,flexWrap:"wrap",children:[h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(uee,{}),onClick:K,children:e("translationEditor.exportJson")}),h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(lC,{}),onClick:ce,children:e("translationEditor.importJson")}),h.jsx(Lt,{title:u?e("translationEditor.copied"):"",children:h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(ef,{}),onClick:Q,children:e("translationEditor.copyJson")})}),q>0&&h.jsx(Ue,{variant:"outlined",size:"small",color:"warning",startIcon:h.jsx(Mh,{}),onClick:H,children:e("translationEditor.resetAll")})]}),F.map(ee=>h.jsxs(se,{sx:{mb:3},children:[h.jsx(re,{variant:"subtitle1",fontWeight:600,sx:{mb:1,textTransform:"capitalize"},children:ee}),h.jsx(Dr,{sx:{mb:1.5}}),B.filter(J=>J.section===ee).map(J=>h.jsxs(se,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr auto"},gap:1,mb:1.5,alignItems:"start"},children:[h.jsxs(se,{children:[h.jsx(re,{variant:"caption",color:"text.secondary",sx:{fontFamily:"monospace"},children:J.key}),h.jsx(re,{variant:"body2",sx:{mt:.25},children:J.enValue})]}),h.jsx(zn,{size:"small",fullWidth:!0,multiline:J.enValue.length>60,minRows:1,maxRows:4,value:J.currentValue,onChange:X=>U(J.key,X.target.value),placeholder:J.enValue,sx:{"& .MuiOutlinedInput-root":J.isOverridden?{borderColor:"primary.main","& fieldset":{borderColor:"primary.main",borderWidth:2}}:{}}}),J.isOverridden&&h.jsx(Lt,{title:e("translationEditor.resetKey"),children:h.jsx(qt,{size:"small",onClick:()=>Y(J.key),children:h.jsx(Mh,{fontSize:"small"})})})]},J.key))]},ee)),B.length===0&&h.jsx(re,{color:"text.secondary",sx:{textAlign:"center",py:4},children:e("translationEditor.noResults")}),h.jsx(N6,{open:!!O,autoHideDuration:3e3,onClose:()=>R(""),message:O})]})}const gh=e=>{const t=["B","KB","MB","GB","TB"];let n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(1)} ${t[r]}`},BG=e=>{const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`},mlt=()=>{const[e,t]=A.useState(null),[n,r]=A.useState(!0),[i,o]=A.useState(!0);if(A.useEffect(()=>{let l=null;const c=async()=>{try{const u=await fetch("api/system/info");if(u.ok){const d=await u.json();t(d),o(!0)}else u.status===404&&(o(!1),l&&(clearInterval(l),l=null))}catch{}finally{r(!1)}};return c(),l=setInterval(c,3e4),()=>{l&&clearInterval(l)}},[]),!i)return null;if(n)return h.jsx(Mn,{children:h.jsx(Qn,{children:h.jsx(re,{children:"Loading system information..."})})});if(!e)return h.jsx(Mn,{children:h.jsx(Qn,{children:h.jsx(re,{color:"error",children:"Failed to load system information"})})});const s=e.memory.used/e.memory.total*100,a=e.storage.used/e.storage.total*100;return h.jsx(Mn,{children:h.jsxs(Qn,{children:[h.jsxs(re,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(H_e,{}),"System Information"]}),h.jsxs(ht,{container:!0,spacing:3,children:[h.jsx(ht,{size:{xs:12,md:6},children:h.jsxs(Wt,{spacing:2,children:[h.jsxs(se,{children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:"Application"}),h.jsxs(Wt,{spacing:1,sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Version:"}),h.jsx(ot,{label:e.version,size:"small",color:"primary"})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Environment:"}),h.jsx(ot,{label:e.environment,size:"small",variant:"outlined",color:e.environment==="Home Assistant Add-on"?"success":"default"})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Node.js:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e.nodeVersion})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Process Uptime:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:BG(e.process.uptime)})]})]})]}),h.jsxs(se,{children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:"System"}),h.jsxs(Wt,{spacing:1,sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Hostname:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e.hostname})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Platform:"}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[e.platform," (",e.arch,")"]})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"CPU:"}),h.jsxs(re,{variant:"body2",color:"text.secondary",sx:{maxWidth:200,textAlign:"right"},noWrap:!0,title:e.cpuModel,children:[e.cpuCount,"x"," ",e.cpuModel.split("@")[0].trim()]})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"System Uptime:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:BG(e.uptime)})]})]})]})]})}),h.jsx(ht,{size:{xs:12,md:6},children:h.jsxs(Wt,{spacing:2,children:[h.jsxs(se,{children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(ZD,{}),"Memory Usage"]}),h.jsxs(se,{sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[h.jsxs(re,{variant:"body2",children:[gh(e.memory.used)," /"," ",gh(e.memory.total)]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[s.toFixed(1),"%"]})]}),h.jsx(se,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:h.jsx(se,{sx:{height:"100%",width:`${s}%`,backgroundColor:s>80?"error.main":s>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]}),h.jsxs(se,{children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(ZD,{}),"HAMH Process Memory"]}),h.jsxs(se,{sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[h.jsxs(re,{variant:"body2",children:["RSS: ",gh(e.process.rss)]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:["Heap: ",gh(e.process.heapUsed)," /"," ",gh(e.process.heapSizeLimit)]})]}),h.jsx(se,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:h.jsx(se,{sx:{height:"100%",width:`${Math.min(e.process.heapUsed/e.process.heapSizeLimit*100,100)}%`,backgroundColor:e.process.heapUsed/e.process.heapSizeLimit>.85?"error.main":e.process.heapUsed/e.process.heapSizeLimit>.6?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]}),h.jsxs(se,{children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(uTe,{}),"Storage Usage"]}),h.jsxs(se,{sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[h.jsxs(re,{variant:"body2",children:[gh(e.storage.used)," /"," ",gh(e.storage.total)]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[a.toFixed(1),"%"]})]}),h.jsx(se,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:h.jsx(se,{sx:{height:"100%",width:`${a}%`,backgroundColor:a>80?"error.main":a>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]})]})}),h.jsxs(ht,{size:{xs:12},children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(rTe,{}),"Network Interfaces"]}),h.jsx(Wt,{spacing:1,sx:{mt:1},children:e.network.interfaces.map(l=>h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsx(re,{variant:"body2",children:l.name}),h.jsx(ot,{label:`${l.address} (${l.family})`,size:"small",variant:"outlined"})]},`${l.name}-${l.address}`))})]})]})]})})},HG=200;function glt(){const[e,t]=A.useState([]),[n,r]=A.useState(null),[i,o]=A.useState(!1),s=A.useRef(null),a=A.useRef(void 0),l=A.useCallback(()=>{if(s.current?.readyState===WebSocket.OPEN)return;const u=window.location.protocol==="https:"?"wss:":"ws:",d=document.querySelector("base")?.href||window.location.origin,p=new URL(d),g=`${u}//${p.host}${p.pathname}api/ws`.replace(/\/+/g,"/").replace(":/","://"),y=new WebSocket(g);s.current=y,y.onopen=()=>{o(!0),y.send(JSON.stringify({type:"subscribe_diagnostics"}))},y.onmessage=b=>{try{const v=JSON.parse(b.data);if(v.type==="diagnostic_event"){const S=v.data;t(C=>{const w=[...C,S];return w.length>HG?w.slice(-HG):w})}else if(v.type==="diagnostic_snapshot"){const S=v.data;r(S),t(S.recentEvents??[])}}catch{}},y.onclose=()=>{o(!1),s.current=null,a.current=setTimeout(l,3e3)},y.onerror=()=>y.close()},[]);A.useEffect(()=>(l(),()=>{clearTimeout(a.current),s.current&&(s.current.send(JSON.stringify({type:"unsubscribe_diagnostics"})),s.current.close())}),[l]);const c=A.useCallback(()=>t([]),[]);return{events:e,snapshot:n,connected:i,clearEvents:c}}function UG(e){const t=e.replace("#",""),n=Number.parseInt(t.substring(0,2),16)/255,r=Number.parseInt(t.substring(2,4),16)/255,i=Number.parseInt(t.substring(4,6),16)/255;return .2126*(n<=.03928?n/12.92:((n+.055)/1.055)**2.4)+.7152*(r<=.03928?r/12.92:((r+.055)/1.055)**2.4)+.0722*(i<=.03928?i/12.92:((i+.055)/1.055)**2.4)>.179?"#000":"#fff"}const e4={state_update:"#4caf50",command_received:"#2196f3",entity_error:"#f44336",session_opened:"#ff9800",session_closed:"#9e9e9e",subscription_changed:"#9c27b0",bridge_started:"#00bcd4",bridge_stopped:"#795548",entity_warning:"#ff9800"},q5={state_update:"diagnostics.stateUpdate",command_received:"diagnostics.command",entity_error:"diagnostics.entityError",session_opened:"diagnostics.sessionOpen",session_closed:"diagnostics.sessionClose",subscription_changed:"diagnostics.subscription",bridge_started:"diagnostics.bridgeStart",bridge_stopped:"diagnostics.bridgeStop",entity_warning:"diagnostics.entityWarning"};function ylt(e){const t=new Date(e),n=String(t.getHours()).padStart(2,"0"),r=String(t.getMinutes()).padStart(2,"0"),i=String(t.getSeconds()).padStart(2,"0"),o=String(t.getMilliseconds()).padStart(3,"0");return`${n}:${r}:${i}.${o}`}const RA=Object.keys(e4);function blt({sortField:e,sortDirection:t}={}){const{t:n}=en(),r=Ki(),{events:i,snapshot:o,connected:s,clearEvents:a}=glt(),[l,c]=A.useState(new Set(RA)),[u,d]=A.useState(!1),p=v=>{c(S=>{const C=new Set(S);return C.has(v)?C.delete(v):C.add(v),C})},g=i.filter(v=>l.has(v.type)),y=A.useMemo(()=>{const v=o?.bridges??[];return e?[...v].sort((S,C)=>{let w=0;return e==="name"?w=S.bridgeName.localeCompare(C.bridgeName):w=S.bridgeId.localeCompare(C.bridgeId),t==="desc"?-w:w}):v},[o?.bridges,e,t]),b={};for(const v of i)b[v.type]=(b[v.type]??0)+1;return h.jsx(Mn,{children:h.jsxs(Qn,{children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(fTe,{}),h.jsx(re,{variant:"h6",children:n("diagnostics.title")}),h.jsx(ot,{icon:h.jsx(G_e,{sx:{fontSize:10,color:s?r.palette.success.main:r.palette.error.main}}),label:n(s?"common.live":"common.offline"),size:"small",variant:"outlined"})]}),h.jsxs(Wt,{direction:"row",spacing:.5,alignItems:"center",children:[h.jsx(Lt,{title:n("diagnostics.filterEvents"),children:h.jsx(qt,{size:"small",onClick:()=>d(v=>!v),color:u?"primary":"default",children:h.jsx(G6,{})})}),h.jsx(Lt,{title:n("diagnostics.clearEvents"),children:h.jsx(qt,{size:"small",onClick:a,children:h.jsx(z_e,{})})})]})]}),h.jsxs(Wt,{direction:"row",spacing:.5,flexWrap:"wrap",sx:{mb:2,gap:.5},children:[RA.map(v=>{const S=b[v]??0;if(S===0&&!u)return null;const C=e4[v];return h.jsx(ot,{label:`${n(q5[v])}: ${S}`,size:"small",sx:{bgcolor:l.has(v)?C:"action.disabledBackground",color:l.has(v)?UG(C):"text.disabled",fontSize:"0.7rem",height:22,cursor:"pointer",opacity:l.has(v)?1:.5},onClick:()=>p(v)},v)}),o?.system&&h.jsx(ot,{label:`Total: ${o.system.eventCount}`,size:"small",variant:"outlined",sx:{fontSize:"0.7rem",height:22}})]}),h.jsx(is,{in:u,children:h.jsx(zr,{variant:"outlined",sx:{p:1.5,mb:2},children:h.jsx(ht,{container:!0,spacing:0,children:RA.map(v=>{const S=e4[v];return h.jsx(ht,{size:{xs:6,sm:4,md:3},children:h.jsx(Ro,{control:h.jsx(ws,{size:"small",checked:l.has(v),onChange:()=>p(v),sx:{color:S,"&.Mui-checked":{color:S}}}),label:h.jsx(re,{variant:"caption",children:n(q5[v])})})},v)})})})}),y.length>0&&h.jsxs(h.Fragment,{children:[h.jsx(ht,{container:!0,spacing:1,sx:{mb:2},children:y.map(v=>h.jsx(vlt,{bridge:v},v.bridgeId))}),h.jsx(Dr,{sx:{mb:2}})]}),h.jsx(se,{sx:{maxHeight:400,overflow:"auto",bgcolor:"background.default",borderRadius:1,p:1},children:g.length===0?h.jsx(re,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:4},children:i.length===0?"Waiting for diagnostic events…":n("diagnostics.noEvents")}):g.map(v=>{const S=e4[v.type];return h.jsxs(se,{sx:{display:"flex",alignItems:"flex-start",gap:1,py:.4,px:.5,minWidth:0,borderBottom:"1px solid",borderColor:"divider","&:hover":{bgcolor:"action.hover"},"&:last-child":{borderBottom:"none"}},children:[h.jsx(re,{variant:"caption",sx:{color:"text.secondary",whiteSpace:"nowrap",fontFamily:"monospace",fontSize:"0.72rem",minWidth:85,pt:.1},children:ylt(v.timestamp)}),h.jsx(ot,{label:q5[v.type]?n(q5[v.type]):v.type,size:"small",sx:{bgcolor:S??"#757575",color:UG(S??"#757575"),fontSize:"0.62rem",fontWeight:600,height:18,minWidth:90}}),v.bridgeName&&h.jsxs(re,{variant:"caption",sx:{color:"primary.main",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:140,flexShrink:0},children:["[",v.bridgeName,"]"]}),v.entityId&&h.jsx(re,{variant:"caption",sx:{color:"warning.main",fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:220,flexShrink:1},children:v.entityId}),h.jsx(re,{variant:"caption",sx:{color:"text.primary",flex:1,wordBreak:"break-word",fontSize:"0.72rem"},children:v.message})]},v.id)})})]})})}function vlt({bridge:e}){const[t,n]=A.useState(!1);return h.jsx(ht,{size:{xs:12,sm:6},children:h.jsxs(zr,{variant:"outlined",sx:{p:1.5,overflow:"hidden",minWidth:0},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"center",sx:{cursor:"pointer"},onClick:()=>n(r=>!r),children:[h.jsxs(se,{sx:{minWidth:0,overflow:"hidden"},children:[h.jsx(re,{variant:"body2",fontWeight:500,noWrap:!0,children:e.bridgeName}),h.jsxs(re,{variant:"caption",color:"text.secondary",noWrap:!0,children:[e.entityCount," devices · ",e.sessionCount," sessions"]})]}),h.jsxs(Wt,{direction:"row",spacing:.5,alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end",sx:{flexShrink:0,ml:1},children:[Object.entries(e.featureFlags).filter(([,r])=>r).map(([r])=>h.jsx(ot,{label:r.replace(/^auto/,"").replace(/([A-Z])/g," $1").trim(),size:"small",variant:"outlined",sx:{fontSize:"0.6rem",height:18}},r)),h.jsx(ot,{label:e.status,size:"small",color:e.status==="running"?"success":e.status==="failed"?"error":"default",sx:{height:20}}),h.jsx(Ql,{sx:{transform:t?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s",fontSize:18,color:"text.secondary"}})]})]}),h.jsx(is,{in:t,children:h.jsx(se,{sx:{mt:1,maxHeight:200,overflow:"auto"},children:e.entities.map(r=>h.jsxs(se,{sx:{display:"flex",alignItems:"baseline",gap:.5,py:.3,borderBottom:"1px solid",borderColor:"divider"},children:[h.jsx(re,{variant:"caption",sx:{fontFamily:"monospace",fontSize:"0.68rem",minWidth:180,flexShrink:0,color:r.available?"text.primary":"error.main"},noWrap:!0,children:r.entityId}),h.jsx(se,{display:"flex",gap:.3,flexWrap:"wrap",children:r.matterClusters.map(i=>h.jsx(ot,{label:i,size:"small",variant:"outlined",sx:{fontSize:"0.58rem",height:16,"& .MuiChip-label":{px:.5}}},i))})]},r.entityId))})})]})})}const xlt=()=>{const[e,t]=A.useState("name"),[n,r]=A.useState("asc");return h.jsxs(se,{sx:{display:"flex",flexDirection:"column",gap:3},children:[h.jsx(dlt,{sortField:e,sortDirection:n,onSortFieldChange:t,onSortDirectionChange:r}),h.jsx(se,{sx:{px:2},children:h.jsx(blt,{sortField:e,sortDirection:n})}),h.jsx(se,{sx:{px:2},children:h.jsx(flt,{})}),h.jsx(se,{sx:{px:2,pb:2},children:h.jsx(mlt,{})}),h.jsx(Dr,{}),h.jsx(plt,{})]})};async function Slt(){const e=await fetch(`api/matter/labels?_s=${Date.now()}`);return await Rn(e,"Failed to fetch labels"),ar(e)}async function wlt(){const e=await fetch(`api/matter/areas?_s=${Date.now()}`);return await Rn(e,"Failed to fetch areas"),ar(e)}async function Clt(){const e=await fetch(`api/matter/filter-values?_s=${Date.now()}`);return await Rn(e,"Failed to fetch filter values"),ar(e)}const km=({values:e,copiedId:t,onCopy:n,searchable:r})=>{const[i,o]=A.useState(""),s=A.useMemo(()=>{if(!i)return e;const a=i.toLowerCase();return e.filter(l=>l.toLowerCase().includes(a))},[e,i]);return e.length===0?h.jsx(se,{sx:{p:2,textAlign:"center"},children:h.jsx(re,{color:"text.secondary",variant:"body2",children:"No values found."})}):h.jsxs(se,{children:[r&&e.length>10&&h.jsx(se,{sx:{px:2,pt:1,pb:.5},children:h.jsx(zn,{size:"small",fullWidth:!0,placeholder:"Search...",value:i,onChange:a=>o(a.target.value),slotProps:{input:{startAdornment:h.jsx(PC,{position:"start",children:h.jsx(DM,{fontSize:"small"})})}}})}),h.jsxs(se,{sx:{p:1.5,display:"flex",flexWrap:"wrap",gap:.75},children:[s.map(a=>h.jsx(ot,{label:a,size:"small",variant:t===a?"filled":"outlined",color:t===a?"success":"default",onClick:()=>n(a),sx:{fontFamily:"monospace",fontSize:"0.8rem"}},a)),i&&s.length===0&&h.jsxs(re,{color:"text.secondary",variant:"body2",sx:{p:1},children:['No matches for "',i,'"']})]})]})},klt=()=>{const{t:e}=en(),[t,n]=A.useState([]),[r,i]=A.useState([]),[o,s]=A.useState(null),[a,l]=A.useState(!0),[c,u]=A.useState(null),[d,p]=A.useState(null),g=A.useCallback(async()=>{l(!0);try{const[b,v,S]=await Promise.all([Slt(),wlt(),Clt()]);n(b),i(v),s(S),u(null)}catch(b){u(b instanceof Error?b.message:e("labels.loadFailed"))}finally{l(!1)}},[e]);A.useEffect(()=>{g()},[g]);const y=b=>{navigator.clipboard.writeText(b),p(b),setTimeout(()=>p(null),2e3)};return a?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsx(Xn,{})}):h.jsxs(se,{sx:{p:2},children:[h.jsxs(re,{variant:"h5",component:"h1",sx:{mb:3},children:[h.jsx(G6,{sx:{mr:1,verticalAlign:"middle"}}),e("labels.title")]}),h.jsx(zt,{severity:"info",sx:{mb:3},children:e("labels.info")}),c&&h.jsx(zt,{severity:"error",sx:{mb:2},children:c}),h.jsxs(re,{variant:"h6",sx:{mb:1},children:[h.jsx(EM,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),e("labels.labelsSection")," (",t.length,")"]}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:e("labels.labelsHint")}),h.jsx(Mn,{sx:{mb:4},children:t.length===0?h.jsx(se,{sx:{p:3,textAlign:"center"},children:h.jsx(re,{color:"text.secondary",children:e("labels.noLabels")})}):h.jsx(tf,{children:h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.displayName")}),h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.labelId")}),h.jsx(Tt,{width:48})]})}),h.jsx(Ec,{children:t.map(b=>h.jsxs(xi,{hover:!0,children:[h.jsxs(Tt,{children:[b.color&&h.jsx(se,{component:"span",sx:{display:"inline-block",width:12,height:12,borderRadius:"50%",backgroundColor:b.color,mr:1,verticalAlign:"middle"}}),b.name]}),h.jsx(Tt,{children:h.jsx("code",{children:b.label_id})}),h.jsx(Tt,{children:h.jsx(Lt,{title:d===b.label_id?e("common.copied"):e("common.copyId"),children:h.jsx(qt,{size:"small",onClick:()=>y(b.label_id),children:h.jsx(ef,{fontSize:"small"})})})})]},b.label_id))})]})})}),h.jsxs(re,{variant:"h6",sx:{mb:1},children:[h.jsx(eee,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),e("labels.areasSection")," (",r.length,")"]}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:e("labels.areasHint")}),h.jsx(Mn,{sx:{mb:4},children:r.length===0?h.jsx(se,{sx:{p:3,textAlign:"center"},children:h.jsx(re,{color:"text.secondary",children:e("labels.noAreas")})}):h.jsx(tf,{children:h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.displayName")}),h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.areaId")}),h.jsx(Tt,{width:48})]})}),h.jsx(Ec,{children:r.map(b=>h.jsxs(xi,{hover:!0,children:[h.jsx(Tt,{children:b.name}),h.jsx(Tt,{children:h.jsx("code",{children:b.area_id})}),h.jsx(Tt,{children:h.jsx(Lt,{title:d===b.area_id?e("common.copied"):e("common.copyId"),children:h.jsx(qt,{size:"small",onClick:()=>y(b.area_id),children:h.jsx(ef,{fontSize:"small"})})})})]},b.area_id))})]})})}),o&&h.jsxs(h.Fragment,{children:[h.jsx(re,{variant:"h6",sx:{mb:2},children:e("labels.otherFilterValues")}),h.jsxs(Md,{defaultExpanded:!0,children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(gTe,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.domains")," (",o.domains.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.domainsHint")}),h.jsx(km,{values:o.domains,copiedId:d,onCopy:y})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx($y,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.platforms")," (",o.platforms.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.platformsHint")}),h.jsx(km,{values:o.platforms,copiedId:d,onCopy:y})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(tH,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.entityCategories")," (",o.entityCategories.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.entityCategoriesHint")}),h.jsx(km,{values:o.entityCategories,copiedId:d,onCopy:y})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(tH,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.deviceClasses")," (",o.deviceClasses.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.deviceClassesHint")}),h.jsx(km,{values:o.deviceClasses,copiedId:d,onCopy:y,searchable:!0})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(aa,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.deviceNames")," (",o.deviceNames.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.deviceNamesHint")}),h.jsx(km,{values:o.deviceNames,copiedId:d,onCopy:y,searchable:!0})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(aa,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.productNames")," (",o.productNames.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.productNamesHint")}),h.jsx(km,{values:o.productNames,copiedId:d,onCopy:y,searchable:!0})]})]})]})]})};async function Elt(){const e=await fetch("api/lock-credentials");return await Rn(e,"Failed to fetch lock credentials"),ar(e)}async function Alt(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await Rn(n,"Failed to update lock credential"),ar(n)}async function Dlt(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}/enabled`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})});return await Rn(n,"Failed to toggle credential"),ar(n)}async function _lt(e){const t=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"DELETE"});await Rn(t,"Failed to delete lock credential")}const Tlt=({open:e,onClose:t,onSave:n,initialEntityId:r="",initialName:i="",isEdit:o=!1})=>{const{t:s}=en(),[a,l]=A.useState(r),[c,u]=A.useState(""),[d,p]=A.useState(i),[g,y]=A.useState(""),[b,v]=A.useState(!1);A.useEffect(()=>{e&&(l(r),p(i),u(""),y(""))},[e,r,i]);const S=async()=>{if(!a.trim()){y(s("lockCredentials.entityRequired"));return}if(!c||c.length<4||c.length>8){y(s("lockCredentials.pinLength"));return}if(!/^\d+$/.test(c)){y(s("lockCredentials.pinDigitsOnly"));return}v(!0);try{await n(a.trim(),c,d.trim()),t()}catch(C){y(C instanceof Error?C.message:s("lockCredentials.saveFailed"))}finally{v(!1)}};return h.jsxs(Po,{open:e,onClose:t,maxWidth:"sm",fullWidth:!0,children:[h.jsx($o,{children:s(o?"lockCredentials.editCredential":"lockCredentials.addCredential")}),h.jsx(No,{children:h.jsxs(se,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[g&&h.jsx(zt,{severity:"error",children:g}),h.jsx(zn,{label:s("lockCredentials.lockEntityId"),placeholder:"lock.front_door",value:a,onChange:C=>l(C.target.value),disabled:o,fullWidth:!0,helperText:s("lockCredentials.lockEntityHelperText")}),h.jsx(zn,{label:s("lockCredentials.pinCode"),type:"password",placeholder:"1234",value:c,onChange:C=>u(C.target.value.replace(/\D/g,"").slice(0,8)),fullWidth:!0,helperText:"4-8 digit PIN code for this lock",inputProps:{inputMode:"numeric",pattern:"[0-9]*"}}),h.jsx(zn,{label:s("lockCredentials.nameOptional"),placeholder:s("lockCredentials.namePlaceholder"),value:d,onChange:C=>p(C.target.value),fullWidth:!0,helperText:s("lockCredentials.nameHelperText")})]})}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:t,disabled:b,children:s("common.cancel")}),h.jsx(Ue,{onClick:S,variant:"contained",disabled:b,startIcon:b?h.jsx(Xn,{size:16}):h.jsx(F4,{}),children:s("common.save")})]})]})},Olt=()=>{const{t:e}=en(),[t,n]=A.useState([]),[r,i]=A.useState(!0),[o,s]=A.useState(null),[a,l]=A.useState(!1),[c,u]=A.useState(null),d=A.useCallback(async()=>{i(!0);try{const w=await Elt();n(w.credentials),s(null)}catch(w){s(w instanceof Error?w.message:e("lockCredentials.loadFailed"))}finally{i(!1)}},[e]);A.useEffect(()=>{d()},[d]);const p=async(w,E,k)=>{await Alt(w,{entityId:w,pinCode:E,name:k||void 0,enabled:!0}),await d()},[g,y]=A.useState(null),b=async w=>{y(null);try{await _lt(w),await d()}catch(E){s(E instanceof Error?E.message:e("lockCredentials.deleteFailed"))}},v=async w=>{try{await Dlt(w.entityId,!w.enabled),await d()}catch(E){s(E instanceof Error?E.message:e("lockCredentials.updateFailed"))}},S=w=>{u(w),l(!0)},C=()=>{u(null),l(!0)};return h.jsxs(se,{sx:{p:2},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[h.jsxs(re,{variant:"h5",component:"h1",children:[h.jsx(ju,{sx:{mr:1,verticalAlign:"middle"}}),e("lockCredentials.title")]}),h.jsx(Ue,{variant:"contained",startIcon:h.jsx(Ts,{}),onClick:C,children:e("lockCredentials.addCredential")})]}),h.jsx(zt,{severity:"info",sx:{mb:3},children:"Configure PIN codes for locks that require authentication for remote lock/unlock operations. The PIN will be sent with lock/unlock commands to Matter locks."}),o&&h.jsx(zt,{severity:"error",sx:{mb:2},children:o}),r?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsx(Xn,{})}):t.length===0?h.jsx(Mn,{children:h.jsxs(Qn,{sx:{textAlign:"center",py:4},children:[h.jsx(ju,{sx:{fontSize:48,color:"text.secondary",mb:2}}),h.jsx(re,{variant:"h6",color:"text.secondary",children:"No lock credentials configured"}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Add a PIN code for your Matter locks to enable remote lock/unlock"}),h.jsx(Ue,{variant:"outlined",startIcon:h.jsx(Ts,{}),onClick:C,children:"Add Your First Credential"})]})}):h.jsx(Mn,{children:h.jsx(Fo,{children:t.map((w,E)=>h.jsxs(Es,{divider:E<t.length-1,onClick:()=>S(w),sx:{cursor:"pointer","&:hover":{bgcolor:"action.hover"}},children:[h.jsx(Io,{children:h.jsx(ju,{color:w.enabled?"primary":"disabled"})}),h.jsx(ao,{primary:w.name||w.entityId,secondary:h.jsxs(h.Fragment,{children:[w.name&&h.jsx(re,{component:"span",variant:"body2",color:"text.secondary",children:w.entityId}),h.jsx(re,{component:"span",variant:"body2",color:"text.secondary",sx:{ml:w.name?2:0},children:"PIN: ****"})]})}),h.jsxs(WO,{children:[h.jsx(Lt,{title:w.enabled?e("lockCredentials.disable"):e("lockCredentials.enable"),children:h.jsx(Mu,{edge:"end",checked:w.enabled,onChange:k=>{k.stopPropagation(),v(w)}})}),h.jsx(Lt,{title:e("common.delete"),children:h.jsx(qt,{edge:"end",onClick:k=>{k.stopPropagation(),y(w.entityId)},sx:{ml:1},children:h.jsx(Pa,{})})})]})]},w.entityId))})}),h.jsx(Tlt,{open:a,onClose:()=>l(!1),onSave:p,initialEntityId:c?.entityId,initialName:c?.name,isEdit:!!c}),h.jsx($4,{open:g!==null,title:e("lockCredentials.confirmDeleteTitle"),message:e("lockCredentials.confirmDeleteMessage",{entity:g??""}),confirmLabel:e("common.delete"),confirmColor:"error",onConfirm:()=>{g&&b(g)},onCancel:()=>y(null)})]})},Mlt=()=>{const e=$c(),{t}=en();return h.jsxs(se,{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",gap:2,p:4,children:[h.jsx(lTe,{color:"disabled",sx:{fontSize:64}}),h.jsx(re,{variant:"h5",fontWeight:600,children:t("notFound.title")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:t("notFound.description")}),h.jsx(Ue,{variant:"contained",startIcon:h.jsx(kM,{}),onClick:()=>e(Ot.dashboard),children:t("notFound.backToDashboard")})]})};function Fi(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Fi(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var jlt={value:()=>{}};function x8(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new t4(n)}function t4(e){this._=e}function Rlt(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",i=n.indexOf(".");if(i>=0&&(r=n.slice(i+1),n=n.slice(0,i)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}t4.prototype=x8.prototype={constructor:t4,on:function(e,t){var n=this._,r=Rlt(e+"",n),i,o=-1,s=r.length;if(arguments.length<2){for(;++o<s;)if((i=(e=r[o]).type)&&(i=Ilt(n[i],e.name)))return i;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<s;)if(i=(e=r[o]).type)n[i]=VG(n[i],e.name,t);else if(t==null)for(i in n)n[i]=VG(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new t4(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=new Array(i),r=0,i,o;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],r=0,i=o.length;r<i;++r)o[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],i=0,o=r.length;i<o;++i)r[i].value.apply(t,n)}};function Ilt(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function VG(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=jlt,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var NT="http://www.w3.org/1999/xhtml";const WG={svg:"http://www.w3.org/2000/svg",xhtml:NT,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function S8(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),WG.hasOwnProperty(t)?{space:WG[t],local:e}:e}function Plt(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===NT&&t.documentElement.namespaceURI===NT?t.createElement(e):t.createElementNS(n,e)}}function Nlt(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function kle(e){var t=S8(e);return(t.local?Nlt:Plt)(t)}function $lt(){}function tI(e){return e==null?$lt:function(){return this.querySelector(e)}}function Llt(e){typeof e!="function"&&(e=tI(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=new Array(s),l,c,u=0;u<s;++u)(l=o[u])&&(c=e.call(l,l.__data__,u,o))&&("__data__"in l&&(c.__data__=l.__data__),a[u]=c);return new ca(r,this._parents)}function Flt(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function zlt(){return[]}function Ele(e){return e==null?zlt:function(){return this.querySelectorAll(e)}}function Blt(e){return function(){return Flt(e.apply(this,arguments))}}function Hlt(e){typeof e=="function"?e=Blt(e):e=Ele(e);for(var t=this._groups,n=t.length,r=[],i=[],o=0;o<n;++o)for(var s=t[o],a=s.length,l,c=0;c<a;++c)(l=s[c])&&(r.push(e.call(l,l.__data__,c,s)),i.push(l));return new ca(r,i)}function Ale(e){return function(){return this.matches(e)}}function Dle(e){return function(t){return t.matches(e)}}var Ult=Array.prototype.find;function Vlt(e){return function(){return Ult.call(this.children,e)}}function Wlt(){return this.firstElementChild}function qlt(e){return this.select(e==null?Wlt:Vlt(typeof e=="function"?e:Dle(e)))}var Klt=Array.prototype.filter;function Glt(){return Array.from(this.children)}function Ylt(e){return function(){return Klt.call(this.children,e)}}function Jlt(e){return this.selectAll(e==null?Glt:Ylt(typeof e=="function"?e:Dle(e)))}function Zlt(e){typeof e!="function"&&(e=Ale(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=[],l,c=0;c<s;++c)(l=o[c])&&e.call(l,l.__data__,c,o)&&a.push(l);return new ca(r,this._parents)}function _le(e){return new Array(e.length)}function Xlt(){return new ca(this._enter||this._groups.map(_le),this._parents)}function Jw(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Jw.prototype={constructor:Jw,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Qlt(e){return function(){return e}}function ect(e,t,n,r,i,o){for(var s=0,a,l=t.length,c=o.length;s<c;++s)(a=t[s])?(a.__data__=o[s],r[s]=a):n[s]=new Jw(e,o[s]);for(;s<l;++s)(a=t[s])&&(i[s]=a)}function tct(e,t,n,r,i,o,s){var a,l,c=new Map,u=t.length,d=o.length,p=new Array(u),g;for(a=0;a<u;++a)(l=t[a])&&(p[a]=g=s.call(l,l.__data__,a,t)+"",c.has(g)?i[a]=l:c.set(g,l));for(a=0;a<d;++a)g=s.call(e,o[a],a,o)+"",(l=c.get(g))?(r[a]=l,l.__data__=o[a],c.delete(g)):n[a]=new Jw(e,o[a]);for(a=0;a<u;++a)(l=t[a])&&c.get(p[a])===l&&(i[a]=l)}function nct(e){return e.__data__}function rct(e,t){if(!arguments.length)return Array.from(this,nct);var n=t?tct:ect,r=this._parents,i=this._groups;typeof e!="function"&&(e=Qlt(e));for(var o=i.length,s=new Array(o),a=new Array(o),l=new Array(o),c=0;c<o;++c){var u=r[c],d=i[c],p=d.length,g=ict(e.call(u,u&&u.__data__,c,r)),y=g.length,b=a[c]=new Array(y),v=s[c]=new Array(y),S=l[c]=new Array(p);n(u,d,b,v,S,g,t);for(var C=0,w=0,E,k;C<y;++C)if(E=b[C]){for(C>=w&&(w=C+1);!(k=v[w])&&++w<y;);E._next=k||null}}return s=new ca(s,r),s._enter=a,s._exit=l,s}function ict(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function oct(){return new ca(this._exit||this._groups.map(_le),this._parents)}function sct(e,t,n){var r=this.enter(),i=this,o=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(i=t(i),i&&(i=i.selection())),n==null?o.remove():n(o),r&&i?r.merge(i).order():i}function act(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,o=r.length,s=Math.min(i,o),a=new Array(i),l=0;l<s;++l)for(var c=n[l],u=r[l],d=c.length,p=a[l]=new Array(d),g,y=0;y<d;++y)(g=c[y]||u[y])&&(p[y]=g);for(;l<i;++l)a[l]=n[l];return new ca(a,this._parents)}function lct(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,o=r[i],s;--i>=0;)(s=r[i])&&(o&&s.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(s,o),o=s);return this}function cct(e){e||(e=uct);function t(d,p){return d&&p?e(d.__data__,p.__data__):!d-!p}for(var n=this._groups,r=n.length,i=new Array(r),o=0;o<r;++o){for(var s=n[o],a=s.length,l=i[o]=new Array(a),c,u=0;u<a;++u)(c=s[u])&&(l[u]=c);l.sort(t)}return new ca(i,this._parents).order()}function uct(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function dct(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function fct(){return Array.from(this)}function hct(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,o=r.length;i<o;++i){var s=r[i];if(s)return s}return null}function pct(){let e=0;for(const t of this)++e;return e}function mct(){return!this.node()}function gct(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],o=0,s=i.length,a;o<s;++o)(a=i[o])&&e.call(a,a.__data__,o,i);return this}function yct(e){return function(){this.removeAttribute(e)}}function bct(e){return function(){this.removeAttributeNS(e.space,e.local)}}function vct(e,t){return function(){this.setAttribute(e,t)}}function xct(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Sct(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function wct(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Cct(e,t){var n=S8(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?bct:yct:typeof t=="function"?n.local?wct:Sct:n.local?xct:vct)(n,t))}function Tle(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function kct(e){return function(){this.style.removeProperty(e)}}function Ect(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Act(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Dct(e,t,n){return arguments.length>1?this.each((t==null?kct:typeof t=="function"?Act:Ect)(e,t,n??"")):Yg(this.node(),e)}function Yg(e,t){return e.style.getPropertyValue(t)||Tle(e).getComputedStyle(e,null).getPropertyValue(t)}function _ct(e){return function(){delete this[e]}}function Tct(e,t){return function(){this[e]=t}}function Oct(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Mct(e,t){return arguments.length>1?this.each((t==null?_ct:typeof t=="function"?Oct:Tct)(e,t)):this.node()[e]}function Ole(e){return e.trim().split(/^|\s+/)}function nI(e){return e.classList||new Mle(e)}function Mle(e){this._node=e,this._names=Ole(e.getAttribute("class")||"")}Mle.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function jle(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Rle(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function jct(e){return function(){jle(this,e)}}function Rct(e){return function(){Rle(this,e)}}function Ict(e,t){return function(){(t.apply(this,arguments)?jle:Rle)(this,e)}}function Pct(e,t){var n=Ole(e+"");if(arguments.length<2){for(var r=nI(this.node()),i=-1,o=n.length;++i<o;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t=="function"?Ict:t?jct:Rct)(n,t))}function Nct(){this.textContent=""}function $ct(e){return function(){this.textContent=e}}function Lct(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Fct(e){return arguments.length?this.each(e==null?Nct:(typeof e=="function"?Lct:$ct)(e)):this.node().textContent}function zct(){this.innerHTML=""}function Bct(e){return function(){this.innerHTML=e}}function Hct(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function Uct(e){return arguments.length?this.each(e==null?zct:(typeof e=="function"?Hct:Bct)(e)):this.node().innerHTML}function Vct(){this.nextSibling&&this.parentNode.appendChild(this)}function Wct(){return this.each(Vct)}function qct(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Kct(){return this.each(qct)}function Gct(e){var t=typeof e=="function"?e:kle(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Yct(){return null}function Jct(e,t){var n=typeof e=="function"?e:kle(e),r=t==null?Yct:typeof t=="function"?t:tI(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Zct(){var e=this.parentNode;e&&e.removeChild(this)}function Xct(){return this.each(Zct)}function Qct(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function eut(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function tut(e){return this.select(e?eut:Qct)}function nut(e){return arguments.length?this.property("__data__",e):this.node().__data__}function rut(e){return function(t){e.call(this,t,this.__data__)}}function iut(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function out(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,o;n<i;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++r]=o;++r?t.length=r:delete this.__on}}}function sut(e,t,n){return function(){var r=this.__on,i,o=rut(t);if(r){for(var s=0,a=r.length;s<a;++s)if((i=r[s]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=o,i.options=n),i.value=t;return}}this.addEventListener(e.type,o,n),i={type:e.type,name:e.name,value:t,listener:o,options:n},r?r.push(i):this.__on=[i]}}function aut(e,t,n){var r=iut(e+""),i,o=r.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,c=a.length,u;l<c;++l)for(i=0,u=a[l];i<o;++i)if((s=r[i]).type===u.type&&s.name===u.name)return u.value}return}for(a=t?sut:out,i=0;i<o;++i)this.each(a(r[i],t,n));return this}function Ile(e,t,n){var r=Tle(e),i=r.CustomEvent;typeof i=="function"?i=new i(t,n):(i=r.document.createEvent("Event"),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function lut(e,t){return function(){return Ile(this,e,t)}}function cut(e,t){return function(){return Ile(this,e,t.apply(this,arguments))}}function uut(e,t){return this.each((typeof t=="function"?cut:lut)(e,t))}function*dut(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,o=r.length,s;i<o;++i)(s=r[i])&&(yield s)}var Ple=[null];function ca(e,t){this._groups=e,this._parents=t}function _v(){return new ca([[document.documentElement]],Ple)}function fut(){return this}ca.prototype=_v.prototype={constructor:ca,select:Llt,selectAll:Hlt,selectChild:qlt,selectChildren:Jlt,filter:Zlt,data:rct,enter:Xlt,exit:oct,join:sct,merge:act,selection:fut,order:lct,sort:cct,call:dct,nodes:fct,node:hct,size:pct,empty:mct,each:gct,attr:Cct,style:Dct,property:Mct,classed:Pct,text:Fct,html:Uct,raise:Wct,lower:Kct,append:Gct,insert:Jct,remove:Xct,clone:tut,datum:nut,on:aut,dispatch:uut,[Symbol.iterator]:dut};function ea(e){return typeof e=="string"?new ca([[document.querySelector(e)]],[document.documentElement]):new ca([[e]],Ple)}function hut(e){let t;for(;t=e.sourceEvent;)e=t;return e}function sl(e,t){if(e=hut(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}const put={passive:!1},b2={capture:!0,passive:!1};function IA(e){e.stopImmediatePropagation()}function Sg(e){e.preventDefault(),e.stopImmediatePropagation()}function Nle(e){var t=e.document.documentElement,n=ea(e).on("dragstart.drag",Sg,b2);"onselectstart"in t?n.on("selectstart.drag",Sg,b2):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function $le(e,t){var n=e.document.documentElement,r=ea(e).on("dragstart.drag",null);t&&(r.on("click.drag",Sg,b2),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const K5=e=>()=>e;function $T(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:o,x:s,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}$T.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function mut(e){return!e.ctrlKey&&!e.button}function gut(){return this.parentNode}function yut(e,t){return t??{x:e.x,y:e.y}}function but(){return navigator.maxTouchPoints||"ontouchstart"in this}function Lle(){var e=mut,t=gut,n=yut,r=but,i={},o=x8("start","drag","end"),s=0,a,l,c,u,d=0;function p(E){E.on("mousedown.drag",g).filter(r).on("touchstart.drag",v).on("touchmove.drag",S,put).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(E,k){if(!(u||!e.call(this,E,k))){var T=w(this,t.call(this,E,k),E,k,"mouse");T&&(ea(E.view).on("mousemove.drag",y,b2).on("mouseup.drag",b,b2),Nle(E.view),IA(E),c=!1,a=E.clientX,l=E.clientY,T("start",E))}}function y(E){if(Sg(E),!c){var k=E.clientX-a,T=E.clientY-l;c=k*k+T*T>d}i.mouse("drag",E)}function b(E){ea(E.view).on("mousemove.drag mouseup.drag",null),$le(E.view,c),Sg(E),i.mouse("end",E)}function v(E,k){if(e.call(this,E,k)){var T=E.changedTouches,_=t.call(this,E,k),O=T.length,R,P;for(R=0;R<O;++R)(P=w(this,_,E,k,T[R].identifier,T[R]))&&(IA(E),P("start",E,T[R]))}}function S(E){var k=E.changedTouches,T=k.length,_,O;for(_=0;_<T;++_)(O=i[k[_].identifier])&&(Sg(E),O("drag",E,k[_]))}function C(E){var k=E.changedTouches,T=k.length,_,O;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),_=0;_<T;++_)(O=i[k[_].identifier])&&(IA(E),O("end",E,k[_]))}function w(E,k,T,_,O,R){var P=o.copy(),L=sl(R||T,k),M,N,$;if(($=n.call(E,new $T("beforestart",{sourceEvent:T,target:p,identifier:O,active:s,x:L[0],y:L[1],dx:0,dy:0,dispatch:P}),_))!=null)return M=$.x-L[0]||0,N=$.y-L[1]||0,function B(F,V,W){var q=L,Z;switch(F){case"start":i[O]=B,Z=s++;break;case"end":delete i[O],--s;case"drag":L=sl(W||V,k),Z=s;break}P.call(F,E,new $T(F,{sourceEvent:V,subject:$,target:p,identifier:O,active:Z,x:L[0]+M,y:L[1]+N,dx:L[0]-q[0],dy:L[1]-q[1],dispatch:P}),_)}}return p.filter=function(E){return arguments.length?(e=typeof E=="function"?E:K5(!!E),p):e},p.container=function(E){return arguments.length?(t=typeof E=="function"?E:K5(E),p):t},p.subject=function(E){return arguments.length?(n=typeof E=="function"?E:K5(E),p):n},p.touchable=function(E){return arguments.length?(r=typeof E=="function"?E:K5(!!E),p):r},p.on=function(){var E=o.on.apply(o,arguments);return E===o?p:E},p.clickDistance=function(E){return arguments.length?(d=(E=+E)*E,p):Math.sqrt(d)},p}function rI(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Fle(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Tv(){}var v2=.7,Zw=1/v2,wg="\\s*([+-]?\\d+)\\s*",x2="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",_c="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",vut=/^#([0-9a-f]{3,8})$/,xut=new RegExp(`^rgb\\(${wg},${wg},${wg}\\)$`),Sut=new RegExp(`^rgb\\(${_c},${_c},${_c}\\)$`),wut=new RegExp(`^rgba\\(${wg},${wg},${wg},${x2}\\)$`),Cut=new RegExp(`^rgba\\(${_c},${_c},${_c},${x2}\\)$`),kut=new RegExp(`^hsl\\(${x2},${_c},${_c}\\)$`),Eut=new RegExp(`^hsla\\(${x2},${_c},${_c},${x2}\\)$`),qG={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};rI(Tv,dp,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:KG,formatHex:KG,formatHex8:Aut,formatHsl:Dut,formatRgb:GG,toString:GG});function KG(){return this.rgb().formatHex()}function Aut(){return this.rgb().formatHex8()}function Dut(){return zle(this).formatHsl()}function GG(){return this.rgb().formatRgb()}function dp(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=vut.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?YG(t):n===3?new ks(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?G5(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?G5(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=xut.exec(e))?new ks(t[1],t[2],t[3],1):(t=Sut.exec(e))?new ks(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=wut.exec(e))?G5(t[1],t[2],t[3],t[4]):(t=Cut.exec(e))?G5(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=kut.exec(e))?XG(t[1],t[2]/100,t[3]/100,1):(t=Eut.exec(e))?XG(t[1],t[2]/100,t[3]/100,t[4]):qG.hasOwnProperty(e)?YG(qG[e]):e==="transparent"?new ks(NaN,NaN,NaN,0):null}function YG(e){return new ks(e>>16&255,e>>8&255,e&255,1)}function G5(e,t,n,r){return r<=0&&(e=t=n=NaN),new ks(e,t,n,r)}function _ut(e){return e instanceof Tv||(e=dp(e)),e?(e=e.rgb(),new ks(e.r,e.g,e.b,e.opacity)):new ks}function LT(e,t,n,r){return arguments.length===1?_ut(e):new ks(e,t,n,r??1)}function ks(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}rI(ks,LT,Fle(Tv,{brighter(e){return e=e==null?Zw:Math.pow(Zw,e),new ks(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?v2:Math.pow(v2,e),new ks(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new ks(qh(this.r),qh(this.g),qh(this.b),Xw(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:JG,formatHex:JG,formatHex8:Tut,formatRgb:ZG,toString:ZG}));function JG(){return`#${Bh(this.r)}${Bh(this.g)}${Bh(this.b)}`}function Tut(){return`#${Bh(this.r)}${Bh(this.g)}${Bh(this.b)}${Bh((isNaN(this.opacity)?1:this.opacity)*255)}`}function ZG(){const e=Xw(this.opacity);return`${e===1?"rgb(":"rgba("}${qh(this.r)}, ${qh(this.g)}, ${qh(this.b)}${e===1?")":`, ${e})`}`}function Xw(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function qh(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Bh(e){return e=qh(e),(e<16?"0":"")+e.toString(16)}function XG(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new ul(e,t,n,r)}function zle(e){if(e instanceof ul)return new ul(e.h,e.s,e.l,e.opacity);if(e instanceof Tv||(e=dp(e)),!e)return new ul;if(e instanceof ul)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),o=Math.max(t,n,r),s=NaN,a=o-i,l=(o+i)/2;return a?(t===o?s=(n-r)/a+(n<r)*6:n===o?s=(r-t)/a+2:s=(t-n)/a+4,a/=l<.5?o+i:2-o-i,s*=60):a=l>0&&l<1?0:s,new ul(s,a,l,e.opacity)}function Out(e,t,n,r){return arguments.length===1?zle(e):new ul(e,t,n,r??1)}function ul(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}rI(ul,Out,Fle(Tv,{brighter(e){return e=e==null?Zw:Math.pow(Zw,e),new ul(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?v2:Math.pow(v2,e),new ul(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new ks(PA(e>=240?e-240:e+120,i,r),PA(e,i,r),PA(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new ul(QG(this.h),Y5(this.s),Y5(this.l),Xw(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Xw(this.opacity);return`${e===1?"hsl(":"hsla("}${QG(this.h)}, ${Y5(this.s)*100}%, ${Y5(this.l)*100}%${e===1?")":`, ${e})`}`}}));function QG(e){return e=(e||0)%360,e<0?e+360:e}function Y5(e){return Math.max(0,Math.min(1,e||0))}function PA(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const iI=e=>()=>e;function Mut(e,t){return function(n){return e+n*t}}function jut(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Rut(e){return(e=+e)==1?Ble:function(t,n){return n-t?jut(t,n,e):iI(isNaN(t)?n:t)}}function Ble(e,t){var n=t-e;return n?Mut(e,n):iI(isNaN(e)?t:e)}const Qw=(function e(t){var n=Rut(t);function r(i,o){var s=n((i=LT(i)).r,(o=LT(o)).r),a=n(i.g,o.g),l=n(i.b,o.b),c=Ble(i.opacity,o.opacity);return function(u){return i.r=s(u),i.g=a(u),i.b=l(u),i.opacity=c(u),i+""}}return r.gamma=e,r})(1);function Iut(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(o){for(i=0;i<n;++i)r[i]=e[i]*(1-o)+t[i]*o;return r}}function Put(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Nut(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=new Array(r),o=new Array(n),s;for(s=0;s<r;++s)i[s]=ib(e[s],t[s]);for(;s<n;++s)o[s]=t[s];return function(a){for(s=0;s<r;++s)o[s]=i[s](a);return o}}function $ut(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function tc(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Lut(e,t){var n={},r={},i;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(i in t)i in e?n[i]=ib(e[i],t[i]):r[i]=t[i];return function(o){for(i in n)r[i]=n[i](o);return r}}var FT=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,NA=new RegExp(FT.source,"g");function Fut(e){return function(){return e}}function zut(e){return function(t){return e(t)+""}}function Hle(e,t){var n=FT.lastIndex=NA.lastIndex=0,r,i,o,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=FT.exec(e))&&(i=NA.exec(t));)(o=i.index)>n&&(o=t.slice(n,o),a[s]?a[s]+=o:a[++s]=o),(r=r[0])===(i=i[0])?a[s]?a[s]+=i:a[++s]=i:(a[++s]=null,l.push({i:s,x:tc(r,i)})),n=NA.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?l[0]?zut(l[0].x):Fut(t):(t=l.length,function(c){for(var u=0,d;u<t;++u)a[(d=l[u]).i]=d.x(c);return a.join("")})}function ib(e,t){var n=typeof t,r;return t==null||n==="boolean"?iI(t):(n==="number"?tc:n==="string"?(r=dp(t))?(t=r,Qw):Hle:t instanceof dp?Qw:t instanceof Date?$ut:Put(t)?Iut:Array.isArray(t)?Nut:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Lut:tc)(e,t)}var eY=180/Math.PI,zT={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ule(e,t,n,r,i,o){var s,a,l;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(l=e*n+t*r)&&(n-=e*l,r-=t*l),(a=Math.sqrt(n*n+r*r))&&(n/=a,r/=a,l/=a),e*r<t*n&&(e=-e,t=-t,l=-l,s=-s),{translateX:i,translateY:o,rotate:Math.atan2(t,e)*eY,skewX:Math.atan(l)*eY,scaleX:s,scaleY:a}}var J5;function But(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?zT:Ule(t.a,t.b,t.c,t.d,t.e,t.f)}function Hut(e){return e==null||(J5||(J5=document.createElementNS("http://www.w3.org/2000/svg","g")),J5.setAttribute("transform",e),!(e=J5.transform.baseVal.consolidate()))?zT:(e=e.matrix,Ule(e.a,e.b,e.c,e.d,e.e,e.f))}function Vle(e,t,n,r){function i(c){return c.length?c.pop()+" ":""}function o(c,u,d,p,g,y){if(c!==d||u!==p){var b=g.push("translate(",null,t,null,n);y.push({i:b-4,x:tc(c,d)},{i:b-2,x:tc(u,p)})}else(d||p)&&g.push("translate("+d+t+p+n)}function s(c,u,d,p){c!==u?(c-u>180?u+=360:u-c>180&&(c+=360),p.push({i:d.push(i(d)+"rotate(",null,r)-2,x:tc(c,u)})):u&&d.push(i(d)+"rotate("+u+r)}function a(c,u,d,p){c!==u?p.push({i:d.push(i(d)+"skewX(",null,r)-2,x:tc(c,u)}):u&&d.push(i(d)+"skewX("+u+r)}function l(c,u,d,p,g,y){if(c!==d||u!==p){var b=g.push(i(g)+"scale(",null,",",null,")");y.push({i:b-4,x:tc(c,d)},{i:b-2,x:tc(u,p)})}else(d!==1||p!==1)&&g.push(i(g)+"scale("+d+","+p+")")}return function(c,u){var d=[],p=[];return c=e(c),u=e(u),o(c.translateX,c.translateY,u.translateX,u.translateY,d,p),s(c.rotate,u.rotate,d,p),a(c.skewX,u.skewX,d,p),l(c.scaleX,c.scaleY,u.scaleX,u.scaleY,d,p),c=u=null,function(g){for(var y=-1,b=p.length,v;++y<b;)d[(v=p[y]).i]=v.x(g);return d.join("")}}}var Uut=Vle(But,"px, ","px)","deg)"),Vut=Vle(Hut,", ",")",")"),Wut=1e-12;function tY(e){return((e=Math.exp(e))+1/e)/2}function qut(e){return((e=Math.exp(e))-1/e)/2}function Kut(e){return((e=Math.exp(2*e))-1)/(e+1)}const n4=(function e(t,n,r){function i(o,s){var a=o[0],l=o[1],c=o[2],u=s[0],d=s[1],p=s[2],g=u-a,y=d-l,b=g*g+y*y,v,S;if(b<Wut)S=Math.log(p/c)/t,v=function(_){return[a+_*g,l+_*y,c*Math.exp(t*_*S)]};else{var C=Math.sqrt(b),w=(p*p-c*c+r*b)/(2*c*n*C),E=(p*p-c*c-r*b)/(2*p*n*C),k=Math.log(Math.sqrt(w*w+1)-w),T=Math.log(Math.sqrt(E*E+1)-E);S=(T-k)/t,v=function(_){var O=_*S,R=tY(k),P=c/(n*C)*(R*Kut(t*O+k)-qut(k));return[a+P*g,l+P*y,c*R/tY(t*O+k)]}}return v.duration=S*1e3*t/Math.SQRT2,v}return i.rho=function(o){var s=Math.max(.001,+o),a=s*s,l=a*a;return e(s,a,l)},i})(Math.SQRT2,2,4);var Jg=0,Cy=0,ny=0,Wle=1e3,e6,ky,t6=0,fp=0,w8=0,S2=typeof performance=="object"&&performance.now?performance:Date,qle=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function oI(){return fp||(qle(Gut),fp=S2.now()+w8)}function Gut(){fp=0}function n6(){this._call=this._time=this._next=null}n6.prototype=Kle.prototype={constructor:n6,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?oI():+n)+(t==null?0:+t),!this._next&&ky!==this&&(ky?ky._next=this:e6=this,ky=this),this._call=e,this._time=n,BT()},stop:function(){this._call&&(this._call=null,this._time=1/0,BT())}};function Kle(e,t,n){var r=new n6;return r.restart(e,t,n),r}function Yut(){oI(),++Jg;for(var e=e6,t;e;)(t=fp-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Jg}function nY(){fp=(t6=S2.now())+w8,Jg=Cy=0;try{Yut()}finally{Jg=0,Zut(),fp=0}}function Jut(){var e=S2.now(),t=e-t6;t>Wle&&(w8-=t,t6=e)}function Zut(){for(var e,t=e6,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:e6=n);ky=e,BT(r)}function BT(e){if(!Jg){Cy&&(Cy=clearTimeout(Cy));var t=e-fp;t>24?(e<1/0&&(Cy=setTimeout(nY,e-S2.now()-w8)),ny&&(ny=clearInterval(ny))):(ny||(t6=S2.now(),ny=setInterval(Jut,Wle)),Jg=1,qle(nY))}}function rY(e,t,n){var r=new n6;return t=t==null?0:+t,r.restart(i=>{r.stop(),e(i+t)},t,n),r}var Xut=x8("start","end","cancel","interrupt"),Qut=[],Gle=0,iY=1,HT=2,r4=3,oY=4,UT=5,i4=6;function C8(e,t,n,r,i,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;edt(e,n,{name:t,index:r,group:i,on:Xut,tween:Qut,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:Gle})}function sI(e,t){var n=Il(e,t);if(n.state>Gle)throw new Error("too late; already scheduled");return n}function Wc(e,t){var n=Il(e,t);if(n.state>r4)throw new Error("too late; already running");return n}function Il(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function edt(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Kle(o,0,n.time);function o(c){n.state=iY,n.timer.restart(s,n.delay,n.time),n.delay<=c&&s(c-n.delay)}function s(c){var u,d,p,g;if(n.state!==iY)return l();for(u in r)if(g=r[u],g.name===n.name){if(g.state===r4)return rY(s);g.state===oY?(g.state=i4,g.timer.stop(),g.on.call("interrupt",e,e.__data__,g.index,g.group),delete r[u]):+u<t&&(g.state=i4,g.timer.stop(),g.on.call("cancel",e,e.__data__,g.index,g.group),delete r[u])}if(rY(function(){n.state===r4&&(n.state=oY,n.timer.restart(a,n.delay,n.time),a(c))}),n.state=HT,n.on.call("start",e,e.__data__,n.index,n.group),n.state===HT){for(n.state=r4,i=new Array(p=n.tween.length),u=0,d=-1;u<p;++u)(g=n.tween[u].value.call(e,e.__data__,n.index,n.group))&&(i[++d]=g);i.length=d+1}}function a(c){for(var u=c<n.duration?n.ease.call(null,c/n.duration):(n.timer.restart(l),n.state=UT,1),d=-1,p=i.length;++d<p;)i[d].call(e,u);n.state===UT&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=i4,n.timer.stop(),delete r[t];for(var c in r)return;delete e.__transition}}function o4(e,t){var n=e.__transition,r,i,o=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((r=n[s]).name!==t){o=!1;continue}i=r.state>HT&&r.state<UT,r.state=i4,r.timer.stop(),r.on.call(i?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}o&&delete e.__transition}}function tdt(e){return this.each(function(){o4(this,e)})}function ndt(e,t){var n,r;return function(){var i=Wc(this,e),o=i.tween;if(o!==n){r=n=o;for(var s=0,a=r.length;s<a;++s)if(r[s].name===t){r=r.slice(),r.splice(s,1);break}}i.tween=r}}function rdt(e,t,n){var r,i;if(typeof n!="function")throw new Error;return function(){var o=Wc(this,e),s=o.tween;if(s!==r){i=(r=s).slice();for(var a={name:t,value:n},l=0,c=i.length;l<c;++l)if(i[l].name===t){i[l]=a;break}l===c&&i.push(a)}o.tween=i}}function idt(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=Il(this.node(),n).tween,i=0,o=r.length,s;i<o;++i)if((s=r[i]).name===e)return s.value;return null}return this.each((t==null?ndt:rdt)(n,e,t))}function aI(e,t,n){var r=e._id;return e.each(function(){var i=Wc(this,r);(i.value||(i.value={}))[t]=n.apply(this,arguments)}),function(i){return Il(i,r).value[t]}}function Yle(e,t){var n;return(typeof t=="number"?tc:t instanceof dp?Qw:(n=dp(t))?(t=n,Qw):Hle)(e,t)}function odt(e){return function(){this.removeAttribute(e)}}function sdt(e){return function(){this.removeAttributeNS(e.space,e.local)}}function adt(e,t,n){var r,i=n+"",o;return function(){var s=this.getAttribute(e);return s===i?null:s===r?o:o=t(r=s,n)}}function ldt(e,t,n){var r,i=n+"",o;return function(){var s=this.getAttributeNS(e.space,e.local);return s===i?null:s===r?o:o=t(r=s,n)}}function cdt(e,t,n){var r,i,o;return function(){var s,a=n(this),l;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),l=a+"",s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a)))}}function udt(e,t,n){var r,i,o;return function(){var s,a=n(this),l;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),l=a+"",s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a)))}}function ddt(e,t){var n=S8(e),r=n==="transform"?Vut:Yle;return this.attrTween(e,typeof t=="function"?(n.local?udt:cdt)(n,r,aI(this,"attr."+e,t)):t==null?(n.local?sdt:odt)(n):(n.local?ldt:adt)(n,r,t))}function fdt(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function hdt(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function pdt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&hdt(e,o)),n}return i._value=t,i}function mdt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&fdt(e,o)),n}return i._value=t,i}function gdt(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=S8(e);return this.tween(n,(r.local?pdt:mdt)(r,t))}function ydt(e,t){return function(){sI(this,e).delay=+t.apply(this,arguments)}}function bdt(e,t){return t=+t,function(){sI(this,e).delay=t}}function vdt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?ydt:bdt)(t,e)):Il(this.node(),t).delay}function xdt(e,t){return function(){Wc(this,e).duration=+t.apply(this,arguments)}}function Sdt(e,t){return t=+t,function(){Wc(this,e).duration=t}}function wdt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?xdt:Sdt)(t,e)):Il(this.node(),t).duration}function Cdt(e,t){if(typeof t!="function")throw new Error;return function(){Wc(this,e).ease=t}}function kdt(e){var t=this._id;return arguments.length?this.each(Cdt(t,e)):Il(this.node(),t).ease}function Edt(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Wc(this,e).ease=n}}function Adt(e){if(typeof e!="function")throw new Error;return this.each(Edt(this._id,e))}function Ddt(e){typeof e!="function"&&(e=Ale(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=[],l,c=0;c<s;++c)(l=o[c])&&e.call(l,l.__data__,c,o)&&a.push(l);return new Gu(r,this._parents,this._name,this._id)}function _dt(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,i=n.length,o=Math.min(r,i),s=new Array(r),a=0;a<o;++a)for(var l=t[a],c=n[a],u=l.length,d=s[a]=new Array(u),p,g=0;g<u;++g)(p=l[g]||c[g])&&(d[g]=p);for(;a<r;++a)s[a]=t[a];return new Gu(s,this._parents,this._name,this._id)}function Tdt(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function Odt(e,t,n){var r,i,o=Tdt(t)?sI:Wc;return function(){var s=o(this,e),a=s.on;a!==r&&(i=(r=a).copy()).on(t,n),s.on=i}}function Mdt(e,t){var n=this._id;return arguments.length<2?Il(this.node(),n).on.on(e):this.each(Odt(n,e,t))}function jdt(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rdt(){return this.on("end.remove",jdt(this._id))}function Idt(e){var t=this._name,n=this._id;typeof e!="function"&&(e=tI(e));for(var r=this._groups,i=r.length,o=new Array(i),s=0;s<i;++s)for(var a=r[s],l=a.length,c=o[s]=new Array(l),u,d,p=0;p<l;++p)(u=a[p])&&(d=e.call(u,u.__data__,p,a))&&("__data__"in u&&(d.__data__=u.__data__),c[p]=d,C8(c[p],t,n,p,c,Il(u,n)));return new Gu(o,this._parents,t,n)}function Pdt(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ele(e));for(var r=this._groups,i=r.length,o=[],s=[],a=0;a<i;++a)for(var l=r[a],c=l.length,u,d=0;d<c;++d)if(u=l[d]){for(var p=e.call(u,u.__data__,d,l),g,y=Il(u,n),b=0,v=p.length;b<v;++b)(g=p[b])&&C8(g,t,n,b,p,y);o.push(p),s.push(u)}return new Gu(o,s,t,n)}var Ndt=_v.prototype.constructor;function $dt(){return new Ndt(this._groups,this._parents)}function Ldt(e,t){var n,r,i;return function(){var o=Yg(this,e),s=(this.style.removeProperty(e),Yg(this,e));return o===s?null:o===n&&s===r?i:i=t(n=o,r=s)}}function Jle(e){return function(){this.style.removeProperty(e)}}function Fdt(e,t,n){var r,i=n+"",o;return function(){var s=Yg(this,e);return s===i?null:s===r?o:o=t(r=s,n)}}function zdt(e,t,n){var r,i,o;return function(){var s=Yg(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),Yg(this,e))),s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a))}}function Bdt(e,t){var n,r,i,o="style."+t,s="end."+o,a;return function(){var l=Wc(this,e),c=l.on,u=l.value[o]==null?a||(a=Jle(t)):void 0;(c!==n||i!==u)&&(r=(n=c).copy()).on(s,i=u),l.on=r}}function Hdt(e,t,n){var r=(e+="")=="transform"?Uut:Yle;return t==null?this.styleTween(e,Ldt(e,r)).on("end.style."+e,Jle(e)):typeof t=="function"?this.styleTween(e,zdt(e,r,aI(this,"style."+e,t))).each(Bdt(this._id,e)):this.styleTween(e,Fdt(e,r,t),n).on("end.style."+e,null)}function Udt(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Vdt(e,t,n){var r,i;function o(){var s=t.apply(this,arguments);return s!==i&&(r=(i=s)&&Udt(e,s,n)),r}return o._value=t,o}function Wdt(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,Vdt(e,t,n??""))}function qdt(e){return function(){this.textContent=e}}function Kdt(e){return function(){var t=e(this);this.textContent=t??""}}function Gdt(e){return this.tween("text",typeof e=="function"?Kdt(aI(this,"text",e)):qdt(e==null?"":e+""))}function Ydt(e){return function(t){this.textContent=e.call(this,t)}}function Jdt(e){var t,n;function r(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&Ydt(i)),t}return r._value=e,r}function Zdt(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,Jdt(e))}function Xdt(){for(var e=this._name,t=this._id,n=Zle(),r=this._groups,i=r.length,o=0;o<i;++o)for(var s=r[o],a=s.length,l,c=0;c<a;++c)if(l=s[c]){var u=Il(l,t);C8(l,e,n,c,s,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Gu(r,this._parents,e,n)}function Qdt(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(o,s){var a={value:s},l={value:function(){--i===0&&o()}};n.each(function(){var c=Wc(this,r),u=c.on;u!==e&&(t=(e=u).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(l)),c.on=t}),i===0&&o()})}var eft=0;function Gu(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Zle(){return++eft}var bu=_v.prototype;Gu.prototype={constructor:Gu,select:Idt,selectAll:Pdt,selectChild:bu.selectChild,selectChildren:bu.selectChildren,filter:Ddt,merge:_dt,selection:$dt,transition:Xdt,call:bu.call,nodes:bu.nodes,node:bu.node,size:bu.size,empty:bu.empty,each:bu.each,on:Mdt,attr:ddt,attrTween:gdt,style:Hdt,styleTween:Wdt,text:Gdt,textTween:Zdt,remove:Rdt,tween:idt,delay:vdt,duration:wdt,ease:kdt,easeVarying:Adt,end:Qdt,[Symbol.iterator]:bu[Symbol.iterator]};function tft(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var nft={time:null,delay:0,duration:250,ease:tft};function rft(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function ift(e){var t,n;e instanceof Gu?(t=e._id,e=e._name):(t=Zle(),(n=nft).time=oI(),e=e==null?null:e+"");for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var s=r[o],a=s.length,l,c=0;c<a;++c)(l=s[c])&&C8(l,e,t,c,s,n||rft(l,t));return new Gu(r,this._parents,e,t)}_v.prototype.interrupt=tdt;_v.prototype.transition=ift;const Z5=e=>()=>e;function oft(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function Ou(e,t,n){this.k=e,this.x=t,this.y=n}Ou.prototype={constructor:Ou,scale:function(e){return e===1?this:new Ou(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Ou(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var k8=new Ou(1,0,0);Xle.prototype=Ou.prototype;function Xle(e){for(;!e.__zoom;)if(!(e=e.parentNode))return k8;return e.__zoom}function $A(e){e.stopImmediatePropagation()}function ry(e){e.preventDefault(),e.stopImmediatePropagation()}function sft(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function aft(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function sY(){return this.__zoom||k8}function lft(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function cft(){return navigator.maxTouchPoints||"ontouchstart"in this}function uft(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],s=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),s>o?(o+s)/2:Math.min(0,o)||Math.max(0,s))}function Qle(){var e=sft,t=aft,n=uft,r=lft,i=cft,o=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,l=n4,c=x8("start","zoom","end"),u,d,p,g=500,y=150,b=0,v=10;function S($){$.property("__zoom",sY).on("wheel.zoom",O,{passive:!1}).on("mousedown.zoom",R).on("dblclick.zoom",P).filter(i).on("touchstart.zoom",L).on("touchmove.zoom",M).on("touchend.zoom touchcancel.zoom",N).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}S.transform=function($,B,F,V){var W=$.selection?$.selection():$;W.property("__zoom",sY),$!==W?k($,B,F,V):W.interrupt().each(function(){T(this,arguments).event(V).start().zoom(null,typeof B=="function"?B.apply(this,arguments):B).end()})},S.scaleBy=function($,B,F,V){S.scaleTo($,function(){var W=this.__zoom.k,q=typeof B=="function"?B.apply(this,arguments):B;return W*q},F,V)},S.scaleTo=function($,B,F,V){S.transform($,function(){var W=t.apply(this,arguments),q=this.__zoom,Z=F==null?E(W):typeof F=="function"?F.apply(this,arguments):F,z=q.invert(Z),U=typeof B=="function"?B.apply(this,arguments):B;return n(w(C(q,U),Z,z),W,s)},F,V)},S.translateBy=function($,B,F,V){S.transform($,function(){return n(this.__zoom.translate(typeof B=="function"?B.apply(this,arguments):B,typeof F=="function"?F.apply(this,arguments):F),t.apply(this,arguments),s)},null,V)},S.translateTo=function($,B,F,V,W){S.transform($,function(){var q=t.apply(this,arguments),Z=this.__zoom,z=V==null?E(q):typeof V=="function"?V.apply(this,arguments):V;return n(k8.translate(z[0],z[1]).scale(Z.k).translate(typeof B=="function"?-B.apply(this,arguments):-B,typeof F=="function"?-F.apply(this,arguments):-F),q,s)},V,W)};function C($,B){return B=Math.max(o[0],Math.min(o[1],B)),B===$.k?$:new Ou(B,$.x,$.y)}function w($,B,F){var V=B[0]-F[0]*$.k,W=B[1]-F[1]*$.k;return V===$.x&&W===$.y?$:new Ou($.k,V,W)}function E($){return[(+$[0][0]+ +$[1][0])/2,(+$[0][1]+ +$[1][1])/2]}function k($,B,F,V){$.on("start.zoom",function(){T(this,arguments).event(V).start()}).on("interrupt.zoom end.zoom",function(){T(this,arguments).event(V).end()}).tween("zoom",function(){var W=this,q=arguments,Z=T(W,q).event(V),z=t.apply(W,q),U=F==null?E(z):typeof F=="function"?F.apply(W,q):F,Y=Math.max(z[1][0]-z[0][0],z[1][1]-z[0][1]),H=W.__zoom,K=typeof B=="function"?B.apply(W,q):B,Q=l(H.invert(U).concat(Y/H.k),K.invert(U).concat(Y/K.k));return function(ie){if(ie===1)ie=K;else{var te=Q(ie),ce=Y/te[2];ie=new Ou(ce,U[0]-te[0]*ce,U[1]-te[1]*ce)}Z.zoom(null,ie)}})}function T($,B,F){return!F&&$.__zooming||new _($,B)}function _($,B){this.that=$,this.args=B,this.active=0,this.sourceEvent=null,this.extent=t.apply($,B),this.taps=0}_.prototype={event:function($){return $&&(this.sourceEvent=$),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function($,B){return this.mouse&&$!=="mouse"&&(this.mouse[1]=B.invert(this.mouse[0])),this.touch0&&$!=="touch"&&(this.touch0[1]=B.invert(this.touch0[0])),this.touch1&&$!=="touch"&&(this.touch1[1]=B.invert(this.touch1[0])),this.that.__zoom=B,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function($){var B=ea(this.that).datum();c.call($,this.that,new oft($,{sourceEvent:this.sourceEvent,target:S,transform:this.that.__zoom,dispatch:c}),B)}};function O($,...B){if(!e.apply(this,arguments))return;var F=T(this,B).event($),V=this.__zoom,W=Math.max(o[0],Math.min(o[1],V.k*Math.pow(2,r.apply(this,arguments)))),q=sl($);if(F.wheel)(F.mouse[0][0]!==q[0]||F.mouse[0][1]!==q[1])&&(F.mouse[1]=V.invert(F.mouse[0]=q)),clearTimeout(F.wheel);else{if(V.k===W)return;F.mouse=[q,V.invert(q)],o4(this),F.start()}ry($),F.wheel=setTimeout(Z,y),F.zoom("mouse",n(w(C(V,W),F.mouse[0],F.mouse[1]),F.extent,s));function Z(){F.wheel=null,F.end()}}function R($,...B){if(p||!e.apply(this,arguments))return;var F=$.currentTarget,V=T(this,B,!0).event($),W=ea($.view).on("mousemove.zoom",U,!0).on("mouseup.zoom",Y,!0),q=sl($,F),Z=$.clientX,z=$.clientY;Nle($.view),$A($),V.mouse=[q,this.__zoom.invert(q)],o4(this),V.start();function U(H){if(ry(H),!V.moved){var K=H.clientX-Z,Q=H.clientY-z;V.moved=K*K+Q*Q>b}V.event(H).zoom("mouse",n(w(V.that.__zoom,V.mouse[0]=sl(H,F),V.mouse[1]),V.extent,s))}function Y(H){W.on("mousemove.zoom mouseup.zoom",null),$le(H.view,V.moved),ry(H),V.event(H).end()}}function P($,...B){if(e.apply(this,arguments)){var F=this.__zoom,V=sl($.changedTouches?$.changedTouches[0]:$,this),W=F.invert(V),q=F.k*($.shiftKey?.5:2),Z=n(w(C(F,q),V,W),t.apply(this,B),s);ry($),a>0?ea(this).transition().duration(a).call(k,Z,V,$):ea(this).call(S.transform,Z,V,$)}}function L($,...B){if(e.apply(this,arguments)){var F=$.touches,V=F.length,W=T(this,B,$.changedTouches.length===V).event($),q,Z,z,U;for($A($),Z=0;Z<V;++Z)z=F[Z],U=sl(z,this),U=[U,this.__zoom.invert(U),z.identifier],W.touch0?!W.touch1&&W.touch0[2]!==U[2]&&(W.touch1=U,W.taps=0):(W.touch0=U,q=!0,W.taps=1+!!u);u&&(u=clearTimeout(u)),q&&(W.taps<2&&(d=U[0],u=setTimeout(function(){u=null},g)),o4(this),W.start())}}function M($,...B){if(this.__zooming){var F=T(this,B).event($),V=$.changedTouches,W=V.length,q,Z,z,U;for(ry($),q=0;q<W;++q)Z=V[q],z=sl(Z,this),F.touch0&&F.touch0[2]===Z.identifier?F.touch0[0]=z:F.touch1&&F.touch1[2]===Z.identifier&&(F.touch1[0]=z);if(Z=F.that.__zoom,F.touch1){var Y=F.touch0[0],H=F.touch0[1],K=F.touch1[0],Q=F.touch1[1],ie=(ie=K[0]-Y[0])*ie+(ie=K[1]-Y[1])*ie,te=(te=Q[0]-H[0])*te+(te=Q[1]-H[1])*te;Z=C(Z,Math.sqrt(ie/te)),z=[(Y[0]+K[0])/2,(Y[1]+K[1])/2],U=[(H[0]+Q[0])/2,(H[1]+Q[1])/2]}else if(F.touch0)z=F.touch0[0],U=F.touch0[1];else return;F.zoom("touch",n(w(Z,z,U),F.extent,s))}}function N($,...B){if(this.__zooming){var F=T(this,B).event($),V=$.changedTouches,W=V.length,q,Z;for($A($),p&&clearTimeout(p),p=setTimeout(function(){p=null},g),q=0;q<W;++q)Z=V[q],F.touch0&&F.touch0[2]===Z.identifier?delete F.touch0:F.touch1&&F.touch1[2]===Z.identifier&&delete F.touch1;if(F.touch1&&!F.touch0&&(F.touch0=F.touch1,delete F.touch1),F.touch0)F.touch0[1]=this.__zoom.invert(F.touch0[0]);else if(F.end(),F.taps===2&&(Z=sl(Z,this),Math.hypot(d[0]-Z[0],d[1]-Z[1])<v)){var z=ea(this).on("dblclick.zoom");z&&z.apply(this,arguments)}}}return S.wheelDelta=function($){return arguments.length?(r=typeof $=="function"?$:Z5(+$),S):r},S.filter=function($){return arguments.length?(e=typeof $=="function"?$:Z5(!!$),S):e},S.touchable=function($){return arguments.length?(i=typeof $=="function"?$:Z5(!!$),S):i},S.extent=function($){return arguments.length?(t=typeof $=="function"?$:Z5([[+$[0][0],+$[0][1]],[+$[1][0],+$[1][1]]]),S):t},S.scaleExtent=function($){return arguments.length?(o[0]=+$[0],o[1]=+$[1],S):[o[0],o[1]]},S.translateExtent=function($){return arguments.length?(s[0][0]=+$[0][0],s[1][0]=+$[1][0],s[0][1]=+$[0][1],s[1][1]=+$[1][1],S):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},S.constrain=function($){return arguments.length?(n=$,S):n},S.duration=function($){return arguments.length?(a=+$,S):a},S.interpolate=function($){return arguments.length?(l=$,S):l},S.on=function(){var $=c.on.apply(c,arguments);return $===c?S:$},S.clickDistance=function($){return arguments.length?(b=($=+$)*$,S):Math.sqrt(b)},S.tapDistance=function($){return arguments.length?(v=+$,S):v},S}const Pc={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},w2=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ece=["Enter"," ","Escape"],tce={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Zg;(function(e){e.Strict="strict",e.Loose="loose"})(Zg||(Zg={}));var Kh;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Kh||(Kh={}));var C2;(function(e){e.Partial="partial",e.Full="full"})(C2||(C2={}));const nce={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Vd;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Vd||(Vd={}));var r6;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(r6||(r6={}));var Mt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(Mt||(Mt={}));const aY={[Mt.Left]:Mt.Right,[Mt.Right]:Mt.Left,[Mt.Top]:Mt.Bottom,[Mt.Bottom]:Mt.Top};function rce(e){return e===null?null:e?"valid":"invalid"}const ice=e=>"id"in e&&"source"in e&&"target"in e,dft=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),lI=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Ov=(e,t=[0,0])=>{const{width:n,height:r}=ed(e),i=e.origin??t,o=n*i[0],s=r*i[1];return{x:e.position.x-o,y:e.position.y-s}},fft=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,i)=>{const o=typeof i=="string";let s=!t.nodeLookup&&!o?i:void 0;t.nodeLookup&&(s=o?t.nodeLookup.get(i):lI(i)?i:t.nodeLookup.get(i.id));const a=s?i6(s,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return E8(r,a)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return A8(n)},Mv=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(i=>{(t.filter===void 0||t.filter(i))&&(n=E8(n,i6(i)),r=!0)}),r?A8(n):{x:0,y:0,width:0,height:0}},cI=(e,t,[n,r,i]=[0,0,1],o=!1,s=!1)=>{const a={...Rv(t,[n,r,i]),width:t.width/i,height:t.height/i},l=[];for(const c of e.values()){const{measured:u,selectable:d=!0,hidden:p=!1}=c;if(s&&!d||p)continue;const g=u.width??c.width??c.initialWidth??null,y=u.height??c.height??c.initialHeight??null,b=k2(a,Qg(c)),v=(g??0)*(y??0),S=o&&b>0;(!c.internals.handleBounds||S||b>=v||c.dragging)&&l.push(c)}return l},hft=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function pft(e,t){const n=new Map,r=t?.nodes?new Set(t.nodes.map(i=>i.id)):null;return e.forEach(i=>{i.measured.width&&i.measured.height&&(t?.includeHiddenNodes||!i.hidden)&&(!r||r.has(i.id))&&n.set(i.id,i)}),n}async function mft({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:o},s){if(e.size===0)return Promise.resolve(!0);const a=pft(e,s),l=Mv(a),c=uI(l,t,n,s?.minZoom??i,s?.maxZoom??o,s?.padding??.1);return await r.setViewport(c,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)}function oce({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const s=n.get(e),a=s.parentId?n.get(s.parentId):void 0,{x:l,y:c}=a?a.internals.positionAbsolute:{x:0,y:0},u=s.origin??r;let d=s.extent||i;if(s.extent==="parent"&&!s.expandParent)if(!a)o?.("005",Pc.error005());else{const g=a.measured.width,y=a.measured.height;g&&y&&(d=[[l,c],[l+g,c+y]])}else a&&e0(s.extent)&&(d=[[s.extent[0][0]+l,s.extent[0][1]+c],[s.extent[1][0]+l,s.extent[1][1]+c]]);const p=e0(d)?hp(t,d,s.measured):t;return(s.measured.width===void 0||s.measured.height===void 0)&&o?.("015",Pc.error015()),{position:{x:p.x-l+(s.measured.width??0)*u[0],y:p.y-c+(s.measured.height??0)*u[1]},positionAbsolute:p}}async function gft({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){const o=new Set(e.map(p=>p.id)),s=[];for(const p of n){if(p.deletable===!1)continue;const g=o.has(p.id),y=!g&&p.parentId&&s.find(b=>b.id===p.parentId);(g||y)&&s.push(p)}const a=new Set(t.map(p=>p.id)),l=r.filter(p=>p.deletable!==!1),u=hft(s,l);for(const p of l)a.has(p.id)&&!u.find(y=>y.id===p.id)&&u.push(p);if(!i)return{edges:u,nodes:s};const d=await i({nodes:s,edges:u});return typeof d=="boolean"?d?{edges:u,nodes:s}:{edges:[],nodes:[]}:d}const Xg=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),hp=(e={x:0,y:0},t,n)=>({x:Xg(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Xg(e.y,t[0][1],t[1][1]-(n?.height??0))});function sce(e,t,n){const{width:r,height:i}=ed(n),{x:o,y:s}=n.internals.positionAbsolute;return hp(e,[[o,s],[o+r,s+i]],t)}const lY=(e,t,n)=>e<t?Xg(Math.abs(e-t),1,t)/t:e>n?-Xg(Math.abs(e-n),1,t)/t:0,ace=(e,t,n=15,r=40)=>{const i=lY(e.x,r,t.width-r)*n,o=lY(e.y,r,t.height-r)*n;return[i,o]},E8=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),VT=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),A8=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Qg=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:Ov(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},i6=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:Ov(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},lce=(e,t)=>A8(E8(VT(e),VT(t))),k2=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},cY=e=>hl(e.width)&&hl(e.height)&&hl(e.x)&&hl(e.y),hl=e=>!isNaN(e)&&isFinite(e),yft=(e,t)=>{},jv=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Rv=({x:e,y:t},[n,r,i],o=!1,s=[1,1])=>{const a={x:(e-n)/i,y:(t-r)/i};return o?jv(a,s):a},o6=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function Em(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function bft(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=Em(e,n),i=Em(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=Em(e.top??e.y??0,n),i=Em(e.bottom??e.y??0,n),o=Em(e.left??e.x??0,t),s=Em(e.right??e.x??0,t);return{top:r,right:s,bottom:i,left:o,x:o+s,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function vft(e,t,n,r,i,o){const{x:s,y:a}=o6(e,[t,n,r]),{x:l,y:c}=o6({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-l,d=o-c;return{left:Math.floor(s),top:Math.floor(a),right:Math.floor(u),bottom:Math.floor(d)}}const uI=(e,t,n,r,i,o)=>{const s=bft(o,t,n),a=(t-s.x)/e.width,l=(n-s.y)/e.height,c=Math.min(a,l),u=Xg(c,r,i),d=e.x+e.width/2,p=e.y+e.height/2,g=t/2-d*u,y=n/2-p*u,b=vft(e,g,y,u,t,n),v={left:Math.min(b.left-s.left,0),top:Math.min(b.top-s.top,0),right:Math.min(b.right-s.right,0),bottom:Math.min(b.bottom-s.bottom,0)};return{x:g-v.left+v.right,y:y-v.top+v.bottom,zoom:u}},E2=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function e0(e){return e!=null&&e!=="parent"}function ed(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function cce(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function uce(e,t={width:0,height:0},n,r,i){const o={...e},s=r.get(n);if(s){const a=s.origin||i;o.x+=s.internals.positionAbsolute.x-(t.width??0)*a[0],o.y+=s.internals.positionAbsolute.y-(t.height??0)*a[1]}return o}function uY(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function xft(){let e,t;return{promise:new Promise((r,i)=>{e=r,t=i}),resolve:e,reject:t}}function Sft(e){return{...tce,...e||{}}}function ob(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){const{x:o,y:s}=pl(e),a=Rv({x:o-(i?.left??0),y:s-(i?.top??0)},r),{x:l,y:c}=n?jv(a,t):a;return{xSnapped:l,ySnapped:c,...a}}const dI=e=>({width:e.offsetWidth,height:e.offsetHeight}),dce=e=>e?.getRootNode?.()||window?.document,wft=["INPUT","SELECT","TEXTAREA"];function fce(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:wft.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const hce=e=>"clientX"in e,pl=(e,t)=>{const n=hce(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},dY=(e,t,n,r,i)=>{const o=t.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(s=>{const a=s.getBoundingClientRect();return{id:s.getAttribute("data-handleid"),type:e,nodeId:i,position:s.getAttribute("data-handlepos"),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...dI(s)}})};function pce({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:s,targetControlY:a}){const l=e*.125+i*.375+s*.375+n*.125,c=t*.125+o*.375+a*.375+r*.125,u=Math.abs(l-e),d=Math.abs(c-t);return[l,c,u,d]}function X5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function fY({pos:e,x1:t,y1:n,x2:r,y2:i,c:o}){switch(e){case Mt.Left:return[t-X5(t-r,o),n];case Mt.Right:return[t+X5(r-t,o),n];case Mt.Top:return[t,n-X5(n-i,o)];case Mt.Bottom:return[t,n+X5(i-n,o)]}}function mce({sourceX:e,sourceY:t,sourcePosition:n=Mt.Bottom,targetX:r,targetY:i,targetPosition:o=Mt.Top,curvature:s=.25}){const[a,l]=fY({pos:n,x1:e,y1:t,x2:r,y2:i,c:s}),[c,u]=fY({pos:o,x1:r,y1:i,x2:e,y2:t,c:s}),[d,p,g,y]=pce({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:u});return[`M${e},${t} C${a},${l} ${c},${u} ${r},${i}`,d,p,g,y]}function gce({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e)/2,o=n<e?n+i:n-i,s=Math.abs(r-t)/2,a=r<t?r+s:r-s;return[o,a,i,s]}function Cft({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const s=i&&n?r+1e3:r,a=Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0);return s+a}function kft({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){const o=E8(i6(e),i6(t));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const s={x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]};return k2(s,A8(o))>0}const Eft=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,Aft=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Dft=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||Eft;let i;return ice(e)?i={...e}:i={...e,id:r(e)},Aft(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function yce({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[i,o,s,a]=gce({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,o,s,a]}const hY={[Mt.Left]:{x:-1,y:0},[Mt.Right]:{x:1,y:0},[Mt.Top]:{x:0,y:-1},[Mt.Bottom]:{x:0,y:1}},_ft=({source:e,sourcePosition:t=Mt.Bottom,target:n})=>t===Mt.Left||t===Mt.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},pY=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Tft({source:e,sourcePosition:t=Mt.Bottom,target:n,targetPosition:r=Mt.Top,center:i,offset:o,stepPosition:s}){const a=hY[t],l=hY[r],c={x:e.x+a.x*o,y:e.y+a.y*o},u={x:n.x+l.x*o,y:n.y+l.y*o},d=_ft({source:c,sourcePosition:t,target:u}),p=d.x!==0?"x":"y",g=d[p];let y=[],b,v;const S={x:0,y:0},C={x:0,y:0},[,,w,E]=gce({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[p]*l[p]===-1){p==="x"?(b=i.x??c.x+(u.x-c.x)*s,v=i.y??(c.y+u.y)/2):(b=i.x??(c.x+u.x)/2,v=i.y??c.y+(u.y-c.y)*s);const T=[{x:b,y:c.y},{x:b,y:u.y}],_=[{x:c.x,y:v},{x:u.x,y:v}];a[p]===g?y=p==="x"?T:_:y=p==="x"?_:T}else{const T=[{x:c.x,y:u.y}],_=[{x:u.x,y:c.y}];if(p==="x"?y=a.x===g?_:T:y=a.y===g?T:_,t===r){const M=Math.abs(e[p]-n[p]);if(M<=o){const N=Math.min(o-1,o-M);a[p]===g?S[p]=(c[p]>e[p]?-1:1)*N:C[p]=(u[p]>n[p]?-1:1)*N}}if(t!==r){const M=p==="x"?"y":"x",N=a[p]===l[M],$=c[M]>u[M],B=c[M]<u[M];(a[p]===1&&(!N&&$||N&&B)||a[p]!==1&&(!N&&B||N&&$))&&(y=p==="x"?T:_)}const O={x:c.x+S.x,y:c.y+S.y},R={x:u.x+C.x,y:u.y+C.y},P=Math.max(Math.abs(O.x-y[0].x),Math.abs(R.x-y[0].x)),L=Math.max(Math.abs(O.y-y[0].y),Math.abs(R.y-y[0].y));P>=L?(b=(O.x+R.x)/2,v=y[0].y):(b=y[0].x,v=(O.y+R.y)/2)}return[[e,{x:c.x+S.x,y:c.y+S.y},...y,{x:u.x+C.x,y:u.y+C.y},n],b,v,w,E]}function Oft(e,t,n,r){const i=Math.min(pY(e,t)/2,pY(t,n)/2,r),{x:o,y:s}=t;if(e.x===o&&o===n.x||e.y===s&&s===n.y)return`L${o} ${s}`;if(e.y===s){const c=e.x<n.x?-1:1,u=e.y<n.y?1:-1;return`L ${o+i*c},${s}Q ${o},${s} ${o},${s+i*u}`}const a=e.x<n.x?1:-1,l=e.y<n.y?-1:1;return`L ${o},${s+i*l}Q ${o},${s} ${o+i*a},${s}`}function WT({sourceX:e,sourceY:t,sourcePosition:n=Mt.Bottom,targetX:r,targetY:i,targetPosition:o=Mt.Top,borderRadius:s=5,centerX:a,centerY:l,offset:c=20,stepPosition:u=.5}){const[d,p,g,y,b]=Tft({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:o,center:{x:a,y:l},offset:c,stepPosition:u});return[d.reduce((S,C,w)=>{let E="";return w>0&&w<d.length-1?E=Oft(d[w-1],C,d[w+1],s):E=`${w===0?"M":"L"}${C.x} ${C.y}`,S+=E,S},""),p,g,y,b]}function mY(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Mft(e){const{sourceNode:t,targetNode:n}=e;if(!mY(t)||!mY(n))return null;const r=t.internals.handleBounds||gY(t.handles),i=n.internals.handleBounds||gY(n.handles),o=yY(r?.source??[],e.sourceHandle),s=yY(e.connectionMode===Zg.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!s)return e.onError?.("008",Pc.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const a=o?.position||Mt.Bottom,l=s?.position||Mt.Top,c=pp(t,o,a),u=pp(n,s,l);return{sourceX:c.x,sourceY:c.y,targetX:u.x,targetY:u.y,sourcePosition:a,targetPosition:l}}function gY(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function pp(e,t,n=Mt.Left,r=!1){const i=(t?.x??0)+e.internals.positionAbsolute.x,o=(t?.y??0)+e.internals.positionAbsolute.y,{width:s,height:a}=t??ed(e);if(r)return{x:i+s/2,y:o+a/2};switch(t?.position??n){case Mt.Top:return{x:i+s/2,y:o};case Mt.Right:return{x:i+s,y:o+a/2};case Mt.Bottom:return{x:i+s/2,y:o+a};case Mt.Left:return{x:i,y:o+a/2}}}function yY(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function qT(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function jft(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((s,a)=>([a.markerStart||r,a.markerEnd||i].forEach(l=>{if(l&&typeof l=="object"){const c=qT(l,t);o.has(c)||(s.push({id:c,color:l.color||n,...l}),o.add(c))}}),s),[]).sort((s,a)=>s.id.localeCompare(a.id))}const bce=1e3,Rft=10,fI={nodeOrigin:[0,0],nodeExtent:w2,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Ift={...fI,checkEquality:!0};function hI(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function Pft(e,t,n){const r=hI(fI,n);for(const i of e.values())if(i.parentId)mI(i,e,t,r);else{const o=Ov(i,r.nodeOrigin),s=e0(i.extent)?i.extent:r.nodeExtent,a=hp(o,s,ed(i));i.internals.positionAbsolute=a}}function Nft(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],r=[];for(const i of e.handles){const o={id:i.id,width:i.width??1,height:i.height??1,nodeId:e.id,x:i.x,y:i.y,position:i.position,type:i.type};i.type==="source"?n.push(o):i.type==="target"&&r.push(o)}return{source:n,target:r}}function pI(e){return e==="manual"}function KT(e,t,n,r={}){const i=hI(Ift,r),o={i:0},s=new Map(t),a=i?.elevateNodesOnSelect&&!pI(i.zIndexMode)?bce:0;let l=e.length>0;t.clear(),n.clear();for(const c of e){let u=s.get(c.id);if(i.checkEquality&&c===u?.internals.userNode)t.set(c.id,u);else{const d=Ov(c,i.nodeOrigin),p=e0(c.extent)?c.extent:i.nodeExtent,g=hp(d,p,ed(c));u={...i.defaults,...c,measured:{width:c.measured?.width,height:c.measured?.height},internals:{positionAbsolute:g,handleBounds:Nft(c,u),z:vce(c,a,i.zIndexMode),userNode:c}},t.set(c.id,u)}(u.measured===void 0||u.measured.width===void 0||u.measured.height===void 0)&&!u.hidden&&(l=!1),c.parentId&&mI(u,t,n,r,o)}return l}function $ft(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function mI(e,t,n,r,i){const{elevateNodesOnSelect:o,nodeOrigin:s,nodeExtent:a,zIndexMode:l}=hI(fI,r),c=e.parentId,u=t.get(c);if(!u){console.warn(`Parent node ${c} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}$ft(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&l==="auto"&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*Rft),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);const d=o&&!pI(l)?bce:0,{x:p,y:g,z:y}=Lft(e,u,s,a,d,l),{positionAbsolute:b}=e.internals,v=p!==b.x||g!==b.y;(v||y!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:v?{x:p,y:g}:b,z:y}})}function vce(e,t,n){const r=hl(e.zIndex)?e.zIndex:0;return pI(n)?r:r+(e.selected?t:0)}function Lft(e,t,n,r,i,o){const{x:s,y:a}=t.internals.positionAbsolute,l=ed(e),c=Ov(e,n),u=e0(e.extent)?hp(c,e.extent,l):c;let d=hp({x:s+u.x,y:a+u.y},r,l);e.extent==="parent"&&(d=sce(d,l,t));const p=vce(e,i,o),g=t.internals.z??0;return{x:d.x,y:d.y,z:g>=p?g+1:p}}function gI(e,t,n,r=[0,0]){const i=[],o=new Map;for(const s of e){const a=t.get(s.parentId);if(!a)continue;const l=o.get(s.parentId)?.expandedRect??Qg(a),c=lce(l,s.rect);o.set(s.parentId,{expandedRect:c,parent:a})}return o.size>0&&o.forEach(({expandedRect:s,parent:a},l)=>{const c=a.internals.positionAbsolute,u=ed(a),d=a.origin??r,p=s.x<c.x?Math.round(Math.abs(c.x-s.x)):0,g=s.y<c.y?Math.round(Math.abs(c.y-s.y)):0,y=Math.max(u.width,Math.round(s.width)),b=Math.max(u.height,Math.round(s.height)),v=(y-u.width)*d[0],S=(b-u.height)*d[1];(p>0||g>0||v||S)&&(i.push({id:l,type:"position",position:{x:a.position.x-p+v,y:a.position.y-g+S}}),n.get(l)?.forEach(C=>{e.some(w=>w.id===C.id)||i.push({id:C.id,type:"position",position:{x:C.position.x+p,y:C.position.y+g}})})),(u.width<s.width||u.height<s.height||p||g)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:y+(p?d[0]*p-v:0),height:b+(g?d[1]*g-S:0)}})}),i}function Fft(e,t,n,r,i,o,s){const a=r?.querySelector(".xyflow__viewport");let l=!1;if(!a)return{changes:[],updatedInternals:l};const c=[],u=window.getComputedStyle(a),{m22:d}=new window.DOMMatrixReadOnly(u.transform),p=[];for(const g of e.values()){const y=t.get(g.id);if(!y)continue;if(y.hidden){t.set(y.id,{...y,internals:{...y.internals,handleBounds:void 0}}),l=!0;continue}const b=dI(g.nodeElement),v=y.measured.width!==b.width||y.measured.height!==b.height;if(!!(b.width&&b.height&&(v||!y.internals.handleBounds||g.force))){const C=g.nodeElement.getBoundingClientRect(),w=e0(y.extent)?y.extent:o;let{positionAbsolute:E}=y.internals;y.parentId&&y.extent==="parent"?E=sce(E,b,t.get(y.parentId)):w&&(E=hp(E,w,b));const k={...y,measured:b,internals:{...y.internals,positionAbsolute:E,handleBounds:{source:dY("source",g.nodeElement,C,d,y.id),target:dY("target",g.nodeElement,C,d,y.id)}}};t.set(y.id,k),y.parentId&&mI(k,t,n,{nodeOrigin:i,zIndexMode:s}),l=!0,v&&(c.push({id:y.id,type:"dimensions",dimensions:b}),y.expandParent&&y.parentId&&p.push({id:y.id,parentId:y.parentId,rect:Qg(k,i)}))}}if(p.length>0){const g=gI(p,t,n,i);c.push(...g)}return{changes:c,updatedInternals:l}}async function zft({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:o}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const s=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,o]],r),a=!!s&&(s.x!==n[0]||s.y!==n[1]||s.k!==n[2]);return Promise.resolve(a)}function bY(e,t,n,r,i,o){let s=i;const a=r.get(s)||new Map;r.set(s,a.set(n,t)),s=`${i}-${e}`;const l=r.get(s)||new Map;if(r.set(s,l.set(n,t)),o){s=`${i}-${e}-${o}`;const c=r.get(s)||new Map;r.set(s,c.set(n,t))}}function xce(e,t,n){e.clear(),t.clear();for(const r of n){const{source:i,target:o,sourceHandle:s=null,targetHandle:a=null}=r,l={edgeId:r.id,source:i,target:o,sourceHandle:s,targetHandle:a},c=`${i}-${s}--${o}-${a}`,u=`${o}-${a}--${i}-${s}`;bY("source",l,u,e,i,s),bY("target",l,c,e,o,a),t.set(r.id,r)}}function Sce(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Sce(n,t):!1}function vY(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function Bft(e,t,n,r){const i=new Map;for(const[o,s]of e)if((s.selected||s.id===r)&&(!s.parentId||!Sce(s,e))&&(s.draggable||t&&typeof s.draggable>"u")){const a=e.get(o);a&&i.set(o,{id:o,position:a.position||{x:0,y:0},distance:{x:n.x-a.internals.positionAbsolute.x,y:n.y-a.internals.positionAbsolute.y},extent:a.extent,parentId:a.parentId,origin:a.origin,expandParent:a.expandParent,internals:{positionAbsolute:a.internals.positionAbsolute||{x:0,y:0}},measured:{width:a.measured.width??0,height:a.measured.height??0}})}return i}function LA({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){const i=[];for(const[s,a]of t){const l=n.get(s)?.internals.userNode;l&&i.push({...l,position:a.position,dragging:r})}if(!e)return[i[0],i];const o=n.get(e)?.internals.userNode;return[o?{...o,position:t.get(e)?.position||o.position,dragging:r}:i[0],i]}function Hft({dragItems:e,snapGrid:t,x:n,y:r}){const i=e.values().next().value;if(!i)return null;const o={x:n-i.distance.x,y:r-i.distance.y},s=jv(o,t);return{x:s.x-o.x,y:s.y-o.y}}function Uft({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let o={x:null,y:null},s=0,a=new Map,l=!1,c={x:0,y:0},u=null,d=!1,p=null,g=!1,y=!1,b=null;function v({noDragClassName:C,handleSelector:w,domNode:E,isSelectable:k,nodeId:T,nodeClickDistance:_=0}){p=ea(E);function O({x:M,y:N}){const{nodeLookup:$,nodeExtent:B,snapGrid:F,snapToGrid:V,nodeOrigin:W,onNodeDrag:q,onSelectionDrag:Z,onError:z,updateNodePositions:U}=t();o={x:M,y:N};let Y=!1;const H=a.size>1,K=H&&B?VT(Mv(a)):null,Q=H&&V?Hft({dragItems:a,snapGrid:F,x:M,y:N}):null;for(const[ie,te]of a){if(!$.has(ie))continue;let ce={x:M-te.distance.x,y:N-te.distance.y};V&&(ce=Q?{x:Math.round(ce.x+Q.x),y:Math.round(ce.y+Q.y)}:jv(ce,F));let ee=null;if(H&&B&&!te.extent&&K){const{positionAbsolute:oe}=te.internals,le=oe.x-K.x+B[0][0],fe=oe.x+te.measured.width-K.x2+B[1][0],ye=oe.y-K.y+B[0][1],Me=oe.y+te.measured.height-K.y2+B[1][1];ee=[[le,ye],[fe,Me]]}const{position:J,positionAbsolute:X}=oce({nodeId:ie,nextPosition:ce,nodeLookup:$,nodeExtent:ee||B,nodeOrigin:W,onError:z});Y=Y||te.position.x!==J.x||te.position.y!==J.y,te.position=J,te.internals.positionAbsolute=X}if(y=y||Y,!!Y&&(U(a,!0),b&&(r||q||!T&&Z))){const[ie,te]=LA({nodeId:T,dragItems:a,nodeLookup:$});r?.(b,a,ie,te),q?.(b,ie,te),T||Z?.(b,te)}}async function R(){if(!u)return;const{transform:M,panBy:N,autoPanSpeed:$,autoPanOnNodeDrag:B}=t();if(!B){l=!1,cancelAnimationFrame(s);return}const[F,V]=ace(c,u,$);(F!==0||V!==0)&&(o.x=(o.x??0)-F/M[2],o.y=(o.y??0)-V/M[2],await N({x:F,y:V})&&O(o)),s=requestAnimationFrame(R)}function P(M){const{nodeLookup:N,multiSelectionActive:$,nodesDraggable:B,transform:F,snapGrid:V,snapToGrid:W,selectNodesOnDrag:q,onNodeDragStart:Z,onSelectionDragStart:z,unselectNodesAndEdges:U}=t();d=!0,(!q||!k)&&!$&&T&&(N.get(T)?.selected||U()),k&&q&&T&&e?.(T);const Y=ob(M.sourceEvent,{transform:F,snapGrid:V,snapToGrid:W,containerBounds:u});if(o=Y,a=Bft(N,B,Y,T),a.size>0&&(n||Z||!T&&z)){const[H,K]=LA({nodeId:T,dragItems:a,nodeLookup:N});n?.(M.sourceEvent,a,H,K),Z?.(M.sourceEvent,H,K),T||z?.(M.sourceEvent,K)}}const L=Lle().clickDistance(_).on("start",M=>{const{domNode:N,nodeDragThreshold:$,transform:B,snapGrid:F,snapToGrid:V}=t();u=N?.getBoundingClientRect()||null,g=!1,y=!1,b=M.sourceEvent,$===0&&P(M),o=ob(M.sourceEvent,{transform:B,snapGrid:F,snapToGrid:V,containerBounds:u}),c=pl(M.sourceEvent,u)}).on("drag",M=>{const{autoPanOnNodeDrag:N,transform:$,snapGrid:B,snapToGrid:F,nodeDragThreshold:V,nodeLookup:W}=t(),q=ob(M.sourceEvent,{transform:$,snapGrid:B,snapToGrid:F,containerBounds:u});if(b=M.sourceEvent,(M.sourceEvent.type==="touchmove"&&M.sourceEvent.touches.length>1||T&&!W.has(T))&&(g=!0),!g){if(!l&&N&&d&&(l=!0,R()),!d){const Z=pl(M.sourceEvent,u),z=Z.x-c.x,U=Z.y-c.y;Math.sqrt(z*z+U*U)>V&&P(M)}(o.x!==q.xSnapped||o.y!==q.ySnapped)&&a&&d&&(c=pl(M.sourceEvent,u),O(q))}}).on("end",M=>{if(!(!d||g)&&(l=!1,d=!1,cancelAnimationFrame(s),a.size>0)){const{nodeLookup:N,updateNodePositions:$,onNodeDragStop:B,onSelectionDragStop:F}=t();if(y&&($(a,!1),y=!1),i||B||!T&&F){const[V,W]=LA({nodeId:T,dragItems:a,nodeLookup:N,dragging:!1});i?.(M.sourceEvent,a,V,W),B?.(M.sourceEvent,V,W),T||F?.(M.sourceEvent,W)}}}).filter(M=>{const N=M.target;return!M.button&&(!C||!vY(N,`.${C}`,E))&&(!w||vY(N,w,E))});p.call(L)}function S(){p?.on(".drag",null)}return{update:v,destroy:S}}function Vft(e,t,n){const r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const o of t.values())k2(i,Qg(o))>0&&r.push(o);return r}const Wft=250;function qft(e,t,n,r){let i=[],o=1/0;const s=Vft(e,n,t+Wft);for(const a of s){const l=[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]];for(const c of l){if(r.nodeId===c.nodeId&&r.type===c.type&&r.id===c.id)continue;const{x:u,y:d}=pp(a,c,c.position,!0),p=Math.sqrt(Math.pow(u-e.x,2)+Math.pow(d-e.y,2));p>t||(p<o?(i=[{...c,x:u,y:d}],o=p):p===o&&i.push({...c,x:u,y:d}))}}if(!i.length)return null;if(i.length>1){const a=r.type==="source"?"target":"source";return i.find(l=>l.type===a)??i[0]}return i[0]}function wce(e,t,n,r,i,o=!1){const s=r.get(e);if(!s)return null;const a=i==="strict"?s.internals.handleBounds?.[t]:[...s.internals.handleBounds?.source??[],...s.internals.handleBounds?.target??[]],l=(n?a?.find(c=>c.id===n):a?.[0])??null;return l&&o?{...l,...pp(s,l,l.position,!0)}:l}function Cce(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Kft(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const kce=()=>!0;function Gft(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:s,domNode:a,nodeLookup:l,lib:c,autoPanOnConnect:u,flowId:d,panBy:p,cancelConnection:g,onConnectStart:y,onConnect:b,onConnectEnd:v,isValidConnection:S=kce,onReconnectEnd:C,updateConnection:w,getTransform:E,getFromHandle:k,autoPanSpeed:T,dragThreshold:_=1,handleDomNode:O}){const R=dce(e.target);let P=0,L;const{x:M,y:N}=pl(e),$=Cce(o,O),B=a?.getBoundingClientRect();let F=!1;if(!B||!$)return;const V=wce(i,$,r,l,t);if(!V)return;let W=pl(e,B),q=!1,Z=null,z=!1,U=null;function Y(){if(!u||!B)return;const[J,X]=ace(W,B,T);p({x:J,y:X}),P=requestAnimationFrame(Y)}const H={...V,nodeId:i,type:$,position:V.position},K=l.get(i);let ie={inProgress:!0,isValid:null,from:pp(K,H,Mt.Left,!0),fromHandle:H,fromPosition:H.position,fromNode:K,to:W,toHandle:null,toPosition:aY[H.position],toNode:null,pointer:W};function te(){F=!0,w(ie),y?.(e,{nodeId:i,handleId:r,handleType:$})}_===0&&te();function ce(J){if(!F){const{x:Me,y:ue}=pl(J),we=Me-M,Oe=ue-N;if(!(we*we+Oe*Oe>_*_))return;te()}if(!k()||!H){ee(J);return}const X=E();W=pl(J,B),L=qft(Rv(W,X,!1,[1,1]),n,l,H),q||(Y(),q=!0);const oe=Ece(J,{handle:L,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:s?"target":"source",isValidConnection:S,doc:R,lib:c,flowId:d,nodeLookup:l});U=oe.handleDomNode,Z=oe.connection,z=Kft(!!L,oe.isValid);const le=l.get(i),fe=le?pp(le,H,Mt.Left,!0):ie.from,ye={...ie,from:fe,isValid:z,to:oe.toHandle&&z?o6({x:oe.toHandle.x,y:oe.toHandle.y},X):W,toHandle:oe.toHandle,toPosition:z&&oe.toHandle?oe.toHandle.position:aY[H.position],toNode:oe.toHandle?l.get(oe.toHandle.nodeId):null,pointer:W};w(ye),ie=ye}function ee(J){if(!("touches"in J&&J.touches.length>0)){if(F){(L||U)&&Z&&z&&b?.(Z);const{inProgress:X,...oe}=ie,le={...oe,toPosition:ie.toHandle?ie.toPosition:null};v?.(J,le),o&&C?.(J,le)}g(),cancelAnimationFrame(P),q=!1,z=!1,Z=null,U=null,R.removeEventListener("mousemove",ce),R.removeEventListener("mouseup",ee),R.removeEventListener("touchmove",ce),R.removeEventListener("touchend",ee)}}R.addEventListener("mousemove",ce),R.addEventListener("mouseup",ee),R.addEventListener("touchmove",ce),R.addEventListener("touchend",ee)}function Ece(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:o,doc:s,lib:a,flowId:l,isValidConnection:c=kce,nodeLookup:u}){const d=o==="target",p=t?s.querySelector(`.${a}-flow__handle[data-id="${l}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y}=pl(e),b=s.elementFromPoint(g,y),v=b?.classList.contains(`${a}-flow__handle`)?b:p,S={handleDomNode:v,isValid:!1,connection:null,toHandle:null};if(v){const C=Cce(void 0,v),w=v.getAttribute("data-nodeid"),E=v.getAttribute("data-handleid"),k=v.classList.contains("connectable"),T=v.classList.contains("connectableend");if(!w||!C)return S;const _={source:d?w:r,sourceHandle:d?E:i,target:d?r:w,targetHandle:d?i:E};S.connection=_;const R=k&&T&&(n===Zg.Strict?d&&C==="source"||!d&&C==="target":w!==r||E!==i);S.isValid=R&&c(_),S.toHandle=wce(w,C,E,u,n,!0)}return S}const GT={onPointerDown:Gft,isValid:Ece};function Yft({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const i=ea(e);function o({translateExtent:a,width:l,height:c,zoomStep:u=1,pannable:d=!0,zoomable:p=!0,inversePan:g=!1}){const y=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const E=n(),k=w.sourceEvent.ctrlKey&&E2()?10:1,T=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*u,_=E[2]*Math.pow(2,T*k);t.scaleTo(_)};let b=[0,0];const v=w=>{(w.sourceEvent.type==="mousedown"||w.sourceEvent.type==="touchstart")&&(b=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY])},S=w=>{const E=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const k=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],T=[k[0]-b[0],k[1]-b[1]];b=k;const _=r()*Math.max(E[2],Math.log(E[2]))*(g?-1:1),O={x:E[0]-T[0]*_,y:E[1]-T[1]*_},R=[[0,0],[l,c]];t.setViewportConstrained({x:O.x,y:O.y,zoom:E[2]},R,a)},C=Qle().on("start",v).on("zoom",d?S:null).on("zoom.wheel",p?y:null);i.call(C,{})}function s(){i.on("zoom",null)}return{update:o,destroy:s,pointer:sl}}const D8=e=>({x:e.x,y:e.y,zoom:e.k}),FA=({x:e,y:t,zoom:n})=>k8.translate(e,t).scale(n),Xm=(e,t)=>e.target.closest(`.${t}`),Ace=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Jft=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,zA=(e,t=0,n=Jft,r=()=>{})=>{const i=typeof t=="number"&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on("end",r):e},Dce=e=>{const t=e.ctrlKey&&E2()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Zft({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:s,onPanZoomStart:a,onPanZoom:l,onPanZoomEnd:c}){return u=>{if(Xm(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();const d=n.property("__zoom").k||1;if(u.ctrlKey&&s){const v=sl(u),S=Dce(u),C=d*Math.pow(2,S);r.scaleTo(n,C,v,u);return}const p=u.deltaMode===1?20:1;let g=i===Kh.Vertical?0:u.deltaX*p,y=i===Kh.Horizontal?0:u.deltaY*p;!E2()&&u.shiftKey&&i!==Kh.Vertical&&(g=u.deltaY*p,y=0),r.translateBy(n,-(g/d)*o,-(y/d)*o,{internal:!0});const b=D8(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(l?.(u,b),e.panScrollTimeout=setTimeout(()=>{c?.(u,b),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,a?.(u,b))}}function Xft({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){const o=r.type==="wheel",s=!t&&o&&!r.ctrlKey,a=Xm(r,e);if(r.ctrlKey&&o&&a&&r.preventDefault(),s||a)return null;r.preventDefault(),n.call(this,r,i)}}function Qft({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const i=D8(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(r.sourceEvent,i)}}function eht({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(n&&Ace(t,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,D8(o.transform))}}function tht({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return s=>{if(!s.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&Ace(t,e.mouseButton??0)&&!e.usedRightMouseButton&&s.sourceEvent&&o(s.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const a=D8(s.transform);e.prevViewport=a,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(s.sourceEvent,a)},n?150:0)}}}function nht({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:s,noWheelClassName:a,noPanClassName:l,lib:c,connectionInProgress:u}){return d=>{const p=e||t,g=n&&d.ctrlKey,y=d.type==="wheel";if(d.button===1&&d.type==="mousedown"&&(Xm(d,`${c}-flow__node`)||Xm(d,`${c}-flow__edge`)))return!0;if(!r&&!p&&!i&&!o&&!n||s||u&&!y||Xm(d,a)&&y||Xm(d,l)&&(!y||i&&y&&!e)||!n&&d.ctrlKey&&y)return!1;if(!n&&d.type==="touchstart"&&d.touches?.length>1)return d.preventDefault(),!1;if(!p&&!i&&!g&&y||!r&&(d.type==="mousedown"||d.type==="touchstart")||Array.isArray(r)&&!r.includes(d.button)&&d.type==="mousedown")return!1;const b=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||y)&&b}}function rht({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:s,onPanZoomEnd:a,onDraggingChange:l}){const c={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=Qle().scaleExtent([t,n]).translateExtent(r),p=ea(e).call(d);C({x:i.x,y:i.y,zoom:Xg(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);const g=p.on("wheel.zoom"),y=p.on("dblclick.zoom");d.wheelDelta(Dce);function b(L,M){return p?new Promise(N=>{d?.interpolate(M?.interpolate==="linear"?ib:n4).transform(zA(p,M?.duration,M?.ease,()=>N(!0)),L)}):Promise.resolve(!1)}function v({noWheelClassName:L,noPanClassName:M,onPaneContextMenu:N,userSelectionActive:$,panOnScroll:B,panOnDrag:F,panOnScrollMode:V,panOnScrollSpeed:W,preventScrolling:q,zoomOnPinch:Z,zoomOnScroll:z,zoomOnDoubleClick:U,zoomActivationKeyPressed:Y,lib:H,onTransformChange:K,connectionInProgress:Q,paneClickDistance:ie,selectionOnDrag:te}){$&&!c.isZoomingOrPanning&&S();const ce=B&&!Y&&!$;d.clickDistance(te?1/0:!hl(ie)||ie<0?0:ie);const ee=ce?Zft({zoomPanValues:c,noWheelClassName:L,d3Selection:p,d3Zoom:d,panOnScrollMode:V,panOnScrollSpeed:W,zoomOnPinch:Z,onPanZoomStart:s,onPanZoom:o,onPanZoomEnd:a}):Xft({noWheelClassName:L,preventScrolling:q,d3ZoomHandler:g});if(p.on("wheel.zoom",ee,{passive:!1}),!$){const X=Qft({zoomPanValues:c,onDraggingChange:l,onPanZoomStart:s});d.on("start",X);const oe=eht({zoomPanValues:c,panOnDrag:F,onPaneContextMenu:!!N,onPanZoom:o,onTransformChange:K});d.on("zoom",oe);const le=tht({zoomPanValues:c,panOnDrag:F,panOnScroll:B,onPaneContextMenu:N,onPanZoomEnd:a,onDraggingChange:l});d.on("end",le)}const J=nht({zoomActivationKeyPressed:Y,panOnDrag:F,zoomOnScroll:z,panOnScroll:B,zoomOnDoubleClick:U,zoomOnPinch:Z,userSelectionActive:$,noPanClassName:M,noWheelClassName:L,lib:H,connectionInProgress:Q});d.filter(J),U?p.on("dblclick.zoom",y):p.on("dblclick.zoom",null)}function S(){d.on("zoom",null)}async function C(L,M,N){const $=FA(L),B=d?.constrain()($,M,N);return B&&await b(B),new Promise(F=>F(B))}async function w(L,M){const N=FA(L);return await b(N,M),new Promise($=>$(N))}function E(L){if(p){const M=FA(L),N=p.property("__zoom");(N.k!==L.zoom||N.x!==L.x||N.y!==L.y)&&d?.transform(p,M,null,{sync:!0})}}function k(){const L=p?Xle(p.node()):{x:0,y:0,k:1};return{x:L.x,y:L.y,zoom:L.k}}function T(L,M){return p?new Promise(N=>{d?.interpolate(M?.interpolate==="linear"?ib:n4).scaleTo(zA(p,M?.duration,M?.ease,()=>N(!0)),L)}):Promise.resolve(!1)}function _(L,M){return p?new Promise(N=>{d?.interpolate(M?.interpolate==="linear"?ib:n4).scaleBy(zA(p,M?.duration,M?.ease,()=>N(!0)),L)}):Promise.resolve(!1)}function O(L){d?.scaleExtent(L)}function R(L){d?.translateExtent(L)}function P(L){const M=!hl(L)||L<0?0:L;d?.clickDistance(M)}return{update:v,destroy:S,setViewport:w,setViewportConstrained:C,getViewport:k,scaleTo:T,scaleBy:_,setScaleExtent:O,setTranslateExtent:R,syncViewport:E,setClickDistance:P}}var t0;(function(e){e.Line="line",e.Handle="handle"})(t0||(t0={}));function iht({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:o}){const s=e-t,a=n-r,l=[s>0?1:s<0?-1:0,a>0?1:a<0?-1:0];return s&&i&&(l[0]=l[0]*-1),a&&o&&(l[1]=l[1]*-1),l}function xY(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),i=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:i}}function Dd(e,t){return Math.max(0,t-e)}function _d(e,t){return Math.max(0,e-t)}function Q5(e,t,n){return Math.max(0,t-e,e-n)}function SY(e,t){return e?!t:t}function oht(e,t,n,r,i,o,s,a){let{affectsX:l,affectsY:c}=t;const{isHorizontal:u,isVertical:d}=t,p=u&&d,{xSnapped:g,ySnapped:y}=n,{minWidth:b,maxWidth:v,minHeight:S,maxHeight:C}=r,{x:w,y:E,width:k,height:T,aspectRatio:_}=e;let O=Math.floor(u?g-e.pointerX:0),R=Math.floor(d?y-e.pointerY:0);const P=k+(l?-O:O),L=T+(c?-R:R),M=-o[0]*k,N=-o[1]*T;let $=Q5(P,b,v),B=Q5(L,S,C);if(s){let W=0,q=0;l&&O<0?W=Dd(w+O+M,s[0][0]):!l&&O>0&&(W=_d(w+P+M,s[1][0])),c&&R<0?q=Dd(E+R+N,s[0][1]):!c&&R>0&&(q=_d(E+L+N,s[1][1])),$=Math.max($,W),B=Math.max(B,q)}if(a){let W=0,q=0;l&&O>0?W=_d(w+O,a[0][0]):!l&&O<0&&(W=Dd(w+P,a[1][0])),c&&R>0?q=_d(E+R,a[0][1]):!c&&R<0&&(q=Dd(E+L,a[1][1])),$=Math.max($,W),B=Math.max(B,q)}if(i){if(u){const W=Q5(P/_,S,C)*_;if($=Math.max($,W),s){let q=0;!l&&!c||l&&!c&&p?q=_d(E+N+P/_,s[1][1])*_:q=Dd(E+N+(l?O:-O)/_,s[0][1])*_,$=Math.max($,q)}if(a){let q=0;!l&&!c||l&&!c&&p?q=Dd(E+P/_,a[1][1])*_:q=_d(E+(l?O:-O)/_,a[0][1])*_,$=Math.max($,q)}}if(d){const W=Q5(L*_,b,v)/_;if(B=Math.max(B,W),s){let q=0;!l&&!c||c&&!l&&p?q=_d(w+L*_+M,s[1][0])/_:q=Dd(w+(c?R:-R)*_+M,s[0][0])/_,B=Math.max(B,q)}if(a){let q=0;!l&&!c||c&&!l&&p?q=Dd(w+L*_,a[1][0])/_:q=_d(w+(c?R:-R)*_,a[0][0])/_,B=Math.max(B,q)}}}R=R+(R<0?B:-B),O=O+(O<0?$:-$),i&&(p?P>L*_?R=(SY(l,c)?-O:O)/_:O=(SY(l,c)?-R:R)*_:u?(R=O/_,c=l):(O=R*_,l=c));const F=l?w+O:w,V=c?E+R:E;return{width:k+(l?-O:O),height:T+(c?-R:R),x:o[0]*O*(l?-1:1)+F,y:o[1]*R*(c?-1:1)+V}}const _ce={width:0,height:0,x:0,y:0},sht={..._ce,pointerX:0,pointerY:0,aspectRatio:1};function aht(e){return[[0,0],[e.measured.width,e.measured.height]]}function lht(e,t,n){const r=t.position.x+e.position.x,i=t.position.y+e.position.y,o=e.measured.width??0,s=e.measured.height??0,a=n[0]*o,l=n[1]*s;return[[r-a,i-l],[r+o-a,i+s-l]]}function cht({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){const o=ea(e);let s={controlDirection:xY("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function a({controlPosition:c,boundaries:u,keepAspectRatio:d,resizeDirection:p,onResizeStart:g,onResize:y,onResizeEnd:b,shouldResize:v}){let S={..._ce},C={...sht};s={boundaries:u,resizeDirection:p,keepAspectRatio:d,controlDirection:xY(c)};let w,E=null,k=[],T,_,O,R=!1;const P=Lle().on("start",L=>{const{nodeLookup:M,transform:N,snapGrid:$,snapToGrid:B,nodeOrigin:F,paneDomNode:V}=n();if(w=M.get(t),!w)return;E=V?.getBoundingClientRect()??null;const{xSnapped:W,ySnapped:q}=ob(L.sourceEvent,{transform:N,snapGrid:$,snapToGrid:B,containerBounds:E});S={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},C={...S,pointerX:W,pointerY:q,aspectRatio:S.width/S.height},T=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(T=M.get(w.parentId),_=T&&w.extent==="parent"?aht(T):void 0),k=[],O=void 0;for(const[Z,z]of M)if(z.parentId===t&&(k.push({id:Z,position:{...z.position},extent:z.extent}),z.extent==="parent"||z.expandParent)){const U=lht(z,w,z.origin??F);O?O=[[Math.min(U[0][0],O[0][0]),Math.min(U[0][1],O[0][1])],[Math.max(U[1][0],O[1][0]),Math.max(U[1][1],O[1][1])]]:O=U}g?.(L,{...S})}).on("drag",L=>{const{transform:M,snapGrid:N,snapToGrid:$,nodeOrigin:B}=n(),F=ob(L.sourceEvent,{transform:M,snapGrid:N,snapToGrid:$,containerBounds:E}),V=[];if(!w)return;const{x:W,y:q,width:Z,height:z}=S,U={},Y=w.origin??B,{width:H,height:K,x:Q,y:ie}=oht(C,s.controlDirection,F,s.boundaries,s.keepAspectRatio,Y,_,O),te=H!==Z,ce=K!==z,ee=Q!==W&&te,J=ie!==q&&ce;if(!ee&&!J&&!te&&!ce)return;if((ee||J||Y[0]===1||Y[1]===1)&&(U.x=ee?Q:S.x,U.y=J?ie:S.y,S.x=U.x,S.y=U.y,k.length>0)){const fe=Q-W,ye=ie-q;for(const Me of k)Me.position={x:Me.position.x-fe+Y[0]*(H-Z),y:Me.position.y-ye+Y[1]*(K-z)},V.push(Me)}if((te||ce)&&(U.width=te&&(!s.resizeDirection||s.resizeDirection==="horizontal")?H:S.width,U.height=ce&&(!s.resizeDirection||s.resizeDirection==="vertical")?K:S.height,S.width=U.width,S.height=U.height),T&&w.expandParent){const fe=Y[0]*(U.width??0);U.x&&U.x<fe&&(S.x=fe,C.x=C.x-(U.x-fe));const ye=Y[1]*(U.height??0);U.y&&U.y<ye&&(S.y=ye,C.y=C.y-(U.y-ye))}const X=iht({width:S.width,prevWidth:Z,height:S.height,prevHeight:z,affectsX:s.controlDirection.affectsX,affectsY:s.controlDirection.affectsY}),oe={...S,direction:X};v?.(L,oe)!==!1&&(R=!0,y?.(L,oe),r(U,V))}).on("end",L=>{R&&(b?.(L,{...S}),i?.({...S}),R=!1)});o.call(P)}function l(){o.on(".drag",null)}return{update:a,destroy:l}}const uht={},wY=e=>{let t;const n=new Set,r=(u,d)=>{const p=typeof u=="function"?u(t):u;if(!Object.is(p,t)){const g=t;t=d??(typeof p!="object"||p===null)?p:Object.assign({},t,p),n.forEach(y=>y(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(uht?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},c=t=e(r,i,l);return l},dht=e=>e?wY(e):wY,{useDebugValue:fht}=on,{useSyncExternalStoreWithSelector:hht}=OAe,pht=e=>e;function Tce(e,t=pht,n){const r=hht(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return fht(r),r}const CY=(e,t)=>{const n=dht(e),r=(i,o=t)=>Tce(n,i,o);return Object.assign(r,n),r},mht=(e,t)=>e?CY(e,t):CY;function Qr(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,i]of e)if(!Object.is(i,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}const _8=A.createContext(null),ght=_8.Provider,Oce=Pc.error001();function tr(e,t){const n=A.useContext(_8);if(n===null)throw new Error(Oce);return Tce(n,e,t)}function ei(){const e=A.useContext(_8);if(e===null)throw new Error(Oce);return A.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const kY={display:"none"},yht={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Mce="react-flow__node-desc",jce="react-flow__edge-desc",bht="react-flow__aria-live",vht=e=>e.ariaLiveMessage,xht=e=>e.ariaLabelConfig;function Sht({rfId:e}){const t=tr(vht);return h.jsx("div",{id:`${bht}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:yht,children:t})}function wht({rfId:e,disableKeyboardA11y:t}){const n=tr(xht);return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:`${Mce}-${e}`,style:kY,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),h.jsx("div",{id:`${jce}-${e}`,style:kY,children:n["edge.a11yDescription.default"]}),!t&&h.jsx(Sht,{rfId:e})]})}const T8=A.forwardRef(({position:e="top-left",children:t,className:n,style:r,...i},o)=>{const s=`${e}`.split("-");return h.jsx("div",{className:Fi(["react-flow__panel",n,...s]),style:r,ref:o,...i,children:t})});T8.displayName="Panel";function Cht({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:h.jsx(T8,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:h.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const kht=e=>{const t=[],n=[];for(const[,r]of e.nodeLookup)r.selected&&t.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&n.push(r);return{selectedNodes:t,selectedEdges:n}},eS=e=>e.id;function Eht(e,t){return Qr(e.selectedNodes.map(eS),t.selectedNodes.map(eS))&&Qr(e.selectedEdges.map(eS),t.selectedEdges.map(eS))}function Aht({onSelectionChange:e}){const t=ei(),{selectedNodes:n,selectedEdges:r}=tr(kht,Eht);return A.useEffect(()=>{const i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[n,r,e]),null}const Dht=e=>!!e.onSelectionChangeHandlers;function _ht({onSelectionChange:e}){const t=tr(Dht);return e||t?h.jsx(Aht,{onSelectionChange:e}):null}const Rce=[0,0],Tht={x:0,y:0,zoom:1},Oht=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],EY=[...Oht,"rfId"],Mht=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),AY={translateExtent:w2,nodeOrigin:Rce,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function jht(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:s,reset:a,setDefaultNodesAndEdges:l}=tr(Mht,Qr),c=ei();A.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{u.current=AY,a()}),[]);const u=A.useRef(AY);return A.useEffect(()=>{for(const d of EY){const p=e[d],g=u.current[d];p!==g&&(typeof e[d]>"u"||(d==="nodes"?t(p):d==="edges"?n(p):d==="minZoom"?r(p):d==="maxZoom"?i(p):d==="translateExtent"?o(p):d==="nodeExtent"?s(p):d==="ariaLabelConfig"?c.setState({ariaLabelConfig:Sft(p)}):d==="fitView"?c.setState({fitViewQueued:p}):d==="fitViewOptions"?c.setState({fitViewOptions:p}):c.setState({[d]:p})))}u.current=e},EY.map(d=>e[d])),null}function DY(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Rht(e){const[t,n]=A.useState(e==="system"?null:e);return A.useEffect(()=>{if(e!=="system"){n(e);return}const r=DY(),i=()=>n(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),t!==null?t:DY()?.matches?"dark":"light"}const _Y=typeof document<"u"?document:null;function A2(e=null,t={target:_Y,actInsideInputWithModifier:!0}){const[n,r]=A.useState(!1),i=A.useRef(!1),o=A.useRef(new Set([])),[s,a]=A.useMemo(()=>{if(e!==null){const c=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.replace("+",`
|
|
489
|
+
`,n)+1}return{type:t,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(t){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;const n=V5(t),r=wm(n);return r.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:r,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;const n=V5(t),r=wm(n);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:r,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(t,n){return this.type!=="comment"||this.indent<=n?!1:t.every(r=>r.type==="newline"||r.type==="space")}*documentEnd(t){this.type!=="doc-mode"&&(t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()))}*lineEnd(t){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:t.end?t.end.push(this.sourceToken):t.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop())}}}function yle(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new mle||null,prettyErrors:t}}function vat(e,t={}){const{lineCounter:n,prettyErrors:r}=yle(t),i=new eI(n?.addNewLine),o=new QR(t),s=Array.from(o.compose(i.parse(e)));if(r&&n)for(const a of s)a.errors.forEach(Gw(e,n)),a.warnings.forEach(Gw(e,n));return s.length>0?s:Object.assign([],{empty:!0},o.streamInfo())}function ble(e,t={}){const{lineCounter:n,prettyErrors:r}=yle(t),i=new eI(n?.addNewLine),o=new QR(t);let s=null;for(const a of o.compose(i.parse(e),!0,e.length))if(!s)s=a;else if(s.options.logLevel!=="silent"){s.errors.push(new zh(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return r&&n&&(s.errors.forEach(Gw(e,n)),s.warnings.forEach(Gw(e,n))),s}function xat(e,t,n){let r;typeof t=="function"?r=t:n===void 0&&t&&typeof t=="object"&&(n=t);const i=ble(e,n);if(!i)return null;if(i.warnings.forEach(o=>Lae(i.options.logLevel,o)),i.errors.length>0){if(i.options.logLevel!=="silent")throw i.errors[0];i.errors=[]}return i.toJS(Object.assign({reviver:r},n))}function Sat(e,t,n){let r=null;if(typeof t=="function"||Array.isArray(t)?r=t:n===void 0&&t&&(n=t),typeof n=="string"&&(n=n.length),typeof n=="number"){const i=Math.round(n);n=i<1?void 0:i>8?{indent:8}:{indent:i}}if(e===void 0){const{keepUndefined:i}=n??t??{};if(!i)return}return Ep(e)&&!r?e.toString(n):new R0(e,r,n).toString(n)}const wat=Object.freeze(Object.defineProperty({__proto__:null,Alias:a8,CST:gat,Composer:QR,Document:R0,Lexer:ple,LineCounter:mle,Pair:zo,Parser:eI,Scalar:sn,Schema:g8,YAMLError:ZR,YAMLMap:Qs,YAMLParseError:zh,YAMLSeq:Of,YAMLWarning:rle,isAlias:zf,isCollection:ii,isDocument:Ep,isMap:T0,isNode:oi,isPair:Xr,isScalar:Ir,isSeq:O0,parse:xat,parseAllDocuments:vat,parseDocument:ble,stringify:Sat,visit:Ap,visitAsync:s8},Symbol.toStringTag,{value:"Module"}));function Cat(e){let t=null;try{t=wat.parse(e.doc.toString())}catch{}const n=pR(e,Jr.YAML);return{data:t,pointers:n}}const vle=e=>{switch(e){case Jr.JSON:return est;case Jr.JSON5:return hst;case Jr.YAML:return Cat}};function kat(e){return Object.entries(e)}function Sy(e,t){if(typeof e=="string"||typeof e!="object"||e===null)return e;if(Array.isArray(e))return e.map(i=>Sy(i,t));if(e instanceof Map){const i=new Map;for(const[o,s]of e){const a=o,l=Sy(s,t);i.set(a,l)}return i}if(e instanceof Set){const i=new Set;for(const o of e){const s=Sy(o,t);i.add(s)}return i}const n={};function r(i,o,s,a){s===i&&a===o?n[s]=Sy(o,t):n[s]=a}for(const[i,o]of kat(e)){const s=t(i,o);if(s.length===2&&typeof s[0]=="string")r(i,o,s[0],s[1]);else for(const[a,l]of s)r(i,o,a,l)}return n}var Eat=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};class Aat{constructor(){this.completions=new Map,this.reservedKeys=new Set}reserve(t){this.reservedKeys.add(t)}add(t){this.reservedKeys.has(t.label)||this.completions.set(t.label,t)}}function rb(e){return!(!e||Ho(e)||e.name==="UnknownPropertyError"||e.type==="undefined")}class Dat{constructor(t){var n,r,i;this.opts=t,this.originalSchema=null,this.schema=null,this.laxSchema=null,this.mode=Jr.JSON,this.mode=(n=t.mode)!==null&&n!==void 0?n:Jr.JSON,this.parser=(i=(r=this.opts)===null||r===void 0?void 0:r.jsonParser)!==null&&i!==void 0?i:vle(this.mode)}doComplete(t){var n;const r=mR(t.state);if(this.originalSchema!==r&&(this.schema=(n=wh(r,r))!==null&&n!==void 0?n:r,this.laxSchema=Tat(this.schema)),!this.schema||!this.laxSchema)return[];ni.log("xxx","trying with original schema");const i=this.doCompleteForSchema(t,this.schema);return i.options.length!==0?i:(ni.log("xxx","no completions with original schema, trying with lax schema"),this.doCompleteForSchema(t,this.laxSchema))}doCompleteForSchema(t,n){var r,i;const o={from:t.pos,to:t.pos,options:[],filter:!1},s=t.state.doc.sliceString(0);let a=Q7(t.state,t.pos),l=t.state.sliceDoc(a.from,t.pos).replace(/^(["'])/,"");if(ni.log("xxx","node",a,"prefix",l,"ctx",t),!(VS(a,this.mode)||_5(a,this.mode))&&!t.explicit)return ni.log("xxx","no completions for non-word/primitive",a),o;const c=Pm(t.state.doc,a),u=Pm(t.state.doc,a,!1);if(a&&(VS(a,this.mode)||_5(a,this.mode)))o.from=a.from,o.to=a.to;else{const y=t.matchBefore(/[A-Za-z0-9._]*/),b=t.pos-c.length;ni.log("xxx","overwriteStart after",b,"ctx.pos",t.pos,"word",y,"currentWord",c,"=>",s[b-1],"..",s[b],"..",s),o.from=a.name===un.INVALID?(r=y?.from)!==null&&r!==void 0?r:t.pos:b,o.to=t.pos}const d=new Aat;let p=!0;const g=oK(a,un.PROPERTY_NAME,this.mode);if(g&&(ni.log("xxx","closestPropertyNameNode",g,"node",a),a=g),_5(a,this.mode)){ni.log("xxx","isPropertyNameNode",a);const y=a.parent;if(y){const b=iK(y,this.mode);p=!b||b.name===un.INVALID&&b.from-b.to===0||(b.parent?yv(b.parent).length<=1:!1),ni.log("xxx","addValue",p,iK(y,this.mode),a),a=(i=oK(y,un.OBJECT,this.mode))!==null&&i!==void 0?i:null}}if(ni.log("xxx",a,c,t,"node at pos",Q7(t.state,t.pos)),a&&[un.OBJECT,un.JSON_TEXT].includes(wi(a.name,this.mode))&&(_5(Q7(t.state,t.pos),this.mode)||g)){if(a.from===t.pos)return ni.log("xxx","no completions for just before opening brace"),o;this.getPropertyCompletions(n,t,a,d,p,u)}else{const y={},b=this.getValueCompletions(n,t,y,d);ni.log("xxx","getValueCompletions res",b)}return o.options=Array.from(d.completions.values()).filter(y=>US(y.label).startsWith(l)),ni.log("xxx","result",o,"prefix",l,"collector.completions",d.completions,"reservedKeys",d.reservedKeys),o}applySnippetCompletion(t){return GJe(typeof t.apply!="string"?t.label:t.apply,t)}getPropertyCompletions(t,n,r,i,o,s){const a=NZe(r,un.PROPERTY,this.mode);ni.log("xxx","getPropertyCompletions",r,n,a),a.forEach(c=>{const u=Pm(n.state.doc,aT(c,un.PROPERTY_NAME,this.mode));i.reserve(US(u))});const l=this.getSchemas(t,n);ni.log("xxx","propertyCompletion schemas",l),l.forEach(c=>{if(typeof c!="object")return;const u=c.properties;u&&Object.entries(u).forEach(([p,g])=>{var y,b;if(typeof g=="object"){const v=(y=g.description)!==null&&y!==void 0?y:"",S=(b=g.type)!==null&&b!==void 0?b:"",C=Array.isArray(S)?S.toString():S,w={label:p,apply:this.getInsertTextForProperty(p,o,s,t,g),type:"property",detail:C,info:()=>Yl("div",{inner:bg(v)})};i.add(this.applySnippetCompletion(w))}});const d=c.propertyNames;if(typeof d=="object"&&(d.enum&&d.enum.forEach(p=>{const g=p?.toString();if(g){const y={label:g,apply:this.getInsertTextForProperty(g,o,s,t),type:"property"};i.add(this.applySnippetCompletion(y))}}),d.const)){const p=d.const.toString(),g={label:p,apply:this.getInsertTextForProperty(p,o,s,t),type:"property"};i.add(this.applySnippetCompletion(g))}})}getInsertTextForProperty(t,n,r,i,o){o=o&&wh(o,i);let s=this.getInsertTextForPropertyName(t,r);if(!n)return s;s+=": ";let a,l=0;if(typeof o=="object"){if(typeof o.default<"u")a||(a=this.getInsertTextForGuessedValue(o.default,"")),l++;else if(o.enum&&(!a&&o.enum.length===1&&(a=this.getInsertTextForGuessedValue(o.enum[0],"")),l+=o.enum.length),typeof o.const<"u"&&(a||(a=this.getInsertTextForGuessedValue(o.const,"")),l++),Array.isArray(o.examples)&&o.examples.length&&(a||(a=this.getInsertTextForGuessedValue(o.examples[0],"")),l+=o.examples.length),a===void 0&&l===0){let c=Array.isArray(o.type)?o.type[0]:o.type;switch(c||(o.properties?c="object":o.items&&(c="array")),c){case"boolean":a="#{}";break;case"string":a=this.getInsertTextForString("");break;case"object":switch(this.mode){case Jr.JSON5:a="{#{}}";break;case Jr.YAML:a="#{}";break;default:a="{#{}}";break}break;case"array":a="[#{}]";break;case"number":case"integer":a="#{0}";break;case"null":a="#{null}";break;default:a="#{}";break}}}return(!a||l>1)&&(ni.log("xxx","value",a,"nValueProposals",l,o),a="#{}"),s+a}getInsertTextForPropertyName(t,n){switch(this.mode){case Jr.JSON5:case Jr.YAML:return n.startsWith('"')?`"${t}"`:n.startsWith("'")?`'${t}'`:t;default:return`"${t}"`}}getInsertTextForString(t,n="#"){switch(this.mode){case Jr.JSON5:return`'${n}{${t}}'`;case Jr.YAML:return`${n}{${t}}`;default:return`"${n}{${t}}"`}}getInsertTextForGuessedValue(t,n=""){switch(typeof t){case"object":return t===null?"${null}"+n:this.getInsertTextForValue(t,n);case"string":{let r=JSON.stringify(t);return r=r.substr(1,r.length-2),r=this.getInsertTextForPlainText(r),this.getInsertTextForString(r,"$")+n}case"number":case"boolean":return"${"+JSON.stringify(t)+"}"+n}return this.getInsertTextForValue(t,n)}getInsertTextForPlainText(t){return t.replace(/[\\$}]/g,"\\$&")}getInsertTextForValue(t,n){const r=JSON.stringify(t,null," ");return r==="{}"?"{#{}}"+n:r==="[]"?"[#{}]"+n:this.getInsertTextForPlainText(r+n)}getValueCompletions(t,n,r,i){let o=$i(n.state).resolveInner(n.pos,-1),s=null,a;if(ni.log("xxx","getValueCompletions",o,n),o&&VS(o,this.mode)&&(s=o,o=o.parent),!o){this.addSchemaValueCompletions(t,r,i);return}if(wi(o.name,this.mode)===un.PROPERTY){const c=aT(o,un.PROPERTY_NAME,this.mode);c&&(a=Pm(n.state.doc,c),o=o.parent)}if(ni.log("xxx","node",o,"parentKey",a),o&&(a!==void 0||wi(o.name,this.mode)===un.ARRAY)){const c=this.getSchemas(t,n);for(const u of c){if(typeof u!="object")return;if(wi(o.name,this.mode)===un.ARRAY&&u.items){let d=i;if(u.uniqueItems&&(d=Object.assign(Object.assign({},d),{add(p){d.completions.has(p.label)||i.add(p)},reserve(p){i.reserve(p)}})),Array.isArray(u.items)){let p=0;if(s){const y=_oe(o,s,this.mode);y>=0&&(p=y)}const g=u.items[p];g&&this.addSchemaValueCompletions(g,r,d)}else this.addSchemaValueCompletions(u.items,r,d)}if((u.type==null||u.type!=="object")&&this.addSchemaValueCompletions(u,r,i),a!==void 0){let d=!1;if(u.properties){const p=u.properties[a];p&&(d=!0,this.addSchemaValueCompletions(p,r,i))}if(u.patternProperties&&!d)for(const p of Object.keys(u.patternProperties)){const g=this.extendedRegExp(p);if(g?.test(a)){d=!0;const y=u.patternProperties[p];y&&this.addSchemaValueCompletions(y,r,i)}}if(u.additionalProperties&&!d){const p=u.additionalProperties;this.addSchemaValueCompletions(p,r,i)}}r.boolean&&(this.addBooleanValueCompletion(!0,i),this.addBooleanValueCompletion(!1,i)),r.null&&this.addNullValueCompletion(i)}}return{valuePrefix:s?Pm(n.state.doc,s,!0,!1):""}}addSchemaValueCompletions(t,n,r){typeof t=="object"&&(this.addEnumValueCompletions(t,r),this.addDefaultValueCompletions(t,r),this.collectTypes(t,n),Array.isArray(t.allOf)&&t.allOf.forEach(i=>this.addSchemaValueCompletions(i,n,r)),Array.isArray(t.anyOf)&&t.anyOf.forEach(i=>this.addSchemaValueCompletions(i,n,r)),Array.isArray(t.oneOf)&&t.oneOf.forEach(i=>this.addSchemaValueCompletions(i,n,r)))}addDefaultValueCompletions(t,n,r=0){let i=!1;if(typeof t.default<"u"){let o=t.type,s=t.default;for(let l=r;l>0;l--)s=[s],o="array";const a=Object.assign(Object.assign({type:o?.toString()},this.getAppliedValue(s)),{detail:"Default value"});n.add(a),i=!0}Array.isArray(t.examples)&&t.examples.forEach(o=>{let s=t.type,a=o;for(let l=r;l>0;l--)a=[a],s="array";n.add(Object.assign({type:s?.toString()},this.getAppliedValue(a))),i=!0}),!i&&typeof t.items=="object"&&!Array.isArray(t.items)&&r<5&&this.addDefaultValueCompletions(t.items,n,r+1)}addEnumValueCompletions(t,n){var r,i;if(typeof t.const<"u"&&n.add(Object.assign(Object.assign({type:(r=t.type)===null||r===void 0?void 0:r.toString()},this.getAppliedValue(t.const)),{info:t.description})),Array.isArray(t.enum))for(let o=0,s=t.enum.length;o<s;o++){const a=t.enum[o];n.add(Object.assign(Object.assign({type:(i=t.type)===null||i===void 0?void 0:i.toString()},this.getAppliedValue(a)),{info:t.description}))}}addBooleanValueCompletion(t,n){n.add({type:"boolean",label:t?"true":"false"})}addNullValueCompletion(t){t.add({type:"null",label:"null"})}collectTypes(t,n){if(Array.isArray(t.enum)||typeof t.const<"u")return;const r=t.type;Array.isArray(r)?r.forEach(i=>n[i]=!0):r&&(n[r]=!0)}getSchemas(t,n){var r,i,o;const{data:s}=this.parser(n.state),a=new pse(t);let l=Aoe(n.state,n.pos,-1,this.mode);if(l===""&&(l=void 0),l!=null&&l.endsWith("/")){l=l.substring(0,l.length-1);const y=jG(t,s,l);if(y!=null)return[y]}let c=l?.replace(/\/[^/]*$/,"");c===""&&(c=void 0);const u=jG(t,s,c),d=l?.split("/").pop(),p=d==null||d in((r=u?.properties)!==null&&r!==void 0?r:{});let g=a.getSchema({pointer:l,data:s??void 0});return!p&&g?.type==="null"&&this.mode==="yaml"&&(g=void 0),ni.log("xxxx","draft.getSchema",g,"data",s,"pointer",l,"pointerPointsToKnownProperty",p),Ho(g)&&(g=(i=g.data)===null||i===void 0?void 0:i.schema),!rb(g)&&u?[u]:(rb(g)||(g=a.getSchema({pointer:c}),l=c),ni.log("xxx","pointer..",JSON.stringify(l)),!rb(g)&&(!l||l==="/")&&(g=(o=wh(t,t))!==null&&o!==void 0?o:t),ni.log("xxx","subSchema..",g),g?Array.isArray(g.allOf)?[g,...g.allOf.map(y=>wh(y,t))]:Array.isArray(g.oneOf)?[g,...g.oneOf.map(y=>wh(y,t))]:Array.isArray(g.anyOf)?[g,...g.anyOf.map(y=>wh(y,t))]:[g]:[])}getAppliedValue(t){const n=US(JSON.stringify(t));switch(this.mode){case Jr.JSON5:return{label:n,apply:IZe(JSON.stringify(t))};case Jr.YAML:return{label:n,apply:n};default:return{label:n,apply:JSON.stringify(t)}}}getValueFromLabel(t){return JSON.parse(t)}extendedRegExp(t){let n="";t.startsWith("(?i)")&&(t=t.substring(4),n="i");try{return new RegExp(t,n+"u")}catch{try{return new RegExp(t,n)}catch{return}}}}function _at(e={}){const t=new Dat(e);return function(r){return t.doComplete(r)}}function Tat(e){return Sy(e,(t,n)=>t==="additionalProperties"&&n===!1?[]:t==="required"&&Array.isArray(n)?[]:t==="unevaluatedProperties"&&n===!1?[]:t==="unevaluatedItems"&&n===!1?[]:[t,n])}function jG(e,t,n){const r=new pse(e),i=r.getSchema({pointer:n,data:t??void 0});if(!rb(i))return;const o=xle(r,i),s={};for(let p of o){let g=Mat(n,p);const y=r.getSchema({pointer:g,data:t??void 0});rb(y)&&Object.assign(s,{[p]:y})}if(o.length===0||Object.keys(s).length===0)return;const a=i,{allOf:l,anyOf:c,oneOf:u}=a,d=Eat(a,["allOf","anyOf","oneOf"]);return Object.assign(Object.assign({},d),{properties:s})}function xle(e,t){if(t=wh(t,e.rootSchema),typeof t!="object"||t==null)return[];const n=[];function r(i){const o=xle(e,i);n.push(...o)}if(typeof t.properties=="object"&&t.properties!=null&&n.push(...Object.keys(t.properties)),typeof t.then=="object"&&t.then!=null&&r(t.then),Array.isArray(t.allOf))for(const i of t.allOf)r(i);if(Array.isArray(t.anyOf))for(const i of t.anyOf)r(i);if(Array.isArray(t.oneOf))for(const i of t.oneOf)r(i);return n}function wh(e,t){if(typeof e=="object"&&e.$ref){const n=Oat(t,e.$ref);if(typeof n=="object"){const r=Object.assign(Object.assign({},e),n);return Reflect.deleteProperty(r,"$ref"),r}}return e}function Oat(e,t){const n=t.split("/");let r=e;return n.forEach(i=>{if(i){if(i==="#"){r=e;return}typeof r=="object"&&(r=r[i])}}),r}function Mat(e,t){return e===void 0?`/${t}`:`${e}/${t}`}const y2=(e,t)=>{const n=e.length>2;let r=e.map((i,o)=>{const s="`"+(t?t(i):i)+"`";return o===e.length-1?"or "+s:s});return n?r.join(", "):r.join(" ")},jat=e=>{var t,n,r;return!((t=e?.data)===null||t===void 0)&&t.pointer&&((n=e?.data)===null||n===void 0?void 0:n.pointer)!=="#"?e.data.pointer.slice(1):!((r=e?.data)===null||r===void 0)&&r.property?`/${e.data.property}`:""},Rat=e=>e.startState.field(kw)!==e.state.field(kw);function Iat(e){const t=new Nat(e);return n=>t.doValidation(n)}const Pat=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class Nat{constructor(t){var n,r,i,o;this.options=t,this.schema=null,this.mode=Jr.JSON,this.rewriteError=s=>{var a,l,c,u,d;const p=s?.data,g=p?.errors;return s.code==="one-of-error"&&g?.length?`Expected one of ${y2(g,b=>b.data.expected)}`:s.code==="type-error"?`Expected \`${!((a=s?.data)===null||a===void 0)&&a.expected&&Array.isArray((l=s?.data)===null||l===void 0?void 0:l.expected)?y2((c=s?.data)===null||c===void 0?void 0:c.expected):(u=s?.data)===null||u===void 0?void 0:u.expected}\` but received \`${(d=s?.data)===null||d===void 0?void 0:d.received}\``:s.message.replaceAll("in `#` ","").replaceAll("at `#`","").replaceAll("/",".").replaceAll("#.","")},this.mode=(r=(n=this.options)===null||n===void 0?void 0:n.mode)!==null&&r!==void 0?r:Jr.JSON,this.parser=(o=(i=this.options)===null||i===void 0?void 0:i.jsonParser)!==null&&o!==void 0?o:vle(this.mode)}get schemaTitle(){var t,n,r;return(r=(n=(t=this.schema)===null||t===void 0?void 0:t.getSchema())===null||n===void 0?void 0:n.title)!==null&&r!==void 0?r:"json-schema"}doValidation(t){const n=mR(t.state);if(!n)return[];if(this.schema=new fse(n),!this.schema)return[];const r=t.state.doc.toString();if(!r?.length)return[];const i=this.parser(t.state);if(i.data==null)return[];let o=[];try{o=this.schema.validate(i.data)}catch{}return ni.log("xxx","validation errors",o,i.data),o.length?o.reduce((s,a)=>{const l=()=>{const d=this.rewriteError(a);s.push({from:0,to:0,message:d,severity:"error",source:this.schemaTitle,renderMessage:()=>{const p=Yl("div",{});return p.innerHTML=bg(d),p}})},c=jat(a),u=i.pointers.get(c);if(a.name==="MaxPropertiesError"||a.name==="MinPropertiesError"||c==="")l();else if(u){const d=Pat.includes(a.name),p=this.rewriteError(a),g=d?u.keyFrom:u.valueFrom,y=d?u.keyTo:u.valueTo;y!==void 0&&g!==void 0&&s.push({from:g,to:y,message:p,renderMessage:()=>{const b=Yl("div",{});return b.innerHTML=bg(p),b},severity:"error",source:this.schemaTitle})}else l();return s},[]):[]}}function $at(e){const t=new Lat(e);return async function(r,i,o){return t.doHover(r,i,o)}}function RG(e){if(e.type)return e.$ref?`${e.$ref} (${e.type})`:e.type;if(e.$ref)return`${e.$ref}`}function MA(e,t,n){return`${t}: ${y2(e[t].map(r=>{try{const{data:i}=n.resolveRef({data:r,pointer:r.$ref});return RG(i||r)}catch{return r.type}}))}`}class Lat{constructor(t){var n,r;this.opts=t,this.schema=null,this.mode=Jr.JSON,this.opts=Object.assign({parser:JSON.parse},this.opts),this.mode=(r=(n=this.opts)===null||n===void 0?void 0:n.mode)!==null&&r!==void 0?r:Jr.JSON}getDataForCursor(t,n,r){const i=mR(t.state);if(!i)return null;this.schema=new fse(i);const o=Aoe(t.state,n,r,this.mode);let s;try{s=this.opts.parser(t.state.doc.toString())}catch{}if(!o)return null;let a=this.schema.getSchema({pointer:o,data:s,withSchemaWarning:!0});return Ho(a)&&(a?.data.schema.$ref?a=this.schema.resolveRef(a):a=a?.data.schema),{schema:a,pointer:o}}formatMessage(t){const{message:n,typeInfo:r}=t;return n?Yl("div",{class:"cm6-json-schema-hover"},[Yl("div",{class:"cm6-json-schema-hover--description",inner:bg(n,!1)}),Yl("div",{class:"cm6-json-schema-hover--code-wrapper"},[Yl("div",{class:"cm6-json-schema-hover--code",inner:bg(r,!1)})])]):Yl("div",{class:"cm6-json-schema-hover"},[Yl("div",{class:"cm6-json-schema-hover--code-wrapper"},[Yl("code",{class:"cm6-json-schema-hover--code",inner:bg(r,!1)})])])}getHoverTexts(t,n){let r="",i=null;const{schema:o}=t;return o.oneOf&&(r=MA(o,"oneOf",n)),o.anyOf&&(r=MA(o,"anyOf",n)),o.allOf&&(r=MA(o,"allOf",n)),o.type&&(r=Array.isArray(o.type)?y2(o.type):o.type),o.$ref&&(r=` Reference: ${o.$ref}`),o.enum&&(r=`\`enum\`: ${y2(o.enum)}`),o.format&&(r+=`\`format\`: ${o.format}`),o.pattern&&(r+=`\`pattern\`: ${o.pattern}`),o.description&&(i=o.description),{message:i,typeInfo:r}}async doHover(t,n,r){var i,o,s,a;const l=n,c=n;try{const u=this.getDataForCursor(t,n,r);if(ni.log("cursorData",u),!u?.schema)return null;const p=((o=(i=this.opts)===null||i===void 0?void 0:i.getHoverTexts)!==null&&o!==void 0?o:this.getHoverTexts)(u,this.schema),y=((a=(s=this.opts)===null||s===void 0?void 0:s.formatHover)!==null&&a!==void 0?a:this.formatMessage)(p);return{pos:l,end:c,arrow:!0,above:!0,create:b=>({dom:y})}}catch(u){return ni.log(u),null}}}const Fat=e=>h.jsx(Fo,{disablePadding:!0,children:e.validationErrors.map((t,n)=>h.jsx(Es,{disableGutters:!0,disablePadding:!0,children:h.jsxs(Wt,{direction:"row",spacing:1,children:[h.jsx(re,{variant:"body2",children:"•"}),h.jsx(re,{variant:"caption",children:t.instancePath.length===0?"/":t.instancePath}),h.jsx(re,{variant:"body2",children:t.message})]})},n.toString()))}),IG=e=>{let t;try{t=JSON.parse(e)}catch{t=void 0}return t};function zat({schema:e,customValidate:t}){const n=A.useMemo(()=>new bne({allErrors:!0}),[]);return A.useCallback(r=>{const i=[];return n.validate(e,r),i.push(...n.errors??[]),i.push(...t?.(r)??[]),i},[n,e,t])}const Bat=e=>{const t=Hat(),[n,r]=A.useState(()=>JSON.stringify(e.value,null,2)),i=zat(e),[o,s]=A.useState([]);A.useEffect(()=>{s(i(e.value))},[i,e.value]);const a=e.onChange,l=A.useCallback(u=>{const d=IG(u),p=i(d);a(d,p.length===0),r(u),s(p)},[i,a]),c=()=>{const u=IG(n);u&&r(JSON.stringify(u,null,2))};return h.jsxs(Wt,{spacing:2,children:[h.jsxs(se,{position:"relative",children:[h.jsx(woe,{value:n,onChange:u=>l(u),extensions:[tGe(),Aq(QKe(),{delay:100}),Aq(Iat(),{delay:100,needsRefresh:Rat}),gie.data.of({autocomplete:_at({mode:"json4"})}),Jre($at()),FZe(e.schema)],theme:t,height:"400px"}),h.jsx(Ue,{sx:{position:"absolute",right:"0",bottom:"0"},onClick:()=>c(),children:"Prettify"})]}),o.length>0&&h.jsx(zt,{severity:"error",variant:"outlined",children:h.jsx(Fat,{validationErrors:o})})]})};function Hat(){return Ki().palette.mode==="dark"?kGe:xGe}const Uat=[{value:"",label:"Auto (based on domain/name)"},{value:"light",label:"💡 Light"},{value:"switch",label:"🔌 Switch"},{value:"climate",label:"🌡️ Climate"},{value:"cover",label:"🪟 Cover"},{value:"fan",label:"🌀 Fan"},{value:"lock",label:"🔒 Lock"},{value:"sensor",label:"📊 Sensor"},{value:"media_player",label:"📺 Media Player"},{value:"vacuum",label:"🧹 Vacuum"},{value:"remote",label:"🎮 Remote"},{value:"humidifier",label:"💧 Humidifier"},{value:"speaker",label:"🔊 Speaker"},{value:"garage",label:"🚗 Garage"},{value:"door",label:"🚪 Door"},{value:"window",label:"🪟 Window"},{value:"motion",label:"🏃 Motion"},{value:"battery",label:"🔋 Battery"},{value:"power",label:"⚡ Power"},{value:"camera",label:"📷 Camera"},{value:"default",label:"🔗 Default"}],Vat=({bridgeId:e,selectedIcon:t,onIconChange:n})=>{const r=A.useRef(null),[i,o]=A.useState(!1),[s,a]=A.useState(null),[l,c]=A.useState(!1),[u,d]=A.useState(null);A.useEffect(()=>{e&&hC(e).then(b=>{o(b),b&&a(`${Db(e)}?t=${Date.now()}`)}).catch(()=>{o(!1)})},[e]);const p=A.useCallback(async b=>{const v=b.target.files?.[0];if(!(!v||!e)){d(null),c(!0);try{await ETe(e,v),o(!0),a(`${Db(e)}?t=${Date.now()}`),n(void 0)}catch(S){d(S instanceof Error?S.message:"Upload failed")}finally{c(!1),r.current&&(r.current.value="")}}},[e,n]),g=A.useCallback(async()=>{if(e){d(null);try{await ATe(e),o(!1),a(null)}catch(b){d(b instanceof Error?b.message:"Delete failed")}}},[e]),y=A.useCallback(b=>{n(b===""?void 0:b)},[n]);return h.jsxs(Wt,{spacing:2,children:[h.jsxs(rs,{fullWidth:!0,size:"small",children:[h.jsx(Ia,{id:"icon-select-label",children:"Bridge Icon"}),h.jsx(ts,{labelId:"icon-select-label",value:t??"",label:"Bridge Icon",onChange:b=>y(b.target.value),disabled:i,children:Uat.map(b=>h.jsx(Bn,{value:b.value,children:b.label},b.value))}),h.jsx(tC,{children:i?"Custom icon is set. Delete it to use preset icons.":"Select a preset icon or upload a custom image"})]}),e&&h.jsxs(se,{children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"Custom Icon"}),h.jsxs(Wt,{direction:"row",spacing:2,alignItems:"center",children:[i&&s&&h.jsx(se,{component:"img",src:s,alt:"Custom bridge icon",sx:{width:48,height:48,objectFit:"contain",borderRadius:1,border:"1px solid",borderColor:"divider"}}),h.jsx("input",{ref:r,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp,image/svg+xml",style:{display:"none"},onChange:p}),h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(B_e,{}),onClick:()=>r.current?.click(),disabled:l,children:l?"Uploading...":"Upload Image"}),i&&h.jsx(Ue,{variant:"outlined",size:"small",color:"error",startIcon:h.jsx(Pa,{}),onClick:g,children:"Delete"})]}),u&&h.jsx(re,{variant:"caption",color:"error",sx:{mt:1},children:u}),h.jsx(re,{variant:"caption",color:"text.secondary",sx:{mt:1,display:"block"},children:"Supported formats: PNG, JPG, GIF, WebP, SVG (max 5MB)"})]}),!e&&h.jsx(re,{variant:"body2",color:"text.secondary",children:"Save the bridge first to upload a custom icon."})]})},Cm={light:"Light",switch:"On/Off Plug-in Unit",lock:"Door Lock",fan:"Fan",binary_sensor:"Sensor",sensor:"Sensor",cover:"Window Covering",climate:"Thermostat",media_player:"Speaker / Video Player",vacuum:"Robot Vacuum Cleaner",humidifier:"Humidifier",valve:"Water Valve",alarm_control_panel:"On/Off Plug-in Unit",event:"Generic Switch",button:"Generic Switch",input_button:"Generic Switch",automation:"On/Off Switch",script:"On/Off Switch",scene:"On/Off Switch",remote:"On/Off",water_heater:"Water Heater",input_boolean:"On/Off Plug-in Unit",select:"Mode Select",input_select:"Mode Select",siren:"On/Off Plug-in Unit"},PG=e=>{try{return JSON.parse(e)}catch{return}};function Wat({filter:e}){const[t,n]=A.useState(!1),[r,i]=A.useState(null),[o,s]=A.useState(null),[a,l]=A.useState(!1),c=A.useRef(null),u=A.useRef(""),d=A.useCallback(async()=>{n(!0),s(null);try{const y=await fetch("api/matter/filter-preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),b=await y.text(),v=PG(b);if(!y.ok){const C=typeof v=="object"&&v!==null&&"error"in v?String(v.error):b||"Failed to fetch preview";throw new Error(C)}const S=v??PG(b);i(S),l(!0)}catch(y){s(y instanceof Error?y.message:"Unknown error")}finally{n(!1)}},[e]);A.useEffect(()=>{if(!(e.include.length>0&&e.include.some(v=>v.type&&v.value))){i(null),l(!1);return}const b=JSON.stringify(e);if(b!==u.current)return u.current=b,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d()},800),()=>{c.current&&clearTimeout(c.current)}},[e,d]);const p=r?r.entities.reduce((y,b)=>(y[b.domain]=(y[b.domain]||0)+1,y),{}):{},g=[];if(r){r.entities.some(v=>v.domain==="vacuum")&&g.push("This filter includes a vacuum. Consider using Server Mode (single device per bridge) for Apple Home/Alexa compatibility."),r.total>50&&g.push(`${r.total} entities is a large number. Consider splitting across multiple bridges for better stability.`);const b=Object.keys(p).filter(v=>!Cm[v]);b.length>0&&g.push(`Unsupported domains will be skipped: ${b.join(", ")}`)}return h.jsxs(se,{sx:{mt:2},children:[h.jsx(Ue,{variant:"outlined",startIcon:t?h.jsx(Xn,{size:16}):h.jsx(aTe,{}),onClick:d,disabled:t,size:"small",children:t?"Loading...":"Preview Matching Entities"}),o&&h.jsx(zt,{severity:"error",sx:{mt:1},children:o}),h.jsx(is,{in:a&&r!==null,children:r&&h.jsxs(se,{sx:{mt:2},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsxs(re,{variant:"subtitle1",fontWeight:"bold",children:[r.total," entities match"]}),r.truncated&&h.jsx(ot,{label:"Showing first 100",size:"small",color:"warning",variant:"outlined"})]}),g.length>0&&h.jsx(Wt,{spacing:.5,sx:{mb:1.5},children:g.map(y=>h.jsx(zt,{severity:"warning",variant:"outlined",icon:y.includes("vacuum")?h.jsx(c0,{fontSize:"small"}):h.jsx(Hu,{fontSize:"small"}),sx:{py:0},children:h.jsx(re,{variant:"caption",children:y})},y))}),h.jsx(se,{display:"flex",gap:.5,flexWrap:"wrap",mb:2,children:Object.entries(p).sort((y,b)=>b[1]-y[1]).map(([y,b])=>h.jsx(ot,{label:`${y}: ${b}${Cm[y]?` → ${Cm[y]}`:""}`,size:"small",variant:"outlined",color:Cm[y]?"default":"warning"},y))}),h.jsx(Fo,{dense:!0,sx:{maxHeight:200,overflow:"auto",bgcolor:"background.paper",borderRadius:1,border:1,borderColor:"divider"},children:r.entities.map(y=>h.jsx(Es,{divider:!0,children:h.jsx(ao,{primary:y.friendly_name||y.entity_id,secondary:`${y.entity_id}${Cm[y.domain]?` → ${Cm[y.domain]}`:""}`,primaryTypographyProps:{variant:"body2"},secondaryTypographyProps:{variant:"caption",fontFamily:"monospace"}})},y.entity_id))}),h.jsx(Ue,{size:"small",onClick:()=>l(!1),sx:{mt:1},children:"Hide Preview"})]})})]})}const qat=xne(),Kat=qat.ObjectFieldTemplate;function Gat(e){return(e.fieldPathId?.$id??"")==="root_filter"?h.jsx(Yat,{...e}):h.jsx(Kat,{...e})}function Yat(e){const t=e.formData?.include?.length??0,n=e.formData?.exclude?.length??0,r=t+n,[i,o]=A.useState(r>0);return h.jsxs(Md,{expanded:i,onChange:(s,a)=>o(a),variant:"outlined",disableGutters:!0,sx:{borderRadius:2,"&::before":{display:"none"},overflow:"hidden"},children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),sx:{px:2,"& .MuiAccordionSummary-content":{alignItems:"center",gap:1.5}},children:[h.jsx(G6,{fontSize:"small",color:"action"}),h.jsx(re,{variant:"subtitle1",fontWeight:600,children:"Entity Filters"}),h.jsx(CQ,{badgeContent:r,color:"primary",sx:{ml:1},max:99,children:h.jsx(se,{})}),h.jsx(re,{variant:"caption",color:"text.secondary",sx:{ml:1},children:i?"Click to collapse":`${r} rule${r!==1?"s":""} configured`})]}),h.jsx(jd,{sx:{px:2,pb:2},children:e.properties.map(s=>h.jsx("div",{children:s.content},s.name))})]})}function Jat(e){const t=A.useRef(e),n=t.current;return t.current=e,n}function NG(e){const{items:t,canAdd:n,onAddClick:r,title:i,formData:o}=e,s=o??[],[a,l]=A.useState(()=>new Set),[c,u]=A.useState(""),d=Jat(s.length);A.useEffect(()=>{if(s.length>d){const b=s.length-1,v=s[b];!v?.type&&!v?.value&&l(S=>new Set([...S,b]))}},[s,d]);const p=A.useCallback(b=>{l(v=>{const S=new Set(v);return S.has(b)?S.delete(b):S.add(b),S})},[]),g=A.useMemo(()=>{if(!c.trim())return null;const b=c.toLowerCase(),v=[];for(let S=0;S<s.length;S++){const C=s[S],w=C?.type??"",E=C?.value??"";(w.toLowerCase().includes(b)||E.toLowerCase().includes(b))&&v.push(S)}return new Set(v)},[c,s]),y=A.useMemo(()=>{const b=Array.from({length:t.length},(v,S)=>S);return g?b.filter(v=>g.has(v)):b},[t.length,g]);return h.jsxs(se,{children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1,children:[h.jsx(re,{variant:"subtitle2",fontWeight:600,children:i}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(ot,{label:t.length,size:"small",color:"default",sx:{height:22,fontSize:"0.75rem"}}),n&&h.jsx(Ue,{size:"small",startIcon:h.jsx(Ts,{}),onClick:r,children:"Add"})]})]}),t.length>3&&h.jsx(zn,{size:"small",fullWidth:!0,placeholder:"Search rules...",value:c,onChange:b=>u(b.target.value),slotProps:{input:{startAdornment:h.jsx(PC,{position:"start",children:h.jsx(DM,{fontSize:"small",color:"action"})})}},sx:{mb:1}}),g&&y.length===0&&h.jsx(re,{variant:"body2",color:"text.secondary",textAlign:"center",py:2,children:"No matching rules"}),h.jsx(Wt,{spacing:.5,children:y.map(b=>{const v=s[b],S=v?.type??"",C=v?.value??"",w=a.has(b),E=S||C;return h.jsxs(se,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:[h.jsxs(se,{display:"flex",alignItems:"center",sx:{px:1.5,py:.75,cursor:"pointer","&:hover":{bgcolor:"action.hover"},bgcolor:w?"action.selected":"transparent"},onClick:()=>p(b),children:[w?h.jsx(M_e,{fontSize:"small",color:"action"}):h.jsx(R_e,{fontSize:"small",color:"action"}),E?h.jsxs(se,{display:"flex",alignItems:"center",gap:1,ml:.5,flex:1,minWidth:0,children:[h.jsx(ot,{label:S,size:"small",variant:"outlined",sx:{height:22,fontSize:"0.75rem",flexShrink:0}}),h.jsx(re,{variant:"body2",noWrap:!0,sx:{flex:1,minWidth:0},children:C})]}):h.jsx(re,{variant:"body2",color:"text.secondary",ml:.5,fontStyle:"italic",children:"New rule (click to configure)"})]}),h.jsx(is,{in:w,children:h.jsx(se,{sx:{px:2,pb:1.5,pt:.5},children:t[b]})})]},b)})})]})}function Zat(e){const{schema:t,formData:n={},onChange:r,disabled:i,readonly:o,fieldPathId:s}=e,a=t.properties??{},l=A.useCallback((c,u)=>{r({...n,[c]:u},s.path)},[n,r,s]);return h.jsxs(se,{children:[h.jsx(re,{variant:"h6",sx:{mb:2},children:"Feature Flags"}),h.jsx(ht,{container:!0,spacing:2,children:Object.entries(a).map(([c,u])=>{const d=n[c]??u.default??!1,p=u.title?.toLowerCase().includes("deprecated")??!1;return h.jsx(ht,{size:{xs:12,sm:6,lg:4},children:h.jsx(Mn,{variant:"outlined",sx:{height:"100%",opacity:p?.6:1,transition:"border-color 0.2s, box-shadow 0.2s",borderColor:d?"primary.main":"divider","&:hover":{transform:"none",boxShadow:"none"}},children:h.jsx(zu,{onClick:()=>{!i&&!o&&l(c,!d)},disabled:i||o,sx:{height:"100%"},children:h.jsxs(Qn,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:1,children:[h.jsxs(se,{sx:{flex:1,minWidth:0},children:[h.jsx(re,{variant:"subtitle2",fontWeight:600,sx:{lineHeight:1.3},children:u.title??c}),d&&h.jsx(ot,{label:"Active",size:"small",color:"primary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]}),h.jsx(Mu,{checked:d,size:"small",disabled:i||o,tabIndex:-1,onClick:g=>g.stopPropagation(),onChange:g=>l(c,g.target.checked)})]}),h.jsx(re,{variant:"caption",color:"text.secondary",sx:{mt:1,lineHeight:1.4,flex:1},children:u.description})]})})})},c)})})]})}const Sle=e=>{const{t}=en(),[n,r]=A.useState("FIELDS_EDITOR"),i=()=>{r(n==="FIELDS_EDITOR"?"JSON_EDITOR":"FIELDS_EDITOR")},[o,s]=A.useState(e.bridge),[a,l]=A.useState(!0),c=A.useCallback(y=>{const b=y;if(!b?.port)return[];const v=e.usedPorts[b.port];return v!==void 0&&v!==e.bridgeId?[{instancePath:"/port",message:`Port is already used by bridge with id ${v}`}]:[]},[e.bridgeId,e.usedPorts]),u=(y,b)=>{const v=S=>S?.icon;s(S=>{const C=v(S);return C!=null?{...y,icon:C}:{...y}}),l(b)},d=A.useCallback(y=>{s(b=>{if(y!=null)return{...b,icon:y};const{icon:v,...S}=b??{};return S})},[]),p=A.useMemo(()=>{const b=o?.featureFlags,v=[];return b?.serverMode&&v.push({severity:"warning",message:"Server Mode is enabled. Only ONE device should be in this bridge. Multiple devices will cause errors."}),b?.serverMode&&b?.vacuumOnOff===!1&&v.push({severity:"warning",message:"Server Mode with Vacuum OnOff disabled: Alexa REQUIRES the OnOff cluster (PowerController) for robotic vacuums. Without it, the vacuum commissions but never appears in Alexa. Only disable this for Apple Home."}),!b?.serverMode&&b?.vacuumOnOff&&v.push({severity:"warning",message:"Vacuum OnOff is enabled in bridge mode. This adds a non-standard cluster to the RVC device type which may cause issues with Apple Home and Google Home."}),b?.autoForceSync&&b?.autoComposedDevices&&v.push({severity:"warning",message:"Auto Force Sync with Auto Composed Devices increases network traffic. Composed devices have more clusters, so each sync cycle sends more data."}),v},[o]),g=async()=>{a&&await e.onSave(o)};return h.jsxs(h.Fragment,{children:[h.jsxs(zt,{severity:"warning",variant:"outlined",children:["Please consult"," ",h.jsx(V2,{href:Ot.faq.bridgeConfig,target:"_blank",children:"the documentation"})," ","for proper bridge configurations."," ",h.jsx("strong",{children:'Especially if you are using labels, see the "Labels" section.'})]}),h.jsxs(zt,{severity:"info",variant:"outlined",children:[h.jsx("strong",{children:"Community tip:"})," Users have reported that bridges with a large number of devices can become unstable depending on the controller. If you experience connectivity issues, consider splitting your devices across multiple bridges."]}),p.map(y=>h.jsx(zt,{severity:y.severity,variant:"outlined",children:y.message},y.message)),h.jsxs(Wt,{spacing:2,children:[h.jsx(se,{display:"flex",justifyContent:"flex-end",children:h.jsx(Ue,{onClick:()=>i(),title:t(n==="FIELDS_EDITOR"?"bridge.jsonEditor":"bridge.formEditor"),children:n==="FIELDS_EDITOR"?h.jsx(dTe,{}):h.jsx(eTe,{})})}),n==="FIELDS_EDITOR"&&h.jsx(EUe,{value:o??{},onChange:u,schema:My,uiSchema:{icon:{"ui:widget":"hidden"},featureFlags:{"ui:field":"featureFlags"},filter:{include:{"ui:options":{ArrayFieldTemplate:NG}},exclude:{"ui:options":{ArrayFieldTemplate:NG}}}},customValidate:c,templates:{ObjectFieldTemplate:Gat},fields:{featureFlags:Zat}}),n==="JSON_EDITOR"&&h.jsx(Bat,{value:o??{},onChange:u,schema:My,customValidate:c}),o?.filter&&h.jsx(Wat,{filter:o.filter}),h.jsx(Mn,{variant:"outlined",children:h.jsxs(Qn,{children:[h.jsx(re,{variant:"subtitle1",gutterBottom:!0,fontWeight:600,children:t("bridge.iconLabel")}),h.jsx(Vat,{bridgeId:e.bridgeId,selectedIcon:o?.icon,onIconChange:d})]})}),h.jsxs(ht,{container:!0,children:[h.jsx(ht,{size:{xs:6,sm:4,md:3},children:h.jsx(Ue,{fullWidth:!0,variant:"outlined",color:"error",onClick:e.onCancel,children:t("common.cancel")})}),h.jsx(ht,{size:{xs:0,sm:4,md:6},sx:{display:{xs:"none",sm:"block"}}}),h.jsx(ht,{size:{xs:6,sm:4,md:3},children:h.jsx(Ue,{fullWidth:!0,variant:"outlined",disabled:!a,onClick:g,children:t("common.save")})})]})]})]})},Xat={name:"",featureFlags:{},filter:{include:[],exclude:[]}};function Qat(e){let t=5540;for(;e[t];)t++;return t}const elt=()=>{const{t:e}=en(),t=Fc(),n=$c(),[r,i]=A.useState(),o=!!h0().content?.length,s=nee(),a=A.useCallback(p=>{i(p?.id)},[]),l=A.useMemo(()=>{if(!s)return;const p=Qat(s);if(r){const g=IX.find(y=>y.id===r);if(g)return{name:g.name,port:p,filter:{...g.filter},featureFlags:{...g.featureFlags},icon:g.icon}}return{...Xat,port:p}},[s,r]),c=c_e(),u=()=>{n(-1)},d=async p=>{await c({...p}).then(()=>t.show({message:e("bridge.saveSuccess"),severity:"success"})).then(()=>u()).catch(g=>t.show({message:g.message,severity:"error"}))};return!l||!s?e("common.loading"):h.jsxs(Wt,{spacing:4,children:[h.jsx(W2,{items:[{name:e("nav.bridges"),to:Ot.bridges},{name:e("common.create"),to:Ot.createBridge}]}),o&&h.jsx(zt,{severity:"info",variant:"outlined",children:h.jsxs(re,{children:["Did you know that you can connect the same bridge with multiple assistants?"," ",h.jsx(V2,{href:Ot.faq.multiFabric,target:"_blank",children:"Learn more."})]})}),h.jsx(hee,{selectedTemplate:r,onSelect:a}),h.jsx(Sle,{bridge:l,usedPorts:s,onSave:d,onCancel:u},r??"custom")]})},tlt=()=>{const{t:e}=en(),t=Fc(),n=$c(),{bridgeId:r}=FJ(),{content:i,isLoading:o}=ree(r),s=nee(),a=u_e(),l=A.useMemo(()=>{if(!(o||!i))return{name:i.name,port:i.port,filter:i.filter,...i.countryCode!=null&&{countryCode:i.countryCode},...i.featureFlags!=null&&{featureFlags:i.featureFlags},...i.icon!=null&&{icon:i.icon},...i.priority!=null&&{priority:i.priority}}},[o,i]),c=()=>{n(-1)},u=async d=>{await a({...d,id:r}).then(()=>t.show({message:e("bridge.updateSuccess"),severity:"success"})).then(()=>c()).catch(p=>t.show({message:p.message,severity:"error"}))};return o||!s?e("common.loading"):!i||!l?e("notFound.title"):h.jsxs(Wt,{spacing:4,children:[h.jsx(W2,{items:[{name:e("nav.bridges"),to:Ot.bridges},{name:i.name,to:Ot.bridge(r)},{name:e("common.edit"),to:Ot.editBridge(r)}]}),h.jsx(Sle,{bridgeId:r,bridge:l,usedPorts:s,onSave:u,onCancel:c})]})};async function nlt(){const e=await fetch("api/backup/snapshots");return await Rn(e,"Failed to fetch backups"),ar(e)}async function rlt(){const e=await fetch("api/backup/snapshots/create",{method:"POST"});return await Rn(e,"Failed to create backup"),ar(e)}async function ilt(e){const t=await fetch(`api/backup/snapshots/${encodeURIComponent(e)}/download`);if(!t.ok)throw new Error("Failed to download backup");const n=await t.blob(),r=window.URL.createObjectURL(n),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(r),document.body.removeChild(i)}async function olt(e,t){const n=await fetch(`api/backup/snapshots/${encodeURIComponent(e)}/restore`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({overwriteExisting:!0,includeMappings:!0,restoreIdentity:!0,...t})});return await Rn(n,"Failed to restore backup"),ar(n)}async function slt(e){const t=await fetch(`api/backup/snapshots/${encodeURIComponent(e)}`,{method:"DELETE"});await Rn(t,"Failed to delete backup")}async function alt(){const e=await fetch("api/backup/settings");return await Rn(e,"Failed to fetch backup settings"),ar(e)}async function llt(e){const t=await fetch("api/backup/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return await Rn(t,"Failed to update backup settings"),ar(t)}function clt(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function wle(){const{t:e}=en(),[t,n]=A.useState(!1),[r,i]=A.useState(null),[o,s]=A.useState(null),[a,l]=A.useState(null),[c,u]=A.useState(new Set),[d,p]=A.useState(!1),[g,y]=A.useState(!0),[b,v]=A.useState(!0),[S,C]=A.useState(!1),[w,E]=A.useState(!1),[k,T]=A.useState(null),_=A.useRef(null),[O,R]=A.useState([]),[P,L]=A.useState(!0),[M,N]=A.useState(null),[$,B]=A.useState(null),[F,V]=A.useState(null),[W,q]=A.useState(!1),Z=A.useCallback(async()=>{try{L(!0);const[J,X]=await Promise.all([nlt(),alt()]);R(J),N(X)}catch(J){i(J instanceof Error?J.message:"Failed to load backups")}finally{L(!1)}},[]);A.useEffect(()=>{Z()},[Z]);const z=async()=>{q(!0),i(null);try{await rlt(),s(e("backup.snapshotCreated")),await Z()}catch(J){i(J instanceof Error?J.message:"Failed to create backup")}finally{q(!1)}},U=async J=>{try{await ilt(J)}catch(X){i(X instanceof Error?X.message:"Failed to download backup")}},Y=async J=>{n(!0),i(null);try{const X=await olt(J);X.errors.length>0?i(`Restored ${X.bridgesRestored} bridges with ${X.errors.length} errors`):s(e("backup.snapshotRestored",{bridges:X.bridgesRestored,mappings:X.mappingsRestored,identities:X.identitiesRestored})),B(null),X.restartRequired&&E(!0)}catch(X){i(X instanceof Error?X.message:"Failed to restore backup")}finally{n(!1)}},H=async J=>{try{await slt(J),V(null),await Z()}catch(X){i(X instanceof Error?X.message:"Failed to delete backup")}},K=async J=>{try{const X=await llt(J);N(X)}catch(X){i(X instanceof Error?X.message:"Failed to update settings")}},Q=async(J=!1)=>{n(!0),i(null);try{const oe=await fetch(J?"api/backup/download?includeIdentity=true":"api/backup/download");if(!oe.ok)throw new Error("Failed to create backup");const le=await oe.blob(),fe=window.URL.createObjectURL(le),ye=document.createElement("a");ye.href=fe,ye.download=oe.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]||"hamh-backup.zip",document.body.appendChild(ye),ye.click(),window.URL.revokeObjectURL(fe),document.body.removeChild(ye),s(e("backup.downloadSuccess"))}catch(X){i(X instanceof Error?X.message:"Unknown error")}finally{n(!1)}},ie=async J=>{const X=J.target.files?.[0];if(X){T(X),n(!0),i(null);try{const oe=new FormData;oe.append("file",X);const le=await fetch("api/backup/restore/preview",{method:"POST",body:oe});if(!le.ok){const ye=await le.text();let Me="Failed to parse backup";try{const ue=JSON.parse(ye);ue.error&&(Me=ue.error)}catch{ye&&(Me=`${Me} (HTTP ${le.status}: ${ye.slice(0,120)})`)}throw new Error(Me)}const fe=await le.json();l(fe),u(new Set(fe.bridges.map(ye=>ye.id))),C(!0)}catch(oe){i(oe instanceof Error?oe.message:"Unknown error")}finally{n(!1),_.current&&(_.current.value="")}}},te=async()=>{if(k){n(!0),i(null);try{const J=new FormData;J.append("file",k),J.append("options",JSON.stringify({bridgeIds:Array.from(c),overwriteExisting:d,includeMappings:g,restoreIdentity:b&&a?.includesIdentity}));const X=await fetch("api/backup/restore",{method:"POST",body:J});if(!X.ok){const le=await X.text();let fe="Failed to restore backup";try{const ye=JSON.parse(le);ye.error&&(fe=ye.error)}catch{le&&(fe=`${fe} (HTTP ${X.status}: ${le.slice(0,120)})`)}throw new Error(fe)}const oe=await X.json();if(oe.errors.length>0)i(`Restored ${oe.bridgesRestored} bridges with ${oe.errors.length} errors`);else{const le=[`Restored ${oe.bridgesRestored} bridges`];oe.mappingsRestored>0&&le.push(`${oe.mappingsRestored} entity mappings`),oe.identitiesRestored>0&&le.push(`${oe.identitiesRestored} identities`),s(`${le.join(", ")}!`)}C(!1),l(null),T(null),oe.restartRequired&&E(!0)}catch(J){i(J instanceof Error?J.message:"Unknown error")}finally{n(!1)}}},ce=J=>{const X=new Set(c);X.has(J)?X.delete(J):X.add(J),u(X)},ee=async()=>{n(!0);try{await fetch("api/backup/restart",{method:"POST"}),s("Application is restarting...")}catch(J){i(J instanceof Error?J.message:"Failed to restart")}finally{n(!1),E(!1)}};return h.jsxs(Mn,{children:[h.jsxs(Qn,{children:[h.jsxs(re,{variant:"h6",gutterBottom:!0,children:[h.jsx(pm,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.title")]}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:e("backup.description")}),r&&h.jsx(zt,{severity:"error",sx:{mb:2},onClose:()=>i(null),children:r}),o&&h.jsx(zt,{severity:"success",sx:{mb:2},onClose:()=>s(null),children:o}),h.jsxs(ht,{container:!0,spacing:2,children:[h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(pm,{color:"primary"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.configBackup")})]}),h.jsxs(se,{sx:{flexGrow:1},children:[h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.configBackupDesc")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.configBackupNote")})]}),h.jsx(Ue,{variant:"contained",startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):h.jsx(pm,{}),onClick:()=>Q(!1),disabled:t,fullWidth:!0,sx:{mt:2},children:e("backup.configBackup")})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(lee,{color:"warning"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.fullBackup")})]}),h.jsxs(se,{sx:{flexGrow:1},children:[h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.fullBackupDesc")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.fullBackupWarning")})]}),h.jsx(Ue,{variant:"contained",color:"warning",startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):h.jsx(pm,{}),onClick:()=>Q(!0),disabled:t,fullWidth:!0,sx:{mt:2},children:e("backup.fullBackup")})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(Mh,{color:"info"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.restoreFromBackup")})]}),h.jsx(se,{sx:{flexGrow:1},children:h.jsx(re,{variant:"body2",color:"text.secondary",children:e("backup.restoreDesc")})}),h.jsxs(Ue,{variant:"outlined",color:"info",startIcon:h.jsx(Mh,{}),component:"label",disabled:t,fullWidth:!0,sx:{mt:2},children:[e("backup.restoreFromBackup"),h.jsx("input",{ref:_,type:"file",accept:".zip",hidden:!0,onChange:ie})]})]})})]}),h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(pm,{color:"primary"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.storedBackups")}),O.length>0&&h.jsx(ot,{label:O.length,size:"small",color:"primary",variant:"outlined"})]}),h.jsx(Ue,{variant:"outlined",size:"small",startIcon:W?h.jsx(Xn,{size:16,color:"inherit"}):h.jsx(Ts,{}),onClick:z,disabled:W,children:e("backup.createSnapshot")})]}),P?h.jsx(se,{display:"flex",justifyContent:"center",p:2,children:h.jsx(Xn,{size:24})}):O.length===0?h.jsx(re,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2},children:e("backup.noSnapshots")}):h.jsx(Fo,{dense:!0,children:O.map(J=>h.jsxs(Es,{secondaryAction:h.jsxs(se,{display:"flex",gap:.5,children:[h.jsx(Lt,{title:e("backup.downloadSnapshot"),children:h.jsx(qt,{size:"small",onClick:()=>U(J.filename),children:h.jsx(lC,{fontSize:"small"})})}),h.jsx(Lt,{title:e("backup.restoreSnapshot"),children:h.jsx(qt,{size:"small",color:"warning",onClick:()=>B(J.filename),children:h.jsx(Mh,{fontSize:"small"})})}),h.jsx(Lt,{title:e("common.delete"),children:h.jsx(qt,{size:"small",color:"error",onClick:()=>V(J.filename),children:h.jsx(Pa,{fontSize:"small"})})})]}),children:[h.jsx(Io,{sx:{minWidth:36},children:h.jsx(pm,{fontSize:"small",color:J.auto?"action":"primary"})}),h.jsx(ao,{primary:h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsxs(re,{variant:"body2",children:["v",J.version]}),h.jsx(ot,{label:J.auto?e("backup.auto"):e("backup.manual"),size:"small",variant:"outlined",color:J.auto?"default":"primary"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:clt(J.sizeBytes)})]}),secondary:new Date(J.createdAt).toLocaleString()})]},J.filename))}),h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:2,children:[h.jsx(f0,{color:"action"}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("backup.settings")})]}),M&&h.jsxs(se,{sx:{display:"flex",flexDirection:"column",gap:2,maxWidth:400},children:[h.jsx(Ro,{control:h.jsx(Mu,{checked:M.autoBackup,onChange:J=>K({autoBackup:J.target.checked})}),label:e("backup.autoBackupLabel")}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mt:-1},children:e("backup.autoBackupDesc")}),h.jsx(zn,{label:e("backup.retentionCount"),type:"number",size:"small",value:M.backupRetentionCount,onChange:J=>{const X=parseInt(J.target.value,10);X>=1&&X<=100&&K({backupRetentionCount:X})},inputProps:{min:1,max:100},helperText:e("backup.retentionCountDesc"),sx:{maxWidth:200}})]})]}),h.jsxs(Po,{open:S,onClose:()=>C(!1),maxWidth:"sm",fullWidth:!0,children:[h.jsx($o,{children:e("backup.restoreTitle")}),h.jsx(No,{children:a&&h.jsxs(h.Fragment,{children:[h.jsxs(re,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Backup created: ",new Date(a.createdAt).toLocaleString()]}),a.includesIdentity&&h.jsx(zt,{severity:"info",sx:{mt:1},children:"This backup includes Matter identity data (keypairs, fabric credentials). Restoring identities allows bridges to reconnect without re-commissioning."}),h.jsxs(re,{variant:"subtitle2",sx:{mt:2,mb:1},children:[e("backup.selectBridges"),":"]}),h.jsx(Fo,{dense:!0,children:a.bridges.map(J=>h.jsxs(Es,{onClick:()=>ce(J.id),sx:{cursor:"pointer"},children:[h.jsx(Io,{children:h.jsx(ws,{edge:"start",checked:c.has(J.id),tabIndex:-1,disableRipple:!0})}),h.jsx(ao,{primary:J.name,secondary:h.jsxs(h.Fragment,{children:["Port: ",J.port,J.hasMappings&&` • ${J.mappingCount} entity mappings`,J.exists&&h.jsx(re,{component:"span",color:"warning.main",sx:{ml:1},children:"(exists)"})]})})]},J.id))}),h.jsxs(se,{sx:{mt:2},children:[h.jsx(Ro,{control:h.jsx(ws,{checked:d,onChange:J=>p(J.target.checked)}),label:e("backup.overwriteExisting")}),h.jsx(Ro,{control:h.jsx(ws,{checked:g,onChange:J=>y(J.target.checked)}),label:e("backup.includeMappings")}),a?.includesIdentity&&h.jsx(Ro,{control:h.jsx(ws,{checked:b,onChange:J=>v(J.target.checked)}),label:e("backup.restoreIdentities")})]})]})}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>C(!1),children:e("common.cancel")}),h.jsx(Ue,{variant:"contained",onClick:te,disabled:t||c.size===0,startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):null,children:e("backup.restore")})]})]}),h.jsxs(Po,{open:w,onClose:()=>E(!1),children:[h.jsxs($o,{children:[h.jsx(jg,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.restartRequired")]}),h.jsxs(No,{children:[h.jsx(re,{children:e("backup.restartMessage")}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mt:1},children:e("backup.restartNote")})]}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>E(!1),children:e("common.later")}),h.jsx(Ue,{variant:"contained",color:"warning",onClick:ee,disabled:t,startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):h.jsx(jg,{}),children:e("backup.restartNow")})]})]}),h.jsxs(Po,{open:$!==null,onClose:()=>B(null),children:[h.jsxs($o,{children:[h.jsx(Mh,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.confirmRestore")]}),h.jsxs(No,{children:[h.jsx(re,{children:e("backup.confirmRestoreMessage",{filename:$})}),h.jsx(zt,{severity:"warning",sx:{mt:2},children:e("backup.restoreWarning")})]}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>B(null),children:e("common.cancel")}),h.jsx(Ue,{variant:"contained",color:"warning",onClick:()=>$&&Y($),disabled:t,startIcon:t?h.jsx(Xn,{size:20,color:"inherit"}):null,children:e("backup.restore")})]})]}),h.jsxs(Po,{open:F!==null,onClose:()=>V(null),children:[h.jsxs($o,{children:[h.jsx(Pa,{sx:{mr:1,verticalAlign:"middle"}}),e("backup.confirmDelete")]}),h.jsx(No,{children:h.jsx(re,{children:e("backup.confirmDeleteMessage",{filename:F})})}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:()=>V(null),children:e("common.cancel")}),h.jsx(Ue,{variant:"contained",color:"error",onClick:()=>F&&H(F),children:e("common.delete")})]})]})]})}const ult=e=>{const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`};function dlt(e={}){const{t}=en(),[n,r]=A.useState(null),[i,o]=A.useState(!0),[s,a]=A.useState(null),[l,c]=A.useState("name"),[u,d]=A.useState("asc"),p=e.sortField??l,g=e.sortDirection??u,y=e.onSortFieldChange??c,b=e.onSortDirectionChange??d,v=A.useCallback(async()=>{try{const E=await fetch("api/health/detailed");if(E.ok){const k=await E.json();r(k),a(null)}else a(t("health.fetchFailed"))}catch{a(t("health.connectionError"))}finally{o(!1)}},[t]);A.useEffect(()=>{v();const E=setInterval(v,1e4);return()=>clearInterval(E)},[v]);const S=A.useCallback(async()=>{try{const E=await fetch("api/diagnostic/export");if(E.ok){const k=await E.blob(),T=URL.createObjectURL(k),_=document.createElement("a");_.href=T;const R=E.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]??`hamh-diagnostic-${new Date().toISOString().replace(/[:.]/g,"-")}.json`;_.download=R,document.body.appendChild(_),_.click(),document.body.removeChild(_),URL.revokeObjectURL(T)}}catch{a(t("health.exportFailed"))}},[t]),C=async E=>{try{await fetch(`api/matter/bridges/${E}/actions/restart`,{method:"POST"}),v()}catch{a(t("health.restartFailed"))}};if(i)return h.jsx(se,{display:"flex",justifyContent:"center",p:4,children:h.jsx(Xn,{})});if(s||!n)return h.jsx(zt,{severity:"error",sx:{m:2},children:s??t("health.unableToLoad")});const w=n.status==="healthy"?h.jsx(Za,{color:"success"}):n.status==="degraded"?h.jsx(u0,{color:"warning"}):h.jsx(Nf,{color:"error"});return h.jsxs(se,{sx:{p:2},children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[w,h.jsx(re,{variant:"h5",children:t("health.systemHealth")}),h.jsx(ot,{label:n.status.toUpperCase(),color:n.status==="healthy"?"success":n.status==="degraded"?"warning":"error",size:"small"})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(dC,{}),onClick:S,children:t("health.exportDiagnostic")}),h.jsx(Lt,{title:t("common.refresh"),children:h.jsx(qt,{onClick:v,"aria-label":"Refresh health data",children:h.jsx(Z2,{})})})]})]}),h.jsxs(ht,{container:!0,spacing:2,children:[h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2},children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:t("health.version")}),h.jsx(re,{variant:"h6",children:n.version})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2},children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:t("health.uptime")}),h.jsx(re,{variant:"h6",children:ult(n.uptime)})]})}),h.jsx(ht,{size:{xs:12,md:4},children:h.jsxs(zr,{sx:{p:2},children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:t("health.homeAssistant")}),h.jsx(ot,{label:n.services.homeAssistant.connected?t("health.connected"):t("health.disconnected"),color:n.services.homeAssistant.connected?"success":"error",size:"small"})]})})]}),h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,flexWrap:"wrap",gap:1,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(ZD,{}),h.jsx(re,{variant:"h6",children:t("health.bridgeStatus")}),h.jsx(ot,{label:`${n.services.bridges.running}/${n.services.bridges.total} ${t("common.running")}`,size:"small",variant:"outlined"})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(wQ,{fontSize:"small",color:"action"}),h.jsxs(rs,{size:"small",sx:{minWidth:120},children:[h.jsx(Ia,{children:t("health.sortBy")}),h.jsxs(ts,{value:p,label:t("health.sortBy"),onChange:E=>y(E.target.value),children:[h.jsx(Bn,{value:"name",children:t("common.name")}),h.jsx(Bn,{value:"created",children:t("health.created")})]})]}),h.jsx(Lt,{title:t(g==="asc"?"health.ascending":"health.descending"),children:h.jsx(qt,{size:"small",onClick:()=>b(g==="asc"?"desc":"asc"),"aria-label":`Sort ${g==="asc"?"descending":"ascending"}`,children:g==="asc"?h.jsx(uC,{fontSize:"small"}):h.jsx(cC,{fontSize:"small"})})})]})]}),h.jsx(ht,{container:!0,spacing:2,alignItems:"stretch",children:[...n.bridgeDetails].sort((E,k)=>{let T=0;return p==="name"?T=E.name.localeCompare(k.name):T=E.id.localeCompare(k.id),g==="asc"?T:-T}).map(E=>h.jsx(ht,{size:{xs:12,sm:6,md:6,lg:4,xl:3},sx:{display:"flex"},children:h.jsx(Mn,{variant:"outlined",sx:{width:"100%",height:"100%",minWidth:280,maxWidth:480,display:"flex",flexDirection:"column",borderColor:E.status==="running"?"success.main":E.status==="failed"?"error.main":"warning.main"},children:h.jsxs(Qn,{sx:{flex:1,display:"flex",flexDirection:"column",p:2,"&:last-child":{pb:2}},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",flexShrink:0,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,minWidth:0,children:[h.jsx(aa,{}),h.jsx(re,{variant:"subtitle1",fontWeight:"bold",noWrap:!0,sx:{maxWidth:140},children:E.name})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:.5,flexShrink:0,children:[h.jsx(ot,{label:E.status.toUpperCase(),color:E.status==="running"?"success":E.status==="failed"?"error":"warning",size:"small"}),E.status==="failed"&&h.jsx(Lt,{title:t("bridge.restart"),children:h.jsx(qt,{size:"small",onClick:()=>C(E.id),children:h.jsx(eH,{})})})]})]}),E.statusReason&&h.jsx(re,{variant:"body2",color:"error",sx:{mt:1,flexShrink:0},children:E.statusReason}),h.jsx(se,{sx:{mt:"auto",pt:1,flexShrink:0},children:h.jsxs(se,{display:"flex",flexWrap:"wrap",gap:.5,alignItems:"center",children:[h.jsx(ot,{label:`${t("common.port")} ${E.port}`,size:"small",variant:"outlined",color:"default"}),h.jsx(ot,{label:`${E.deviceCount} ${t("common.devices")}`,size:"small",variant:"outlined",color:"default"}),h.jsx(ot,{label:`${E.fabricCount} ${t("common.fabrics")}`,size:"small",variant:"outlined",color:"default"}),E.failedEntityCount>0&&h.jsx(ot,{label:`${E.failedEntityCount} failed`,color:"error",size:"small"})]})}),E.connectivity&&E.status==="running"&&h.jsx(se,{sx:{mt:1,flexShrink:0},children:h.jsxs(re,{variant:"caption",color:"text.secondary",children:[t("health.sessions"),":"," ",E.connectivity.totalSessions," |"," ",t("health.subscriptions"),":"," ",E.connectivity.totalSubscriptions,E.connectivity.fabricSummary&&E.connectivity.fabricSummary.length>1&&` (${E.connectivity.fabricSummary.length} ${t("health.fabrics")})`]})}),E.fabrics.length>0&&h.jsxs(se,{sx:{mt:1,flexShrink:0},children:[h.jsxs(re,{variant:"caption",color:"text.secondary",children:[t("health.connectedTo"),":"]}),h.jsx(se,{display:"flex",gap:.5,flexWrap:"wrap",mt:.5,children:E.fabrics.map(k=>h.jsx(Lt,{title:h.jsxs(se,{sx:{fontSize:"0.75rem"},children:[h.jsxs("div",{children:["Fabric #",k.fabricIndex]}),h.jsxs("div",{children:["Vendor: ",Mg(k.rootVendorId)," ","(0x",k.rootVendorId.toString(16).toUpperCase().padStart(4,"0"),")"]}),h.jsxs("div",{children:["Fabric ID: ",k.fabricId]}),h.jsxs("div",{children:["Node ID: ",k.nodeId]}),h.jsxs("div",{children:["Root Node ID: ",k.rootNodeId]})]}),children:h.jsx(ot,{icon:h.jsx(yQ,{fabric:k}),label:k.label||Mg(k.rootVendorId),size:"small",variant:"outlined"})},k.fabricIndex))})]})]})})},E.id))}),n.recovery.enabled&&h.jsxs(h.Fragment,{children:[h.jsx(Dr,{sx:{my:3}}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,mb:1,children:[h.jsx(eH,{}),h.jsx(re,{variant:"h6",children:t("health.autoRecovery")}),h.jsx(ot,{label:t("common.enabled"),color:"success",size:"small"})]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[t("health.recoveryAttempts"),": ",n.recovery.recoveryCount,n.recovery.lastRecoveryAttempt&&` | Last attempt: ${new Date(n.recovery.lastRecoveryAttempt).toLocaleString()}`]})]}),h.jsx(Dr,{sx:{my:3}}),h.jsx(wle,{})]})}const $G=e=>e==="pass"?"success":e==="warn"?"warning":"error";function flt(){const{t:e}=en(),[t,n]=A.useState(null),[r,i]=A.useState(!1),[o,s]=A.useState(null),[a,l]=A.useState(!1),c=A.useCallback(async()=>{i(!0),s(null);try{const g=await fetch("api/network");g.ok?n(await g.json()):s(e("health.fetchFailed"))}catch{s(e("health.connectionError"))}finally{i(!1)}},[e]);A.useEffect(()=>{c()},[c]);const u=t?.checks.filter(g=>g.status==="pass").length??0,d=t?.checks.filter(g=>g.status==="warn").length??0,p=t?.checks.filter(g=>g.status==="fail").length??0;return h.jsxs(zr,{variant:"outlined",sx:{p:2},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1,children:[h.jsx(re,{variant:"subtitle1",fontWeight:"bold",children:e("health.networkDiagnostics")}),h.jsx(Ue,{size:"small",onClick:c,disabled:r,children:r?h.jsx(Xn,{size:16}):e("health.refresh")})]}),o&&h.jsx(zt,{severity:"error",sx:{mb:1},children:o}),t&&h.jsxs(h.Fragment,{children:[h.jsxs(se,{display:"flex",gap:1,mb:1.5,flexWrap:"wrap",children:[u>0&&h.jsx(ot,{label:`${u} ${e("health.checksPassed")}`,color:"success",size:"small",variant:"outlined"}),d>0&&h.jsx(ot,{label:`${d} ${e("health.checksWarning")}`,color:"warning",size:"small",variant:"outlined"}),p>0&&h.jsx(ot,{label:`${p} ${e("health.checksFailed")}`,color:"error",size:"small",variant:"outlined"}),h.jsx(ot,{label:t.matterConfig.boundInterface?`mDNS: ${t.matterConfig.boundInterface}`:"mDNS: all interfaces",size:"small",variant:"outlined"}),h.jsx(ot,{label:`IPv4: ${t.matterConfig.ipv4Enabled?"on":"off"}`,size:"small",variant:"outlined"})]}),t.checks.filter(g=>g.status!=="pass").map(g=>h.jsxs(zt,{severity:$G(g.status),sx:{mb:1},children:[h.jsx("strong",{children:g.message}),g.detail&&h.jsx(re,{variant:"body2",sx:{mt:.5},children:g.detail})]},g.name)),h.jsx(Ue,{size:"small",onClick:()=>l(!a),sx:{mt:.5},children:e(a?"health.hideDetails":"health.showDetails")}),h.jsxs(is,{in:a,children:[h.jsx(re,{variant:"subtitle2",sx:{mt:1,mb:.5},children:e("health.allChecks")}),h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{children:e("health.check")}),h.jsx(Tt,{children:e("health.statusLabel")}),h.jsx(Tt,{children:e("health.message")})]})}),h.jsx(Ec,{children:t.checks.map(g=>h.jsxs(xi,{children:[h.jsx(Tt,{children:h.jsx(re,{variant:"body2",children:g.name})}),h.jsx(Tt,{children:h.jsx(ot,{label:g.status,color:$G(g.status),size:"small"})}),h.jsxs(Tt,{children:[h.jsx(re,{variant:"body2",children:g.message}),g.detail&&h.jsx(re,{variant:"caption",color:"text.secondary",display:"block",children:g.detail})]})]},g.name))})]}),h.jsx(re,{variant:"subtitle2",sx:{mt:2,mb:.5},children:e("health.networkInterfaces")}),h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{children:e("health.interfaceName")}),h.jsx(Tt,{children:"IPv4"}),h.jsx(Tt,{children:"IPv6"}),h.jsx(Tt,{children:"MAC"})]})}),h.jsx(Ec,{children:t.interfaces.filter(g=>!g.internal).map(g=>h.jsxs(xi,{children:[h.jsx(Tt,{children:g.name}),h.jsx(Tt,{children:g.ipv4.join(", ")||"-"}),h.jsx(Tt,{children:h.jsx(re,{variant:"body2",sx:{wordBreak:"break-all",maxWidth:240},children:g.ipv6.join(", ")||"-"})}),h.jsx(Tt,{children:g.mac})]},g.name))})]})]})]})]})}const PT="hamh-translation-overrides";function wy(e,t=""){const n={};for(const[r,i]of Object.entries(e)){const o=t?`${t}.${r}`:r;typeof i=="object"&&i!==null&&!Array.isArray(i)?Object.assign(n,wy(i,o)):n[o]=String(i??"")}return n}function jA(e){const t={};for(const[n,r]of Object.entries(e)){const i=n.split(".");let o=t;for(let s=0;s<i.length-1;s++)i[s]in o||(o[i[s]]={}),o=o[i[s]];o[i[i.length-1]]=r}return t}function LG(e){try{const t=localStorage.getItem(PT);return t?JSON.parse(t)[e]??{}:{}}catch{return{}}}function FG(e,t){try{const n=localStorage.getItem(PT),r=n?JSON.parse(n):{};Object.keys(t).length===0?delete r[e]:r[e]=t,localStorage.setItem(PT,JSON.stringify(r))}catch{}}const Cle="hamh-custom-languages";function hlt(){try{const e=localStorage.getItem(Cle);return e?JSON.parse(e):[]}catch{return[]}}function zG(e){localStorage.setItem(Cle,JSON.stringify(e))}const W5=[{code:"de",name:"Deutsch"},{code:"fr",name:"Français"},{code:"es",name:"Español"},{code:"it",name:"Italiano"},{code:"zh",name:"中文"},{code:"zh-TW",name:"繁體中文"},{code:"th",name:"ไทย"},{code:"sv",name:"Svenska"},{code:"tr",name:"Türkçe"},{code:"ru",name:"Русский"}];function plt(){const{t:e,i18n:t}=en(),n=t.language??"en",r=W5.some(ee=>ee.code===n)?n:n.split("-")[0]??"en",[i,o]=A.useState(()=>r==="en"?"de":r),[s,a]=A.useState(""),[l,c]=A.useState(()=>LG(i)),[u,d]=A.useState(!1),[p,g]=A.useState("all"),[y,b]=A.useState(hlt),[v,S]=A.useState(!1),[C,w]=A.useState(""),[E,k]=A.useState(""),[T,_]=A.useState(""),[O,R]=A.useState(""),P=A.useMemo(()=>[...W5,...y],[y]),L=A.useCallback(ee=>y.some(J=>J.code===ee),[y]),M=A.useMemo(()=>wy(oZ),[]),N=A.useMemo(()=>{const ee=t.getResourceBundle(i,"translation");return ee?wy(ee):{}},[i,t]),$=A.useMemo(()=>Object.keys(M).map(J=>({key:J,section:J.split(".")[0],enValue:M[J],currentValue:l[J]??N[J]??"",isOverridden:J in l})),[M,N,l]),B=A.useMemo(()=>{let ee=$;if(s){const J=s.toLowerCase();ee=ee.filter(X=>X.key.toLowerCase().includes(J)||X.enValue.toLowerCase().includes(J)||X.currentValue.toLowerCase().includes(J))}return p==="missing"?ee=ee.filter(J=>!J.currentValue):p==="edited"&&(ee=ee.filter(J=>J.isOverridden)),ee},[$,s,p]),F=A.useMemo(()=>[...new Set(B.map(ee=>ee.section))],[B]),V=Object.keys(M).length,W=$.filter(ee=>ee.currentValue).length,q=Object.keys(l).length,Z=V>0?W/V*100:0;A.useEffect(()=>{c(LG(i))},[i]);const z=A.useCallback(ee=>{c(ee),FG(i,ee);const J=t.getResourceBundle(i,"translation"),X=J?wy(J):{},oe={};for(const[le,fe]of Object.entries(ee))fe&&fe!==X[le]&&(oe[le]=fe);if(Object.keys(oe).length>0){const le=jA({...X,...oe});t.addResourceBundle(i,"translation",le,!0,!0)}},[i,t]),U=A.useCallback((ee,J)=>{const X={...l,[ee]:J};J||delete X[ee],z(X)},[l,z]),Y=A.useCallback(ee=>{const J={...l};delete J[ee],z(J)},[l,z]),H=A.useCallback(()=>{z({})},[z]),K=A.useCallback(()=>{const ee={};for(const ye of Object.keys(M))ee[ye]=l[ye]??N[ye]??"";const J=jA(ee),X=JSON.stringify(J,null,2),oe=new Blob([X],{type:"application/json"}),le=URL.createObjectURL(oe),fe=document.createElement("a");fe.href=le,fe.download=`${i}.json`,document.body.appendChild(fe),fe.click(),document.body.removeChild(fe),URL.revokeObjectURL(le)},[M,N,l,i]),Q=A.useCallback(()=>{const ee={};for(const X of Object.keys(M))ee[X]=l[X]??N[X]??"";const J=jA(ee);navigator.clipboard.writeText(JSON.stringify(J,null,2)),d(!0),setTimeout(()=>d(!1),2e3)},[M,N,l]),ie=A.useCallback(()=>{const ee=C.trim().toLowerCase(),J=E.trim();if(!ee){_(e("translationEditor.codeRequired"));return}if(!J){_(e("translationEditor.nameRequired"));return}if(W5.some(oe=>oe.code===ee)||y.some(oe=>oe.code===ee)||ee==="en"){_(e("translationEditor.languageExists"));return}const X=[...y,{code:ee,name:J}];b(X),zG(X),t.addResourceBundle(ee,"translation",{},!0,!0),o(ee),S(!1),w(""),k(""),_("")},[C,E,y,t,e]),te=A.useCallback(()=>{if(!L(i))return;const ee=y.filter(J=>J.code!==i);b(ee),zG(ee),FG(i,{}),o(W5[0].code)},[i,y,L]),ce=A.useCallback(()=>{const ee=document.createElement("input");ee.type="file",ee.accept=".json",ee.onchange=()=>{const J=ee.files?.[0];if(!J)return;const X=new FileReader;X.onload=()=>{try{const oe=JSON.parse(X.result);if(typeof oe!="object"||oe===null)throw new Error;const le=wy(oe),fe=new Set(Object.keys(M)),ye={};let Me=0;for(const[ue,we]of Object.entries(le))fe.has(ue)&&we&&(ye[ue]=we,Me++);z({...l,...ye}),R(e("translationEditor.importSuccess",{count:Me}))}catch{R(e("translationEditor.importFailed"))}},X.readAsText(J)},ee.click()},[M,l,z,e]);return h.jsxs(se,{sx:{p:2},children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,flexWrap:"wrap",gap:1,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(hTe,{}),h.jsx(re,{variant:"h5",children:e("translationEditor.title")})]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsxs(rs,{size:"small",sx:{minWidth:140},children:[h.jsx(Ia,{children:e("translationEditor.editLanguage")}),h.jsx(ts,{value:i,label:e("translationEditor.editLanguage"),onChange:ee=>o(ee.target.value),children:P.map(ee=>h.jsxs(Bn,{value:ee.code,children:[h.jsx(ao,{primary:ee.name}),L(ee.code)&&h.jsx(Io,{sx:{minWidth:"auto",ml:1},children:h.jsx(nH,{fontSize:"small",color:"disabled"})})]},ee.code))})]}),h.jsx(Lt,{title:e("translationEditor.addLanguage"),children:h.jsx(qt,{size:"small",onClick:()=>S(ee=>!ee),children:h.jsx(Ts,{fontSize:"small"})})}),L(i)&&h.jsx(Lt,{title:e("translationEditor.removeLanguage"),children:h.jsx(qt,{size:"small",color:"error",onClick:te,children:h.jsx(nH,{fontSize:"small"})})})]})]}),h.jsx(is,{in:v,children:h.jsxs(se,{display:"flex",gap:1,mb:2,alignItems:"flex-start",flexWrap:"wrap",children:[h.jsx(zn,{size:"small",label:e("translationEditor.newLanguageCode"),value:C,onChange:ee=>w(ee.target.value),error:!!T,sx:{width:180}}),h.jsx(zn,{size:"small",label:e("translationEditor.newLanguageName"),value:E,onChange:ee=>k(ee.target.value),sx:{width:220}}),h.jsx(Ue,{variant:"contained",size:"small",onClick:ie,children:e("translationEditor.addLanguageButton")}),T&&h.jsx(re,{variant:"caption",color:"error",sx:{mt:.5},children:T})]})}),h.jsx(zt,{severity:"info",sx:{mb:2},children:e("translationEditor.info")}),h.jsxs(se,{display:"flex",alignItems:"center",gap:2,mb:2,flexWrap:"wrap",children:[h.jsxs(se,{sx:{flexGrow:1,minWidth:200},children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5,children:[h.jsx(re,{variant:"body2",color:"text.secondary",children:e("translationEditor.progress",{translated:W,total:V})}),h.jsxs(re,{variant:"body2",fontWeight:600,children:[Math.round(Z),"%"]})]}),h.jsx(UO,{variant:"determinate",value:Z,sx:{height:8,borderRadius:4}})]}),q>0&&h.jsx(ot,{label:e("translationEditor.localEdits",{count:q}),color:"primary",size:"small"})]}),h.jsxs(se,{display:"flex",gap:1,mb:2,flexWrap:"wrap",children:[h.jsx(zn,{size:"small",placeholder:e("translationEditor.searchPlaceholder"),value:s,onChange:ee=>a(ee.target.value),sx:{flexGrow:1,minWidth:200},slotProps:{input:{startAdornment:h.jsx(PC,{position:"start",children:h.jsx(DM,{fontSize:"small"})})}}}),h.jsx(rs,{size:"small",sx:{minWidth:130},children:h.jsxs(ts,{value:p,onChange:ee=>g(ee.target.value),children:[h.jsx(Bn,{value:"all",children:e("translationEditor.filterAll")}),h.jsx(Bn,{value:"missing",children:e("translationEditor.filterMissing")}),h.jsx(Bn,{value:"edited",children:e("translationEditor.filterEdited")})]})})]}),h.jsxs(se,{display:"flex",gap:1,mb:3,flexWrap:"wrap",children:[h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(uee,{}),onClick:K,children:e("translationEditor.exportJson")}),h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(lC,{}),onClick:ce,children:e("translationEditor.importJson")}),h.jsx(Lt,{title:u?e("translationEditor.copied"):"",children:h.jsx(Ue,{variant:"outlined",size:"small",startIcon:h.jsx(ef,{}),onClick:Q,children:e("translationEditor.copyJson")})}),q>0&&h.jsx(Ue,{variant:"outlined",size:"small",color:"warning",startIcon:h.jsx(Mh,{}),onClick:H,children:e("translationEditor.resetAll")})]}),F.map(ee=>h.jsxs(se,{sx:{mb:3},children:[h.jsx(re,{variant:"subtitle1",fontWeight:600,sx:{mb:1,textTransform:"capitalize"},children:ee}),h.jsx(Dr,{sx:{mb:1.5}}),B.filter(J=>J.section===ee).map(J=>h.jsxs(se,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr auto"},gap:1,mb:1.5,alignItems:"start"},children:[h.jsxs(se,{children:[h.jsx(re,{variant:"caption",color:"text.secondary",sx:{fontFamily:"monospace"},children:J.key}),h.jsx(re,{variant:"body2",sx:{mt:.25},children:J.enValue})]}),h.jsx(zn,{size:"small",fullWidth:!0,multiline:J.enValue.length>60,minRows:1,maxRows:4,value:J.currentValue,onChange:X=>U(J.key,X.target.value),placeholder:J.enValue,sx:{"& .MuiOutlinedInput-root":J.isOverridden?{borderColor:"primary.main","& fieldset":{borderColor:"primary.main",borderWidth:2}}:{}}}),J.isOverridden&&h.jsx(Lt,{title:e("translationEditor.resetKey"),children:h.jsx(qt,{size:"small",onClick:()=>Y(J.key),children:h.jsx(Mh,{fontSize:"small"})})})]},J.key))]},ee)),B.length===0&&h.jsx(re,{color:"text.secondary",sx:{textAlign:"center",py:4},children:e("translationEditor.noResults")}),h.jsx(N6,{open:!!O,autoHideDuration:3e3,onClose:()=>R(""),message:O})]})}const gh=e=>{const t=["B","KB","MB","GB","TB"];let n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(1)} ${t[r]}`},BG=e=>{const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`},mlt=()=>{const[e,t]=A.useState(null),[n,r]=A.useState(!0),[i,o]=A.useState(!0);if(A.useEffect(()=>{let l=null;const c=async()=>{try{const u=await fetch("api/system/info");if(u.ok){const d=await u.json();t(d),o(!0)}else u.status===404&&(o(!1),l&&(clearInterval(l),l=null))}catch{}finally{r(!1)}};return c(),l=setInterval(c,3e4),()=>{l&&clearInterval(l)}},[]),!i)return null;if(n)return h.jsx(Mn,{children:h.jsx(Qn,{children:h.jsx(re,{children:"Loading system information..."})})});if(!e)return h.jsx(Mn,{children:h.jsx(Qn,{children:h.jsx(re,{color:"error",children:"Failed to load system information"})})});const s=e.memory.used/e.memory.total*100,a=e.storage.used/e.storage.total*100;return h.jsx(Mn,{children:h.jsxs(Qn,{children:[h.jsxs(re,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(H_e,{}),"System Information"]}),h.jsxs(ht,{container:!0,spacing:3,children:[h.jsx(ht,{size:{xs:12,md:6},children:h.jsxs(Wt,{spacing:2,children:[h.jsxs(se,{children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:"Application"}),h.jsxs(Wt,{spacing:1,sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Version:"}),h.jsx(ot,{label:e.version,size:"small",color:"primary"})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Environment:"}),h.jsx(ot,{label:e.environment,size:"small",variant:"outlined",color:e.environment==="Home Assistant Add-on"?"success":"default"})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Node.js:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e.nodeVersion})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Process Uptime:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:BG(e.process.uptime)})]})]})]}),h.jsxs(se,{children:[h.jsx(re,{variant:"subtitle2",color:"text.secondary",children:"System"}),h.jsxs(Wt,{spacing:1,sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Hostname:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e.hostname})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"Platform:"}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[e.platform," (",e.arch,")"]})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"CPU:"}),h.jsxs(re,{variant:"body2",color:"text.secondary",sx:{maxWidth:200,textAlign:"right"},noWrap:!0,title:e.cpuModel,children:[e.cpuCount,"x"," ",e.cpuModel.split("@")[0].trim()]})]}),h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between"},children:[h.jsx(re,{variant:"body2",children:"System Uptime:"}),h.jsx(re,{variant:"body2",color:"text.secondary",children:BG(e.uptime)})]})]})]})]})}),h.jsx(ht,{size:{xs:12,md:6},children:h.jsxs(Wt,{spacing:2,children:[h.jsxs(se,{children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(ZD,{}),"Memory Usage"]}),h.jsxs(se,{sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[h.jsxs(re,{variant:"body2",children:[gh(e.memory.used)," /"," ",gh(e.memory.total)]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[s.toFixed(1),"%"]})]}),h.jsx(se,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:h.jsx(se,{sx:{height:"100%",width:`${s}%`,backgroundColor:s>80?"error.main":s>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]}),h.jsxs(se,{children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(ZD,{}),"HAMH Process Memory"]}),h.jsxs(se,{sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[h.jsxs(re,{variant:"body2",children:["RSS: ",gh(e.process.rss)]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:["Heap: ",gh(e.process.heapUsed)," /"," ",gh(e.process.heapSizeLimit)]})]}),h.jsx(se,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:h.jsx(se,{sx:{height:"100%",width:`${Math.min(e.process.heapUsed/e.process.heapSizeLimit*100,100)}%`,backgroundColor:e.process.heapUsed/e.process.heapSizeLimit>.85?"error.main":e.process.heapUsed/e.process.heapSizeLimit>.6?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]}),h.jsxs(se,{children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(uTe,{}),"Storage Usage"]}),h.jsxs(se,{sx:{mt:1},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[h.jsxs(re,{variant:"body2",children:[gh(e.storage.used)," /"," ",gh(e.storage.total)]}),h.jsxs(re,{variant:"body2",color:"text.secondary",children:[a.toFixed(1),"%"]})]}),h.jsx(se,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:h.jsx(se,{sx:{height:"100%",width:`${a}%`,backgroundColor:a>80?"error.main":a>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]})]})}),h.jsxs(ht,{size:{xs:12},children:[h.jsxs(re,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(rTe,{}),"Network Interfaces"]}),h.jsx(Wt,{spacing:1,sx:{mt:1},children:e.network.interfaces.map(l=>h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsx(re,{variant:"body2",children:l.name}),h.jsx(ot,{label:`${l.address} (${l.family})`,size:"small",variant:"outlined"})]},`${l.name}-${l.address}`))})]})]})]})})},HG=200;function glt(){const[e,t]=A.useState([]),[n,r]=A.useState(null),[i,o]=A.useState(!1),s=A.useRef(null),a=A.useRef(void 0),l=A.useCallback(()=>{if(s.current?.readyState===WebSocket.OPEN)return;const u=window.location.protocol==="https:"?"wss:":"ws:",d=document.querySelector("base")?.href||window.location.origin,p=new URL(d),g=`${u}//${p.host}${p.pathname}api/ws`.replace(/\/+/g,"/").replace(":/","://"),y=new WebSocket(g);s.current=y,y.onopen=()=>{o(!0),y.send(JSON.stringify({type:"subscribe_diagnostics"}))},y.onmessage=b=>{try{const v=JSON.parse(b.data);if(v.type==="diagnostic_event"){const S=v.data;t(C=>{const w=[...C,S];return w.length>HG?w.slice(-HG):w})}else if(v.type==="diagnostic_snapshot"){const S=v.data;r(S),t(S.recentEvents??[])}}catch{}},y.onclose=()=>{o(!1),s.current=null,a.current=setTimeout(l,3e3)},y.onerror=()=>y.close()},[]);A.useEffect(()=>(l(),()=>{clearTimeout(a.current),s.current&&(s.current.send(JSON.stringify({type:"unsubscribe_diagnostics"})),s.current.close())}),[l]);const c=A.useCallback(()=>t([]),[]);return{events:e,snapshot:n,connected:i,clearEvents:c}}function UG(e){const t=e.replace("#",""),n=Number.parseInt(t.substring(0,2),16)/255,r=Number.parseInt(t.substring(2,4),16)/255,i=Number.parseInt(t.substring(4,6),16)/255;return .2126*(n<=.03928?n/12.92:((n+.055)/1.055)**2.4)+.7152*(r<=.03928?r/12.92:((r+.055)/1.055)**2.4)+.0722*(i<=.03928?i/12.92:((i+.055)/1.055)**2.4)>.179?"#000":"#fff"}const e4={state_update:"#4caf50",command_received:"#2196f3",entity_error:"#f44336",session_opened:"#ff9800",session_closed:"#9e9e9e",subscription_changed:"#9c27b0",bridge_started:"#00bcd4",bridge_stopped:"#795548",entity_warning:"#ff9800"},q5={state_update:"diagnostics.stateUpdate",command_received:"diagnostics.command",entity_error:"diagnostics.entityError",session_opened:"diagnostics.sessionOpen",session_closed:"diagnostics.sessionClose",subscription_changed:"diagnostics.subscription",bridge_started:"diagnostics.bridgeStart",bridge_stopped:"diagnostics.bridgeStop",entity_warning:"diagnostics.entityWarning"};function ylt(e){const t=new Date(e),n=String(t.getHours()).padStart(2,"0"),r=String(t.getMinutes()).padStart(2,"0"),i=String(t.getSeconds()).padStart(2,"0"),o=String(t.getMilliseconds()).padStart(3,"0");return`${n}:${r}:${i}.${o}`}const RA=Object.keys(e4);function blt({sortField:e,sortDirection:t}={}){const{t:n}=en(),r=Ki(),{events:i,snapshot:o,connected:s,clearEvents:a}=glt(),[l,c]=A.useState(new Set(RA)),[u,d]=A.useState(!1),p=v=>{c(S=>{const C=new Set(S);return C.has(v)?C.delete(v):C.add(v),C})},g=i.filter(v=>l.has(v.type)),y=A.useMemo(()=>{const v=o?.bridges??[];return e?[...v].sort((S,C)=>{let w=0;return e==="name"?w=S.bridgeName.localeCompare(C.bridgeName):w=S.bridgeId.localeCompare(C.bridgeId),t==="desc"?-w:w}):v},[o?.bridges,e,t]),b={};for(const v of i)b[v.type]=(b[v.type]??0)+1;return h.jsx(Mn,{children:h.jsxs(Qn,{children:[h.jsxs(se,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[h.jsxs(se,{display:"flex",alignItems:"center",gap:1,children:[h.jsx(fTe,{}),h.jsx(re,{variant:"h6",children:n("diagnostics.title")}),h.jsx(ot,{icon:h.jsx(G_e,{sx:{fontSize:10,color:s?r.palette.success.main:r.palette.error.main}}),label:n(s?"common.live":"common.offline"),size:"small",variant:"outlined"})]}),h.jsxs(Wt,{direction:"row",spacing:.5,alignItems:"center",children:[h.jsx(Lt,{title:n("diagnostics.filterEvents"),children:h.jsx(qt,{size:"small",onClick:()=>d(v=>!v),color:u?"primary":"default",children:h.jsx(G6,{})})}),h.jsx(Lt,{title:n("diagnostics.clearEvents"),children:h.jsx(qt,{size:"small",onClick:a,children:h.jsx(z_e,{})})})]})]}),h.jsxs(Wt,{direction:"row",spacing:.5,flexWrap:"wrap",sx:{mb:2,gap:.5},children:[RA.map(v=>{const S=b[v]??0;if(S===0&&!u)return null;const C=e4[v];return h.jsx(ot,{label:`${n(q5[v])}: ${S}`,size:"small",sx:{bgcolor:l.has(v)?C:"action.disabledBackground",color:l.has(v)?UG(C):"text.disabled",fontSize:"0.7rem",height:22,cursor:"pointer",opacity:l.has(v)?1:.5},onClick:()=>p(v)},v)}),o?.system&&h.jsx(ot,{label:`Total: ${o.system.eventCount}`,size:"small",variant:"outlined",sx:{fontSize:"0.7rem",height:22}})]}),h.jsx(is,{in:u,children:h.jsx(zr,{variant:"outlined",sx:{p:1.5,mb:2},children:h.jsx(ht,{container:!0,spacing:0,children:RA.map(v=>{const S=e4[v];return h.jsx(ht,{size:{xs:6,sm:4,md:3},children:h.jsx(Ro,{control:h.jsx(ws,{size:"small",checked:l.has(v),onChange:()=>p(v),sx:{color:S,"&.Mui-checked":{color:S}}}),label:h.jsx(re,{variant:"caption",children:n(q5[v])})})},v)})})})}),y.length>0&&h.jsxs(h.Fragment,{children:[h.jsx(ht,{container:!0,spacing:1,sx:{mb:2},children:y.map(v=>h.jsx(vlt,{bridge:v},v.bridgeId))}),h.jsx(Dr,{sx:{mb:2}})]}),h.jsx(se,{sx:{maxHeight:400,overflow:"auto",bgcolor:"background.default",borderRadius:1,p:1},children:g.length===0?h.jsx(re,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:4},children:i.length===0?"Waiting for diagnostic events…":n("diagnostics.noEvents")}):g.map(v=>{const S=e4[v.type];return h.jsxs(se,{sx:{display:"flex",alignItems:"flex-start",gap:1,py:.4,px:.5,minWidth:0,borderBottom:"1px solid",borderColor:"divider","&:hover":{bgcolor:"action.hover"},"&:last-child":{borderBottom:"none"}},children:[h.jsx(re,{variant:"caption",sx:{color:"text.secondary",whiteSpace:"nowrap",fontFamily:"monospace",fontSize:"0.72rem",minWidth:85,pt:.1},children:ylt(v.timestamp)}),h.jsx(ot,{label:q5[v.type]?n(q5[v.type]):v.type,size:"small",sx:{bgcolor:S??"#757575",color:UG(S??"#757575"),fontSize:"0.62rem",fontWeight:600,height:18,minWidth:90}}),v.bridgeName&&h.jsxs(re,{variant:"caption",sx:{color:"primary.main",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:140,flexShrink:0},children:["[",v.bridgeName,"]"]}),v.entityId&&h.jsx(re,{variant:"caption",sx:{color:"warning.main",fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:220,flexShrink:1},children:v.entityId}),h.jsx(re,{variant:"caption",sx:{color:"text.primary",flex:1,wordBreak:"break-word",fontSize:"0.72rem"},children:v.message})]},v.id)})})]})})}function vlt({bridge:e}){const[t,n]=A.useState(!1);return h.jsx(ht,{size:{xs:12,sm:6},children:h.jsxs(zr,{variant:"outlined",sx:{p:1.5,overflow:"hidden",minWidth:0},children:[h.jsxs(se,{display:"flex",justifyContent:"space-between",alignItems:"center",sx:{cursor:"pointer"},onClick:()=>n(r=>!r),children:[h.jsxs(se,{sx:{minWidth:0,overflow:"hidden"},children:[h.jsx(re,{variant:"body2",fontWeight:500,noWrap:!0,children:e.bridgeName}),h.jsxs(re,{variant:"caption",color:"text.secondary",noWrap:!0,children:[e.entityCount," devices · ",e.sessionCount," sessions"]})]}),h.jsxs(Wt,{direction:"row",spacing:.5,alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end",sx:{flexShrink:0,ml:1},children:[Object.entries(e.featureFlags).filter(([,r])=>r).map(([r])=>h.jsx(ot,{label:r.replace(/^auto/,"").replace(/([A-Z])/g," $1").trim(),size:"small",variant:"outlined",sx:{fontSize:"0.6rem",height:18}},r)),h.jsx(ot,{label:e.status,size:"small",color:e.status==="running"?"success":e.status==="failed"?"error":"default",sx:{height:20}}),h.jsx(Ql,{sx:{transform:t?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s",fontSize:18,color:"text.secondary"}})]})]}),h.jsx(is,{in:t,children:h.jsx(se,{sx:{mt:1,maxHeight:200,overflow:"auto"},children:e.entities.map(r=>h.jsxs(se,{sx:{display:"flex",alignItems:"baseline",gap:.5,py:.3,borderBottom:"1px solid",borderColor:"divider"},children:[h.jsx(re,{variant:"caption",sx:{fontFamily:"monospace",fontSize:"0.68rem",minWidth:180,flexShrink:0,color:r.available?"text.primary":"error.main"},noWrap:!0,children:r.entityId}),h.jsx(se,{display:"flex",gap:.3,flexWrap:"wrap",children:r.matterClusters.map(i=>h.jsx(ot,{label:i,size:"small",variant:"outlined",sx:{fontSize:"0.58rem",height:16,"& .MuiChip-label":{px:.5}}},i))})]},r.entityId))})})]})})}const xlt=()=>{const[e,t]=A.useState("name"),[n,r]=A.useState("asc");return h.jsxs(se,{sx:{display:"flex",flexDirection:"column",gap:3},children:[h.jsx(dlt,{sortField:e,sortDirection:n,onSortFieldChange:t,onSortDirectionChange:r}),h.jsx(se,{sx:{px:2},children:h.jsx(blt,{sortField:e,sortDirection:n})}),h.jsx(se,{sx:{px:2},children:h.jsx(flt,{})}),h.jsx(se,{sx:{px:2,pb:2},children:h.jsx(mlt,{})}),h.jsx(Dr,{}),h.jsx(plt,{})]})};async function Slt(){const e=await fetch(`api/matter/labels?_s=${Date.now()}`);return await Rn(e,"Failed to fetch labels"),ar(e)}async function wlt(){const e=await fetch(`api/matter/areas?_s=${Date.now()}`);return await Rn(e,"Failed to fetch areas"),ar(e)}async function Clt(){const e=await fetch(`api/matter/filter-values?_s=${Date.now()}`);return await Rn(e,"Failed to fetch filter values"),ar(e)}const km=({values:e,copiedId:t,onCopy:n,searchable:r})=>{const[i,o]=A.useState(""),s=A.useMemo(()=>{if(!i)return e;const a=i.toLowerCase();return e.filter(l=>l.toLowerCase().includes(a))},[e,i]);return e.length===0?h.jsx(se,{sx:{p:2,textAlign:"center"},children:h.jsx(re,{color:"text.secondary",variant:"body2",children:"No values found."})}):h.jsxs(se,{children:[r&&e.length>10&&h.jsx(se,{sx:{px:2,pt:1,pb:.5},children:h.jsx(zn,{size:"small",fullWidth:!0,placeholder:"Search...",value:i,onChange:a=>o(a.target.value),slotProps:{input:{startAdornment:h.jsx(PC,{position:"start",children:h.jsx(DM,{fontSize:"small"})})}}})}),h.jsxs(se,{sx:{p:1.5,display:"flex",flexWrap:"wrap",gap:.75},children:[s.map(a=>h.jsx(ot,{label:a,size:"small",variant:t===a?"filled":"outlined",color:t===a?"success":"default",onClick:()=>n(a),sx:{fontFamily:"monospace",fontSize:"0.8rem"}},a)),i&&s.length===0&&h.jsxs(re,{color:"text.secondary",variant:"body2",sx:{p:1},children:['No matches for "',i,'"']})]})]})},klt=()=>{const{t:e}=en(),[t,n]=A.useState([]),[r,i]=A.useState([]),[o,s]=A.useState(null),[a,l]=A.useState(!0),[c,u]=A.useState(null),[d,p]=A.useState(null),g=A.useCallback(async()=>{l(!0);try{const[b,v,S]=await Promise.all([Slt(),wlt(),Clt()]);n(b),i(v),s(S),u(null)}catch(b){u(b instanceof Error?b.message:e("labels.loadFailed"))}finally{l(!1)}},[e]);A.useEffect(()=>{g()},[g]);const y=b=>{navigator.clipboard.writeText(b),p(b),setTimeout(()=>p(null),2e3)};return a?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsx(Xn,{})}):h.jsxs(se,{sx:{p:2},children:[h.jsxs(re,{variant:"h5",component:"h1",sx:{mb:3},children:[h.jsx(G6,{sx:{mr:1,verticalAlign:"middle"}}),e("labels.title")]}),h.jsx(zt,{severity:"info",sx:{mb:3},children:e("labels.info")}),c&&h.jsx(zt,{severity:"error",sx:{mb:2},children:c}),h.jsxs(re,{variant:"h6",sx:{mb:1},children:[h.jsx(EM,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),e("labels.labelsSection")," (",t.length,")"]}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:e("labels.labelsHint")}),h.jsx(Mn,{sx:{mb:4},children:t.length===0?h.jsx(se,{sx:{p:3,textAlign:"center"},children:h.jsx(re,{color:"text.secondary",children:e("labels.noLabels")})}):h.jsx(tf,{children:h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.displayName")}),h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.labelId")}),h.jsx(Tt,{width:48})]})}),h.jsx(Ec,{children:t.map(b=>h.jsxs(xi,{hover:!0,children:[h.jsxs(Tt,{children:[b.color&&h.jsx(se,{component:"span",sx:{display:"inline-block",width:12,height:12,borderRadius:"50%",backgroundColor:b.color,mr:1,verticalAlign:"middle"}}),b.name]}),h.jsx(Tt,{children:h.jsx("code",{children:b.label_id})}),h.jsx(Tt,{children:h.jsx(Lt,{title:d===b.label_id?e("common.copied"):e("common.copyId"),children:h.jsx(qt,{size:"small",onClick:()=>y(b.label_id),children:h.jsx(ef,{fontSize:"small"})})})})]},b.label_id))})]})})}),h.jsxs(re,{variant:"h6",sx:{mb:1},children:[h.jsx(eee,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),e("labels.areasSection")," (",r.length,")"]}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:e("labels.areasHint")}),h.jsx(Mn,{sx:{mb:4},children:r.length===0?h.jsx(se,{sx:{p:3,textAlign:"center"},children:h.jsx(re,{color:"text.secondary",children:e("labels.noAreas")})}):h.jsx(tf,{children:h.jsxs(kc,{size:"small",children:[h.jsx(nf,{children:h.jsxs(xi,{children:[h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.displayName")}),h.jsx(Tt,{sx:{fontWeight:"bold"},children:e("labels.areaId")}),h.jsx(Tt,{width:48})]})}),h.jsx(Ec,{children:r.map(b=>h.jsxs(xi,{hover:!0,children:[h.jsx(Tt,{children:b.name}),h.jsx(Tt,{children:h.jsx("code",{children:b.area_id})}),h.jsx(Tt,{children:h.jsx(Lt,{title:d===b.area_id?e("common.copied"):e("common.copyId"),children:h.jsx(qt,{size:"small",onClick:()=>y(b.area_id),children:h.jsx(ef,{fontSize:"small"})})})})]},b.area_id))})]})})}),o&&h.jsxs(h.Fragment,{children:[h.jsx(re,{variant:"h6",sx:{mb:2},children:e("labels.otherFilterValues")}),h.jsxs(Md,{defaultExpanded:!0,children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(gTe,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.domains")," (",o.domains.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.domainsHint")}),h.jsx(km,{values:o.domains,copiedId:d,onCopy:y})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx($y,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.platforms")," (",o.platforms.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.platformsHint")}),h.jsx(km,{values:o.platforms,copiedId:d,onCopy:y})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(tH,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.entityCategories")," (",o.entityCategories.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.entityCategoriesHint")}),h.jsx(km,{values:o.entityCategories,copiedId:d,onCopy:y})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(tH,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.deviceClasses")," (",o.deviceClasses.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.deviceClassesHint")}),h.jsx(km,{values:o.deviceClasses,copiedId:d,onCopy:y,searchable:!0})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(aa,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.deviceNames")," (",o.deviceNames.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.deviceNamesHint")}),h.jsx(km,{values:o.deviceNames,copiedId:d,onCopy:y,searchable:!0})]})]}),h.jsxs(Md,{children:[h.jsxs(Rd,{expandIcon:h.jsx(Ql,{}),children:[h.jsx(aa,{sx:{mr:1}}),h.jsxs(re,{children:[e("labels.productNames")," (",o.productNames.length,")"]})]}),h.jsxs(jd,{sx:{p:0},children:[h.jsx(re,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:e("labels.productNamesHint")}),h.jsx(km,{values:o.productNames,copiedId:d,onCopy:y,searchable:!0})]})]})]})]})};async function Elt(){const e=await fetch("api/lock-credentials");return await Rn(e,"Failed to fetch lock credentials"),ar(e)}async function Alt(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});return await Rn(n,"Failed to update lock credential"),ar(n)}async function Dlt(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}/enabled`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})});return await Rn(n,"Failed to toggle credential"),ar(n)}async function _lt(e){const t=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"DELETE"});await Rn(t,"Failed to delete lock credential")}const Tlt=({open:e,onClose:t,onSave:n,initialEntityId:r="",initialName:i="",isEdit:o=!1})=>{const{t:s}=en(),[a,l]=A.useState(r),[c,u]=A.useState(""),[d,p]=A.useState(i),[g,y]=A.useState(""),[b,v]=A.useState(!1);A.useEffect(()=>{e&&(l(r),p(i),u(""),y(""))},[e,r,i]);const S=async()=>{if(!a.trim()){y(s("lockCredentials.entityRequired"));return}if(!c||c.length<4||c.length>8){y(s("lockCredentials.pinLength"));return}if(!/^\d+$/.test(c)){y(s("lockCredentials.pinDigitsOnly"));return}v(!0);try{await n(a.trim(),c,d.trim()),t()}catch(C){y(C instanceof Error?C.message:s("lockCredentials.saveFailed"))}finally{v(!1)}};return h.jsxs(Po,{open:e,onClose:t,maxWidth:"sm",fullWidth:!0,children:[h.jsx($o,{children:s(o?"lockCredentials.editCredential":"lockCredentials.addCredential")}),h.jsx(No,{children:h.jsxs(se,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[g&&h.jsx(zt,{severity:"error",children:g}),h.jsx(zn,{label:s("lockCredentials.lockEntityId"),placeholder:"lock.front_door",value:a,onChange:C=>l(C.target.value),disabled:o,fullWidth:!0,helperText:s("lockCredentials.lockEntityHelperText")}),h.jsx(zn,{label:s("lockCredentials.pinCode"),type:"password",placeholder:"1234",value:c,onChange:C=>u(C.target.value.replace(/\D/g,"").slice(0,8)),fullWidth:!0,helperText:"4-8 digit PIN code for this lock",inputProps:{inputMode:"numeric",pattern:"[0-9]*"}}),h.jsx(zn,{label:s("lockCredentials.nameOptional"),placeholder:s("lockCredentials.namePlaceholder"),value:d,onChange:C=>p(C.target.value),fullWidth:!0,helperText:s("lockCredentials.nameHelperText")})]})}),h.jsxs(es,{children:[h.jsx(Ue,{onClick:t,disabled:b,children:s("common.cancel")}),h.jsx(Ue,{onClick:S,variant:"contained",disabled:b,startIcon:b?h.jsx(Xn,{size:16}):h.jsx(F4,{}),children:s("common.save")})]})]})},Olt=()=>{const{t:e}=en(),[t,n]=A.useState([]),[r,i]=A.useState(!0),[o,s]=A.useState(null),[a,l]=A.useState(!1),[c,u]=A.useState(null),d=A.useCallback(async()=>{i(!0);try{const w=await Elt();n(w.credentials),s(null)}catch(w){s(w instanceof Error?w.message:e("lockCredentials.loadFailed"))}finally{i(!1)}},[e]);A.useEffect(()=>{d()},[d]);const p=async(w,E,k)=>{await Alt(w,{entityId:w,pinCode:E,name:k||void 0,enabled:!0}),await d()},[g,y]=A.useState(null),b=async w=>{y(null);try{await _lt(w),await d()}catch(E){s(E instanceof Error?E.message:e("lockCredentials.deleteFailed"))}},v=async w=>{try{await Dlt(w.entityId,!w.enabled),await d()}catch(E){s(E instanceof Error?E.message:e("lockCredentials.updateFailed"))}},S=w=>{u(w),l(!0)},C=()=>{u(null),l(!0)};return h.jsxs(se,{sx:{p:2},children:[h.jsxs(se,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[h.jsxs(re,{variant:"h5",component:"h1",children:[h.jsx(ju,{sx:{mr:1,verticalAlign:"middle"}}),e("lockCredentials.title")]}),h.jsx(Ue,{variant:"contained",startIcon:h.jsx(Ts,{}),onClick:C,children:e("lockCredentials.addCredential")})]}),h.jsx(zt,{severity:"info",sx:{mb:3},children:"Configure PIN codes for locks that require authentication for remote lock/unlock operations. The PIN will be sent with lock/unlock commands to Matter locks."}),o&&h.jsx(zt,{severity:"error",sx:{mb:2},children:o}),r?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsx(Xn,{})}):t.length===0?h.jsx(Mn,{children:h.jsxs(Qn,{sx:{textAlign:"center",py:4},children:[h.jsx(ju,{sx:{fontSize:48,color:"text.secondary",mb:2}}),h.jsx(re,{variant:"h6",color:"text.secondary",children:"No lock credentials configured"}),h.jsx(re,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Add a PIN code for your Matter locks to enable remote lock/unlock"}),h.jsx(Ue,{variant:"outlined",startIcon:h.jsx(Ts,{}),onClick:C,children:"Add Your First Credential"})]})}):h.jsx(Mn,{children:h.jsx(Fo,{children:t.map((w,E)=>h.jsxs(Es,{divider:E<t.length-1,onClick:()=>S(w),sx:{cursor:"pointer","&:hover":{bgcolor:"action.hover"}},children:[h.jsx(Io,{children:h.jsx(ju,{color:w.enabled?"primary":"disabled"})}),h.jsx(ao,{primary:w.name||w.entityId,secondary:h.jsxs(h.Fragment,{children:[w.name&&h.jsx(re,{component:"span",variant:"body2",color:"text.secondary",children:w.entityId}),h.jsx(re,{component:"span",variant:"body2",color:"text.secondary",sx:{ml:w.name?2:0},children:"PIN: ****"})]})}),h.jsxs(WO,{children:[h.jsx(Lt,{title:w.enabled?e("lockCredentials.disable"):e("lockCredentials.enable"),children:h.jsx(Mu,{edge:"end",checked:w.enabled,onChange:k=>{k.stopPropagation(),v(w)}})}),h.jsx(Lt,{title:e("common.delete"),children:h.jsx(qt,{edge:"end",onClick:k=>{k.stopPropagation(),y(w.entityId)},sx:{ml:1},children:h.jsx(Pa,{})})})]})]},w.entityId))})}),h.jsx(Tlt,{open:a,onClose:()=>l(!1),onSave:p,initialEntityId:c?.entityId,initialName:c?.name,isEdit:!!c}),h.jsx($4,{open:g!==null,title:e("lockCredentials.confirmDeleteTitle"),message:e("lockCredentials.confirmDeleteMessage",{entity:g??""}),confirmLabel:e("common.delete"),confirmColor:"error",onConfirm:()=>{g&&b(g)},onCancel:()=>y(null)})]})},Mlt=()=>{const e=$c(),{t}=en();return h.jsxs(se,{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",gap:2,p:4,children:[h.jsx(lTe,{color:"disabled",sx:{fontSize:64}}),h.jsx(re,{variant:"h5",fontWeight:600,children:t("notFound.title")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:t("notFound.description")}),h.jsx(Ue,{variant:"contained",startIcon:h.jsx(kM,{}),onClick:()=>e(Ot.dashboard),children:t("notFound.backToDashboard")})]})};function Fi(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Fi(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var jlt={value:()=>{}};function x8(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new t4(n)}function t4(e){this._=e}function Rlt(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",i=n.indexOf(".");if(i>=0&&(r=n.slice(i+1),n=n.slice(0,i)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}t4.prototype=x8.prototype={constructor:t4,on:function(e,t){var n=this._,r=Rlt(e+"",n),i,o=-1,s=r.length;if(arguments.length<2){for(;++o<s;)if((i=(e=r[o]).type)&&(i=Ilt(n[i],e.name)))return i;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<s;)if(i=(e=r[o]).type)n[i]=VG(n[i],e.name,t);else if(t==null)for(i in n)n[i]=VG(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new t4(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=new Array(i),r=0,i,o;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],r=0,i=o.length;r<i;++r)o[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],i=0,o=r.length;i<o;++i)r[i].value.apply(t,n)}};function Ilt(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function VG(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=jlt,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var NT="http://www.w3.org/1999/xhtml";const WG={svg:"http://www.w3.org/2000/svg",xhtml:NT,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function S8(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),WG.hasOwnProperty(t)?{space:WG[t],local:e}:e}function Plt(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===NT&&t.documentElement.namespaceURI===NT?t.createElement(e):t.createElementNS(n,e)}}function Nlt(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function kle(e){var t=S8(e);return(t.local?Nlt:Plt)(t)}function $lt(){}function tI(e){return e==null?$lt:function(){return this.querySelector(e)}}function Llt(e){typeof e!="function"&&(e=tI(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=new Array(s),l,c,u=0;u<s;++u)(l=o[u])&&(c=e.call(l,l.__data__,u,o))&&("__data__"in l&&(c.__data__=l.__data__),a[u]=c);return new ca(r,this._parents)}function Flt(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function zlt(){return[]}function Ele(e){return e==null?zlt:function(){return this.querySelectorAll(e)}}function Blt(e){return function(){return Flt(e.apply(this,arguments))}}function Hlt(e){typeof e=="function"?e=Blt(e):e=Ele(e);for(var t=this._groups,n=t.length,r=[],i=[],o=0;o<n;++o)for(var s=t[o],a=s.length,l,c=0;c<a;++c)(l=s[c])&&(r.push(e.call(l,l.__data__,c,s)),i.push(l));return new ca(r,i)}function Ale(e){return function(){return this.matches(e)}}function Dle(e){return function(t){return t.matches(e)}}var Ult=Array.prototype.find;function Vlt(e){return function(){return Ult.call(this.children,e)}}function Wlt(){return this.firstElementChild}function qlt(e){return this.select(e==null?Wlt:Vlt(typeof e=="function"?e:Dle(e)))}var Klt=Array.prototype.filter;function Glt(){return Array.from(this.children)}function Ylt(e){return function(){return Klt.call(this.children,e)}}function Jlt(e){return this.selectAll(e==null?Glt:Ylt(typeof e=="function"?e:Dle(e)))}function Zlt(e){typeof e!="function"&&(e=Ale(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=[],l,c=0;c<s;++c)(l=o[c])&&e.call(l,l.__data__,c,o)&&a.push(l);return new ca(r,this._parents)}function _le(e){return new Array(e.length)}function Xlt(){return new ca(this._enter||this._groups.map(_le),this._parents)}function Jw(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Jw.prototype={constructor:Jw,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Qlt(e){return function(){return e}}function ect(e,t,n,r,i,o){for(var s=0,a,l=t.length,c=o.length;s<c;++s)(a=t[s])?(a.__data__=o[s],r[s]=a):n[s]=new Jw(e,o[s]);for(;s<l;++s)(a=t[s])&&(i[s]=a)}function tct(e,t,n,r,i,o,s){var a,l,c=new Map,u=t.length,d=o.length,p=new Array(u),g;for(a=0;a<u;++a)(l=t[a])&&(p[a]=g=s.call(l,l.__data__,a,t)+"",c.has(g)?i[a]=l:c.set(g,l));for(a=0;a<d;++a)g=s.call(e,o[a],a,o)+"",(l=c.get(g))?(r[a]=l,l.__data__=o[a],c.delete(g)):n[a]=new Jw(e,o[a]);for(a=0;a<u;++a)(l=t[a])&&c.get(p[a])===l&&(i[a]=l)}function nct(e){return e.__data__}function rct(e,t){if(!arguments.length)return Array.from(this,nct);var n=t?tct:ect,r=this._parents,i=this._groups;typeof e!="function"&&(e=Qlt(e));for(var o=i.length,s=new Array(o),a=new Array(o),l=new Array(o),c=0;c<o;++c){var u=r[c],d=i[c],p=d.length,g=ict(e.call(u,u&&u.__data__,c,r)),y=g.length,b=a[c]=new Array(y),v=s[c]=new Array(y),S=l[c]=new Array(p);n(u,d,b,v,S,g,t);for(var C=0,w=0,E,k;C<y;++C)if(E=b[C]){for(C>=w&&(w=C+1);!(k=v[w])&&++w<y;);E._next=k||null}}return s=new ca(s,r),s._enter=a,s._exit=l,s}function ict(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function oct(){return new ca(this._exit||this._groups.map(_le),this._parents)}function sct(e,t,n){var r=this.enter(),i=this,o=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(i=t(i),i&&(i=i.selection())),n==null?o.remove():n(o),r&&i?r.merge(i).order():i}function act(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,o=r.length,s=Math.min(i,o),a=new Array(i),l=0;l<s;++l)for(var c=n[l],u=r[l],d=c.length,p=a[l]=new Array(d),g,y=0;y<d;++y)(g=c[y]||u[y])&&(p[y]=g);for(;l<i;++l)a[l]=n[l];return new ca(a,this._parents)}function lct(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,o=r[i],s;--i>=0;)(s=r[i])&&(o&&s.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(s,o),o=s);return this}function cct(e){e||(e=uct);function t(d,p){return d&&p?e(d.__data__,p.__data__):!d-!p}for(var n=this._groups,r=n.length,i=new Array(r),o=0;o<r;++o){for(var s=n[o],a=s.length,l=i[o]=new Array(a),c,u=0;u<a;++u)(c=s[u])&&(l[u]=c);l.sort(t)}return new ca(i,this._parents).order()}function uct(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function dct(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function fct(){return Array.from(this)}function hct(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,o=r.length;i<o;++i){var s=r[i];if(s)return s}return null}function pct(){let e=0;for(const t of this)++e;return e}function mct(){return!this.node()}function gct(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],o=0,s=i.length,a;o<s;++o)(a=i[o])&&e.call(a,a.__data__,o,i);return this}function yct(e){return function(){this.removeAttribute(e)}}function bct(e){return function(){this.removeAttributeNS(e.space,e.local)}}function vct(e,t){return function(){this.setAttribute(e,t)}}function xct(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Sct(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function wct(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Cct(e,t){var n=S8(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?bct:yct:typeof t=="function"?n.local?wct:Sct:n.local?xct:vct)(n,t))}function Tle(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function kct(e){return function(){this.style.removeProperty(e)}}function Ect(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Act(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function Dct(e,t,n){return arguments.length>1?this.each((t==null?kct:typeof t=="function"?Act:Ect)(e,t,n??"")):Yg(this.node(),e)}function Yg(e,t){return e.style.getPropertyValue(t)||Tle(e).getComputedStyle(e,null).getPropertyValue(t)}function _ct(e){return function(){delete this[e]}}function Tct(e,t){return function(){this[e]=t}}function Oct(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Mct(e,t){return arguments.length>1?this.each((t==null?_ct:typeof t=="function"?Oct:Tct)(e,t)):this.node()[e]}function Ole(e){return e.trim().split(/^|\s+/)}function nI(e){return e.classList||new Mle(e)}function Mle(e){this._node=e,this._names=Ole(e.getAttribute("class")||"")}Mle.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function jle(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Rle(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function jct(e){return function(){jle(this,e)}}function Rct(e){return function(){Rle(this,e)}}function Ict(e,t){return function(){(t.apply(this,arguments)?jle:Rle)(this,e)}}function Pct(e,t){var n=Ole(e+"");if(arguments.length<2){for(var r=nI(this.node()),i=-1,o=n.length;++i<o;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t=="function"?Ict:t?jct:Rct)(n,t))}function Nct(){this.textContent=""}function $ct(e){return function(){this.textContent=e}}function Lct(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Fct(e){return arguments.length?this.each(e==null?Nct:(typeof e=="function"?Lct:$ct)(e)):this.node().textContent}function zct(){this.innerHTML=""}function Bct(e){return function(){this.innerHTML=e}}function Hct(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function Uct(e){return arguments.length?this.each(e==null?zct:(typeof e=="function"?Hct:Bct)(e)):this.node().innerHTML}function Vct(){this.nextSibling&&this.parentNode.appendChild(this)}function Wct(){return this.each(Vct)}function qct(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Kct(){return this.each(qct)}function Gct(e){var t=typeof e=="function"?e:kle(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Yct(){return null}function Jct(e,t){var n=typeof e=="function"?e:kle(e),r=t==null?Yct:typeof t=="function"?t:tI(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Zct(){var e=this.parentNode;e&&e.removeChild(this)}function Xct(){return this.each(Zct)}function Qct(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function eut(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function tut(e){return this.select(e?eut:Qct)}function nut(e){return arguments.length?this.property("__data__",e):this.node().__data__}function rut(e){return function(t){e.call(this,t,this.__data__)}}function iut(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function out(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,o;n<i;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++r]=o;++r?t.length=r:delete this.__on}}}function sut(e,t,n){return function(){var r=this.__on,i,o=rut(t);if(r){for(var s=0,a=r.length;s<a;++s)if((i=r[s]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=o,i.options=n),i.value=t;return}}this.addEventListener(e.type,o,n),i={type:e.type,name:e.name,value:t,listener:o,options:n},r?r.push(i):this.__on=[i]}}function aut(e,t,n){var r=iut(e+""),i,o=r.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,c=a.length,u;l<c;++l)for(i=0,u=a[l];i<o;++i)if((s=r[i]).type===u.type&&s.name===u.name)return u.value}return}for(a=t?sut:out,i=0;i<o;++i)this.each(a(r[i],t,n));return this}function Ile(e,t,n){var r=Tle(e),i=r.CustomEvent;typeof i=="function"?i=new i(t,n):(i=r.document.createEvent("Event"),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function lut(e,t){return function(){return Ile(this,e,t)}}function cut(e,t){return function(){return Ile(this,e,t.apply(this,arguments))}}function uut(e,t){return this.each((typeof t=="function"?cut:lut)(e,t))}function*dut(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,o=r.length,s;i<o;++i)(s=r[i])&&(yield s)}var Ple=[null];function ca(e,t){this._groups=e,this._parents=t}function _v(){return new ca([[document.documentElement]],Ple)}function fut(){return this}ca.prototype=_v.prototype={constructor:ca,select:Llt,selectAll:Hlt,selectChild:qlt,selectChildren:Jlt,filter:Zlt,data:rct,enter:Xlt,exit:oct,join:sct,merge:act,selection:fut,order:lct,sort:cct,call:dct,nodes:fct,node:hct,size:pct,empty:mct,each:gct,attr:Cct,style:Dct,property:Mct,classed:Pct,text:Fct,html:Uct,raise:Wct,lower:Kct,append:Gct,insert:Jct,remove:Xct,clone:tut,datum:nut,on:aut,dispatch:uut,[Symbol.iterator]:dut};function ea(e){return typeof e=="string"?new ca([[document.querySelector(e)]],[document.documentElement]):new ca([[e]],Ple)}function hut(e){let t;for(;t=e.sourceEvent;)e=t;return e}function sl(e,t){if(e=hut(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}const put={passive:!1},b2={capture:!0,passive:!1};function IA(e){e.stopImmediatePropagation()}function Sg(e){e.preventDefault(),e.stopImmediatePropagation()}function Nle(e){var t=e.document.documentElement,n=ea(e).on("dragstart.drag",Sg,b2);"onselectstart"in t?n.on("selectstart.drag",Sg,b2):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function $le(e,t){var n=e.document.documentElement,r=ea(e).on("dragstart.drag",null);t&&(r.on("click.drag",Sg,b2),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const K5=e=>()=>e;function $T(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:o,x:s,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}$T.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function mut(e){return!e.ctrlKey&&!e.button}function gut(){return this.parentNode}function yut(e,t){return t??{x:e.x,y:e.y}}function but(){return navigator.maxTouchPoints||"ontouchstart"in this}function Lle(){var e=mut,t=gut,n=yut,r=but,i={},o=x8("start","drag","end"),s=0,a,l,c,u,d=0;function p(E){E.on("mousedown.drag",g).filter(r).on("touchstart.drag",v).on("touchmove.drag",S,put).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(E,k){if(!(u||!e.call(this,E,k))){var T=w(this,t.call(this,E,k),E,k,"mouse");T&&(ea(E.view).on("mousemove.drag",y,b2).on("mouseup.drag",b,b2),Nle(E.view),IA(E),c=!1,a=E.clientX,l=E.clientY,T("start",E))}}function y(E){if(Sg(E),!c){var k=E.clientX-a,T=E.clientY-l;c=k*k+T*T>d}i.mouse("drag",E)}function b(E){ea(E.view).on("mousemove.drag mouseup.drag",null),$le(E.view,c),Sg(E),i.mouse("end",E)}function v(E,k){if(e.call(this,E,k)){var T=E.changedTouches,_=t.call(this,E,k),O=T.length,R,P;for(R=0;R<O;++R)(P=w(this,_,E,k,T[R].identifier,T[R]))&&(IA(E),P("start",E,T[R]))}}function S(E){var k=E.changedTouches,T=k.length,_,O;for(_=0;_<T;++_)(O=i[k[_].identifier])&&(Sg(E),O("drag",E,k[_]))}function C(E){var k=E.changedTouches,T=k.length,_,O;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),_=0;_<T;++_)(O=i[k[_].identifier])&&(IA(E),O("end",E,k[_]))}function w(E,k,T,_,O,R){var P=o.copy(),L=sl(R||T,k),M,N,$;if(($=n.call(E,new $T("beforestart",{sourceEvent:T,target:p,identifier:O,active:s,x:L[0],y:L[1],dx:0,dy:0,dispatch:P}),_))!=null)return M=$.x-L[0]||0,N=$.y-L[1]||0,function B(F,V,W){var q=L,Z;switch(F){case"start":i[O]=B,Z=s++;break;case"end":delete i[O],--s;case"drag":L=sl(W||V,k),Z=s;break}P.call(F,E,new $T(F,{sourceEvent:V,subject:$,target:p,identifier:O,active:Z,x:L[0]+M,y:L[1]+N,dx:L[0]-q[0],dy:L[1]-q[1],dispatch:P}),_)}}return p.filter=function(E){return arguments.length?(e=typeof E=="function"?E:K5(!!E),p):e},p.container=function(E){return arguments.length?(t=typeof E=="function"?E:K5(E),p):t},p.subject=function(E){return arguments.length?(n=typeof E=="function"?E:K5(E),p):n},p.touchable=function(E){return arguments.length?(r=typeof E=="function"?E:K5(!!E),p):r},p.on=function(){var E=o.on.apply(o,arguments);return E===o?p:E},p.clickDistance=function(E){return arguments.length?(d=(E=+E)*E,p):Math.sqrt(d)},p}function rI(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Fle(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Tv(){}var v2=.7,Zw=1/v2,wg="\\s*([+-]?\\d+)\\s*",x2="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",_c="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",vut=/^#([0-9a-f]{3,8})$/,xut=new RegExp(`^rgb\\(${wg},${wg},${wg}\\)$`),Sut=new RegExp(`^rgb\\(${_c},${_c},${_c}\\)$`),wut=new RegExp(`^rgba\\(${wg},${wg},${wg},${x2}\\)$`),Cut=new RegExp(`^rgba\\(${_c},${_c},${_c},${x2}\\)$`),kut=new RegExp(`^hsl\\(${x2},${_c},${_c}\\)$`),Eut=new RegExp(`^hsla\\(${x2},${_c},${_c},${x2}\\)$`),qG={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};rI(Tv,dp,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:KG,formatHex:KG,formatHex8:Aut,formatHsl:Dut,formatRgb:GG,toString:GG});function KG(){return this.rgb().formatHex()}function Aut(){return this.rgb().formatHex8()}function Dut(){return zle(this).formatHsl()}function GG(){return this.rgb().formatRgb()}function dp(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=vut.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?YG(t):n===3?new ks(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?G5(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?G5(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=xut.exec(e))?new ks(t[1],t[2],t[3],1):(t=Sut.exec(e))?new ks(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=wut.exec(e))?G5(t[1],t[2],t[3],t[4]):(t=Cut.exec(e))?G5(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=kut.exec(e))?XG(t[1],t[2]/100,t[3]/100,1):(t=Eut.exec(e))?XG(t[1],t[2]/100,t[3]/100,t[4]):qG.hasOwnProperty(e)?YG(qG[e]):e==="transparent"?new ks(NaN,NaN,NaN,0):null}function YG(e){return new ks(e>>16&255,e>>8&255,e&255,1)}function G5(e,t,n,r){return r<=0&&(e=t=n=NaN),new ks(e,t,n,r)}function _ut(e){return e instanceof Tv||(e=dp(e)),e?(e=e.rgb(),new ks(e.r,e.g,e.b,e.opacity)):new ks}function LT(e,t,n,r){return arguments.length===1?_ut(e):new ks(e,t,n,r??1)}function ks(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}rI(ks,LT,Fle(Tv,{brighter(e){return e=e==null?Zw:Math.pow(Zw,e),new ks(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?v2:Math.pow(v2,e),new ks(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new ks(qh(this.r),qh(this.g),qh(this.b),Xw(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:JG,formatHex:JG,formatHex8:Tut,formatRgb:ZG,toString:ZG}));function JG(){return`#${Bh(this.r)}${Bh(this.g)}${Bh(this.b)}`}function Tut(){return`#${Bh(this.r)}${Bh(this.g)}${Bh(this.b)}${Bh((isNaN(this.opacity)?1:this.opacity)*255)}`}function ZG(){const e=Xw(this.opacity);return`${e===1?"rgb(":"rgba("}${qh(this.r)}, ${qh(this.g)}, ${qh(this.b)}${e===1?")":`, ${e})`}`}function Xw(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function qh(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Bh(e){return e=qh(e),(e<16?"0":"")+e.toString(16)}function XG(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new ul(e,t,n,r)}function zle(e){if(e instanceof ul)return new ul(e.h,e.s,e.l,e.opacity);if(e instanceof Tv||(e=dp(e)),!e)return new ul;if(e instanceof ul)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),o=Math.max(t,n,r),s=NaN,a=o-i,l=(o+i)/2;return a?(t===o?s=(n-r)/a+(n<r)*6:n===o?s=(r-t)/a+2:s=(t-n)/a+4,a/=l<.5?o+i:2-o-i,s*=60):a=l>0&&l<1?0:s,new ul(s,a,l,e.opacity)}function Out(e,t,n,r){return arguments.length===1?zle(e):new ul(e,t,n,r??1)}function ul(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}rI(ul,Out,Fle(Tv,{brighter(e){return e=e==null?Zw:Math.pow(Zw,e),new ul(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?v2:Math.pow(v2,e),new ul(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new ks(PA(e>=240?e-240:e+120,i,r),PA(e,i,r),PA(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new ul(QG(this.h),Y5(this.s),Y5(this.l),Xw(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Xw(this.opacity);return`${e===1?"hsl(":"hsla("}${QG(this.h)}, ${Y5(this.s)*100}%, ${Y5(this.l)*100}%${e===1?")":`, ${e})`}`}}));function QG(e){return e=(e||0)%360,e<0?e+360:e}function Y5(e){return Math.max(0,Math.min(1,e||0))}function PA(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const iI=e=>()=>e;function Mut(e,t){return function(n){return e+n*t}}function jut(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Rut(e){return(e=+e)==1?Ble:function(t,n){return n-t?jut(t,n,e):iI(isNaN(t)?n:t)}}function Ble(e,t){var n=t-e;return n?Mut(e,n):iI(isNaN(e)?t:e)}const Qw=(function e(t){var n=Rut(t);function r(i,o){var s=n((i=LT(i)).r,(o=LT(o)).r),a=n(i.g,o.g),l=n(i.b,o.b),c=Ble(i.opacity,o.opacity);return function(u){return i.r=s(u),i.g=a(u),i.b=l(u),i.opacity=c(u),i+""}}return r.gamma=e,r})(1);function Iut(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(o){for(i=0;i<n;++i)r[i]=e[i]*(1-o)+t[i]*o;return r}}function Put(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Nut(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=new Array(r),o=new Array(n),s;for(s=0;s<r;++s)i[s]=ib(e[s],t[s]);for(;s<n;++s)o[s]=t[s];return function(a){for(s=0;s<r;++s)o[s]=i[s](a);return o}}function $ut(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function tc(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Lut(e,t){var n={},r={},i;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(i in t)i in e?n[i]=ib(e[i],t[i]):r[i]=t[i];return function(o){for(i in n)r[i]=n[i](o);return r}}var FT=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,NA=new RegExp(FT.source,"g");function Fut(e){return function(){return e}}function zut(e){return function(t){return e(t)+""}}function Hle(e,t){var n=FT.lastIndex=NA.lastIndex=0,r,i,o,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=FT.exec(e))&&(i=NA.exec(t));)(o=i.index)>n&&(o=t.slice(n,o),a[s]?a[s]+=o:a[++s]=o),(r=r[0])===(i=i[0])?a[s]?a[s]+=i:a[++s]=i:(a[++s]=null,l.push({i:s,x:tc(r,i)})),n=NA.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?l[0]?zut(l[0].x):Fut(t):(t=l.length,function(c){for(var u=0,d;u<t;++u)a[(d=l[u]).i]=d.x(c);return a.join("")})}function ib(e,t){var n=typeof t,r;return t==null||n==="boolean"?iI(t):(n==="number"?tc:n==="string"?(r=dp(t))?(t=r,Qw):Hle:t instanceof dp?Qw:t instanceof Date?$ut:Put(t)?Iut:Array.isArray(t)?Nut:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Lut:tc)(e,t)}var eY=180/Math.PI,zT={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Ule(e,t,n,r,i,o){var s,a,l;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(l=e*n+t*r)&&(n-=e*l,r-=t*l),(a=Math.sqrt(n*n+r*r))&&(n/=a,r/=a,l/=a),e*r<t*n&&(e=-e,t=-t,l=-l,s=-s),{translateX:i,translateY:o,rotate:Math.atan2(t,e)*eY,skewX:Math.atan(l)*eY,scaleX:s,scaleY:a}}var J5;function But(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?zT:Ule(t.a,t.b,t.c,t.d,t.e,t.f)}function Hut(e){return e==null||(J5||(J5=document.createElementNS("http://www.w3.org/2000/svg","g")),J5.setAttribute("transform",e),!(e=J5.transform.baseVal.consolidate()))?zT:(e=e.matrix,Ule(e.a,e.b,e.c,e.d,e.e,e.f))}function Vle(e,t,n,r){function i(c){return c.length?c.pop()+" ":""}function o(c,u,d,p,g,y){if(c!==d||u!==p){var b=g.push("translate(",null,t,null,n);y.push({i:b-4,x:tc(c,d)},{i:b-2,x:tc(u,p)})}else(d||p)&&g.push("translate("+d+t+p+n)}function s(c,u,d,p){c!==u?(c-u>180?u+=360:u-c>180&&(c+=360),p.push({i:d.push(i(d)+"rotate(",null,r)-2,x:tc(c,u)})):u&&d.push(i(d)+"rotate("+u+r)}function a(c,u,d,p){c!==u?p.push({i:d.push(i(d)+"skewX(",null,r)-2,x:tc(c,u)}):u&&d.push(i(d)+"skewX("+u+r)}function l(c,u,d,p,g,y){if(c!==d||u!==p){var b=g.push(i(g)+"scale(",null,",",null,")");y.push({i:b-4,x:tc(c,d)},{i:b-2,x:tc(u,p)})}else(d!==1||p!==1)&&g.push(i(g)+"scale("+d+","+p+")")}return function(c,u){var d=[],p=[];return c=e(c),u=e(u),o(c.translateX,c.translateY,u.translateX,u.translateY,d,p),s(c.rotate,u.rotate,d,p),a(c.skewX,u.skewX,d,p),l(c.scaleX,c.scaleY,u.scaleX,u.scaleY,d,p),c=u=null,function(g){for(var y=-1,b=p.length,v;++y<b;)d[(v=p[y]).i]=v.x(g);return d.join("")}}}var Uut=Vle(But,"px, ","px)","deg)"),Vut=Vle(Hut,", ",")",")"),Wut=1e-12;function tY(e){return((e=Math.exp(e))+1/e)/2}function qut(e){return((e=Math.exp(e))-1/e)/2}function Kut(e){return((e=Math.exp(2*e))-1)/(e+1)}const n4=(function e(t,n,r){function i(o,s){var a=o[0],l=o[1],c=o[2],u=s[0],d=s[1],p=s[2],g=u-a,y=d-l,b=g*g+y*y,v,S;if(b<Wut)S=Math.log(p/c)/t,v=function(_){return[a+_*g,l+_*y,c*Math.exp(t*_*S)]};else{var C=Math.sqrt(b),w=(p*p-c*c+r*b)/(2*c*n*C),E=(p*p-c*c-r*b)/(2*p*n*C),k=Math.log(Math.sqrt(w*w+1)-w),T=Math.log(Math.sqrt(E*E+1)-E);S=(T-k)/t,v=function(_){var O=_*S,R=tY(k),P=c/(n*C)*(R*Kut(t*O+k)-qut(k));return[a+P*g,l+P*y,c*R/tY(t*O+k)]}}return v.duration=S*1e3*t/Math.SQRT2,v}return i.rho=function(o){var s=Math.max(.001,+o),a=s*s,l=a*a;return e(s,a,l)},i})(Math.SQRT2,2,4);var Jg=0,Cy=0,ny=0,Wle=1e3,e6,ky,t6=0,fp=0,w8=0,S2=typeof performance=="object"&&performance.now?performance:Date,qle=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function oI(){return fp||(qle(Gut),fp=S2.now()+w8)}function Gut(){fp=0}function n6(){this._call=this._time=this._next=null}n6.prototype=Kle.prototype={constructor:n6,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?oI():+n)+(t==null?0:+t),!this._next&&ky!==this&&(ky?ky._next=this:e6=this,ky=this),this._call=e,this._time=n,BT()},stop:function(){this._call&&(this._call=null,this._time=1/0,BT())}};function Kle(e,t,n){var r=new n6;return r.restart(e,t,n),r}function Yut(){oI(),++Jg;for(var e=e6,t;e;)(t=fp-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Jg}function nY(){fp=(t6=S2.now())+w8,Jg=Cy=0;try{Yut()}finally{Jg=0,Zut(),fp=0}}function Jut(){var e=S2.now(),t=e-t6;t>Wle&&(w8-=t,t6=e)}function Zut(){for(var e,t=e6,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:e6=n);ky=e,BT(r)}function BT(e){if(!Jg){Cy&&(Cy=clearTimeout(Cy));var t=e-fp;t>24?(e<1/0&&(Cy=setTimeout(nY,e-S2.now()-w8)),ny&&(ny=clearInterval(ny))):(ny||(t6=S2.now(),ny=setInterval(Jut,Wle)),Jg=1,qle(nY))}}function rY(e,t,n){var r=new n6;return t=t==null?0:+t,r.restart(i=>{r.stop(),e(i+t)},t,n),r}var Xut=x8("start","end","cancel","interrupt"),Qut=[],Gle=0,iY=1,HT=2,r4=3,oY=4,UT=5,i4=6;function C8(e,t,n,r,i,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;edt(e,n,{name:t,index:r,group:i,on:Xut,tween:Qut,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:Gle})}function sI(e,t){var n=Il(e,t);if(n.state>Gle)throw new Error("too late; already scheduled");return n}function Wc(e,t){var n=Il(e,t);if(n.state>r4)throw new Error("too late; already running");return n}function Il(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function edt(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Kle(o,0,n.time);function o(c){n.state=iY,n.timer.restart(s,n.delay,n.time),n.delay<=c&&s(c-n.delay)}function s(c){var u,d,p,g;if(n.state!==iY)return l();for(u in r)if(g=r[u],g.name===n.name){if(g.state===r4)return rY(s);g.state===oY?(g.state=i4,g.timer.stop(),g.on.call("interrupt",e,e.__data__,g.index,g.group),delete r[u]):+u<t&&(g.state=i4,g.timer.stop(),g.on.call("cancel",e,e.__data__,g.index,g.group),delete r[u])}if(rY(function(){n.state===r4&&(n.state=oY,n.timer.restart(a,n.delay,n.time),a(c))}),n.state=HT,n.on.call("start",e,e.__data__,n.index,n.group),n.state===HT){for(n.state=r4,i=new Array(p=n.tween.length),u=0,d=-1;u<p;++u)(g=n.tween[u].value.call(e,e.__data__,n.index,n.group))&&(i[++d]=g);i.length=d+1}}function a(c){for(var u=c<n.duration?n.ease.call(null,c/n.duration):(n.timer.restart(l),n.state=UT,1),d=-1,p=i.length;++d<p;)i[d].call(e,u);n.state===UT&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=i4,n.timer.stop(),delete r[t];for(var c in r)return;delete e.__transition}}function o4(e,t){var n=e.__transition,r,i,o=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((r=n[s]).name!==t){o=!1;continue}i=r.state>HT&&r.state<UT,r.state=i4,r.timer.stop(),r.on.call(i?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}o&&delete e.__transition}}function tdt(e){return this.each(function(){o4(this,e)})}function ndt(e,t){var n,r;return function(){var i=Wc(this,e),o=i.tween;if(o!==n){r=n=o;for(var s=0,a=r.length;s<a;++s)if(r[s].name===t){r=r.slice(),r.splice(s,1);break}}i.tween=r}}function rdt(e,t,n){var r,i;if(typeof n!="function")throw new Error;return function(){var o=Wc(this,e),s=o.tween;if(s!==r){i=(r=s).slice();for(var a={name:t,value:n},l=0,c=i.length;l<c;++l)if(i[l].name===t){i[l]=a;break}l===c&&i.push(a)}o.tween=i}}function idt(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=Il(this.node(),n).tween,i=0,o=r.length,s;i<o;++i)if((s=r[i]).name===e)return s.value;return null}return this.each((t==null?ndt:rdt)(n,e,t))}function aI(e,t,n){var r=e._id;return e.each(function(){var i=Wc(this,r);(i.value||(i.value={}))[t]=n.apply(this,arguments)}),function(i){return Il(i,r).value[t]}}function Yle(e,t){var n;return(typeof t=="number"?tc:t instanceof dp?Qw:(n=dp(t))?(t=n,Qw):Hle)(e,t)}function odt(e){return function(){this.removeAttribute(e)}}function sdt(e){return function(){this.removeAttributeNS(e.space,e.local)}}function adt(e,t,n){var r,i=n+"",o;return function(){var s=this.getAttribute(e);return s===i?null:s===r?o:o=t(r=s,n)}}function ldt(e,t,n){var r,i=n+"",o;return function(){var s=this.getAttributeNS(e.space,e.local);return s===i?null:s===r?o:o=t(r=s,n)}}function cdt(e,t,n){var r,i,o;return function(){var s,a=n(this),l;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),l=a+"",s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a)))}}function udt(e,t,n){var r,i,o;return function(){var s,a=n(this),l;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),l=a+"",s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a)))}}function ddt(e,t){var n=S8(e),r=n==="transform"?Vut:Yle;return this.attrTween(e,typeof t=="function"?(n.local?udt:cdt)(n,r,aI(this,"attr."+e,t)):t==null?(n.local?sdt:odt)(n):(n.local?ldt:adt)(n,r,t))}function fdt(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function hdt(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function pdt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&hdt(e,o)),n}return i._value=t,i}function mdt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&fdt(e,o)),n}return i._value=t,i}function gdt(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=S8(e);return this.tween(n,(r.local?pdt:mdt)(r,t))}function ydt(e,t){return function(){sI(this,e).delay=+t.apply(this,arguments)}}function bdt(e,t){return t=+t,function(){sI(this,e).delay=t}}function vdt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?ydt:bdt)(t,e)):Il(this.node(),t).delay}function xdt(e,t){return function(){Wc(this,e).duration=+t.apply(this,arguments)}}function Sdt(e,t){return t=+t,function(){Wc(this,e).duration=t}}function wdt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?xdt:Sdt)(t,e)):Il(this.node(),t).duration}function Cdt(e,t){if(typeof t!="function")throw new Error;return function(){Wc(this,e).ease=t}}function kdt(e){var t=this._id;return arguments.length?this.each(Cdt(t,e)):Il(this.node(),t).ease}function Edt(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Wc(this,e).ease=n}}function Adt(e){if(typeof e!="function")throw new Error;return this.each(Edt(this._id,e))}function Ddt(e){typeof e!="function"&&(e=Ale(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=[],l,c=0;c<s;++c)(l=o[c])&&e.call(l,l.__data__,c,o)&&a.push(l);return new Gu(r,this._parents,this._name,this._id)}function _dt(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,i=n.length,o=Math.min(r,i),s=new Array(r),a=0;a<o;++a)for(var l=t[a],c=n[a],u=l.length,d=s[a]=new Array(u),p,g=0;g<u;++g)(p=l[g]||c[g])&&(d[g]=p);for(;a<r;++a)s[a]=t[a];return new Gu(s,this._parents,this._name,this._id)}function Tdt(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function Odt(e,t,n){var r,i,o=Tdt(t)?sI:Wc;return function(){var s=o(this,e),a=s.on;a!==r&&(i=(r=a).copy()).on(t,n),s.on=i}}function Mdt(e,t){var n=this._id;return arguments.length<2?Il(this.node(),n).on.on(e):this.each(Odt(n,e,t))}function jdt(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Rdt(){return this.on("end.remove",jdt(this._id))}function Idt(e){var t=this._name,n=this._id;typeof e!="function"&&(e=tI(e));for(var r=this._groups,i=r.length,o=new Array(i),s=0;s<i;++s)for(var a=r[s],l=a.length,c=o[s]=new Array(l),u,d,p=0;p<l;++p)(u=a[p])&&(d=e.call(u,u.__data__,p,a))&&("__data__"in u&&(d.__data__=u.__data__),c[p]=d,C8(c[p],t,n,p,c,Il(u,n)));return new Gu(o,this._parents,t,n)}function Pdt(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ele(e));for(var r=this._groups,i=r.length,o=[],s=[],a=0;a<i;++a)for(var l=r[a],c=l.length,u,d=0;d<c;++d)if(u=l[d]){for(var p=e.call(u,u.__data__,d,l),g,y=Il(u,n),b=0,v=p.length;b<v;++b)(g=p[b])&&C8(g,t,n,b,p,y);o.push(p),s.push(u)}return new Gu(o,s,t,n)}var Ndt=_v.prototype.constructor;function $dt(){return new Ndt(this._groups,this._parents)}function Ldt(e,t){var n,r,i;return function(){var o=Yg(this,e),s=(this.style.removeProperty(e),Yg(this,e));return o===s?null:o===n&&s===r?i:i=t(n=o,r=s)}}function Jle(e){return function(){this.style.removeProperty(e)}}function Fdt(e,t,n){var r,i=n+"",o;return function(){var s=Yg(this,e);return s===i?null:s===r?o:o=t(r=s,n)}}function zdt(e,t,n){var r,i,o;return function(){var s=Yg(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),Yg(this,e))),s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a))}}function Bdt(e,t){var n,r,i,o="style."+t,s="end."+o,a;return function(){var l=Wc(this,e),c=l.on,u=l.value[o]==null?a||(a=Jle(t)):void 0;(c!==n||i!==u)&&(r=(n=c).copy()).on(s,i=u),l.on=r}}function Hdt(e,t,n){var r=(e+="")=="transform"?Uut:Yle;return t==null?this.styleTween(e,Ldt(e,r)).on("end.style."+e,Jle(e)):typeof t=="function"?this.styleTween(e,zdt(e,r,aI(this,"style."+e,t))).each(Bdt(this._id,e)):this.styleTween(e,Fdt(e,r,t),n).on("end.style."+e,null)}function Udt(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Vdt(e,t,n){var r,i;function o(){var s=t.apply(this,arguments);return s!==i&&(r=(i=s)&&Udt(e,s,n)),r}return o._value=t,o}function Wdt(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,Vdt(e,t,n??""))}function qdt(e){return function(){this.textContent=e}}function Kdt(e){return function(){var t=e(this);this.textContent=t??""}}function Gdt(e){return this.tween("text",typeof e=="function"?Kdt(aI(this,"text",e)):qdt(e==null?"":e+""))}function Ydt(e){return function(t){this.textContent=e.call(this,t)}}function Jdt(e){var t,n;function r(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&Ydt(i)),t}return r._value=e,r}function Zdt(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,Jdt(e))}function Xdt(){for(var e=this._name,t=this._id,n=Zle(),r=this._groups,i=r.length,o=0;o<i;++o)for(var s=r[o],a=s.length,l,c=0;c<a;++c)if(l=s[c]){var u=Il(l,t);C8(l,e,n,c,s,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new Gu(r,this._parents,e,n)}function Qdt(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(o,s){var a={value:s},l={value:function(){--i===0&&o()}};n.each(function(){var c=Wc(this,r),u=c.on;u!==e&&(t=(e=u).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(l)),c.on=t}),i===0&&o()})}var eft=0;function Gu(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Zle(){return++eft}var bu=_v.prototype;Gu.prototype={constructor:Gu,select:Idt,selectAll:Pdt,selectChild:bu.selectChild,selectChildren:bu.selectChildren,filter:Ddt,merge:_dt,selection:$dt,transition:Xdt,call:bu.call,nodes:bu.nodes,node:bu.node,size:bu.size,empty:bu.empty,each:bu.each,on:Mdt,attr:ddt,attrTween:gdt,style:Hdt,styleTween:Wdt,text:Gdt,textTween:Zdt,remove:Rdt,tween:idt,delay:vdt,duration:wdt,ease:kdt,easeVarying:Adt,end:Qdt,[Symbol.iterator]:bu[Symbol.iterator]};function tft(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var nft={time:null,delay:0,duration:250,ease:tft};function rft(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function ift(e){var t,n;e instanceof Gu?(t=e._id,e=e._name):(t=Zle(),(n=nft).time=oI(),e=e==null?null:e+"");for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var s=r[o],a=s.length,l,c=0;c<a;++c)(l=s[c])&&C8(l,e,t,c,s,n||rft(l,t));return new Gu(r,this._parents,e,t)}_v.prototype.interrupt=tdt;_v.prototype.transition=ift;const Z5=e=>()=>e;function oft(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function Ou(e,t,n){this.k=e,this.x=t,this.y=n}Ou.prototype={constructor:Ou,scale:function(e){return e===1?this:new Ou(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Ou(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var k8=new Ou(1,0,0);Xle.prototype=Ou.prototype;function Xle(e){for(;!e.__zoom;)if(!(e=e.parentNode))return k8;return e.__zoom}function $A(e){e.stopImmediatePropagation()}function ry(e){e.preventDefault(),e.stopImmediatePropagation()}function sft(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function aft(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function sY(){return this.__zoom||k8}function lft(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function cft(){return navigator.maxTouchPoints||"ontouchstart"in this}function uft(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],s=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),s>o?(o+s)/2:Math.min(0,o)||Math.max(0,s))}function Qle(){var e=sft,t=aft,n=uft,r=lft,i=cft,o=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,l=n4,c=x8("start","zoom","end"),u,d,p,g=500,y=150,b=0,v=10;function S($){$.property("__zoom",sY).on("wheel.zoom",O,{passive:!1}).on("mousedown.zoom",R).on("dblclick.zoom",P).filter(i).on("touchstart.zoom",L).on("touchmove.zoom",M).on("touchend.zoom touchcancel.zoom",N).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}S.transform=function($,B,F,V){var W=$.selection?$.selection():$;W.property("__zoom",sY),$!==W?k($,B,F,V):W.interrupt().each(function(){T(this,arguments).event(V).start().zoom(null,typeof B=="function"?B.apply(this,arguments):B).end()})},S.scaleBy=function($,B,F,V){S.scaleTo($,function(){var W=this.__zoom.k,q=typeof B=="function"?B.apply(this,arguments):B;return W*q},F,V)},S.scaleTo=function($,B,F,V){S.transform($,function(){var W=t.apply(this,arguments),q=this.__zoom,Z=F==null?E(W):typeof F=="function"?F.apply(this,arguments):F,z=q.invert(Z),U=typeof B=="function"?B.apply(this,arguments):B;return n(w(C(q,U),Z,z),W,s)},F,V)},S.translateBy=function($,B,F,V){S.transform($,function(){return n(this.__zoom.translate(typeof B=="function"?B.apply(this,arguments):B,typeof F=="function"?F.apply(this,arguments):F),t.apply(this,arguments),s)},null,V)},S.translateTo=function($,B,F,V,W){S.transform($,function(){var q=t.apply(this,arguments),Z=this.__zoom,z=V==null?E(q):typeof V=="function"?V.apply(this,arguments):V;return n(k8.translate(z[0],z[1]).scale(Z.k).translate(typeof B=="function"?-B.apply(this,arguments):-B,typeof F=="function"?-F.apply(this,arguments):-F),q,s)},V,W)};function C($,B){return B=Math.max(o[0],Math.min(o[1],B)),B===$.k?$:new Ou(B,$.x,$.y)}function w($,B,F){var V=B[0]-F[0]*$.k,W=B[1]-F[1]*$.k;return V===$.x&&W===$.y?$:new Ou($.k,V,W)}function E($){return[(+$[0][0]+ +$[1][0])/2,(+$[0][1]+ +$[1][1])/2]}function k($,B,F,V){$.on("start.zoom",function(){T(this,arguments).event(V).start()}).on("interrupt.zoom end.zoom",function(){T(this,arguments).event(V).end()}).tween("zoom",function(){var W=this,q=arguments,Z=T(W,q).event(V),z=t.apply(W,q),U=F==null?E(z):typeof F=="function"?F.apply(W,q):F,Y=Math.max(z[1][0]-z[0][0],z[1][1]-z[0][1]),H=W.__zoom,K=typeof B=="function"?B.apply(W,q):B,Q=l(H.invert(U).concat(Y/H.k),K.invert(U).concat(Y/K.k));return function(ie){if(ie===1)ie=K;else{var te=Q(ie),ce=Y/te[2];ie=new Ou(ce,U[0]-te[0]*ce,U[1]-te[1]*ce)}Z.zoom(null,ie)}})}function T($,B,F){return!F&&$.__zooming||new _($,B)}function _($,B){this.that=$,this.args=B,this.active=0,this.sourceEvent=null,this.extent=t.apply($,B),this.taps=0}_.prototype={event:function($){return $&&(this.sourceEvent=$),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function($,B){return this.mouse&&$!=="mouse"&&(this.mouse[1]=B.invert(this.mouse[0])),this.touch0&&$!=="touch"&&(this.touch0[1]=B.invert(this.touch0[0])),this.touch1&&$!=="touch"&&(this.touch1[1]=B.invert(this.touch1[0])),this.that.__zoom=B,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function($){var B=ea(this.that).datum();c.call($,this.that,new oft($,{sourceEvent:this.sourceEvent,target:S,transform:this.that.__zoom,dispatch:c}),B)}};function O($,...B){if(!e.apply(this,arguments))return;var F=T(this,B).event($),V=this.__zoom,W=Math.max(o[0],Math.min(o[1],V.k*Math.pow(2,r.apply(this,arguments)))),q=sl($);if(F.wheel)(F.mouse[0][0]!==q[0]||F.mouse[0][1]!==q[1])&&(F.mouse[1]=V.invert(F.mouse[0]=q)),clearTimeout(F.wheel);else{if(V.k===W)return;F.mouse=[q,V.invert(q)],o4(this),F.start()}ry($),F.wheel=setTimeout(Z,y),F.zoom("mouse",n(w(C(V,W),F.mouse[0],F.mouse[1]),F.extent,s));function Z(){F.wheel=null,F.end()}}function R($,...B){if(p||!e.apply(this,arguments))return;var F=$.currentTarget,V=T(this,B,!0).event($),W=ea($.view).on("mousemove.zoom",U,!0).on("mouseup.zoom",Y,!0),q=sl($,F),Z=$.clientX,z=$.clientY;Nle($.view),$A($),V.mouse=[q,this.__zoom.invert(q)],o4(this),V.start();function U(H){if(ry(H),!V.moved){var K=H.clientX-Z,Q=H.clientY-z;V.moved=K*K+Q*Q>b}V.event(H).zoom("mouse",n(w(V.that.__zoom,V.mouse[0]=sl(H,F),V.mouse[1]),V.extent,s))}function Y(H){W.on("mousemove.zoom mouseup.zoom",null),$le(H.view,V.moved),ry(H),V.event(H).end()}}function P($,...B){if(e.apply(this,arguments)){var F=this.__zoom,V=sl($.changedTouches?$.changedTouches[0]:$,this),W=F.invert(V),q=F.k*($.shiftKey?.5:2),Z=n(w(C(F,q),V,W),t.apply(this,B),s);ry($),a>0?ea(this).transition().duration(a).call(k,Z,V,$):ea(this).call(S.transform,Z,V,$)}}function L($,...B){if(e.apply(this,arguments)){var F=$.touches,V=F.length,W=T(this,B,$.changedTouches.length===V).event($),q,Z,z,U;for($A($),Z=0;Z<V;++Z)z=F[Z],U=sl(z,this),U=[U,this.__zoom.invert(U),z.identifier],W.touch0?!W.touch1&&W.touch0[2]!==U[2]&&(W.touch1=U,W.taps=0):(W.touch0=U,q=!0,W.taps=1+!!u);u&&(u=clearTimeout(u)),q&&(W.taps<2&&(d=U[0],u=setTimeout(function(){u=null},g)),o4(this),W.start())}}function M($,...B){if(this.__zooming){var F=T(this,B).event($),V=$.changedTouches,W=V.length,q,Z,z,U;for(ry($),q=0;q<W;++q)Z=V[q],z=sl(Z,this),F.touch0&&F.touch0[2]===Z.identifier?F.touch0[0]=z:F.touch1&&F.touch1[2]===Z.identifier&&(F.touch1[0]=z);if(Z=F.that.__zoom,F.touch1){var Y=F.touch0[0],H=F.touch0[1],K=F.touch1[0],Q=F.touch1[1],ie=(ie=K[0]-Y[0])*ie+(ie=K[1]-Y[1])*ie,te=(te=Q[0]-H[0])*te+(te=Q[1]-H[1])*te;Z=C(Z,Math.sqrt(ie/te)),z=[(Y[0]+K[0])/2,(Y[1]+K[1])/2],U=[(H[0]+Q[0])/2,(H[1]+Q[1])/2]}else if(F.touch0)z=F.touch0[0],U=F.touch0[1];else return;F.zoom("touch",n(w(Z,z,U),F.extent,s))}}function N($,...B){if(this.__zooming){var F=T(this,B).event($),V=$.changedTouches,W=V.length,q,Z;for($A($),p&&clearTimeout(p),p=setTimeout(function(){p=null},g),q=0;q<W;++q)Z=V[q],F.touch0&&F.touch0[2]===Z.identifier?delete F.touch0:F.touch1&&F.touch1[2]===Z.identifier&&delete F.touch1;if(F.touch1&&!F.touch0&&(F.touch0=F.touch1,delete F.touch1),F.touch0)F.touch0[1]=this.__zoom.invert(F.touch0[0]);else if(F.end(),F.taps===2&&(Z=sl(Z,this),Math.hypot(d[0]-Z[0],d[1]-Z[1])<v)){var z=ea(this).on("dblclick.zoom");z&&z.apply(this,arguments)}}}return S.wheelDelta=function($){return arguments.length?(r=typeof $=="function"?$:Z5(+$),S):r},S.filter=function($){return arguments.length?(e=typeof $=="function"?$:Z5(!!$),S):e},S.touchable=function($){return arguments.length?(i=typeof $=="function"?$:Z5(!!$),S):i},S.extent=function($){return arguments.length?(t=typeof $=="function"?$:Z5([[+$[0][0],+$[0][1]],[+$[1][0],+$[1][1]]]),S):t},S.scaleExtent=function($){return arguments.length?(o[0]=+$[0],o[1]=+$[1],S):[o[0],o[1]]},S.translateExtent=function($){return arguments.length?(s[0][0]=+$[0][0],s[1][0]=+$[1][0],s[0][1]=+$[0][1],s[1][1]=+$[1][1],S):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},S.constrain=function($){return arguments.length?(n=$,S):n},S.duration=function($){return arguments.length?(a=+$,S):a},S.interpolate=function($){return arguments.length?(l=$,S):l},S.on=function(){var $=c.on.apply(c,arguments);return $===c?S:$},S.clickDistance=function($){return arguments.length?(b=($=+$)*$,S):Math.sqrt(b)},S.tapDistance=function($){return arguments.length?(v=+$,S):v},S}const Pc={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},w2=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],ece=["Enter"," ","Escape"],tce={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Zg;(function(e){e.Strict="strict",e.Loose="loose"})(Zg||(Zg={}));var Kh;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Kh||(Kh={}));var C2;(function(e){e.Partial="partial",e.Full="full"})(C2||(C2={}));const nce={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Vd;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Vd||(Vd={}));var r6;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(r6||(r6={}));var Mt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(Mt||(Mt={}));const aY={[Mt.Left]:Mt.Right,[Mt.Right]:Mt.Left,[Mt.Top]:Mt.Bottom,[Mt.Bottom]:Mt.Top};function rce(e){return e===null?null:e?"valid":"invalid"}const ice=e=>"id"in e&&"source"in e&&"target"in e,dft=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),lI=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),Ov=(e,t=[0,0])=>{const{width:n,height:r}=ed(e),i=e.origin??t,o=n*i[0],s=r*i[1];return{x:e.position.x-o,y:e.position.y-s}},fft=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,i)=>{const o=typeof i=="string";let s=!t.nodeLookup&&!o?i:void 0;t.nodeLookup&&(s=o?t.nodeLookup.get(i):lI(i)?i:t.nodeLookup.get(i.id));const a=s?i6(s,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return E8(r,a)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return A8(n)},Mv=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(i=>{(t.filter===void 0||t.filter(i))&&(n=E8(n,i6(i)),r=!0)}),r?A8(n):{x:0,y:0,width:0,height:0}},cI=(e,t,[n,r,i]=[0,0,1],o=!1,s=!1)=>{const a={...Rv(t,[n,r,i]),width:t.width/i,height:t.height/i},l=[];for(const c of e.values()){const{measured:u,selectable:d=!0,hidden:p=!1}=c;if(s&&!d||p)continue;const g=u.width??c.width??c.initialWidth??null,y=u.height??c.height??c.initialHeight??null,b=k2(a,Qg(c)),v=(g??0)*(y??0),S=o&&b>0;(!c.internals.handleBounds||S||b>=v||c.dragging)&&l.push(c)}return l},hft=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function pft(e,t){const n=new Map,r=t?.nodes?new Set(t.nodes.map(i=>i.id)):null;return e.forEach(i=>{i.measured.width&&i.measured.height&&(t?.includeHiddenNodes||!i.hidden)&&(!r||r.has(i.id))&&n.set(i.id,i)}),n}async function mft({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:o},s){if(e.size===0)return Promise.resolve(!0);const a=pft(e,s),l=Mv(a),c=uI(l,t,n,s?.minZoom??i,s?.maxZoom??o,s?.padding??.1);return await r.setViewport(c,{duration:s?.duration,ease:s?.ease,interpolate:s?.interpolate}),Promise.resolve(!0)}function oce({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:i,onError:o}){const s=n.get(e),a=s.parentId?n.get(s.parentId):void 0,{x:l,y:c}=a?a.internals.positionAbsolute:{x:0,y:0},u=s.origin??r;let d=s.extent||i;if(s.extent==="parent"&&!s.expandParent)if(!a)o?.("005",Pc.error005());else{const g=a.measured.width,y=a.measured.height;g&&y&&(d=[[l,c],[l+g,c+y]])}else a&&e0(s.extent)&&(d=[[s.extent[0][0]+l,s.extent[0][1]+c],[s.extent[1][0]+l,s.extent[1][1]+c]]);const p=e0(d)?hp(t,d,s.measured):t;return(s.measured.width===void 0||s.measured.height===void 0)&&o?.("015",Pc.error015()),{position:{x:p.x-l+(s.measured.width??0)*u[0],y:p.y-c+(s.measured.height??0)*u[1]},positionAbsolute:p}}async function gft({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){const o=new Set(e.map(p=>p.id)),s=[];for(const p of n){if(p.deletable===!1)continue;const g=o.has(p.id),y=!g&&p.parentId&&s.find(b=>b.id===p.parentId);(g||y)&&s.push(p)}const a=new Set(t.map(p=>p.id)),l=r.filter(p=>p.deletable!==!1),u=hft(s,l);for(const p of l)a.has(p.id)&&!u.find(y=>y.id===p.id)&&u.push(p);if(!i)return{edges:u,nodes:s};const d=await i({nodes:s,edges:u});return typeof d=="boolean"?d?{edges:u,nodes:s}:{edges:[],nodes:[]}:d}const Xg=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),hp=(e={x:0,y:0},t,n)=>({x:Xg(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Xg(e.y,t[0][1],t[1][1]-(n?.height??0))});function sce(e,t,n){const{width:r,height:i}=ed(n),{x:o,y:s}=n.internals.positionAbsolute;return hp(e,[[o,s],[o+r,s+i]],t)}const lY=(e,t,n)=>e<t?Xg(Math.abs(e-t),1,t)/t:e>n?-Xg(Math.abs(e-n),1,t)/t:0,ace=(e,t,n=15,r=40)=>{const i=lY(e.x,r,t.width-r)*n,o=lY(e.y,r,t.height-r)*n;return[i,o]},E8=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),VT=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),A8=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Qg=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:Ov(e,t);return{x:n,y:r,width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}},i6=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:Ov(e,t);return{x:n,y:r,x2:n+(e.measured?.width??e.width??e.initialWidth??0),y2:r+(e.measured?.height??e.height??e.initialHeight??0)}},lce=(e,t)=>A8(E8(VT(e),VT(t))),k2=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},cY=e=>hl(e.width)&&hl(e.height)&&hl(e.x)&&hl(e.y),hl=e=>!isNaN(e)&&isFinite(e),yft=(e,t)=>{},jv=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),Rv=({x:e,y:t},[n,r,i],o=!1,s=[1,1])=>{const a={x:(e-n)/i,y:(t-r)/i};return o?jv(a,s):a},o6=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function Em(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function bft(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=Em(e,n),i=Em(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=Em(e.top??e.y??0,n),i=Em(e.bottom??e.y??0,n),o=Em(e.left??e.x??0,t),s=Em(e.right??e.x??0,t);return{top:r,right:s,bottom:i,left:o,x:o+s,y:r+i}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function vft(e,t,n,r,i,o){const{x:s,y:a}=o6(e,[t,n,r]),{x:l,y:c}=o6({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-l,d=o-c;return{left:Math.floor(s),top:Math.floor(a),right:Math.floor(u),bottom:Math.floor(d)}}const uI=(e,t,n,r,i,o)=>{const s=bft(o,t,n),a=(t-s.x)/e.width,l=(n-s.y)/e.height,c=Math.min(a,l),u=Xg(c,r,i),d=e.x+e.width/2,p=e.y+e.height/2,g=t/2-d*u,y=n/2-p*u,b=vft(e,g,y,u,t,n),v={left:Math.min(b.left-s.left,0),top:Math.min(b.top-s.top,0),right:Math.min(b.right-s.right,0),bottom:Math.min(b.bottom-s.bottom,0)};return{x:g-v.left+v.right,y:y-v.top+v.bottom,zoom:u}},E2=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function e0(e){return e!=null&&e!=="parent"}function ed(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function cce(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function uce(e,t={width:0,height:0},n,r,i){const o={...e},s=r.get(n);if(s){const a=s.origin||i;o.x+=s.internals.positionAbsolute.x-(t.width??0)*a[0],o.y+=s.internals.positionAbsolute.y-(t.height??0)*a[1]}return o}function uY(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function xft(){let e,t;return{promise:new Promise((r,i)=>{e=r,t=i}),resolve:e,reject:t}}function Sft(e){return{...tce,...e||{}}}function ob(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){const{x:o,y:s}=pl(e),a=Rv({x:o-(i?.left??0),y:s-(i?.top??0)},r),{x:l,y:c}=n?jv(a,t):a;return{xSnapped:l,ySnapped:c,...a}}const dI=e=>({width:e.offsetWidth,height:e.offsetHeight}),dce=e=>e?.getRootNode?.()||window?.document,wft=["INPUT","SELECT","TEXTAREA"];function fce(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:wft.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const hce=e=>"clientX"in e,pl=(e,t)=>{const n=hce(e),r=n?e.clientX:e.touches?.[0].clientX,i=n?e.clientY:e.touches?.[0].clientY;return{x:r-(t?.left??0),y:i-(t?.top??0)}},dY=(e,t,n,r,i)=>{const o=t.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(s=>{const a=s.getBoundingClientRect();return{id:s.getAttribute("data-handleid"),type:e,nodeId:i,position:s.getAttribute("data-handlepos"),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...dI(s)}})};function pce({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:i,sourceControlY:o,targetControlX:s,targetControlY:a}){const l=e*.125+i*.375+s*.375+n*.125,c=t*.125+o*.375+a*.375+r*.125,u=Math.abs(l-e),d=Math.abs(c-t);return[l,c,u,d]}function X5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function fY({pos:e,x1:t,y1:n,x2:r,y2:i,c:o}){switch(e){case Mt.Left:return[t-X5(t-r,o),n];case Mt.Right:return[t+X5(r-t,o),n];case Mt.Top:return[t,n-X5(n-i,o)];case Mt.Bottom:return[t,n+X5(i-n,o)]}}function mce({sourceX:e,sourceY:t,sourcePosition:n=Mt.Bottom,targetX:r,targetY:i,targetPosition:o=Mt.Top,curvature:s=.25}){const[a,l]=fY({pos:n,x1:e,y1:t,x2:r,y2:i,c:s}),[c,u]=fY({pos:o,x1:r,y1:i,x2:e,y2:t,c:s}),[d,p,g,y]=pce({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:u});return[`M${e},${t} C${a},${l} ${c},${u} ${r},${i}`,d,p,g,y]}function gce({sourceX:e,sourceY:t,targetX:n,targetY:r}){const i=Math.abs(n-e)/2,o=n<e?n+i:n-i,s=Math.abs(r-t)/2,a=r<t?r+s:r-s;return[o,a,i,s]}function Cft({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:i=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const s=i&&n?r+1e3:r,a=Math.max(e.parentId||i&&e.selected?e.internals.z:0,t.parentId||i&&t.selected?t.internals.z:0);return s+a}function kft({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){const o=E8(i6(e),i6(t));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const s={x:-i[0]/i[2],y:-i[1]/i[2],width:n/i[2],height:r/i[2]};return k2(s,A8(o))>0}const Eft=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,Aft=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),Dft=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||Eft;let i;return ice(e)?i={...e}:i={...e,id:r(e)},Aft(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function yce({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[i,o,s,a]=gce({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,o,s,a]}const hY={[Mt.Left]:{x:-1,y:0},[Mt.Right]:{x:1,y:0},[Mt.Top]:{x:0,y:-1},[Mt.Bottom]:{x:0,y:1}},_ft=({source:e,sourcePosition:t=Mt.Bottom,target:n})=>t===Mt.Left||t===Mt.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},pY=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function Tft({source:e,sourcePosition:t=Mt.Bottom,target:n,targetPosition:r=Mt.Top,center:i,offset:o,stepPosition:s}){const a=hY[t],l=hY[r],c={x:e.x+a.x*o,y:e.y+a.y*o},u={x:n.x+l.x*o,y:n.y+l.y*o},d=_ft({source:c,sourcePosition:t,target:u}),p=d.x!==0?"x":"y",g=d[p];let y=[],b,v;const S={x:0,y:0},C={x:0,y:0},[,,w,E]=gce({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[p]*l[p]===-1){p==="x"?(b=i.x??c.x+(u.x-c.x)*s,v=i.y??(c.y+u.y)/2):(b=i.x??(c.x+u.x)/2,v=i.y??c.y+(u.y-c.y)*s);const T=[{x:b,y:c.y},{x:b,y:u.y}],_=[{x:c.x,y:v},{x:u.x,y:v}];a[p]===g?y=p==="x"?T:_:y=p==="x"?_:T}else{const T=[{x:c.x,y:u.y}],_=[{x:u.x,y:c.y}];if(p==="x"?y=a.x===g?_:T:y=a.y===g?T:_,t===r){const M=Math.abs(e[p]-n[p]);if(M<=o){const N=Math.min(o-1,o-M);a[p]===g?S[p]=(c[p]>e[p]?-1:1)*N:C[p]=(u[p]>n[p]?-1:1)*N}}if(t!==r){const M=p==="x"?"y":"x",N=a[p]===l[M],$=c[M]>u[M],B=c[M]<u[M];(a[p]===1&&(!N&&$||N&&B)||a[p]!==1&&(!N&&B||N&&$))&&(y=p==="x"?T:_)}const O={x:c.x+S.x,y:c.y+S.y},R={x:u.x+C.x,y:u.y+C.y},P=Math.max(Math.abs(O.x-y[0].x),Math.abs(R.x-y[0].x)),L=Math.max(Math.abs(O.y-y[0].y),Math.abs(R.y-y[0].y));P>=L?(b=(O.x+R.x)/2,v=y[0].y):(b=y[0].x,v=(O.y+R.y)/2)}return[[e,{x:c.x+S.x,y:c.y+S.y},...y,{x:u.x+C.x,y:u.y+C.y},n],b,v,w,E]}function Oft(e,t,n,r){const i=Math.min(pY(e,t)/2,pY(t,n)/2,r),{x:o,y:s}=t;if(e.x===o&&o===n.x||e.y===s&&s===n.y)return`L${o} ${s}`;if(e.y===s){const c=e.x<n.x?-1:1,u=e.y<n.y?1:-1;return`L ${o+i*c},${s}Q ${o},${s} ${o},${s+i*u}`}const a=e.x<n.x?1:-1,l=e.y<n.y?-1:1;return`L ${o},${s+i*l}Q ${o},${s} ${o+i*a},${s}`}function WT({sourceX:e,sourceY:t,sourcePosition:n=Mt.Bottom,targetX:r,targetY:i,targetPosition:o=Mt.Top,borderRadius:s=5,centerX:a,centerY:l,offset:c=20,stepPosition:u=.5}){const[d,p,g,y,b]=Tft({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:o,center:{x:a,y:l},offset:c,stepPosition:u});return[d.reduce((S,C,w)=>{let E="";return w>0&&w<d.length-1?E=Oft(d[w-1],C,d[w+1],s):E=`${w===0?"M":"L"}${C.x} ${C.y}`,S+=E,S},""),p,g,y,b]}function mY(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function Mft(e){const{sourceNode:t,targetNode:n}=e;if(!mY(t)||!mY(n))return null;const r=t.internals.handleBounds||gY(t.handles),i=n.internals.handleBounds||gY(n.handles),o=yY(r?.source??[],e.sourceHandle),s=yY(e.connectionMode===Zg.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!s)return e.onError?.("008",Pc.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const a=o?.position||Mt.Bottom,l=s?.position||Mt.Top,c=pp(t,o,a),u=pp(n,s,l);return{sourceX:c.x,sourceY:c.y,targetX:u.x,targetY:u.y,sourcePosition:a,targetPosition:l}}function gY(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function pp(e,t,n=Mt.Left,r=!1){const i=(t?.x??0)+e.internals.positionAbsolute.x,o=(t?.y??0)+e.internals.positionAbsolute.y,{width:s,height:a}=t??ed(e);if(r)return{x:i+s/2,y:o+a/2};switch(t?.position??n){case Mt.Top:return{x:i+s/2,y:o};case Mt.Right:return{x:i+s,y:o+a/2};case Mt.Bottom:return{x:i+s/2,y:o+a};case Mt.Left:return{x:i,y:o+a/2}}}function yY(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function qT(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function jft(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:i}){const o=new Set;return e.reduce((s,a)=>([a.markerStart||r,a.markerEnd||i].forEach(l=>{if(l&&typeof l=="object"){const c=qT(l,t);o.has(c)||(s.push({id:c,color:l.color||n,...l}),o.add(c))}}),s),[]).sort((s,a)=>s.id.localeCompare(a.id))}const bce=1e3,Rft=10,fI={nodeOrigin:[0,0],nodeExtent:w2,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Ift={...fI,checkEquality:!0};function hI(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function Pft(e,t,n){const r=hI(fI,n);for(const i of e.values())if(i.parentId)mI(i,e,t,r);else{const o=Ov(i,r.nodeOrigin),s=e0(i.extent)?i.extent:r.nodeExtent,a=hp(o,s,ed(i));i.internals.positionAbsolute=a}}function Nft(e,t){if(!e.handles)return e.measured?t?.internals.handleBounds:void 0;const n=[],r=[];for(const i of e.handles){const o={id:i.id,width:i.width??1,height:i.height??1,nodeId:e.id,x:i.x,y:i.y,position:i.position,type:i.type};i.type==="source"?n.push(o):i.type==="target"&&r.push(o)}return{source:n,target:r}}function pI(e){return e==="manual"}function KT(e,t,n,r={}){const i=hI(Ift,r),o={i:0},s=new Map(t),a=i?.elevateNodesOnSelect&&!pI(i.zIndexMode)?bce:0;let l=e.length>0;t.clear(),n.clear();for(const c of e){let u=s.get(c.id);if(i.checkEquality&&c===u?.internals.userNode)t.set(c.id,u);else{const d=Ov(c,i.nodeOrigin),p=e0(c.extent)?c.extent:i.nodeExtent,g=hp(d,p,ed(c));u={...i.defaults,...c,measured:{width:c.measured?.width,height:c.measured?.height},internals:{positionAbsolute:g,handleBounds:Nft(c,u),z:vce(c,a,i.zIndexMode),userNode:c}},t.set(c.id,u)}(u.measured===void 0||u.measured.width===void 0||u.measured.height===void 0)&&!u.hidden&&(l=!1),c.parentId&&mI(u,t,n,r,o)}return l}function $ft(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function mI(e,t,n,r,i){const{elevateNodesOnSelect:o,nodeOrigin:s,nodeExtent:a,zIndexMode:l}=hI(fI,r),c=e.parentId,u=t.get(c);if(!u){console.warn(`Parent node ${c} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}$ft(e,n),i&&!u.parentId&&u.internals.rootParentIndex===void 0&&l==="auto"&&(u.internals.rootParentIndex=++i.i,u.internals.z=u.internals.z+i.i*Rft),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);const d=o&&!pI(l)?bce:0,{x:p,y:g,z:y}=Lft(e,u,s,a,d,l),{positionAbsolute:b}=e.internals,v=p!==b.x||g!==b.y;(v||y!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:v?{x:p,y:g}:b,z:y}})}function vce(e,t,n){const r=hl(e.zIndex)?e.zIndex:0;return pI(n)?r:r+(e.selected?t:0)}function Lft(e,t,n,r,i,o){const{x:s,y:a}=t.internals.positionAbsolute,l=ed(e),c=Ov(e,n),u=e0(e.extent)?hp(c,e.extent,l):c;let d=hp({x:s+u.x,y:a+u.y},r,l);e.extent==="parent"&&(d=sce(d,l,t));const p=vce(e,i,o),g=t.internals.z??0;return{x:d.x,y:d.y,z:g>=p?g+1:p}}function gI(e,t,n,r=[0,0]){const i=[],o=new Map;for(const s of e){const a=t.get(s.parentId);if(!a)continue;const l=o.get(s.parentId)?.expandedRect??Qg(a),c=lce(l,s.rect);o.set(s.parentId,{expandedRect:c,parent:a})}return o.size>0&&o.forEach(({expandedRect:s,parent:a},l)=>{const c=a.internals.positionAbsolute,u=ed(a),d=a.origin??r,p=s.x<c.x?Math.round(Math.abs(c.x-s.x)):0,g=s.y<c.y?Math.round(Math.abs(c.y-s.y)):0,y=Math.max(u.width,Math.round(s.width)),b=Math.max(u.height,Math.round(s.height)),v=(y-u.width)*d[0],S=(b-u.height)*d[1];(p>0||g>0||v||S)&&(i.push({id:l,type:"position",position:{x:a.position.x-p+v,y:a.position.y-g+S}}),n.get(l)?.forEach(C=>{e.some(w=>w.id===C.id)||i.push({id:C.id,type:"position",position:{x:C.position.x+p,y:C.position.y+g}})})),(u.width<s.width||u.height<s.height||p||g)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:y+(p?d[0]*p-v:0),height:b+(g?d[1]*g-S:0)}})}),i}function Fft(e,t,n,r,i,o,s){const a=r?.querySelector(".xyflow__viewport");let l=!1;if(!a)return{changes:[],updatedInternals:l};const c=[],u=window.getComputedStyle(a),{m22:d}=new window.DOMMatrixReadOnly(u.transform),p=[];for(const g of e.values()){const y=t.get(g.id);if(!y)continue;if(y.hidden){t.set(y.id,{...y,internals:{...y.internals,handleBounds:void 0}}),l=!0;continue}const b=dI(g.nodeElement),v=y.measured.width!==b.width||y.measured.height!==b.height;if(!!(b.width&&b.height&&(v||!y.internals.handleBounds||g.force))){const C=g.nodeElement.getBoundingClientRect(),w=e0(y.extent)?y.extent:o;let{positionAbsolute:E}=y.internals;y.parentId&&y.extent==="parent"?E=sce(E,b,t.get(y.parentId)):w&&(E=hp(E,w,b));const k={...y,measured:b,internals:{...y.internals,positionAbsolute:E,handleBounds:{source:dY("source",g.nodeElement,C,d,y.id),target:dY("target",g.nodeElement,C,d,y.id)}}};t.set(y.id,k),y.parentId&&mI(k,t,n,{nodeOrigin:i,zIndexMode:s}),l=!0,v&&(c.push({id:y.id,type:"dimensions",dimensions:b}),y.expandParent&&y.parentId&&p.push({id:y.id,parentId:y.parentId,rect:Qg(k,i)}))}}if(p.length>0){const g=gI(p,t,n,i);c.push(...g)}return{changes:c,updatedInternals:l}}async function zft({delta:e,panZoom:t,transform:n,translateExtent:r,width:i,height:o}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const s=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[i,o]],r),a=!!s&&(s.x!==n[0]||s.y!==n[1]||s.k!==n[2]);return Promise.resolve(a)}function bY(e,t,n,r,i,o){let s=i;const a=r.get(s)||new Map;r.set(s,a.set(n,t)),s=`${i}-${e}`;const l=r.get(s)||new Map;if(r.set(s,l.set(n,t)),o){s=`${i}-${e}-${o}`;const c=r.get(s)||new Map;r.set(s,c.set(n,t))}}function xce(e,t,n){e.clear(),t.clear();for(const r of n){const{source:i,target:o,sourceHandle:s=null,targetHandle:a=null}=r,l={edgeId:r.id,source:i,target:o,sourceHandle:s,targetHandle:a},c=`${i}-${s}--${o}-${a}`,u=`${o}-${a}--${i}-${s}`;bY("source",l,u,e,i,s),bY("target",l,c,e,o,a),t.set(r.id,r)}}function Sce(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Sce(n,t):!1}function vY(e,t,n){let r=e;do{if(r?.matches?.(t))return!0;if(r===n)return!1;r=r?.parentElement}while(r);return!1}function Bft(e,t,n,r){const i=new Map;for(const[o,s]of e)if((s.selected||s.id===r)&&(!s.parentId||!Sce(s,e))&&(s.draggable||t&&typeof s.draggable>"u")){const a=e.get(o);a&&i.set(o,{id:o,position:a.position||{x:0,y:0},distance:{x:n.x-a.internals.positionAbsolute.x,y:n.y-a.internals.positionAbsolute.y},extent:a.extent,parentId:a.parentId,origin:a.origin,expandParent:a.expandParent,internals:{positionAbsolute:a.internals.positionAbsolute||{x:0,y:0}},measured:{width:a.measured.width??0,height:a.measured.height??0}})}return i}function LA({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){const i=[];for(const[s,a]of t){const l=n.get(s)?.internals.userNode;l&&i.push({...l,position:a.position,dragging:r})}if(!e)return[i[0],i];const o=n.get(e)?.internals.userNode;return[o?{...o,position:t.get(e)?.position||o.position,dragging:r}:i[0],i]}function Hft({dragItems:e,snapGrid:t,x:n,y:r}){const i=e.values().next().value;if(!i)return null;const o={x:n-i.distance.x,y:r-i.distance.y},s=jv(o,t);return{x:s.x-o.x,y:s.y-o.y}}function Uft({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:i}){let o={x:null,y:null},s=0,a=new Map,l=!1,c={x:0,y:0},u=null,d=!1,p=null,g=!1,y=!1,b=null;function v({noDragClassName:C,handleSelector:w,domNode:E,isSelectable:k,nodeId:T,nodeClickDistance:_=0}){p=ea(E);function O({x:M,y:N}){const{nodeLookup:$,nodeExtent:B,snapGrid:F,snapToGrid:V,nodeOrigin:W,onNodeDrag:q,onSelectionDrag:Z,onError:z,updateNodePositions:U}=t();o={x:M,y:N};let Y=!1;const H=a.size>1,K=H&&B?VT(Mv(a)):null,Q=H&&V?Hft({dragItems:a,snapGrid:F,x:M,y:N}):null;for(const[ie,te]of a){if(!$.has(ie))continue;let ce={x:M-te.distance.x,y:N-te.distance.y};V&&(ce=Q?{x:Math.round(ce.x+Q.x),y:Math.round(ce.y+Q.y)}:jv(ce,F));let ee=null;if(H&&B&&!te.extent&&K){const{positionAbsolute:oe}=te.internals,le=oe.x-K.x+B[0][0],fe=oe.x+te.measured.width-K.x2+B[1][0],ye=oe.y-K.y+B[0][1],Me=oe.y+te.measured.height-K.y2+B[1][1];ee=[[le,ye],[fe,Me]]}const{position:J,positionAbsolute:X}=oce({nodeId:ie,nextPosition:ce,nodeLookup:$,nodeExtent:ee||B,nodeOrigin:W,onError:z});Y=Y||te.position.x!==J.x||te.position.y!==J.y,te.position=J,te.internals.positionAbsolute=X}if(y=y||Y,!!Y&&(U(a,!0),b&&(r||q||!T&&Z))){const[ie,te]=LA({nodeId:T,dragItems:a,nodeLookup:$});r?.(b,a,ie,te),q?.(b,ie,te),T||Z?.(b,te)}}async function R(){if(!u)return;const{transform:M,panBy:N,autoPanSpeed:$,autoPanOnNodeDrag:B}=t();if(!B){l=!1,cancelAnimationFrame(s);return}const[F,V]=ace(c,u,$);(F!==0||V!==0)&&(o.x=(o.x??0)-F/M[2],o.y=(o.y??0)-V/M[2],await N({x:F,y:V})&&O(o)),s=requestAnimationFrame(R)}function P(M){const{nodeLookup:N,multiSelectionActive:$,nodesDraggable:B,transform:F,snapGrid:V,snapToGrid:W,selectNodesOnDrag:q,onNodeDragStart:Z,onSelectionDragStart:z,unselectNodesAndEdges:U}=t();d=!0,(!q||!k)&&!$&&T&&(N.get(T)?.selected||U()),k&&q&&T&&e?.(T);const Y=ob(M.sourceEvent,{transform:F,snapGrid:V,snapToGrid:W,containerBounds:u});if(o=Y,a=Bft(N,B,Y,T),a.size>0&&(n||Z||!T&&z)){const[H,K]=LA({nodeId:T,dragItems:a,nodeLookup:N});n?.(M.sourceEvent,a,H,K),Z?.(M.sourceEvent,H,K),T||z?.(M.sourceEvent,K)}}const L=Lle().clickDistance(_).on("start",M=>{const{domNode:N,nodeDragThreshold:$,transform:B,snapGrid:F,snapToGrid:V}=t();u=N?.getBoundingClientRect()||null,g=!1,y=!1,b=M.sourceEvent,$===0&&P(M),o=ob(M.sourceEvent,{transform:B,snapGrid:F,snapToGrid:V,containerBounds:u}),c=pl(M.sourceEvent,u)}).on("drag",M=>{const{autoPanOnNodeDrag:N,transform:$,snapGrid:B,snapToGrid:F,nodeDragThreshold:V,nodeLookup:W}=t(),q=ob(M.sourceEvent,{transform:$,snapGrid:B,snapToGrid:F,containerBounds:u});if(b=M.sourceEvent,(M.sourceEvent.type==="touchmove"&&M.sourceEvent.touches.length>1||T&&!W.has(T))&&(g=!0),!g){if(!l&&N&&d&&(l=!0,R()),!d){const Z=pl(M.sourceEvent,u),z=Z.x-c.x,U=Z.y-c.y;Math.sqrt(z*z+U*U)>V&&P(M)}(o.x!==q.xSnapped||o.y!==q.ySnapped)&&a&&d&&(c=pl(M.sourceEvent,u),O(q))}}).on("end",M=>{if(!(!d||g)&&(l=!1,d=!1,cancelAnimationFrame(s),a.size>0)){const{nodeLookup:N,updateNodePositions:$,onNodeDragStop:B,onSelectionDragStop:F}=t();if(y&&($(a,!1),y=!1),i||B||!T&&F){const[V,W]=LA({nodeId:T,dragItems:a,nodeLookup:N,dragging:!1});i?.(M.sourceEvent,a,V,W),B?.(M.sourceEvent,V,W),T||F?.(M.sourceEvent,W)}}}).filter(M=>{const N=M.target;return!M.button&&(!C||!vY(N,`.${C}`,E))&&(!w||vY(N,w,E))});p.call(L)}function S(){p?.on(".drag",null)}return{update:v,destroy:S}}function Vft(e,t,n){const r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const o of t.values())k2(i,Qg(o))>0&&r.push(o);return r}const Wft=250;function qft(e,t,n,r){let i=[],o=1/0;const s=Vft(e,n,t+Wft);for(const a of s){const l=[...a.internals.handleBounds?.source??[],...a.internals.handleBounds?.target??[]];for(const c of l){if(r.nodeId===c.nodeId&&r.type===c.type&&r.id===c.id)continue;const{x:u,y:d}=pp(a,c,c.position,!0),p=Math.sqrt(Math.pow(u-e.x,2)+Math.pow(d-e.y,2));p>t||(p<o?(i=[{...c,x:u,y:d}],o=p):p===o&&i.push({...c,x:u,y:d}))}}if(!i.length)return null;if(i.length>1){const a=r.type==="source"?"target":"source";return i.find(l=>l.type===a)??i[0]}return i[0]}function wce(e,t,n,r,i,o=!1){const s=r.get(e);if(!s)return null;const a=i==="strict"?s.internals.handleBounds?.[t]:[...s.internals.handleBounds?.source??[],...s.internals.handleBounds?.target??[]],l=(n?a?.find(c=>c.id===n):a?.[0])??null;return l&&o?{...l,...pp(s,l,l.position,!0)}:l}function Cce(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Kft(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const kce=()=>!0;function Gft(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:s,domNode:a,nodeLookup:l,lib:c,autoPanOnConnect:u,flowId:d,panBy:p,cancelConnection:g,onConnectStart:y,onConnect:b,onConnectEnd:v,isValidConnection:S=kce,onReconnectEnd:C,updateConnection:w,getTransform:E,getFromHandle:k,autoPanSpeed:T,dragThreshold:_=1,handleDomNode:O}){const R=dce(e.target);let P=0,L;const{x:M,y:N}=pl(e),$=Cce(o,O),B=a?.getBoundingClientRect();let F=!1;if(!B||!$)return;const V=wce(i,$,r,l,t);if(!V)return;let W=pl(e,B),q=!1,Z=null,z=!1,U=null;function Y(){if(!u||!B)return;const[J,X]=ace(W,B,T);p({x:J,y:X}),P=requestAnimationFrame(Y)}const H={...V,nodeId:i,type:$,position:V.position},K=l.get(i);let ie={inProgress:!0,isValid:null,from:pp(K,H,Mt.Left,!0),fromHandle:H,fromPosition:H.position,fromNode:K,to:W,toHandle:null,toPosition:aY[H.position],toNode:null,pointer:W};function te(){F=!0,w(ie),y?.(e,{nodeId:i,handleId:r,handleType:$})}_===0&&te();function ce(J){if(!F){const{x:Me,y:ue}=pl(J),we=Me-M,Oe=ue-N;if(!(we*we+Oe*Oe>_*_))return;te()}if(!k()||!H){ee(J);return}const X=E();W=pl(J,B),L=qft(Rv(W,X,!1,[1,1]),n,l,H),q||(Y(),q=!0);const oe=Ece(J,{handle:L,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:s?"target":"source",isValidConnection:S,doc:R,lib:c,flowId:d,nodeLookup:l});U=oe.handleDomNode,Z=oe.connection,z=Kft(!!L,oe.isValid);const le=l.get(i),fe=le?pp(le,H,Mt.Left,!0):ie.from,ye={...ie,from:fe,isValid:z,to:oe.toHandle&&z?o6({x:oe.toHandle.x,y:oe.toHandle.y},X):W,toHandle:oe.toHandle,toPosition:z&&oe.toHandle?oe.toHandle.position:aY[H.position],toNode:oe.toHandle?l.get(oe.toHandle.nodeId):null,pointer:W};w(ye),ie=ye}function ee(J){if(!("touches"in J&&J.touches.length>0)){if(F){(L||U)&&Z&&z&&b?.(Z);const{inProgress:X,...oe}=ie,le={...oe,toPosition:ie.toHandle?ie.toPosition:null};v?.(J,le),o&&C?.(J,le)}g(),cancelAnimationFrame(P),q=!1,z=!1,Z=null,U=null,R.removeEventListener("mousemove",ce),R.removeEventListener("mouseup",ee),R.removeEventListener("touchmove",ce),R.removeEventListener("touchend",ee)}}R.addEventListener("mousemove",ce),R.addEventListener("mouseup",ee),R.addEventListener("touchmove",ce),R.addEventListener("touchend",ee)}function Ece(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:o,doc:s,lib:a,flowId:l,isValidConnection:c=kce,nodeLookup:u}){const d=o==="target",p=t?s.querySelector(`.${a}-flow__handle[data-id="${l}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y}=pl(e),b=s.elementFromPoint(g,y),v=b?.classList.contains(`${a}-flow__handle`)?b:p,S={handleDomNode:v,isValid:!1,connection:null,toHandle:null};if(v){const C=Cce(void 0,v),w=v.getAttribute("data-nodeid"),E=v.getAttribute("data-handleid"),k=v.classList.contains("connectable"),T=v.classList.contains("connectableend");if(!w||!C)return S;const _={source:d?w:r,sourceHandle:d?E:i,target:d?r:w,targetHandle:d?i:E};S.connection=_;const R=k&&T&&(n===Zg.Strict?d&&C==="source"||!d&&C==="target":w!==r||E!==i);S.isValid=R&&c(_),S.toHandle=wce(w,C,E,u,n,!0)}return S}const GT={onPointerDown:Gft,isValid:Ece};function Yft({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const i=ea(e);function o({translateExtent:a,width:l,height:c,zoomStep:u=1,pannable:d=!0,zoomable:p=!0,inversePan:g=!1}){const y=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const E=n(),k=w.sourceEvent.ctrlKey&&E2()?10:1,T=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*u,_=E[2]*Math.pow(2,T*k);t.scaleTo(_)};let b=[0,0];const v=w=>{(w.sourceEvent.type==="mousedown"||w.sourceEvent.type==="touchstart")&&(b=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY])},S=w=>{const E=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const k=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],T=[k[0]-b[0],k[1]-b[1]];b=k;const _=r()*Math.max(E[2],Math.log(E[2]))*(g?-1:1),O={x:E[0]-T[0]*_,y:E[1]-T[1]*_},R=[[0,0],[l,c]];t.setViewportConstrained({x:O.x,y:O.y,zoom:E[2]},R,a)},C=Qle().on("start",v).on("zoom",d?S:null).on("zoom.wheel",p?y:null);i.call(C,{})}function s(){i.on("zoom",null)}return{update:o,destroy:s,pointer:sl}}const D8=e=>({x:e.x,y:e.y,zoom:e.k}),FA=({x:e,y:t,zoom:n})=>k8.translate(e,t).scale(n),Xm=(e,t)=>e.target.closest(`.${t}`),Ace=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Jft=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,zA=(e,t=0,n=Jft,r=()=>{})=>{const i=typeof t=="number"&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on("end",r):e},Dce=e=>{const t=e.ctrlKey&&E2()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Zft({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:s,onPanZoomStart:a,onPanZoom:l,onPanZoomEnd:c}){return u=>{if(Xm(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();const d=n.property("__zoom").k||1;if(u.ctrlKey&&s){const v=sl(u),S=Dce(u),C=d*Math.pow(2,S);r.scaleTo(n,C,v,u);return}const p=u.deltaMode===1?20:1;let g=i===Kh.Vertical?0:u.deltaX*p,y=i===Kh.Horizontal?0:u.deltaY*p;!E2()&&u.shiftKey&&i!==Kh.Vertical&&(g=u.deltaY*p,y=0),r.translateBy(n,-(g/d)*o,-(y/d)*o,{internal:!0});const b=D8(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(l?.(u,b),e.panScrollTimeout=setTimeout(()=>{c?.(u,b),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,a?.(u,b))}}function Xft({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){const o=r.type==="wheel",s=!t&&o&&!r.ctrlKey,a=Xm(r,e);if(r.ctrlKey&&o&&a&&r.preventDefault(),s||a)return null;r.preventDefault(),n.call(this,r,i)}}function Qft({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const i=D8(r.transform);e.mouseButton=r.sourceEvent?.button||0,e.isZoomingOrPanning=!0,e.prevViewport=i,r.sourceEvent?.type==="mousedown"&&t(!0),n&&n?.(r.sourceEvent,i)}}function eht({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(n&&Ace(t,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,D8(o.transform))}}function tht({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return s=>{if(!s.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&Ace(t,e.mouseButton??0)&&!e.usedRightMouseButton&&s.sourceEvent&&o(s.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const a=D8(s.transform);e.prevViewport=a,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(s.sourceEvent,a)},n?150:0)}}}function nht({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:s,noWheelClassName:a,noPanClassName:l,lib:c,connectionInProgress:u}){return d=>{const p=e||t,g=n&&d.ctrlKey,y=d.type==="wheel";if(d.button===1&&d.type==="mousedown"&&(Xm(d,`${c}-flow__node`)||Xm(d,`${c}-flow__edge`)))return!0;if(!r&&!p&&!i&&!o&&!n||s||u&&!y||Xm(d,a)&&y||Xm(d,l)&&(!y||i&&y&&!e)||!n&&d.ctrlKey&&y)return!1;if(!n&&d.type==="touchstart"&&d.touches?.length>1)return d.preventDefault(),!1;if(!p&&!i&&!g&&y||!r&&(d.type==="mousedown"||d.type==="touchstart")||Array.isArray(r)&&!r.includes(d.button)&&d.type==="mousedown")return!1;const b=Array.isArray(r)&&r.includes(d.button)||!d.button||d.button<=1;return(!d.ctrlKey||y)&&b}}function rht({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:i,onPanZoom:o,onPanZoomStart:s,onPanZoomEnd:a,onDraggingChange:l}){const c={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},u=e.getBoundingClientRect(),d=Qle().scaleExtent([t,n]).translateExtent(r),p=ea(e).call(d);C({x:i.x,y:i.y,zoom:Xg(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);const g=p.on("wheel.zoom"),y=p.on("dblclick.zoom");d.wheelDelta(Dce);function b(L,M){return p?new Promise(N=>{d?.interpolate(M?.interpolate==="linear"?ib:n4).transform(zA(p,M?.duration,M?.ease,()=>N(!0)),L)}):Promise.resolve(!1)}function v({noWheelClassName:L,noPanClassName:M,onPaneContextMenu:N,userSelectionActive:$,panOnScroll:B,panOnDrag:F,panOnScrollMode:V,panOnScrollSpeed:W,preventScrolling:q,zoomOnPinch:Z,zoomOnScroll:z,zoomOnDoubleClick:U,zoomActivationKeyPressed:Y,lib:H,onTransformChange:K,connectionInProgress:Q,paneClickDistance:ie,selectionOnDrag:te}){$&&!c.isZoomingOrPanning&&S();const ce=B&&!Y&&!$;d.clickDistance(te?1/0:!hl(ie)||ie<0?0:ie);const ee=ce?Zft({zoomPanValues:c,noWheelClassName:L,d3Selection:p,d3Zoom:d,panOnScrollMode:V,panOnScrollSpeed:W,zoomOnPinch:Z,onPanZoomStart:s,onPanZoom:o,onPanZoomEnd:a}):Xft({noWheelClassName:L,preventScrolling:q,d3ZoomHandler:g});if(p.on("wheel.zoom",ee,{passive:!1}),!$){const X=Qft({zoomPanValues:c,onDraggingChange:l,onPanZoomStart:s});d.on("start",X);const oe=eht({zoomPanValues:c,panOnDrag:F,onPaneContextMenu:!!N,onPanZoom:o,onTransformChange:K});d.on("zoom",oe);const le=tht({zoomPanValues:c,panOnDrag:F,panOnScroll:B,onPaneContextMenu:N,onPanZoomEnd:a,onDraggingChange:l});d.on("end",le)}const J=nht({zoomActivationKeyPressed:Y,panOnDrag:F,zoomOnScroll:z,panOnScroll:B,zoomOnDoubleClick:U,zoomOnPinch:Z,userSelectionActive:$,noPanClassName:M,noWheelClassName:L,lib:H,connectionInProgress:Q});d.filter(J),U?p.on("dblclick.zoom",y):p.on("dblclick.zoom",null)}function S(){d.on("zoom",null)}async function C(L,M,N){const $=FA(L),B=d?.constrain()($,M,N);return B&&await b(B),new Promise(F=>F(B))}async function w(L,M){const N=FA(L);return await b(N,M),new Promise($=>$(N))}function E(L){if(p){const M=FA(L),N=p.property("__zoom");(N.k!==L.zoom||N.x!==L.x||N.y!==L.y)&&d?.transform(p,M,null,{sync:!0})}}function k(){const L=p?Xle(p.node()):{x:0,y:0,k:1};return{x:L.x,y:L.y,zoom:L.k}}function T(L,M){return p?new Promise(N=>{d?.interpolate(M?.interpolate==="linear"?ib:n4).scaleTo(zA(p,M?.duration,M?.ease,()=>N(!0)),L)}):Promise.resolve(!1)}function _(L,M){return p?new Promise(N=>{d?.interpolate(M?.interpolate==="linear"?ib:n4).scaleBy(zA(p,M?.duration,M?.ease,()=>N(!0)),L)}):Promise.resolve(!1)}function O(L){d?.scaleExtent(L)}function R(L){d?.translateExtent(L)}function P(L){const M=!hl(L)||L<0?0:L;d?.clickDistance(M)}return{update:v,destroy:S,setViewport:w,setViewportConstrained:C,getViewport:k,scaleTo:T,scaleBy:_,setScaleExtent:O,setTranslateExtent:R,syncViewport:E,setClickDistance:P}}var t0;(function(e){e.Line="line",e.Handle="handle"})(t0||(t0={}));function iht({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:i,affectsY:o}){const s=e-t,a=n-r,l=[s>0?1:s<0?-1:0,a>0?1:a<0?-1:0];return s&&i&&(l[0]=l[0]*-1),a&&o&&(l[1]=l[1]*-1),l}function xY(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),i=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:i}}function Dd(e,t){return Math.max(0,t-e)}function _d(e,t){return Math.max(0,e-t)}function Q5(e,t,n){return Math.max(0,t-e,e-n)}function SY(e,t){return e?!t:t}function oht(e,t,n,r,i,o,s,a){let{affectsX:l,affectsY:c}=t;const{isHorizontal:u,isVertical:d}=t,p=u&&d,{xSnapped:g,ySnapped:y}=n,{minWidth:b,maxWidth:v,minHeight:S,maxHeight:C}=r,{x:w,y:E,width:k,height:T,aspectRatio:_}=e;let O=Math.floor(u?g-e.pointerX:0),R=Math.floor(d?y-e.pointerY:0);const P=k+(l?-O:O),L=T+(c?-R:R),M=-o[0]*k,N=-o[1]*T;let $=Q5(P,b,v),B=Q5(L,S,C);if(s){let W=0,q=0;l&&O<0?W=Dd(w+O+M,s[0][0]):!l&&O>0&&(W=_d(w+P+M,s[1][0])),c&&R<0?q=Dd(E+R+N,s[0][1]):!c&&R>0&&(q=_d(E+L+N,s[1][1])),$=Math.max($,W),B=Math.max(B,q)}if(a){let W=0,q=0;l&&O>0?W=_d(w+O,a[0][0]):!l&&O<0&&(W=Dd(w+P,a[1][0])),c&&R>0?q=_d(E+R,a[0][1]):!c&&R<0&&(q=Dd(E+L,a[1][1])),$=Math.max($,W),B=Math.max(B,q)}if(i){if(u){const W=Q5(P/_,S,C)*_;if($=Math.max($,W),s){let q=0;!l&&!c||l&&!c&&p?q=_d(E+N+P/_,s[1][1])*_:q=Dd(E+N+(l?O:-O)/_,s[0][1])*_,$=Math.max($,q)}if(a){let q=0;!l&&!c||l&&!c&&p?q=Dd(E+P/_,a[1][1])*_:q=_d(E+(l?O:-O)/_,a[0][1])*_,$=Math.max($,q)}}if(d){const W=Q5(L*_,b,v)/_;if(B=Math.max(B,W),s){let q=0;!l&&!c||c&&!l&&p?q=_d(w+L*_+M,s[1][0])/_:q=Dd(w+(c?R:-R)*_+M,s[0][0])/_,B=Math.max(B,q)}if(a){let q=0;!l&&!c||c&&!l&&p?q=Dd(w+L*_,a[1][0])/_:q=_d(w+(c?R:-R)*_,a[0][0])/_,B=Math.max(B,q)}}}R=R+(R<0?B:-B),O=O+(O<0?$:-$),i&&(p?P>L*_?R=(SY(l,c)?-O:O)/_:O=(SY(l,c)?-R:R)*_:u?(R=O/_,c=l):(O=R*_,l=c));const F=l?w+O:w,V=c?E+R:E;return{width:k+(l?-O:O),height:T+(c?-R:R),x:o[0]*O*(l?-1:1)+F,y:o[1]*R*(c?-1:1)+V}}const _ce={width:0,height:0,x:0,y:0},sht={..._ce,pointerX:0,pointerY:0,aspectRatio:1};function aht(e){return[[0,0],[e.measured.width,e.measured.height]]}function lht(e,t,n){const r=t.position.x+e.position.x,i=t.position.y+e.position.y,o=e.measured.width??0,s=e.measured.height??0,a=n[0]*o,l=n[1]*s;return[[r-a,i-l],[r+o-a,i+s-l]]}function cht({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){const o=ea(e);let s={controlDirection:xY("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function a({controlPosition:c,boundaries:u,keepAspectRatio:d,resizeDirection:p,onResizeStart:g,onResize:y,onResizeEnd:b,shouldResize:v}){let S={..._ce},C={...sht};s={boundaries:u,resizeDirection:p,keepAspectRatio:d,controlDirection:xY(c)};let w,E=null,k=[],T,_,O,R=!1;const P=Lle().on("start",L=>{const{nodeLookup:M,transform:N,snapGrid:$,snapToGrid:B,nodeOrigin:F,paneDomNode:V}=n();if(w=M.get(t),!w)return;E=V?.getBoundingClientRect()??null;const{xSnapped:W,ySnapped:q}=ob(L.sourceEvent,{transform:N,snapGrid:$,snapToGrid:B,containerBounds:E});S={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},C={...S,pointerX:W,pointerY:q,aspectRatio:S.width/S.height},T=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(T=M.get(w.parentId),_=T&&w.extent==="parent"?aht(T):void 0),k=[],O=void 0;for(const[Z,z]of M)if(z.parentId===t&&(k.push({id:Z,position:{...z.position},extent:z.extent}),z.extent==="parent"||z.expandParent)){const U=lht(z,w,z.origin??F);O?O=[[Math.min(U[0][0],O[0][0]),Math.min(U[0][1],O[0][1])],[Math.max(U[1][0],O[1][0]),Math.max(U[1][1],O[1][1])]]:O=U}g?.(L,{...S})}).on("drag",L=>{const{transform:M,snapGrid:N,snapToGrid:$,nodeOrigin:B}=n(),F=ob(L.sourceEvent,{transform:M,snapGrid:N,snapToGrid:$,containerBounds:E}),V=[];if(!w)return;const{x:W,y:q,width:Z,height:z}=S,U={},Y=w.origin??B,{width:H,height:K,x:Q,y:ie}=oht(C,s.controlDirection,F,s.boundaries,s.keepAspectRatio,Y,_,O),te=H!==Z,ce=K!==z,ee=Q!==W&&te,J=ie!==q&&ce;if(!ee&&!J&&!te&&!ce)return;if((ee||J||Y[0]===1||Y[1]===1)&&(U.x=ee?Q:S.x,U.y=J?ie:S.y,S.x=U.x,S.y=U.y,k.length>0)){const fe=Q-W,ye=ie-q;for(const Me of k)Me.position={x:Me.position.x-fe+Y[0]*(H-Z),y:Me.position.y-ye+Y[1]*(K-z)},V.push(Me)}if((te||ce)&&(U.width=te&&(!s.resizeDirection||s.resizeDirection==="horizontal")?H:S.width,U.height=ce&&(!s.resizeDirection||s.resizeDirection==="vertical")?K:S.height,S.width=U.width,S.height=U.height),T&&w.expandParent){const fe=Y[0]*(U.width??0);U.x&&U.x<fe&&(S.x=fe,C.x=C.x-(U.x-fe));const ye=Y[1]*(U.height??0);U.y&&U.y<ye&&(S.y=ye,C.y=C.y-(U.y-ye))}const X=iht({width:S.width,prevWidth:Z,height:S.height,prevHeight:z,affectsX:s.controlDirection.affectsX,affectsY:s.controlDirection.affectsY}),oe={...S,direction:X};v?.(L,oe)!==!1&&(R=!0,y?.(L,oe),r(U,V))}).on("end",L=>{R&&(b?.(L,{...S}),i?.({...S}),R=!1)});o.call(P)}function l(){o.on(".drag",null)}return{update:a,destroy:l}}const uht={},wY=e=>{let t;const n=new Set,r=(u,d)=>{const p=typeof u=="function"?u(t):u;if(!Object.is(p,t)){const g=t;t=d??(typeof p!="object"||p===null)?p:Object.assign({},t,p),n.forEach(y=>y(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(uht?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},c=t=e(r,i,l);return l},dht=e=>e?wY(e):wY,{useDebugValue:fht}=on,{useSyncExternalStoreWithSelector:hht}=OAe,pht=e=>e;function Tce(e,t=pht,n){const r=hht(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return fht(r),r}const CY=(e,t)=>{const n=dht(e),r=(i,o=t)=>Tce(n,i,o);return Object.assign(r,n),r},mht=(e,t)=>e?CY(e,t):CY;function Qr(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[r,i]of e)if(!Object.is(i,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}const _8=A.createContext(null),ght=_8.Provider,Oce=Pc.error001();function tr(e,t){const n=A.useContext(_8);if(n===null)throw new Error(Oce);return Tce(n,e,t)}function ei(){const e=A.useContext(_8);if(e===null)throw new Error(Oce);return A.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const kY={display:"none"},yht={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Mce="react-flow__node-desc",jce="react-flow__edge-desc",bht="react-flow__aria-live",vht=e=>e.ariaLiveMessage,xht=e=>e.ariaLabelConfig;function Sht({rfId:e}){const t=tr(vht);return h.jsx("div",{id:`${bht}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:yht,children:t})}function wht({rfId:e,disableKeyboardA11y:t}){const n=tr(xht);return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:`${Mce}-${e}`,style:kY,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),h.jsx("div",{id:`${jce}-${e}`,style:kY,children:n["edge.a11yDescription.default"]}),!t&&h.jsx(Sht,{rfId:e})]})}const T8=A.forwardRef(({position:e="top-left",children:t,className:n,style:r,...i},o)=>{const s=`${e}`.split("-");return h.jsx("div",{className:Fi(["react-flow__panel",n,...s]),style:r,ref:o,...i,children:t})});T8.displayName="Panel";function Cht({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:h.jsx(T8,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:h.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const kht=e=>{const t=[],n=[];for(const[,r]of e.nodeLookup)r.selected&&t.push(r.internals.userNode);for(const[,r]of e.edgeLookup)r.selected&&n.push(r);return{selectedNodes:t,selectedEdges:n}},eS=e=>e.id;function Eht(e,t){return Qr(e.selectedNodes.map(eS),t.selectedNodes.map(eS))&&Qr(e.selectedEdges.map(eS),t.selectedEdges.map(eS))}function Aht({onSelectionChange:e}){const t=ei(),{selectedNodes:n,selectedEdges:r}=tr(kht,Eht);return A.useEffect(()=>{const i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[n,r,e]),null}const Dht=e=>!!e.onSelectionChangeHandlers;function _ht({onSelectionChange:e}){const t=tr(Dht);return e||t?h.jsx(Aht,{onSelectionChange:e}):null}const Rce=[0,0],Tht={x:0,y:0,zoom:1},Oht=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],EY=[...Oht,"rfId"],Mht=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),AY={translateExtent:w2,nodeOrigin:Rce,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function jht(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:s,reset:a,setDefaultNodesAndEdges:l}=tr(Mht,Qr),c=ei();A.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{u.current=AY,a()}),[]);const u=A.useRef(AY);return A.useEffect(()=>{for(const d of EY){const p=e[d],g=u.current[d];p!==g&&(typeof e[d]>"u"||(d==="nodes"?t(p):d==="edges"?n(p):d==="minZoom"?r(p):d==="maxZoom"?i(p):d==="translateExtent"?o(p):d==="nodeExtent"?s(p):d==="ariaLabelConfig"?c.setState({ariaLabelConfig:Sft(p)}):d==="fitView"?c.setState({fitViewQueued:p}):d==="fitViewOptions"?c.setState({fitViewOptions:p}):c.setState({[d]:p})))}u.current=e},EY.map(d=>e[d])),null}function DY(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function Rht(e){const[t,n]=A.useState(e==="system"?null:e);return A.useEffect(()=>{if(e!=="system"){n(e);return}const r=DY(),i=()=>n(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),t!==null?t:DY()?.matches?"dark":"light"}const _Y=typeof document<"u"?document:null;function A2(e=null,t={target:_Y,actInsideInputWithModifier:!0}){const[n,r]=A.useState(!1),i=A.useRef(!1),o=A.useRef(new Set([])),[s,a]=A.useMemo(()=>{if(e!==null){const c=(Array.isArray(e)?e:[e]).filter(d=>typeof d=="string").map(d=>d.replace("+",`
|
|
490
490
|
`).replace(`
|
|
491
491
|
|
|
492
492
|
`,`
|
|
@@ -496,4 +496,4 @@ ${n.comment}`:n.comment}this.doc.range[2]=n.offset;break}default:this.errors.pus
|
|
|
496
496
|
To pick up a draggable item, press the space bar.
|
|
497
497
|
While dragging, use the arrow keys to move the item.
|
|
498
498
|
Press space again to drop the item in its new position, or press escape to cancel.
|
|
499
|
-
`},_gt={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function Tgt(e){let{announcements:t=_gt,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=Dgt}=e;const{announce:o,announcement:s}=kgt(),a=Nv("DndLiveRegion"),[l,c]=A.useState(!1);if(A.useEffect(()=>{c(!0)},[]),Egt(A.useMemo(()=>({onDragStart(d){let{active:p}=d;o(t.onDragStart({active:p}))},onDragMove(d){let{active:p,over:g}=d;t.onDragMove&&o(t.onDragMove({active:p,over:g}))},onDragOver(d){let{active:p,over:g}=d;o(t.onDragOver({active:p,over:g}))},onDragEnd(d){let{active:p,over:g}=d;o(t.onDragEnd({active:p,over:g}))},onDragCancel(d){let{active:p,over:g}=d;o(t.onDragCancel({active:p,over:g}))}}),[o,t])),!l)return null;const u=on.createElement(on.Fragment,null,on.createElement(wgt,{id:r,value:i.draggable}),on.createElement(Cgt,{id:a,announcement:s}));return n?qd.createPortal(u,n):u}var Wi;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Wi||(Wi={}));function l6(){}function JY(e,t){return A.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Ogt(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return A.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const El=Object.freeze({x:0,y:0});function pue(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function mue(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function Mgt(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function ZY(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function gue(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function XY(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}const jgt=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=XY(t,t.left,t.top),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=pue(XY(l),i);o.push({id:a,data:{droppableContainer:s,value:c}})}}return o.sort(mue)},Rgt=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=ZY(t),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=ZY(l),u=i.reduce((p,g,y)=>p+pue(c[y],g),0),d=Number((u/4).toFixed(4));o.push({id:a,data:{droppableContainer:s,value:d}})}}return o.sort(mue)};function Igt(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),o=Math.min(t.top+t.height,e.top+e.height),s=i-r,a=o-n;if(r<i&&n<o){const l=t.width*t.height,c=e.width*e.height,u=s*a,d=u/(l+c-u);return Number(d.toFixed(4))}return 0}const Pgt=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=[];for(const o of r){const{id:s}=o,a=n.get(s);if(a){const l=Igt(a,t);l>0&&i.push({id:s,data:{droppableContainer:o,value:l}})}}return i.sort(Mgt)};function Ngt(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function yue(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:El}function $gt(e){return function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];return i.reduce((s,a)=>({...s,top:s.top+e*a.y,bottom:s.bottom+e*a.y,left:s.left+e*a.x,right:s.right+e*a.x}),{...n})}}const Lgt=$gt(1);function Fgt(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function zgt(e,t,n){const r=Fgt(t);if(!r)return e;const{scaleX:i,scaleY:o,x:s,y:a}=r,l=e.left-s-(1-i)*parseFloat(n),c=e.top-a-(1-o)*parseFloat(n.slice(n.indexOf(" ")+1)),u=i?e.width/i:e.width,d=o?e.height/o:e.height;return{width:u,height:d,top:c,right:l+u,bottom:c+d,left:l}}const Bgt={ignoreTransform:!1};function N0(e,t){t===void 0&&(t=Bgt);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:c,transformOrigin:u}=Ps(e).getComputedStyle(e);c&&(n=zgt(n,c,u))}const{top:r,left:i,width:o,height:s,bottom:a,right:l}=n;return{top:r,left:i,width:o,height:s,bottom:a,right:l}}function QY(e){return N0(e,{ignoreTransform:!0})}function Hgt(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function Ugt(e,t){return t===void 0&&(t=Ps(e).getComputedStyle(e)),t.position==="fixed"}function Vgt(e,t){t===void 0&&(t=Ps(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(i=>{const o=t[i];return typeof o=="string"?n.test(o):!1})}function R8(e,t){const n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(xI(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!Iv(i)||due(i)||n.includes(i))return n;const o=Ps(e).getComputedStyle(i);return i!==e&&Vgt(i,o)&&n.push(i),Ugt(i,o)?n:r(i.parentNode)}return e?r(e):n}function bue(e){const[t]=R8(e,1);return t??null}function qA(e){return!j8||!e?null:I0(e)?e:vI(e)?xI(e)||e===P0(e).scrollingElement?window:Iv(e)?e:null:null}function vue(e){return I0(e)?e.scrollX:e.scrollLeft}function xue(e){return I0(e)?e.scrollY:e.scrollTop}function XT(e){return{x:vue(e),y:xue(e)}}var io;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(io||(io={}));function Sue(e){return!j8||!e?!1:e===document.scrollingElement}function wue(e){const t={x:0,y:0},n=Sue(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},i=e.scrollTop<=t.y,o=e.scrollLeft<=t.x,s=e.scrollTop>=r.y,a=e.scrollLeft>=r.x;return{isTop:i,isLeft:o,isBottom:s,isRight:a,maxScroll:r,minScroll:t}}const Wgt={x:.2,y:.2};function qgt(e,t,n,r,i){let{top:o,left:s,right:a,bottom:l}=n;r===void 0&&(r=10),i===void 0&&(i=Wgt);const{isTop:c,isBottom:u,isLeft:d,isRight:p}=wue(e),g={x:0,y:0},y={x:0,y:0},b={height:t.height*i.y,width:t.width*i.x};return!c&&o<=t.top+b.height?(g.y=io.Backward,y.y=r*Math.abs((t.top+b.height-o)/b.height)):!u&&l>=t.bottom-b.height&&(g.y=io.Forward,y.y=r*Math.abs((t.bottom-b.height-l)/b.height)),!p&&a>=t.right-b.width?(g.x=io.Forward,y.x=r*Math.abs((t.right-b.width-a)/b.width)):!d&&s<=t.left+b.width&&(g.x=io.Backward,y.x=r*Math.abs((t.left+b.width-s)/b.width)),{direction:g,speed:y}}function Kgt(e){if(e===document.scrollingElement){const{innerWidth:o,innerHeight:s}=window;return{top:0,left:0,right:o,bottom:s,width:o,height:s}}const{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Cue(e){return e.reduce((t,n)=>Cg(t,XT(n)),El)}function Ggt(e){return e.reduce((t,n)=>t+vue(n),0)}function Ygt(e){return e.reduce((t,n)=>t+xue(n),0)}function Jgt(e,t){if(t===void 0&&(t=N0),!e)return;const{top:n,left:r,bottom:i,right:o}=t(e);bue(e)&&(i<=0||o<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const Zgt=[["x",["left","right"],Ggt],["y",["top","bottom"],Ygt]];class CI{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const r=R8(n),i=Cue(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,s,a]of Zgt)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=a(r),u=i[o]-c;return this.rect[l]+u},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class sb{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=t}add(t,n,r){var i;(i=this.target)==null||i.addEventListener(t,n,r),this.listeners.push([t,n,r])}}function Xgt(e){const{EventTarget:t}=Ps(e);return e instanceof t?e:P0(e)}function KA(e,t){const n=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+r**2)>t:"x"in t&&"y"in t?n>t.x&&r>t.y:"x"in t?n>t.x:"y"in t?r>t.y:!1}var ka;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(ka||(ka={}));function eJ(e){e.preventDefault()}function Qgt(e){e.stopPropagation()}var Jn;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Jn||(Jn={}));const kue={start:[Jn.Space,Jn.Enter],cancel:[Jn.Esc],end:[Jn.Space,Jn.Enter,Jn.Tab]},e0t=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Jn.Right:return{...n,x:n.x+25};case Jn.Left:return{...n,x:n.x-25};case Jn.Down:return{...n,y:n.y+25};case Jn.Up:return{...n,y:n.y-25}}};class kI{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new sb(P0(n)),this.windowListeners=new sb(Ps(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(ka.Resize,this.handleCancel),this.windowListeners.add(ka.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(ka.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,r=t.node.current;r&&Jgt(r),n(El)}handleKeyDown(t){if(wI(t)){const{active:n,context:r,options:i}=this.props,{keyboardCodes:o=kue,coordinateGetter:s=e0t,scrollBehavior:a="smooth"}=i,{code:l}=t;if(o.end.includes(l)){this.handleEnd(t);return}if(o.cancel.includes(l)){this.handleCancel(t);return}const{collisionRect:c}=r.current,u=c?{x:c.left,y:c.top}:El;this.referenceCoordinates||(this.referenceCoordinates=u);const d=s(t,{active:n,context:r.current,currentCoordinates:u});if(d){const p=_2(d,u),g={x:0,y:0},{scrollableAncestors:y}=r.current;for(const b of y){const v=t.code,{isTop:S,isRight:C,isLeft:w,isBottom:E,maxScroll:k,minScroll:T}=wue(b),_=Kgt(b),O={x:Math.min(v===Jn.Right?_.right-_.width/2:_.right,Math.max(v===Jn.Right?_.left:_.left+_.width/2,d.x)),y:Math.min(v===Jn.Down?_.bottom-_.height/2:_.bottom,Math.max(v===Jn.Down?_.top:_.top+_.height/2,d.y))},R=v===Jn.Right&&!C||v===Jn.Left&&!w,P=v===Jn.Down&&!E||v===Jn.Up&&!S;if(R&&O.x!==d.x){const L=b.scrollLeft+p.x,M=v===Jn.Right&&L<=k.x||v===Jn.Left&&L>=T.x;if(M&&!p.y){b.scrollTo({left:L,behavior:a});return}M?g.x=b.scrollLeft-L:g.x=v===Jn.Right?b.scrollLeft-k.x:b.scrollLeft-T.x,g.x&&b.scrollBy({left:-g.x,behavior:a});break}else if(P&&O.y!==d.y){const L=b.scrollTop+p.y,M=v===Jn.Down&&L<=k.y||v===Jn.Up&&L>=T.y;if(M&&!p.x){b.scrollTo({top:L,behavior:a});return}M?g.y=b.scrollTop-L:g.y=v===Jn.Down?b.scrollTop-k.y:b.scrollTop-T.y,g.y&&b.scrollBy({top:-g.y,behavior:a});break}}this.handleMove(t,Cg(_2(d,this.referenceCoordinates),g))}}}handleMove(t,n){const{onMove:r}=this.props;t.preventDefault(),r(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}kI.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:r=kue,onActivation:i}=t,{active:o}=n;const{code:s}=e.nativeEvent;if(r.start.includes(s)){const a=o.activatorNode.current;return a&&e.target!==a?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function tJ(e){return!!(e&&"distance"in e)}function nJ(e){return!!(e&&"delay"in e)}class EI{constructor(t,n,r){var i;r===void 0&&(r=Xgt(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:o}=t,{target:s}=o;this.props=t,this.events=n,this.document=P0(s),this.documentListeners=new sb(this.document),this.listeners=new sb(r),this.windowListeners=new sb(Ps(s)),this.initialCoordinates=(i=ZT(o))!=null?i:El,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(ka.Resize,this.handleCancel),this.windowListeners.add(ka.DragStart,eJ),this.windowListeners.add(ka.VisibilityChange,this.handleCancel),this.windowListeners.add(ka.ContextMenu,eJ),this.documentListeners.add(ka.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(nJ(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(tJ(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:r,onPending:i}=this.props;i(r,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(ka.Click,Qgt,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(ka.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:r,initialCoordinates:i,props:o}=this,{onMove:s,options:{activationConstraint:a}}=o;if(!i)return;const l=(n=ZT(t))!=null?n:El,c=_2(i,l);if(!r&&a){if(tJ(a)){if(a.tolerance!=null&&KA(c,a.tolerance))return this.handleCancel();if(KA(c,a.distance))return this.handleStart()}if(nJ(a)&&KA(c,a.tolerance))return this.handleCancel();this.handlePending(a,c);return}t.cancelable&&t.preventDefault(),s(l)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===Jn.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const t0t={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class AI extends EI{constructor(t){const{event:n}=t,r=P0(n.target);super(t,t0t,r)}}AI.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];const n0t={move:{name:"mousemove"},end:{name:"mouseup"}};var QT;(function(e){e[e.RightClick=2]="RightClick"})(QT||(QT={}));class r0t extends EI{constructor(t){super(t,n0t,P0(t.event.target))}}r0t.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===QT.RightClick?!1:(r?.({event:n}),!0)}}];const GA={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class i0t extends EI{constructor(t){super(t,GA)}static setup(){return window.addEventListener(GA.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(GA.move.name,t)};function t(){}}}i0t.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;const{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var ab;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(ab||(ab={}));var c6;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(c6||(c6={}));function o0t(e){let{acceleration:t,activator:n=ab.Pointer,canScroll:r,draggingRect:i,enabled:o,interval:s=5,order:a=c6.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:u,delta:d,threshold:p}=e;const g=a0t({delta:d,disabled:!o}),[y,b]=ygt(),v=A.useRef({x:0,y:0}),S=A.useRef({x:0,y:0}),C=A.useMemo(()=>{switch(n){case ab.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case ab.DraggableRect:return i}},[n,i,l]),w=A.useRef(null),E=A.useCallback(()=>{const T=w.current;if(!T)return;const _=v.current.x*S.current.x,O=v.current.y*S.current.y;T.scrollBy(_,O)},[]),k=A.useMemo(()=>a===c6.TreeOrder?[...c].reverse():c,[a,c]);A.useEffect(()=>{if(!o||!c.length||!C){b();return}for(const T of k){if(r?.(T)===!1)continue;const _=c.indexOf(T),O=u[_];if(!O)continue;const{direction:R,speed:P}=qgt(T,O,C,t,p);for(const L of["x","y"])g[L][R[L]]||(P[L]=0,R[L]=0);if(P.x>0||P.y>0){b(),w.current=T,y(E,s),v.current=P,S.current=R;return}}v.current={x:0,y:0},S.current={x:0,y:0},b()},[t,E,r,b,o,s,JSON.stringify(C),JSON.stringify(g),y,c,k,u,JSON.stringify(p)])}const s0t={x:{[io.Backward]:!1,[io.Forward]:!1},y:{[io.Backward]:!1,[io.Forward]:!1}};function a0t(e){let{delta:t,disabled:n}=e;const r=JT(t);return Pv(i=>{if(n||!r||!i)return s0t;const o={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[io.Backward]:i.x[io.Backward]||o.x===-1,[io.Forward]:i.x[io.Forward]||o.x===1},y:{[io.Backward]:i.y[io.Backward]||o.y===-1,[io.Forward]:i.y[io.Forward]||o.y===1}}},[n,t,r])}function l0t(e,t){const n=t!=null?e.get(t):void 0,r=n?n.node.current:null;return Pv(i=>{var o;return t==null?null:(o=r??i)!=null?o:null},[r,t])}function c0t(e,t){return A.useMemo(()=>e.reduce((n,r)=>{const{sensor:i}=r,o=i.activators.map(s=>({eventName:s.eventName,handler:t(s.handler,r)}));return[...n,...o]},[]),[e,t])}var O2;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(O2||(O2={}));var eO;(function(e){e.Optimized="optimized"})(eO||(eO={}));const rJ=new Map;function u0t(e,t){let{dragging:n,dependencies:r,config:i}=t;const[o,s]=A.useState(null),{frequency:a,measure:l,strategy:c}=i,u=A.useRef(e),d=v(),p=D2(d),g=A.useCallback(function(S){S===void 0&&(S=[]),!p.current&&s(C=>C===null?S:C.concat(S.filter(w=>!C.includes(w))))},[p]),y=A.useRef(null),b=Pv(S=>{if(d&&!n)return rJ;if(!S||S===rJ||u.current!==e||o!=null){const C=new Map;for(let w of e){if(!w)continue;if(o&&o.length>0&&!o.includes(w.id)&&w.rect.current){C.set(w.id,w.rect.current);continue}const E=w.node.current,k=E?new CI(l(E),E):null;w.rect.current=k,k&&C.set(w.id,k)}return C}return S},[e,o,n,d,l]);return A.useEffect(()=>{u.current=e},[e]),A.useEffect(()=>{d||g()},[n,d]),A.useEffect(()=>{o&&o.length>0&&s(null)},[JSON.stringify(o)]),A.useEffect(()=>{d||typeof a!="number"||y.current!==null||(y.current=setTimeout(()=>{g(),y.current=null},a))},[a,d,g,...r]),{droppableRects:b,measureDroppableContainers:g,measuringScheduled:o!=null};function v(){switch(c){case O2.Always:return!1;case O2.BeforeDragging:return n;default:return!n}}}function Eue(e,t){return Pv(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function d0t(e,t){return Eue(e,t)}function f0t(e){let{callback:t,disabled:n}=e;const r=SI(t),i=A.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(r)},[r,n]);return A.useEffect(()=>()=>i?.disconnect(),[i]),i}function I8(e){let{callback:t,disabled:n}=e;const r=SI(t),i=A.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(r)},[n]);return A.useEffect(()=>()=>i?.disconnect(),[i]),i}function h0t(e){return new CI(N0(e),e)}function iJ(e,t,n){t===void 0&&(t=h0t);const[r,i]=A.useState(null);function o(){i(l=>{if(!e)return null;if(e.isConnected===!1){var c;return(c=l??n)!=null?c:null}const u=t(e);return JSON.stringify(l)===JSON.stringify(u)?l:u})}const s=f0t({callback(l){if(e)for(const c of l){const{type:u,target:d}=c;if(u==="childList"&&d instanceof HTMLElement&&d.contains(e)){o();break}}}}),a=I8({callback:o});return Nc(()=>{o(),e?(a?.observe(e),s?.observe(document.body,{childList:!0,subtree:!0})):(a?.disconnect(),s?.disconnect())},[e]),r}function p0t(e){const t=Eue(e);return yue(e,t)}const oJ=[];function m0t(e){const t=A.useRef(e),n=Pv(r=>e?r&&r!==oJ&&e&&t.current&&e.parentNode===t.current.parentNode?r:R8(e):oJ,[e]);return A.useEffect(()=>{t.current=e},[e]),n}function g0t(e){const[t,n]=A.useState(null),r=A.useRef(e),i=A.useCallback(o=>{const s=qA(o.target);s&&n(a=>a?(a.set(s,XT(s)),new Map(a)):null)},[]);return A.useEffect(()=>{const o=r.current;if(e!==o){s(o);const a=e.map(l=>{const c=qA(l);return c?(c.addEventListener("scroll",i,{passive:!0}),[c,XT(c)]):null}).filter(l=>l!=null);n(a.length?new Map(a):null),r.current=e}return()=>{s(e),s(o)};function s(a){a.forEach(l=>{const c=qA(l);c?.removeEventListener("scroll",i)})}},[i,e]),A.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,s)=>Cg(o,s),El):Cue(e):El,[e,t])}function sJ(e,t){t===void 0&&(t=[]);const n=A.useRef(null);return A.useEffect(()=>{n.current=null},t),A.useEffect(()=>{const r=e!==El;r&&!n.current&&(n.current=e),!r&&n.current&&(n.current=null)},[e]),n.current?_2(e,n.current):El}function y0t(e){A.useEffect(()=>{if(!j8)return;const t=e.map(n=>{let{sensor:r}=n;return r.setup==null?void 0:r.setup()});return()=>{for(const n of t)n?.()}},e.map(t=>{let{sensor:n}=t;return n}))}function b0t(e,t){return A.useMemo(()=>e.reduce((n,r)=>{let{eventName:i,handler:o}=r;return n[i]=s=>{o(s,t)},n},{}),[e,t])}function Aue(e){return A.useMemo(()=>e?Hgt(e):null,[e])}const aJ=[];function v0t(e,t){t===void 0&&(t=N0);const[n]=e,r=Aue(n?Ps(n):null),[i,o]=A.useState(aJ);function s(){o(()=>e.length?e.map(l=>Sue(l)?r:new CI(t(l),l)):aJ)}const a=I8({callback:s});return Nc(()=>{a?.disconnect(),s(),e.forEach(l=>a?.observe(l))},[e]),i}function x0t(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Iv(t)?t:e}function S0t(e){let{measure:t}=e;const[n,r]=A.useState(null),i=A.useCallback(c=>{for(const{target:u}of c)if(Iv(u)){r(d=>{const p=t(u);return d?{...d,width:p.width,height:p.height}:p});break}},[t]),o=I8({callback:i}),s=A.useCallback(c=>{const u=x0t(c);o?.disconnect(),u&&o?.observe(u),r(u?t(u):null)},[t,o]),[a,l]=a6(s);return A.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const w0t=[{sensor:AI,options:{}},{sensor:kI,options:{}}],C0t={current:{}},s4={draggable:{measure:QY},droppable:{measure:QY,strategy:O2.WhileDragging,frequency:eO.Optimized},dragOverlay:{measure:N0}};class lb extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,r;return(n=(r=this.get(t))==null?void 0:r.node.current)!=null?n:void 0}}const k0t={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new lb,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:l6},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:s4,measureDroppableContainers:l6,windowRect:null,measuringScheduled:!1},E0t={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:l6,draggableNodes:new Map,over:null,measureDroppableContainers:l6},P8=A.createContext(E0t),Due=A.createContext(k0t);function A0t(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new lb}}}function D0t(e,t){switch(t.type){case Wi.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Wi.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Wi.DragEnd:case Wi.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Wi.RegisterDroppable:{const{element:n}=t,{id:r}=n,i=new lb(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case Wi.SetDroppableDisabled:{const{id:n,key:r,disabled:i}=t,o=e.droppable.containers.get(n);if(!o||r!==o.key)return e;const s=new lb(e.droppable.containers);return s.set(n,{...o,disabled:i}),{...e,droppable:{...e.droppable,containers:s}}}case Wi.UnregisterDroppable:{const{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;const o=new lb(e.droppable.containers);return o.delete(n),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function _0t(e){let{disabled:t}=e;const{active:n,activatorEvent:r,draggableNodes:i}=A.useContext(P8),o=JT(r),s=JT(n?.id);return A.useEffect(()=>{if(!t&&!r&&o&&s!=null){if(!wI(o)||document.activeElement===o.target)return;const a=i.get(s);if(!a)return;const{activatorNode:l,node:c}=a;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const u of[l.current,c.current]){if(!u)continue;const d=xgt(u);if(d){d.focus();break}}})}},[r,t,i,s,o]),null}function T0t(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((i,o)=>o({transform:i,...r}),n):n}function O0t(e){return A.useMemo(()=>({draggable:{...s4.draggable,...e?.draggable},droppable:{...s4.droppable,...e?.droppable},dragOverlay:{...s4.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function M0t(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e;const o=A.useRef(!1),{x:s,y:a}=typeof i=="boolean"?{x:i,y:i}:i;Nc(()=>{if(!s&&!a||!t){o.current=!1;return}if(o.current||!r)return;const c=t?.node.current;if(!c||c.isConnected===!1)return;const u=n(c),d=yue(u,r);if(s||(d.x=0),a||(d.y=0),o.current=!0,Math.abs(d.x)>0||Math.abs(d.y)>0){const p=bue(c);p&&p.scrollBy({top:d.y,left:d.x})}},[t,s,a,r,n])}const _ue=A.createContext({...El,scaleX:1,scaleY:1});var Ld;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Ld||(Ld={}));const j0t=A.memo(function(t){var n,r,i,o;let{id:s,accessibility:a,autoScroll:l=!0,children:c,sensors:u=w0t,collisionDetection:d=Pgt,measuring:p,modifiers:g,...y}=t;const b=A.useReducer(D0t,void 0,A0t),[v,S]=b,[C,w]=Agt(),[E,k]=A.useState(Ld.Uninitialized),T=E===Ld.Initialized,{draggable:{active:_,nodes:O,translate:R},droppable:{containers:P}}=v,L=_!=null?O.get(_):null,M=A.useRef({initial:null,translated:null}),N=A.useMemo(()=>{var We;return _!=null?{id:_,data:(We=L?.data)!=null?We:C0t,rect:M}:null},[_,L]),$=A.useRef(null),[B,F]=A.useState(null),[V,W]=A.useState(null),q=D2(y,Object.values(y)),Z=Nv("DndDescribedBy",s),z=A.useMemo(()=>P.getEnabled(),[P]),U=O0t(p),{droppableRects:Y,measureDroppableContainers:H,measuringScheduled:K}=u0t(z,{dragging:T,dependencies:[R.x,R.y],config:U.droppable}),Q=l0t(O,_),ie=A.useMemo(()=>V?ZT(V):null,[V]),te=Ge(),ce=d0t(Q,U.draggable.measure);M0t({activeNode:_!=null?O.get(_):null,config:te.layoutShiftCompensation,initialRect:ce,measure:U.draggable.measure});const ee=iJ(Q,U.draggable.measure,ce),J=iJ(Q?Q.parentElement:null),X=A.useRef({activatorEvent:null,active:null,activeNode:Q,collisionRect:null,collisions:null,droppableRects:Y,draggableNodes:O,draggingNode:null,draggingNodeRect:null,droppableContainers:P,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),oe=P.getNodeFor((n=X.current.over)==null?void 0:n.id),le=S0t({measure:U.dragOverlay.measure}),fe=(r=le.nodeRef.current)!=null?r:Q,ye=T?(i=le.rect)!=null?i:ee:null,Me=!!(le.nodeRef.current&&le.rect),ue=p0t(Me?null:ee),we=Aue(fe?Ps(fe):null),Oe=m0t(T?oe??Q:null),He=v0t(Oe),ze=T0t(g,{transform:{x:R.x-ue.x,y:R.y-ue.y,scaleX:1,scaleY:1},activatorEvent:V,active:N,activeNodeRect:ee,containerNodeRect:J,draggingNodeRect:ye,over:X.current.over,overlayNodeRect:le.rect,scrollableAncestors:Oe,scrollableAncestorRects:He,windowRect:we}),At=ie?Cg(ie,R):null,gt=g0t(Oe),$e=sJ(gt),je=sJ(gt,[ee]),Ve=Cg(ze,$e),Ke=ye?Lgt(ye,ze):null,at=N&&Ke?d({active:N,collisionRect:Ke,droppableRects:Y,droppableContainers:z,pointerCoordinates:At}):null,ut=gue(at,"id"),[Qe,Bt]=A.useState(null),Ht=Me?ze:Cg(ze,je),Pt=Ngt(Ht,(o=Qe?.rect)!=null?o:null,ee),Dn=A.useRef(null),tn=A.useCallback((We,Je)=>{let{sensor:St,options:In}=Je;if($.current==null)return;const dn=O.get($.current);if(!dn)return;const _t=We.nativeEvent,yn=new St({active:$.current,activeNode:dn,event:_t,options:In,context:X,onAbort(yt){if(!O.get(yt))return;const{onDragAbort:ae}=q.current,pe={id:yt};ae?.(pe),C({type:"onDragAbort",event:pe})},onPending(yt,Kt,ae,pe){if(!O.get(yt))return;const{onDragPending:Pe}=q.current,qe={id:yt,constraint:Kt,initialCoordinates:ae,offset:pe};Pe?.(qe),C({type:"onDragPending",event:qe})},onStart(yt){const Kt=$.current;if(Kt==null)return;const ae=O.get(Kt);if(!ae)return;const{onDragStart:pe}=q.current,xe={activatorEvent:_t,active:{id:Kt,data:ae.data,rect:M}};qd.unstable_batchedUpdates(()=>{pe?.(xe),k(Ld.Initializing),S({type:Wi.DragStart,initialCoordinates:yt,active:Kt}),C({type:"onDragStart",event:xe}),F(Dn.current),W(_t)})},onMove(yt){S({type:Wi.DragMove,coordinates:yt})},onEnd:dt(Wi.DragEnd),onCancel:dt(Wi.DragCancel)});Dn.current=yn;function dt(yt){return async function(){const{active:ae,collisions:pe,over:xe,scrollAdjustedTranslate:Pe}=X.current;let qe=null;if(ae&&Pe){const{cancelDrop:wt}=q.current;qe={activatorEvent:_t,active:ae,collisions:pe,delta:Pe,over:xe},yt===Wi.DragEnd&&typeof wt=="function"&&await Promise.resolve(wt(qe))&&(yt=Wi.DragCancel)}$.current=null,qd.unstable_batchedUpdates(()=>{S({type:yt}),k(Ld.Uninitialized),Bt(null),F(null),W(null),Dn.current=null;const wt=yt===Wi.DragEnd?"onDragEnd":"onDragCancel";if(qe){const lt=q.current[wt];lt?.(qe),C({type:wt,event:qe})}})}}},[O]),pt=A.useCallback((We,Je)=>(St,In)=>{const dn=St.nativeEvent,_t=O.get(In);if($.current!==null||!_t||dn.dndKit||dn.defaultPrevented)return;const yn={active:_t};We(St,Je.options,yn)===!0&&(dn.dndKit={capturedBy:Je.sensor},$.current=In,tn(St,Je))},[O,tn]),Yt=c0t(u,pt);y0t(u),Nc(()=>{ee&&E===Ld.Initializing&&k(Ld.Initialized)},[ee,E]),A.useEffect(()=>{const{onDragMove:We}=q.current,{active:Je,activatorEvent:St,collisions:In,over:dn}=X.current;if(!Je||!St)return;const _t={active:Je,activatorEvent:St,collisions:In,delta:{x:Ve.x,y:Ve.y},over:dn};qd.unstable_batchedUpdates(()=>{We?.(_t),C({type:"onDragMove",event:_t})})},[Ve.x,Ve.y]),A.useEffect(()=>{const{active:We,activatorEvent:Je,collisions:St,droppableContainers:In,scrollAdjustedTranslate:dn}=X.current;if(!We||$.current==null||!Je||!dn)return;const{onDragOver:_t}=q.current,yn=In.get(ut),dt=yn&&yn.rect.current?{id:yn.id,rect:yn.rect.current,data:yn.data,disabled:yn.disabled}:null,yt={active:We,activatorEvent:Je,collisions:St,delta:{x:dn.x,y:dn.y},over:dt};qd.unstable_batchedUpdates(()=>{Bt(dt),_t?.(yt),C({type:"onDragOver",event:yt})})},[ut]),Nc(()=>{X.current={activatorEvent:V,active:N,activeNode:Q,collisionRect:Ke,collisions:at,droppableRects:Y,draggableNodes:O,draggingNode:fe,draggingNodeRect:ye,droppableContainers:P,over:Qe,scrollableAncestors:Oe,scrollAdjustedTranslate:Ve},M.current={initial:ye,translated:Ke}},[N,Q,at,Ke,O,fe,ye,Y,P,Qe,Oe,Ve]),o0t({...te,delta:R,draggingRect:Ke,pointerCoordinates:At,scrollableAncestors:Oe,scrollableAncestorRects:He});const an=A.useMemo(()=>({active:N,activeNode:Q,activeNodeRect:ee,activatorEvent:V,collisions:at,containerNodeRect:J,dragOverlay:le,draggableNodes:O,droppableContainers:P,droppableRects:Y,over:Qe,measureDroppableContainers:H,scrollableAncestors:Oe,scrollableAncestorRects:He,measuringConfiguration:U,measuringScheduled:K,windowRect:we}),[N,Q,ee,V,at,J,le,O,P,Y,Qe,H,Oe,He,U,K,we]),wn=A.useMemo(()=>({activatorEvent:V,activators:Yt,active:N,activeNodeRect:ee,ariaDescribedById:{draggable:Z},dispatch:S,draggableNodes:O,over:Qe,measureDroppableContainers:H}),[V,Yt,N,ee,S,Z,O,Qe,H]);return on.createElement(hue.Provider,{value:w},on.createElement(P8.Provider,{value:wn},on.createElement(Due.Provider,{value:an},on.createElement(_ue.Provider,{value:Pt},c)),on.createElement(_0t,{disabled:a?.restoreFocus===!1})),on.createElement(Tgt,{...a,hiddenTextDescribedById:Z}));function Ge(){const We=B?.autoScrollEnabled===!1,Je=typeof l=="object"?l.enabled===!1:l===!1,St=T&&!We&&!Je;return typeof l=="object"?{...l,enabled:St}:{enabled:St}}}),R0t=A.createContext(null),lJ="button",I0t="Draggable";function P0t(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e;const o=Nv(I0t),{activators:s,activatorEvent:a,active:l,activeNodeRect:c,ariaDescribedById:u,draggableNodes:d,over:p}=A.useContext(P8),{role:g=lJ,roleDescription:y="draggable",tabIndex:b=0}=i??{},v=l?.id===t,S=A.useContext(v?_ue:R0t),[C,w]=a6(),[E,k]=a6(),T=b0t(s,t),_=D2(n);Nc(()=>(d.set(t,{id:t,key:o,node:C,activatorNode:E,data:_}),()=>{const R=d.get(t);R&&R.key===o&&d.delete(t)}),[d,t]);const O=A.useMemo(()=>({role:g,tabIndex:b,"aria-disabled":r,"aria-pressed":v&&g===lJ?!0:void 0,"aria-roledescription":y,"aria-describedby":u.draggable}),[r,g,b,v,y,u.draggable]);return{active:l,activatorEvent:a,activeNodeRect:c,attributes:O,isDragging:v,listeners:r?void 0:T,node:C,over:p,setNodeRef:w,setActivatorNodeRef:k,transform:S}}function N0t(){return A.useContext(Due)}const $0t="Droppable",L0t={timeout:25};function F0t(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e;const o=Nv($0t),{active:s,dispatch:a,over:l,measureDroppableContainers:c}=A.useContext(P8),u=A.useRef({disabled:n}),d=A.useRef(!1),p=A.useRef(null),g=A.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:v}={...L0t,...i},S=D2(b??r),C=A.useCallback(()=>{if(!d.current){d.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{c(Array.isArray(S.current)?S.current:[S.current]),g.current=null},v)},[v]),w=I8({callback:C,disabled:y||!s}),E=A.useCallback((O,R)=>{w&&(R&&(w.unobserve(R),d.current=!1),O&&w.observe(O))},[w]),[k,T]=a6(E),_=D2(t);return A.useEffect(()=>{!w||!k.current||(w.disconnect(),d.current=!1,w.observe(k.current))},[k,w]),A.useEffect(()=>(a({type:Wi.RegisterDroppable,element:{id:r,key:o,disabled:n,node:k,rect:p,data:_}}),()=>a({type:Wi.UnregisterDroppable,key:o,id:r})),[r]),A.useEffect(()=>{n!==u.current.disabled&&(a({type:Wi.SetDroppableDisabled,id:r,key:o,disabled:n}),u.current.disabled=n)},[r,o,n,a]),{active:s,rect:p,isOver:l?.id===r,node:k,over:l,setNodeRef:T}}function DI(e,t,n){const r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function z0t(e,t){return e.reduce((n,r,i)=>{const o=t.get(r);return o&&(n[i]=o),n},Array(e.length))}function rS(e){return e!==null&&e>=0}function B0t(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function H0t(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const Tue=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e;const o=DI(t,r,n),s=t[i],a=o[i];return!a||!s?null:{x:a.left-s.left,y:a.top-s.top,scaleX:a.width/s.width,scaleY:a.height/s.height}},iS={scaleX:1,scaleY:1},U0t=e=>{var t;let{activeIndex:n,activeNodeRect:r,index:i,rects:o,overIndex:s}=e;const a=(t=o[n])!=null?t:r;if(!a)return null;if(i===n){const c=o[s];return c?{x:0,y:n<s?c.top+c.height-(a.top+a.height):c.top-a.top,...iS}:null}const l=V0t(o,i,n);return i>n&&i<=s?{x:0,y:-a.height-l,...iS}:i<n&&i>=s?{x:0,y:a.height+l,...iS}:{x:0,y:0,...iS}};function V0t(e,t,n){const r=e[t],i=e[t-1],o=e[t+1];return r?n<t?i?r.top-(i.top+i.height):o?o.top-(r.top+r.height):0:o?o.top-(r.top+r.height):i?r.top-(i.top+i.height):0:0}const Oue="Sortable",Mue=on.createContext({activeIndex:-1,containerId:Oue,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Tue,disabled:{draggable:!1,droppable:!1}});function W0t(e){let{children:t,id:n,items:r,strategy:i=Tue,disabled:o=!1}=e;const{active:s,dragOverlay:a,droppableRects:l,over:c,measureDroppableContainers:u}=N0t(),d=Nv(Oue,n),p=a.rect!==null,g=A.useMemo(()=>r.map(T=>typeof T=="object"&&"id"in T?T.id:T),[r]),y=s!=null,b=s?g.indexOf(s.id):-1,v=c?g.indexOf(c.id):-1,S=A.useRef(g),C=!B0t(g,S.current),w=v!==-1&&b===-1||C,E=H0t(o);Nc(()=>{C&&y&&u(g)},[C,g,y,u]),A.useEffect(()=>{S.current=g},[g]);const k=A.useMemo(()=>({activeIndex:b,containerId:d,disabled:E,disableTransforms:w,items:g,overIndex:v,useDragOverlay:p,sortedRects:z0t(g,l),strategy:i}),[b,d,E.draggable,E.droppable,w,g,v,l,p,i]);return on.createElement(Mue.Provider,{value:k},t)}const q0t=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return DI(n,r,i).indexOf(t)},K0t=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:o,newIndex:s,previousItems:a,previousContainerId:l,transition:c}=e;return!c||!r||a!==o&&i===s?!1:n?!0:s!==i&&t===l},G0t={duration:200,easing:"ease"},jue="transform",Y0t=T2.Transition.toString({property:jue,duration:0,easing:"linear"}),J0t={roleDescription:"sortable"};function Z0t(e){let{disabled:t,index:n,node:r,rect:i}=e;const[o,s]=A.useState(null),a=A.useRef(n);return Nc(()=>{if(!t&&n!==a.current&&r.current){const l=i.current;if(l){const c=N0(r.current,{ignoreTransform:!0}),u={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(u.x||u.y)&&s(u)}}n!==a.current&&(a.current=n)},[t,n,r,i]),A.useEffect(()=>{o&&s(null)},[o]),o}function X0t(e){let{animateLayoutChanges:t=K0t,attributes:n,disabled:r,data:i,getNewIndex:o=q0t,id:s,strategy:a,resizeObserverConfig:l,transition:c=G0t}=e;const{items:u,containerId:d,activeIndex:p,disabled:g,disableTransforms:y,sortedRects:b,overIndex:v,useDragOverlay:S,strategy:C}=A.useContext(Mue),w=Q0t(r,g),E=u.indexOf(s),k=A.useMemo(()=>({sortable:{containerId:d,index:E,items:u},...i}),[d,i,E,u]),T=A.useMemo(()=>u.slice(u.indexOf(s)),[u,s]),{rect:_,node:O,isOver:R,setNodeRef:P}=F0t({id:s,data:k,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:T,...l}}),{active:L,activatorEvent:M,activeNodeRect:N,attributes:$,setNodeRef:B,listeners:F,isDragging:V,over:W,setActivatorNodeRef:q,transform:Z}=P0t({id:s,data:k,attributes:{...J0t,...n},disabled:w.draggable}),z=ggt(P,B),U=!!L,Y=U&&!y&&rS(p)&&rS(v),H=!S&&V,K=H&&Y?Z:null,ie=Y?K??(a??C)({rects:b,activeNodeRect:N,activeIndex:p,overIndex:v,index:E}):null,te=rS(p)&&rS(v)?o({id:s,items:u,activeIndex:p,overIndex:v}):E,ce=L?.id,ee=A.useRef({activeId:ce,items:u,newIndex:te,containerId:d}),J=u!==ee.current.items,X=t({active:L,containerId:d,isDragging:V,isSorting:U,id:s,index:E,items:u,newIndex:ee.current.newIndex,previousItems:ee.current.items,previousContainerId:ee.current.containerId,transition:c,wasDragging:ee.current.activeId!=null}),oe=Z0t({disabled:!X,index:E,node:O,rect:_});return A.useEffect(()=>{U&&ee.current.newIndex!==te&&(ee.current.newIndex=te),d!==ee.current.containerId&&(ee.current.containerId=d),u!==ee.current.items&&(ee.current.items=u)},[U,te,d,u]),A.useEffect(()=>{if(ce===ee.current.activeId)return;if(ce!=null&&ee.current.activeId==null){ee.current.activeId=ce;return}const fe=setTimeout(()=>{ee.current.activeId=ce},50);return()=>clearTimeout(fe)},[ce]),{active:L,activeIndex:p,attributes:$,data:k,rect:_,index:E,newIndex:te,items:u,isOver:R,isSorting:U,isDragging:V,listeners:F,node:O,overIndex:v,over:W,setNodeRef:z,setActivatorNodeRef:q,setDroppableNodeRef:P,setDraggableNodeRef:B,transform:oe??ie,transition:le()};function le(){if(oe||J&&ee.current.newIndex===E)return Y0t;if(!(H&&!wI(M)||!c)&&(U||X))return T2.Transition.toString({...c,property:jue})}}function Q0t(e,t){var n,r;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e?.draggable)!=null?n:t.draggable,droppable:(r=e?.droppable)!=null?r:t.droppable}}function u6(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const e1t=[Jn.Down,Jn.Right,Jn.Up,Jn.Left],t1t=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:o,over:s,scrollableAncestors:a}}=t;if(e1t.includes(e.code)){if(e.preventDefault(),!n||!r)return;const l=[];o.getEnabled().forEach(d=>{if(!d||d!=null&&d.disabled)return;const p=i.get(d.id);if(p)switch(e.code){case Jn.Down:r.top<p.top&&l.push(d);break;case Jn.Up:r.top>p.top&&l.push(d);break;case Jn.Left:r.left>p.left&&l.push(d);break;case Jn.Right:r.left<p.left&&l.push(d);break}});const c=Rgt({collisionRect:r,droppableRects:i,droppableContainers:l});let u=gue(c,"id");if(u===s?.id&&c.length>1&&(u=c[1].id),u!=null){const d=o.get(n.id),p=o.get(u),g=p?i.get(p.id):null,y=p?.node.current;if(y&&g&&d&&p){const v=R8(y).some((T,_)=>a[_]!==T),S=Rue(d,p),C=n1t(d,p),w=v||!S?{x:0,y:0}:{x:C?r.width-g.width:0,y:C?r.height-g.height:0},E={x:g.left,y:g.top};return w.x&&w.y?E:_2(E,w)}}}};function Rue(e,t){return!u6(e)||!u6(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function n1t(e,t){return!u6(e)||!u6(t)||!Rue(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const r1t=({bridge:e,index:t})=>{const{attributes:n,listeners:r,setNodeRef:i,transform:o,transition:s,isDragging:a}=X0t({id:e.id}),[l,c]=A.useState(!1);A.useEffect(()=>{hC(e.id).then(c)},[e.id]);const u={transform:T2.Transform.toString(o),transition:s,opacity:a?.5:1};return h.jsx(Mn,{ref:i,style:u,variant:"outlined",sx:{cursor:"grab","&:active":{cursor:"grabbing"},bgcolor:a?"action.selected":"background.paper",width:"fit-content"},children:h.jsxs(Qn,{sx:{display:"flex",alignItems:"center",gap:1.5,py:1,"&:last-child":{pb:1}},children:[h.jsx(se,{...n,...r,sx:{display:"flex",alignItems:"center",color:"text.secondary"},children:h.jsx(q_e,{})}),h.jsx(ot,{label:t+1,size:"small",color:"primary",sx:{minWidth:32,fontWeight:"bold"}}),l?h.jsx(se,{component:"img",src:Db(e.id),alt:e.name,sx:{width:40,height:40,borderRadius:"50%",objectFit:"cover",boxShadow:2}}):h.jsx(wl,{sx:{bgcolor:jM(e),width:40,height:40,boxShadow:2},children:(()=>{const d=MM(e);return h.jsx(d,{sx:{fontSize:24}})})()}),h.jsxs(se,{sx:{flex:1},children:[h.jsx(re,{variant:"subtitle1",fontWeight:500,children:e.name}),h.jsxs(re,{variant:"caption",color:"text.secondary",children:["Port: ",e.port," • Priority: ",e.priority??100]})]})]})})},i1t=()=>{const{t:e}=en(),t=Fc(),{content:n,isLoading:r}=h0(),i=h_e(),[o,s]=A.useState([]),[a,l]=A.useState(!1);A.useEffect(()=>{if(n){const g=[...n].sort((y,b)=>{const v=y.priority??100,S=b.priority??100;return v-S});s(g),l(!1)}},[n]);const c=Ogt(JY(AI),JY(kI,{coordinateGetter:t1t})),u=A.useCallback(g=>{const{active:y,over:b}=g;b&&y.id!==b.id&&(s(v=>{const S=v.findIndex(w=>w.id===y.id),C=v.findIndex(w=>w.id===b.id);return DI(v,S,C)}),l(!0))},[]),d=A.useCallback(async()=>{const g=o.map((y,b)=>({id:y.id,priority:(b+1)*10}));try{await i(g),t.show({message:e("startup.saveSuccess"),severity:"success"}),l(!1)}catch(y){t.show({message:y instanceof Error?y.message:e("startup.saveFailed"),severity:"error"})}},[o,i,t,e]),p=A.useMemo(()=>o.map(g=>g.id),[o]);return r?h.jsxs(re,{children:[e("common.loading"),"..."]}):h.jsxs(Wt,{spacing:3,children:[h.jsx(W2,{items:[{name:e("nav.bridges"),to:Ot.bridges},{name:e("startup.title"),to:Ot.startup}]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:2,children:[h.jsx(c0,{color:"primary",fontSize:"large"}),h.jsxs(se,{children:[h.jsx(re,{variant:"h5",fontWeight:600,children:e("startup.title")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e("startup.description")})]})]}),a&&h.jsx(zt,{severity:"info",action:h.jsx(Ue,{color:"inherit",size:"small",startIcon:h.jsx(F4,{}),onClick:d,children:e("startup.saveChanges")}),children:e("startup.unsavedChanges")}),h.jsx(j0t,{sensors:c,collisionDetection:jgt,onDragEnd:u,children:h.jsx(W0t,{items:p,strategy:U0t,children:h.jsx(Wt,{spacing:1,children:o.map((g,y)=>h.jsx(r1t,{bridge:g,index:y},g.id))})})}),o.length===0&&h.jsx(re,{color:"text.secondary",textAlign:"center",py:4,children:e("startup.noBridges")}),a&&o.length>0&&h.jsx(se,{display:"flex",justifyContent:"flex-end",children:h.jsx(Ue,{variant:"contained",startIcon:h.jsx(F4,{}),onClick:d,children:e("startup.saveOrder")})})]})},oS="https://riddix.github.io/home-assistant-matter-hub",Ot={dashboard:"/",bridges:"/bridges",bridge:e=>`/bridges/${e}`,createBridge:"/bridges/create",areaSetup:"/bridges/area-setup",editBridge:e=>`/bridges/${e}/edit`,devices:"/devices",networkMap:"/network-map",health:"/health",labels:"/labels",lockCredentials:"/lock-credentials",plugins:"/plugins",settings:"/settings",startup:"/startup",githubRepository:"https://github.com/riddix/home-assistant-matter-hub/",documentation:oS,support:`${oS}/support`,faq:{multiFabric:`${oS}/connect-multiple-fabrics`,bridgeConfig:`${oS}/bridge-configuration`}},o1t=[{path:"",element:h.jsx(fwe,{}),children:[{path:"",element:h.jsx(uOe,{})},{path:Ot.bridges,element:h.jsx(iOe,{})},{path:Ot.createBridge,element:h.jsx(elt,{})},{path:Ot.areaSetup,element:h.jsx(H6e,{})},{path:Ot.bridge(":bridgeId"),element:h.jsx(T_e,{})},{path:Ot.editBridge(":bridgeId"),element:h.jsx(tlt,{})},{path:Ot.devices,element:h.jsx(_Oe,{})},{path:Ot.networkMap,element:h.jsx(Bmt,{})},{path:Ot.health,element:h.jsx(xlt,{})},{path:Ot.labels,element:h.jsx(klt,{})},{path:Ot.lockCredentials,element:h.jsx(Olt,{})},{path:Ot.plugins,element:h.jsx(ugt,{})},{path:Ot.settings,element:h.jsx(mgt,{})},{path:Ot.startup,element:h.jsx(i1t,{})},{path:"*",element:h.jsx(Mlt,{})}]}],s1t={items:{isInitialized:!1,isLoading:!1}},a1t=FO(s1t,e=>{e.addCase(Lo.pending,t=>{t.items.isLoading=!0}).addCase(Lo.rejected,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=void 0,t.items.error=n.error}).addCase(Lo.fulfilled,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(AX.fulfilled,(t,n)=>{t.items.content?.push(n.payload)}).addCase(_X.fulfilled,(t,n)=>{const r=t.items.content?.findIndex(i=>i.id===n.payload.id)??-1;r!==-1&&(t.items.content[r]=n.payload)}).addCase(TX.fulfilled,(t,n)=>{const r=t.items.content?.findIndex(i=>i.id===n.payload.id)??-1;r!==-1&&(t.items.content[r]=n.payload)}).addCase(DX.fulfilled,(t,n)=>{if(t.items.content){const r=t.items.content.findIndex(i=>i.id===n.meta.arg);r!==-1&&t.items.content.splice(r,1)}}).addCase(OX,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(MX,(t,n)=>{if(t.items.content){const r=t.items.content.findIndex(i=>i.id===n.payload.id);r!==-1?t.items.content[r]=n.payload:t.items.content.push(n.payload)}})}),l1t={byBridge:{}},c1t=FO(l1t,e=>{e.addCase(Ru.pending,(t,n)=>{t.byBridge[n.meta.arg]=YA(t.byBridge[n.meta.arg],n)}).addCase(Ru.rejected,(t,n)=>{t.byBridge[n.meta.arg]=YA(t.byBridge[n.meta.arg],n)}).addCase(Ru.fulfilled,(t,n)=>{t.byBridge[n.meta.arg]=YA(t.byBridge[n.meta.arg],n)})}),u1t={isInitialized:!1,isLoading:!1,content:void 0,error:void 0},YA=FO(u1t,e=>{e.addCase(Ru.pending,t=>{t.isLoading=!0}).addCase(Ru.rejected,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=void 0,t.error=n.error}).addCase(Ru.fulfilled,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=n.payload,t.error=void 0})}),d1t=K4e({reducer:{bridges:a1t,devices:c1t}}),_I=M3e({createStyledComponent:ge("div",{name:"MuiContainer",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`maxWidth${ve(String(n.maxWidth))}`],n.fixed&&t.fixed,n.disableGutters&&t.disableGutters]}}),useThemeProps:e=>ct({props:e,name:"MuiContainer"})});function f1t(e){return tt("MuiToolbar",e)}st("MuiToolbar",["root","gutters","regular","dense"]);const h1t=e=>{const{classes:t,disableGutters:n,variant:r}=e;return nt({root:["root",!n&&"gutters",r]},f1t,t)},p1t=ge("div",{name:"MuiToolbar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,!n.disableGutters&&t.gutters,t[n.variant]]}})(Ye(({theme:e})=>({position:"relative",display:"flex",alignItems:"center",variants:[{props:({ownerState:t})=>!t.disableGutters,style:{paddingLeft:e.spacing(2),paddingRight:e.spacing(2),[e.breakpoints.up("sm")]:{paddingLeft:e.spacing(3),paddingRight:e.spacing(3)}}},{props:{variant:"dense"},style:{minHeight:48}},{props:{variant:"regular"},style:e.mixins.toolbar}]}))),Iue=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiToolbar"}),{className:i,component:o="div",disableGutters:s=!1,variant:a="regular",...l}=r,c={...r,component:o,disableGutters:s,variant:a},u=h1t(c);return h.jsx(p1t,{as:o,className:_e(u.root,i),ref:n,ownerState:c,...l})});class m1t extends A.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){console.error("ErrorBoundary caught:",t,n.componentStack)}render(){return this.state.hasError?h.jsxs(se,{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",gap:2,p:4,children:[h.jsx(QO,{color:"error",sx:{fontSize:64}}),h.jsx(re,{variant:"h5",fontWeight:600,children:pi.t("errorBoundary.title")}),h.jsx(re,{variant:"body2",color:"text.secondary",textAlign:"center",maxWidth:480,children:this.state.error?.message??pi.t("errorBoundary.fallbackMessage")}),h.jsx(Ue,{variant:"contained",onClick:()=>{this.setState({hasError:!1,error:null}),window.location.reload()},children:pi.t("errorBoundary.reload")})]}):this.props.children}}function g1t(e){return tt("MuiFab",e)}const cJ=st("MuiFab",["root","primary","secondary","extended","circular","focusVisible","disabled","colorInherit","sizeSmall","sizeMedium","sizeLarge","info","error","warning","success"]),y1t=e=>{const{color:t,variant:n,classes:r,size:i}=e,o={root:["root",n,`size${ve(i)}`,t==="inherit"?"colorInherit":t]},s=nt(o,g1t,r);return{...r,...s}},b1t=ge(ss,{name:"MuiFab",slot:"Root",shouldForwardProp:e=>Li(e)||e==="classes",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[n.variant],t[`size${ve(n.size)}`],n.color==="inherit"&&t.colorInherit,t[ve(n.size)],t[n.color]]}})(Ye(({theme:e})=>({...e.typography.button,minHeight:36,transition:e.transitions.create(["background-color","box-shadow","border-color"],{duration:e.transitions.duration.short}),borderRadius:"50%",padding:0,minWidth:0,width:56,height:56,zIndex:(e.vars||e).zIndex.fab,boxShadow:(e.vars||e).shadows[6],"&:active":{boxShadow:(e.vars||e).shadows[12]},color:e.vars?e.vars.palette.grey[900]:e.palette.getContrastText?.(e.palette.grey[300]),backgroundColor:(e.vars||e).palette.grey[300],"&:hover":{backgroundColor:(e.vars||e).palette.grey.A100,"@media (hover: none)":{backgroundColor:(e.vars||e).palette.grey[300]},textDecoration:"none"},[`&.${cJ.focusVisible}`]:{boxShadow:(e.vars||e).shadows[6]},variants:[{props:{size:"small"},style:{width:40,height:40}},{props:{size:"medium"},style:{width:48,height:48}},{props:{variant:"extended"},style:{borderRadius:48/2,padding:"0 16px",width:"auto",minHeight:"auto",minWidth:48,height:48}},{props:{variant:"extended",size:"small"},style:{width:"auto",padding:"0 8px",borderRadius:34/2,minWidth:34,height:34}},{props:{variant:"extended",size:"medium"},style:{width:"auto",padding:"0 16px",borderRadius:40/2,minWidth:40,height:40}},{props:{color:"inherit"},style:{color:"inherit"}}]})),Ye(({theme:e})=>({variants:[...Object.entries(e.palette).filter(Gn(["dark","contrastText"])).map(([t])=>({props:{color:t},style:{color:(e.vars||e).palette[t].contrastText,backgroundColor:(e.vars||e).palette[t].main,"&:hover":{backgroundColor:(e.vars||e).palette[t].dark,"@media (hover: none)":{backgroundColor:(e.vars||e).palette[t].main}}}}))]})),Ye(({theme:e})=>({[`&.${cJ.disabled}`]:{color:(e.vars||e).palette.action.disabled,boxShadow:(e.vars||e).shadows[0],backgroundColor:(e.vars||e).palette.action.disabledBackground}}))),v1t=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiFab"}),{children:i,className:o,color:s="default",component:a="button",disabled:l=!1,disableFocusRipple:c=!1,focusVisibleClassName:u,size:d="large",variant:p="circular",...g}=r,y={...r,color:s,component:a,disabled:l,disableFocusRipple:c,size:d,variant:p},b=y1t(y);return h.jsx(b1t,{className:_e(b.root,o),component:a,disabled:l,focusRipple:!c,focusVisibleClassName:_e(b.focusVisible,u),ownerState:y,ref:n,...g,classes:b,children:i})}),x1t=[{code:"en",flag:"🇬🇧",name:"English"},{code:"de",flag:"🇩🇪",name:"Deutsch"},{code:"fr",flag:"🇫🇷",name:"Français"},{code:"es",flag:"🇪🇸",name:"Español"},{code:"it",flag:"🇮🇹",name:"Italiano"},{code:"zh",flag:"🇨🇳",name:"中文"},{code:"zh-TW",flag:"🇹🇼",name:"繁體中文"},{code:"th",flag:"🇹🇭",name:"ไทย"},{code:"sv",flag:"🇸🇪",name:"Svenska"},{code:"tr",flag:"🇹🇷",name:"Türkçe"},{code:"ru",flag:"🇷🇺",name:"Русский"}],S1t="hamh-custom-languages";function w1t(){try{const e=localStorage.getItem(S1t);return e?JSON.parse(e).map(n=>({code:n.code,flag:"🌐",name:n.name})):[]}catch{return[]}}const C1t="https://github.com/RiDDiX/home-assistant-matter-hub/issues/new?labels=translation&title=Translation+improvement";function k1t(){const{t:e,i18n:t}=en(),[n,r]=A.useState(!1),i=A.useRef(null),o=A.useMemo(()=>[...x1t,...w1t()],[]),s=t.language??"en",a=o.some(d=>d.code===s)?s:s.split("-")[0]??"en",l=A.useCallback(()=>{r(d=>!d)},[]),c=A.useCallback(d=>{t.changeLanguage(d),r(!1)},[t]),u=A.useCallback(()=>{r(!1)},[]);return h.jsx(rX,{onClickAway:u,children:h.jsxs(se,{children:[h.jsx(v1t,{ref:i,size:"small",color:"primary",onClick:l,"aria-label":"Change language",sx:{position:"fixed",bottom:24,right:24,zIndex:1300},children:h.jsx(Q_e,{})}),h.jsx(G2,{open:n,anchorEl:i.current,placement:"top-end",transition:!0,sx:{zIndex:1300},children:({TransitionProps:d})=>h.jsx(M4,{...d,timeout:200,children:h.jsxs(zr,{elevation:8,sx:{mb:1,py:.5,minWidth:160,borderRadius:2,overflow:"hidden"},children:[o.map(p=>h.jsxs(se,{onClick:()=>c(p.code),sx:{display:"flex",alignItems:"center",gap:1.5,px:2,py:1,cursor:"pointer",bgcolor:a===p.code?"action.selected":"transparent","&:hover":{bgcolor:"action.hover"},transition:"background-color 0.15s"},children:[h.jsx(re,{sx:{fontSize:"1.4rem",lineHeight:1,userSelect:"none"},children:p.flag}),h.jsx(re,{variant:"body2",fontWeight:a===p.code?600:400,children:p.name})]},p.code)),h.jsx(Dr,{}),h.jsxs(se,{sx:{display:"flex",alignItems:"flex-start",gap:.75,px:2,py:1},children:[h.jsx(VO,{sx:{fontSize:14,mt:.25,color:"text.secondary"}}),h.jsxs(re,{variant:"caption",color:"text.secondary",sx:{lineHeight:1.4},children:[e("languageSwitcher.disclaimer")," ",h.jsx(V2,{href:C1t,target:"_blank",rel:"noopener",sx:{fontSize:"inherit"},children:e("languageSwitcher.contribute")})]})]})]})})})]})})}const E1t="home-assistant-matter-hub",A1t={name:E1t};function Pue(){const e="2.1.0-alpha.603",[t,n]=A.useState(null);A.useEffect(()=>{fetch("api/health").then(i=>i.ok?i.json():null).then(i=>{i?.version&&n(i.version)}).catch(()=>{})},[]);const r=A.useMemo(()=>!t||e==="0.0.0-dev"?!1:e!==t,[t]);return A.useMemo(()=>({name:A1t.name,version:t??e,frontendVersion:e,backendVersion:t,versionMismatch:r}),[t,r])}const D1t=()=>{const{t:e}=en(),t=[{name:e("footer.github"),url:Ot.githubRepository},{name:e("footer.documentation"),url:Ot.documentation},{name:e("footer.support"),url:Ot.support}];return h.jsxs(_I,{sx:{mt:16,mb:4},children:[h.jsx(Dr,{sx:{mt:4,mb:4}}),h.jsx(ht,{container:!0,spacing:2,justifyContent:"center",children:t.map((n,r)=>h.jsx(ht,{size:{xs:12,sm:"auto"},children:h.jsx(Ue,{fullWidth:!0,size:"small",variant:"outlined",component:V2,href:n.url,target:"_blank",children:n.name})},r.toString()))})]})};function _1t(e){return tt("MuiAppBar",e)}st("MuiAppBar",["root","positionFixed","positionAbsolute","positionSticky","positionStatic","positionRelative","colorDefault","colorPrimary","colorSecondary","colorInherit","colorTransparent","colorError","colorInfo","colorSuccess","colorWarning"]);const T1t=e=>{const{color:t,position:n,classes:r}=e,i={root:["root",`color${ve(t)}`,`position${ve(n)}`]};return nt(i,_1t,r)},uJ=(e,t)=>e?`${e.replace(")","")}, ${t})`:t,O1t=ge(zr,{name:"MuiAppBar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`position${ve(n.position)}`],t[`color${ve(n.color)}`]]}})(Ye(({theme:e})=>({display:"flex",flexDirection:"column",width:"100%",boxSizing:"border-box",flexShrink:0,variants:[{props:{position:"fixed"},style:{position:"fixed",zIndex:(e.vars||e).zIndex.appBar,top:0,left:"auto",right:0,"@media print":{position:"absolute"}}},{props:{position:"absolute"},style:{position:"absolute",zIndex:(e.vars||e).zIndex.appBar,top:0,left:"auto",right:0}},{props:{position:"sticky"},style:{position:"sticky",zIndex:(e.vars||e).zIndex.appBar,top:0,left:"auto",right:0}},{props:{position:"static"},style:{position:"static"}},{props:{position:"relative"},style:{position:"relative"}},{props:{color:"inherit"},style:{"--AppBar-color":"inherit",color:"var(--AppBar-color)"}},{props:{color:"default"},style:{"--AppBar-background":e.vars?e.vars.palette.AppBar.defaultBg:e.palette.grey[100],"--AppBar-color":e.vars?e.vars.palette.text.primary:e.palette.getContrastText(e.palette.grey[100]),...e.applyStyles("dark",{"--AppBar-background":e.vars?e.vars.palette.AppBar.defaultBg:e.palette.grey[900],"--AppBar-color":e.vars?e.vars.palette.text.primary:e.palette.getContrastText(e.palette.grey[900])})}},...Object.entries(e.palette).filter(Gn(["contrastText"])).map(([t])=>({props:{color:t},style:{"--AppBar-background":(e.vars??e).palette[t].main,"--AppBar-color":(e.vars??e).palette[t].contrastText}})),{props:t=>t.enableColorOnDark===!0&&!["inherit","transparent"].includes(t.color),style:{backgroundColor:"var(--AppBar-background)",color:"var(--AppBar-color)"}},{props:t=>t.enableColorOnDark===!1&&!["inherit","transparent"].includes(t.color),style:{backgroundColor:"var(--AppBar-background)",color:"var(--AppBar-color)",...e.applyStyles("dark",{backgroundColor:e.vars?uJ(e.vars.palette.AppBar.darkBg,"var(--AppBar-background)"):null,color:e.vars?uJ(e.vars.palette.AppBar.darkColor,"var(--AppBar-color)"):null})}},{props:{color:"transparent"},style:{"--AppBar-background":"transparent","--AppBar-color":"inherit",backgroundColor:"var(--AppBar-background)",color:"var(--AppBar-color)",...e.applyStyles("dark",{backgroundImage:"none"})}}]}))),M1t=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiAppBar"}),{className:i,color:o="primary",enableColorOnDark:s=!1,position:a="fixed",...l}=r,c={...r,color:o,position:a,enableColorOnDark:s},u=T1t(c);return h.jsx(O1t,{square:!0,component:"header",ownerState:c,elevation:4,className:_e(u.root,i,a==="fixed"&&"mui-fixed"),ref:n,...l})});function j1t(e,t,n){const r=t.getBoundingClientRect(),i=n&&n.getBoundingClientRect(),o=oa(t);let s;if(t.fakeTransform)s=t.fakeTransform;else{const c=o.getComputedStyle(t);s=c.getPropertyValue("-webkit-transform")||c.getPropertyValue("transform")}let a=0,l=0;if(s&&s!=="none"&&typeof s=="string"){const c=s.split("(")[1].split(")")[0].split(",");a=parseInt(c[4],10),l=parseInt(c[5],10)}return e==="left"?i?`translateX(${i.right+a-r.left}px)`:`translateX(${o.innerWidth+a-r.left}px)`:e==="right"?i?`translateX(-${r.right-i.left-a}px)`:`translateX(-${r.left+r.width-a}px)`:e==="up"?i?`translateY(${i.bottom+l-r.top}px)`:`translateY(${o.innerHeight+l-r.top}px)`:i?`translateY(-${r.top-i.top+r.height-l}px)`:`translateY(-${r.top+r.height-l}px)`}function R1t(e){return typeof e=="function"?e():e}function sS(e,t,n){const r=R1t(n),i=j1t(e,t,r);i&&(t.style.webkitTransform=i,t.style.transform=i)}const I1t=A.forwardRef(function(t,n){const r=Ki(),i={enter:r.transitions.easing.easeOut,exit:r.transitions.easing.sharp},o={enter:r.transitions.duration.enteringScreen,exit:r.transitions.duration.leavingScreen},{addEndListener:s,appear:a=!0,children:l,container:c,direction:u="down",easing:d=i,in:p,onEnter:g,onEntered:y,onEntering:b,onExit:v,onExited:S,onExiting:C,style:w,timeout:E=o,TransitionComponent:k=Ja,...T}=t,_=A.useRef(null),O=Br(Rf(l),_,n),R=W=>q=>{W&&(q===void 0?W(_.current):W(_.current,q))},P=R((W,q)=>{sS(u,W,c),IO(W),g&&g(W,q)}),L=R((W,q)=>{const Z=gf({timeout:E,style:w,easing:d},{mode:"enter"});W.style.webkitTransition=r.transitions.create("-webkit-transform",{...Z}),W.style.transition=r.transitions.create("transform",{...Z}),W.style.webkitTransform="none",W.style.transform="none",b&&b(W,q)}),M=R(y),N=R(C),$=R(W=>{const q=gf({timeout:E,style:w,easing:d},{mode:"exit"});W.style.webkitTransition=r.transitions.create("-webkit-transform",q),W.style.transition=r.transitions.create("transform",q),sS(u,W,c),v&&v(W)}),B=R(W=>{W.style.webkitTransition="",W.style.transition="",S&&S(W)}),F=W=>{s&&s(_.current,W)},V=A.useCallback(()=>{_.current&&sS(u,_.current,c)},[u,c]);return A.useEffect(()=>{if(p||u==="down"||u==="right")return;const W=H2(()=>{_.current&&sS(u,_.current,c)}),q=oa(_.current);return q.addEventListener("resize",W),()=>{W.clear(),q.removeEventListener("resize",W)}},[u,p,c]),A.useEffect(()=>{p||V()},[p,V]),h.jsx(k,{nodeRef:_,onEnter:P,onEntered:M,onEntering:L,onExit:$,onExited:B,onExiting:N,addEndListener:F,appear:a,in:p,timeout:E,...T,children:(W,{ownerState:q,...Z})=>A.cloneElement(l,{ref:O,style:{visibility:W==="exited"&&!p?"hidden":void 0,...w,...l.props.style},...Z})})});function P1t(e){return tt("MuiDrawer",e)}st("MuiDrawer",["root","docked","paper","anchorLeft","anchorRight","anchorTop","anchorBottom","paperAnchorLeft","paperAnchorRight","paperAnchorTop","paperAnchorBottom","paperAnchorDockedLeft","paperAnchorDockedRight","paperAnchorDockedTop","paperAnchorDockedBottom","modal"]);const Nue=(e,t)=>{const{ownerState:n}=e;return[t.root,(n.variant==="permanent"||n.variant==="persistent")&&t.docked,n.variant==="temporary"&&t.modal]},N1t=e=>{const{classes:t,anchor:n,variant:r}=e,i={root:["root",`anchor${ve(n)}`],docked:[(r==="permanent"||r==="persistent")&&"docked"],modal:["modal"],paper:["paper",`paperAnchor${ve(n)}`,r!=="temporary"&&`paperAnchorDocked${ve(n)}`]};return nt(i,P1t,t)},$1t=ge(nM,{name:"MuiDrawer",slot:"Root",overridesResolver:Nue})(Ye(({theme:e})=>({zIndex:(e.vars||e).zIndex.drawer}))),L1t=ge("div",{shouldForwardProp:Li,name:"MuiDrawer",slot:"Docked",skipVariantsResolver:!1,overridesResolver:Nue})({flex:"0 0 auto"}),F1t=ge(zr,{name:"MuiDrawer",slot:"Paper",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.paper,t[`paperAnchor${ve(n.anchor)}`],n.variant!=="temporary"&&t[`paperAnchorDocked${ve(n.anchor)}`]]}})(Ye(({theme:e})=>({overflowY:"auto",display:"flex",flexDirection:"column",height:"100%",flex:"1 0 auto",zIndex:(e.vars||e).zIndex.drawer,WebkitOverflowScrolling:"touch",position:"fixed",top:0,outline:0,variants:[{props:{anchor:"left"},style:{left:0}},{props:{anchor:"top"},style:{top:0,left:0,right:0,height:"auto",maxHeight:"100%"}},{props:{anchor:"right"},style:{right:0}},{props:{anchor:"bottom"},style:{top:"auto",left:0,bottom:0,right:0,height:"auto",maxHeight:"100%"}},{props:({ownerState:t})=>t.anchor==="left"&&t.variant!=="temporary",style:{borderRight:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:t})=>t.anchor==="top"&&t.variant!=="temporary",style:{borderBottom:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:t})=>t.anchor==="right"&&t.variant!=="temporary",style:{borderLeft:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:t})=>t.anchor==="bottom"&&t.variant!=="temporary",style:{borderTop:`1px solid ${(e.vars||e).palette.divider}`}}]}))),$ue={left:"right",right:"left",top:"down",bottom:"up"};function z1t(e){return["left","right"].includes(e)}function B1t({direction:e},t){return e==="rtl"&&z1t(t)?$ue[t]:t}const H1t=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiDrawer"}),i=Ki(),o=Lc(),s={enter:i.transitions.duration.enteringScreen,exit:i.transitions.duration.leavingScreen},{anchor:a="left",BackdropProps:l,children:c,className:u,elevation:d=16,hideBackdrop:p=!1,ModalProps:{BackdropProps:g,...y}={},onClose:b,open:v=!1,PaperProps:S={},SlideProps:C,TransitionComponent:w,transitionDuration:E=s,variant:k="temporary",slots:T={},slotProps:_={},...O}=r,R=A.useRef(!1);A.useEffect(()=>{R.current=!0},[]);const P=B1t({direction:o?"rtl":"ltr"},a),M={...r,anchor:a,elevation:d,open:v,variant:k,...O},N=N1t(M),$={slots:{transition:w,...T},slotProps:{paper:S,transition:C,..._,backdrop:MO(_.backdrop||{...l,...g},{transitionDuration:E})}},[B,F]=ft("root",{ref:n,elementType:$1t,className:_e(N.root,N.modal,u),shouldForwardComponentProp:!0,ownerState:M,externalForwardedProps:{...$,...O,...y},additionalProps:{open:v,onClose:b,hideBackdrop:p,slots:{backdrop:$.slots.backdrop},slotProps:{backdrop:$.slotProps.backdrop}}}),[V,W]=ft("paper",{elementType:F1t,shouldForwardComponentProp:!0,className:_e(N.paper,S.className),ownerState:M,externalForwardedProps:$,additionalProps:{elevation:k==="temporary"?d:0,square:!0,...k==="temporary"&&{role:"dialog","aria-modal":"true"}}}),[q,Z]=ft("docked",{elementType:L1t,ref:n,className:_e(N.root,N.docked,u),ownerState:M,externalForwardedProps:$,additionalProps:O}),[z,U]=ft("transition",{elementType:I1t,ownerState:M,externalForwardedProps:$,additionalProps:{in:v,direction:$ue[P],timeout:E,appear:R.current}}),Y=h.jsx(V,{...W,children:c});if(k==="permanent")return h.jsx(q,{...Z,children:Y});const H=h.jsx(z,{...U,children:Y});return k==="persistent"?h.jsx(q,{...Z,children:H}):h.jsx(B,{...F,children:H})}),U1t=PZ({themeId:ja}),V1t={error:Nf,warn:u0,info:eM,debug:dC},W1t=({open:e,onClose:t})=>{const{t:n}=en(),r=Ki(),i=A.useMemo(()=>({error:r.palette.error.main,warn:r.palette.warning.main,info:r.palette.info.main,debug:r.palette.secondary.main}),[r]),[o,s]=A.useState([]),[a,l]=A.useState(!0),[c,u]=A.useState("error,warn,info".split(",")),[d,p]=A.useState(""),[g,y]=A.useState(!0),b=A.useCallback(async()=>{try{const E=new URLSearchParams({level:c.join(","),limit:"500",...d&&{search:d}}),k=await fetch(`api/logs?${E}`);if(k.ok){const T=await k.json();s(T.entries)}}catch(E){console.error("Failed to fetch logs:",E)}finally{l(!1)}},[c,d]);A.useEffect(()=>{e&&b()},[e,b]),A.useEffect(()=>{if(!g||!e)return;const E=setInterval(b,5e3);return()=>clearInterval(E)},[g,e,b]);const v=E=>{u(Array.isArray(E.target.value)?E.target.value:[E.target.value])},S=E=>{p(E.target.value)},C=async()=>{try{await fetch("api/logs",{method:"DELETE"}),s([])}catch(E){console.error("Failed to clear logs:",E)}},w=E=>{const k=V1t[E]||eM;return h.jsx(k,{sx:{fontSize:16,color:i[E]}})};return h.jsxs(Po,{open:e,onClose:t,maxWidth:"lg",fullWidth:!0,children:[h.jsxs($o,{sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(dC,{}),n("logs.title"),h.jsx(se,{sx:{flexGrow:1}}),h.jsx(Lt,{title:n("logs.autoRefresh"),children:h.jsx(ot,{label:g?"Auto":"Manual",color:g?"success":"default",size:"small",onClick:()=>y(!g),sx:{cursor:"pointer"}})}),h.jsx(qt,{onClick:t,children:h.jsx(L4,{})})]}),h.jsxs(No,{children:[h.jsx(Wt,{spacing:2,sx:{mb:2},children:h.jsxs(Wt,{direction:"row",spacing:2,alignItems:"center",children:[h.jsxs(rs,{size:"small",sx:{minWidth:200},children:[h.jsx(Ia,{children:n("logs.logLevel")}),h.jsxs(ts,{value:c,label:n("logs.logLevel"),onChange:v,multiple:!0,renderValue:E=>h.jsx(se,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:(Array.isArray(E)?E:[E]).map(k=>h.jsx(ot,{label:k.toUpperCase(),size:"small",sx:{backgroundColor:i[k],color:"white"}},k))}),children:[h.jsx(Bn,{value:"error",children:n("logs.error")}),h.jsx(Bn,{value:"warn",children:n("logs.warning")}),h.jsx(Bn,{value:"info",children:n("logs.info")}),h.jsx(Bn,{value:"debug",children:n("logs.debug")})]})]}),h.jsx(zn,{size:"small",placeholder:n("logs.searchPlaceholder"),value:d,onChange:S,sx:{flexGrow:1}}),h.jsx(Ue,{variant:"outlined",onClick:b,children:n("common.refresh")}),h.jsx(Ue,{variant:"outlined",color:"error",onClick:C,children:n("common.delete")})]})}),h.jsx(se,{sx:{height:400,overflow:"auto",backgroundColor:"background.paper",border:1,borderColor:"divider",borderRadius:1,p:1},children:a?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsxs(re,{children:[n("common.loading"),"..."]})}):o.length===0?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsx(re,{color:"text.secondary",children:n("logs.noResults")})}):h.jsx(Wt,{spacing:1,children:o.map((E,k)=>h.jsxs(se,{sx:{p:1,borderRadius:1,backgroundColor:"action.hover",fontFamily:"monospace",fontSize:"0.875rem",wordBreak:"break-all"},children:[h.jsxs(se,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[w(E.level),h.jsx(re,{variant:"caption",color:"text.secondary",children:new Date(E.timestamp).toLocaleString()}),h.jsx(ot,{label:E.level.toUpperCase(),size:"small",sx:{backgroundColor:i[E.level],color:r.palette.getContrastText(i[E.level]??r.palette.grey[500]),fontSize:"0.7rem",height:20}})]}),h.jsx(re,{sx:{ml:3},children:E.message}),E.context&&h.jsx(re,{sx:{ml:3,color:"text.secondary",fontSize:"0.8rem"},children:JSON.stringify(E.context,null,2)})]},`${E.timestamp}-${E.level}-${k}`))})})]}),h.jsx(es,{children:h.jsx(Ue,{onClick:t,children:n("common.close")})})]})};function dJ(){const{t:e}=en(),{isConnected:t}=RX(),[n,r]=A.useState(null),[i,o]=A.useState(!1);A.useEffect(()=>{const b=async()=>{try{const S=await fetch("api/health");if(S.ok){const C=await S.json();r(C),o(!1)}else o(!0)}catch{o(!0)}};b();const v=setInterval(b,3e4);return()=>clearInterval(v)},[]);const s=b=>{const v=Math.floor(b/3600),S=Math.floor(b%3600/60);return v>0?`${v}h ${S}m`:`${S}m`},a=n?.status==="healthy"&&!i,l=n?.services?.bridges,c=l&&l.total>0&&l.running===l.total,u=l&&l.total===0,d=n?h.jsxs(se,{sx:{p:.5},children:[h.jsxs("div",{children:[h.jsxs("strong",{children:[e("health.version"),":"]})," ",n.version??e("status.unknown")]}),h.jsxs("div",{children:[h.jsxs("strong",{children:[e("health.uptime"),":"]})," ",s(n.uptime??0)]}),n.services?.bridges&&h.jsxs("div",{children:[h.jsxs("strong",{children:[e("nav.bridges"),":"]})," ",n.services.bridges.running??0,"/",n.services.bridges.total??0," ",e("common.running").toLowerCase(),(n.services.bridges.stopped??0)>0&&` (${n.services.bridges.stopped} ${e("common.stopped").toLowerCase()})`]}),n.services?.homeAssistant&&h.jsxs("div",{children:[h.jsxs("strong",{children:[e("health.homeAssistant"),":"]})," ",n.services.homeAssistant.connected?e("health.connected"):e("health.disconnected")]}),h.jsxs("div",{children:[h.jsx("strong",{children:"WebSocket:"})," ",e(t?"health.connected":"health.disconnected")]})]}):e("status.loadingHealth"),p=()=>i||!a?h.jsx(Nf,{fontSize:"small"}):c?h.jsx(Za,{fontSize:"small"}):h.jsx(Y6,{fontSize:"small"}),g=()=>i||!a?"error":!c||!t?"warning":"success",y=()=>e(i?"status.error":a?t?u?"status.noBridges":c?"common.online":"common.starting":"common.offline":"status.unhealthy");return h.jsx(Lt,{title:d,arrow:!0,children:h.jsx(ot,{icon:p(),label:y(),color:g(),size:"small",variant:"filled",sx:{borderRadius:1,fontWeight:600,"& .MuiChip-icon":{color:"inherit"}}})})}const q1t=e=>A.createElement("svg",{viewBox:"0 0 91 89",xmlSpace:"preserve",xmlns:"http://www.w3.org/2000/svg",...e},A.createElement("g",{style:{display:"inline"}},A.createElement("path",{style:{fill:"#18bcf2",fillOpacity:1,strokeWidth:.266194},d:"m 49.149143,1.473171 38.513568,38.536435 c 0,0 1.248354,1.186052 2.207681,3.092371 0.959329,1.906323 1.10864,4.600698 1.10864,4.600698 v 36.786372 c 0,0 -0.01549,1.748506 -1.49842,3.050572 -1.482931,1.302064 -3.333077,1.362947 -3.333077,1.362947 l -81.325658,7.7e-5 c 0,0 -1.7523855,-0.0091 -3.17112,-1.352526 C -0.07808495,85.913164 0.05953025,84.487808 0.05953025,84.487808 V 47.704546 c 0,0 -0.0018381,-2.218618 0.95921785,-4.315832 0.9610554,-2.097209 2.3010618,-3.355005 2.3010618,-3.355005 L 41.545959,1.4719546 c 0,0 1.465224,-1.46837077 3.753488,-1.46837077 2.288268,0 3.849696,1.46958717 3.849696,1.46958717 z"}),A.createElement("path",{style:{fill:"#ffffff",fillOpacity:1,strokeWidth:.175841},d:"m 31.689717,32.051124 c 2.813363,2.331095 6.157331,3.89845 9.721813,4.556421 V 17.180647 l 3.873694,-2.282955 3.870527,2.282955 V 36.60772 c 3.565364,-0.658847 6.910387,-2.226204 9.725159,-4.556417 l 7.032345,4.154609 c -11.437354,11.557779 -29.852321,11.557779 -41.290025,0 z m 8.546732,49.60988 C 44.314996,65.760441 35.09933,49.470196 19.574984,45.139543 v 8.312381 c 3.383916,1.32244 6.386113,3.496288 8.728705,6.320026 L 11.83076,69.485301 v 4.56907 l 3.873697,2.270836 16.469936,-9.713534 c 1.224356,3.48294 1.56683,7.225375 0.996449,10.879778 z M 70.977694,45.139543 c -15.515726,4.34014 -24.72189,20.626696 -20.643519,36.521461 l 7.047658,-4.15742 c -0.569325,-3.654411 -0.2265,-7.3965 0.996449,-10.87979 l 16.457611,9.701233 3.870711,-2.283125 v -4.55677 L 62.233673,59.77195 c 2.342772,-2.822684 5.34497,-4.996533 8.728708,-6.320026 z"}))),K1t=e=>{const t=Pue();return h.jsxs(se,{component:Oc,to:Ot.dashboard,sx:{display:"flex",alignItems:"center",justifyContent:e.large?"flex-start":"center",flexGrow:1,textDecoration:"none",color:"inherit"},children:[h.jsx(q1t,{style:{height:"40px"}}),h.jsx(re,{variant:"inherit",component:"span",sx:{mr:1,ml:1},children:t.name.split("-").map(ve).join("-")}),e.large&&h.jsx(re,{variant:"caption",component:"span",children:t.version})]})},G1t=()=>{const e=U1t("(min-width:600px)"),{mode:t,setMode:n}=I6(),[r,i]=A.useState(!1),[o,s]=A.useState(!1),a=$c(),l=Yu(),c=y=>y?y==="/"?l.pathname==="/":l.pathname.startsWith(y):!1,u=()=>{n(t==="dark"?"light":"dark")},{t:d}=en(),p=[{label:d("dashboard.title"),icon:h.jsx(kM,{}),to:Ot.dashboard},{label:d("nav.bridges"),icon:h.jsx(Ly,{}),to:Ot.bridges},{label:d("nav.devices"),icon:h.jsx(aa,{}),to:Ot.devices},{label:d("nav.networkMap"),icon:h.jsx(SM,{}),to:Ot.networkMap},{label:d("nav.startupOrder"),icon:h.jsx(c0,{}),to:Ot.startup},{label:d("nav.lockCredentials"),icon:h.jsx(ju,{}),to:Ot.lockCredentials},{label:d("nav.filterReference"),icon:h.jsx(EM,{}),to:Ot.labels},{label:"Plugins",icon:h.jsx($y,{}),to:Ot.plugins},{label:d("nav.settings"),icon:h.jsx(f0,{}),to:Ot.settings},{label:d(t==="dark"?"nav.lightMode":"nav.darkMode"),icon:t==="dark"?h.jsx(tTe,{}):h.jsx(U_e,{}),onClick:u},{label:d("nav.systemLogs"),icon:h.jsx(dC,{}),onClick:()=>i(!0)},{label:d("nav.health"),icon:h.jsx(iM,{}),to:Ot.health}],g=y=>{s(!1),y.onClick?y.onClick():y.to&&a(y.to)};return h.jsxs(se,{children:[h.jsx(M1t,{sx:{height:"72px"},children:h.jsx(Iue,{sx:{paddingLeft:"0 !important",paddingRight:"0 !important"},children:h.jsxs(_I,{sx:{padding:2,height:"100%",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsx(K1t,{large:e}),e?h.jsxs(se,{sx:{display:"flex",alignItems:"center",gap:1},children:[p.map(y=>y.to?h.jsx(Lt,{title:y.label,children:h.jsx(qt,{component:Oc,to:y.to,sx:{color:"inherit",bgcolor:c(y.to)?"rgba(255,255,255,0.15)":"transparent",borderRadius:1},children:y.icon})},y.label):h.jsx(Lt,{title:y.label,children:h.jsx(qt,{onClick:y.onClick,sx:{color:"inherit"},children:y.icon})},y.label)),h.jsx(dJ,{})]}):h.jsxs(se,{sx:{display:"flex",alignItems:"center",gap:.5},children:[h.jsx(dJ,{}),h.jsx(qt,{onClick:()=>s(!0),sx:{color:"inherit"},children:h.jsx(nTe,{})})]})]})})}),h.jsx(H1t,{anchor:"right",open:o,onClose:()=>s(!1),children:h.jsx(Fo,{sx:{width:250},children:p.map(y=>h.jsxs(oCe,{selected:c(y.to),onClick:()=>g(y),children:[h.jsx(Io,{children:y.icon}),h.jsx(ao,{primary:y.label})]},y.label))})}),h.jsx(W1t,{open:r,onClose:()=>i(!1)})]})},Y1t=()=>{const{versionMismatch:e,frontendVersion:t,backendVersion:n}=Pue(),{isConnected:r}=RX();return h.jsxs(se,{children:[h.jsx(G1t,{}),h.jsx(Iue,{}),e&&h.jsxs(zt,{severity:"warning",variant:"filled",sx:{borderRadius:0},action:h.jsx(Ue,{color:"inherit",size:"small",onClick:()=>window.location.reload(),children:"Reload"}),children:["Version mismatch: frontend ",t,", backend ",n,". Please reload to get the latest UI."]}),!r&&h.jsx(zt,{severity:"error",variant:"filled",sx:{borderRadius:0},children:"Connection lost — data may be outdated. Reconnecting…"}),h.jsx(_I,{sx:{p:2},children:h.jsx(m1t,{children:h.jsx(HJ,{})})}),h.jsx(D1t,{}),h.jsx(k1t,{})]})},J1t=M6({colorSchemes:{light:{palette:{primary:{main:"#1976d2",light:"#42a5f5",dark:"#1565c0"},secondary:{main:"#9c27b0",light:"#ba68c8",dark:"#7b1fa2"},background:{default:"#f5f5f5",paper:"#ffffff"}}},dark:{palette:{primary:{main:"#90caf9",light:"#e3f2fd",dark:"#42a5f5"},secondary:{main:"#ce93d8",light:"#f3e5f5",dark:"#ab47bc"},background:{default:"#121212",paper:"#1e1e1e"}}}},typography:{fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',h1:{fontSize:"2.5rem",fontWeight:500},h2:{fontSize:"2rem",fontWeight:500},h3:{fontSize:"1.75rem",fontWeight:500},h4:{fontSize:"1.5rem",fontWeight:500},h5:{fontSize:"1.25rem",fontWeight:500},h6:{fontSize:"1rem",fontWeight:500}},shape:{borderRadius:8},components:{MuiCard:{styleOverrides:{root:{transition:"transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out","&:hover":{transform:"translateY(-2px)",boxShadow:"0 4px 20px rgba(0,0,0,0.12)"}}}},MuiButton:{styleOverrides:{root:{textTransform:"none",fontWeight:500}}},MuiChip:{styleOverrides:{root:{fontWeight:500}}},MuiAppBar:{styleOverrides:{root:{backgroundImage:"none"}}}}});let a4=document.getElementsByTagName("base")[0]?.href?.replace(/\/$/,"");a4?.startsWith("http")&&(a4=new URL(a4).pathname);const Z1t=Pme([{path:"/",element:h.jsx(Y1t,{}),children:o1t}],{basename:a4});Xfe.createRoot(document.getElementById("root")).render(h.jsx(A.StrictMode,{children:h.jsx(mhe,{store:d1t,children:h.jsxs(H5e,{theme:J1t,children:[h.jsx($5e,{}),h.jsx(JZ,{styles:{".rjsf-field-array > .MuiFormControl-root > .MuiPaper-root > .MuiBox-root > .MuiGrid-root > .MuiGrid-root:has(> .MuiBox-root > .MuiPaper-root > .MuiBox-root > .rjsf-field)":{overflow:"initial !important",flexGrow:1}}}),h.jsx(dwe,{children:h.jsx(n4e,{children:h.jsx(Gme,{router:Z1t})})})]})})}));
|
|
499
|
+
`},_gt={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function Tgt(e){let{announcements:t=_gt,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=Dgt}=e;const{announce:o,announcement:s}=kgt(),a=Nv("DndLiveRegion"),[l,c]=A.useState(!1);if(A.useEffect(()=>{c(!0)},[]),Egt(A.useMemo(()=>({onDragStart(d){let{active:p}=d;o(t.onDragStart({active:p}))},onDragMove(d){let{active:p,over:g}=d;t.onDragMove&&o(t.onDragMove({active:p,over:g}))},onDragOver(d){let{active:p,over:g}=d;o(t.onDragOver({active:p,over:g}))},onDragEnd(d){let{active:p,over:g}=d;o(t.onDragEnd({active:p,over:g}))},onDragCancel(d){let{active:p,over:g}=d;o(t.onDragCancel({active:p,over:g}))}}),[o,t])),!l)return null;const u=on.createElement(on.Fragment,null,on.createElement(wgt,{id:r,value:i.draggable}),on.createElement(Cgt,{id:a,announcement:s}));return n?qd.createPortal(u,n):u}var Wi;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Wi||(Wi={}));function l6(){}function JY(e,t){return A.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Ogt(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return A.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const El=Object.freeze({x:0,y:0});function pue(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function mue(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function Mgt(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function ZY(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function gue(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function XY(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}const jgt=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=XY(t,t.left,t.top),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=pue(XY(l),i);o.push({id:a,data:{droppableContainer:s,value:c}})}}return o.sort(mue)},Rgt=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=ZY(t),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=ZY(l),u=i.reduce((p,g,y)=>p+pue(c[y],g),0),d=Number((u/4).toFixed(4));o.push({id:a,data:{droppableContainer:s,value:d}})}}return o.sort(mue)};function Igt(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),o=Math.min(t.top+t.height,e.top+e.height),s=i-r,a=o-n;if(r<i&&n<o){const l=t.width*t.height,c=e.width*e.height,u=s*a,d=u/(l+c-u);return Number(d.toFixed(4))}return 0}const Pgt=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=[];for(const o of r){const{id:s}=o,a=n.get(s);if(a){const l=Igt(a,t);l>0&&i.push({id:s,data:{droppableContainer:o,value:l}})}}return i.sort(Mgt)};function Ngt(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function yue(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:El}function $gt(e){return function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];return i.reduce((s,a)=>({...s,top:s.top+e*a.y,bottom:s.bottom+e*a.y,left:s.left+e*a.x,right:s.right+e*a.x}),{...n})}}const Lgt=$gt(1);function Fgt(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function zgt(e,t,n){const r=Fgt(t);if(!r)return e;const{scaleX:i,scaleY:o,x:s,y:a}=r,l=e.left-s-(1-i)*parseFloat(n),c=e.top-a-(1-o)*parseFloat(n.slice(n.indexOf(" ")+1)),u=i?e.width/i:e.width,d=o?e.height/o:e.height;return{width:u,height:d,top:c,right:l+u,bottom:c+d,left:l}}const Bgt={ignoreTransform:!1};function N0(e,t){t===void 0&&(t=Bgt);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:c,transformOrigin:u}=Ps(e).getComputedStyle(e);c&&(n=zgt(n,c,u))}const{top:r,left:i,width:o,height:s,bottom:a,right:l}=n;return{top:r,left:i,width:o,height:s,bottom:a,right:l}}function QY(e){return N0(e,{ignoreTransform:!0})}function Hgt(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function Ugt(e,t){return t===void 0&&(t=Ps(e).getComputedStyle(e)),t.position==="fixed"}function Vgt(e,t){t===void 0&&(t=Ps(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(i=>{const o=t[i];return typeof o=="string"?n.test(o):!1})}function R8(e,t){const n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(xI(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!Iv(i)||due(i)||n.includes(i))return n;const o=Ps(e).getComputedStyle(i);return i!==e&&Vgt(i,o)&&n.push(i),Ugt(i,o)?n:r(i.parentNode)}return e?r(e):n}function bue(e){const[t]=R8(e,1);return t??null}function qA(e){return!j8||!e?null:I0(e)?e:vI(e)?xI(e)||e===P0(e).scrollingElement?window:Iv(e)?e:null:null}function vue(e){return I0(e)?e.scrollX:e.scrollLeft}function xue(e){return I0(e)?e.scrollY:e.scrollTop}function XT(e){return{x:vue(e),y:xue(e)}}var io;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(io||(io={}));function Sue(e){return!j8||!e?!1:e===document.scrollingElement}function wue(e){const t={x:0,y:0},n=Sue(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},i=e.scrollTop<=t.y,o=e.scrollLeft<=t.x,s=e.scrollTop>=r.y,a=e.scrollLeft>=r.x;return{isTop:i,isLeft:o,isBottom:s,isRight:a,maxScroll:r,minScroll:t}}const Wgt={x:.2,y:.2};function qgt(e,t,n,r,i){let{top:o,left:s,right:a,bottom:l}=n;r===void 0&&(r=10),i===void 0&&(i=Wgt);const{isTop:c,isBottom:u,isLeft:d,isRight:p}=wue(e),g={x:0,y:0},y={x:0,y:0},b={height:t.height*i.y,width:t.width*i.x};return!c&&o<=t.top+b.height?(g.y=io.Backward,y.y=r*Math.abs((t.top+b.height-o)/b.height)):!u&&l>=t.bottom-b.height&&(g.y=io.Forward,y.y=r*Math.abs((t.bottom-b.height-l)/b.height)),!p&&a>=t.right-b.width?(g.x=io.Forward,y.x=r*Math.abs((t.right-b.width-a)/b.width)):!d&&s<=t.left+b.width&&(g.x=io.Backward,y.x=r*Math.abs((t.left+b.width-s)/b.width)),{direction:g,speed:y}}function Kgt(e){if(e===document.scrollingElement){const{innerWidth:o,innerHeight:s}=window;return{top:0,left:0,right:o,bottom:s,width:o,height:s}}const{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Cue(e){return e.reduce((t,n)=>Cg(t,XT(n)),El)}function Ggt(e){return e.reduce((t,n)=>t+vue(n),0)}function Ygt(e){return e.reduce((t,n)=>t+xue(n),0)}function Jgt(e,t){if(t===void 0&&(t=N0),!e)return;const{top:n,left:r,bottom:i,right:o}=t(e);bue(e)&&(i<=0||o<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const Zgt=[["x",["left","right"],Ggt],["y",["top","bottom"],Ygt]];class CI{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const r=R8(n),i=Cue(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,s,a]of Zgt)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=a(r),u=i[o]-c;return this.rect[l]+u},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class sb{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=t}add(t,n,r){var i;(i=this.target)==null||i.addEventListener(t,n,r),this.listeners.push([t,n,r])}}function Xgt(e){const{EventTarget:t}=Ps(e);return e instanceof t?e:P0(e)}function KA(e,t){const n=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+r**2)>t:"x"in t&&"y"in t?n>t.x&&r>t.y:"x"in t?n>t.x:"y"in t?r>t.y:!1}var ka;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(ka||(ka={}));function eJ(e){e.preventDefault()}function Qgt(e){e.stopPropagation()}var Jn;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Jn||(Jn={}));const kue={start:[Jn.Space,Jn.Enter],cancel:[Jn.Esc],end:[Jn.Space,Jn.Enter,Jn.Tab]},e0t=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Jn.Right:return{...n,x:n.x+25};case Jn.Left:return{...n,x:n.x-25};case Jn.Down:return{...n,y:n.y+25};case Jn.Up:return{...n,y:n.y-25}}};class kI{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new sb(P0(n)),this.windowListeners=new sb(Ps(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(ka.Resize,this.handleCancel),this.windowListeners.add(ka.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(ka.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,r=t.node.current;r&&Jgt(r),n(El)}handleKeyDown(t){if(wI(t)){const{active:n,context:r,options:i}=this.props,{keyboardCodes:o=kue,coordinateGetter:s=e0t,scrollBehavior:a="smooth"}=i,{code:l}=t;if(o.end.includes(l)){this.handleEnd(t);return}if(o.cancel.includes(l)){this.handleCancel(t);return}const{collisionRect:c}=r.current,u=c?{x:c.left,y:c.top}:El;this.referenceCoordinates||(this.referenceCoordinates=u);const d=s(t,{active:n,context:r.current,currentCoordinates:u});if(d){const p=_2(d,u),g={x:0,y:0},{scrollableAncestors:y}=r.current;for(const b of y){const v=t.code,{isTop:S,isRight:C,isLeft:w,isBottom:E,maxScroll:k,minScroll:T}=wue(b),_=Kgt(b),O={x:Math.min(v===Jn.Right?_.right-_.width/2:_.right,Math.max(v===Jn.Right?_.left:_.left+_.width/2,d.x)),y:Math.min(v===Jn.Down?_.bottom-_.height/2:_.bottom,Math.max(v===Jn.Down?_.top:_.top+_.height/2,d.y))},R=v===Jn.Right&&!C||v===Jn.Left&&!w,P=v===Jn.Down&&!E||v===Jn.Up&&!S;if(R&&O.x!==d.x){const L=b.scrollLeft+p.x,M=v===Jn.Right&&L<=k.x||v===Jn.Left&&L>=T.x;if(M&&!p.y){b.scrollTo({left:L,behavior:a});return}M?g.x=b.scrollLeft-L:g.x=v===Jn.Right?b.scrollLeft-k.x:b.scrollLeft-T.x,g.x&&b.scrollBy({left:-g.x,behavior:a});break}else if(P&&O.y!==d.y){const L=b.scrollTop+p.y,M=v===Jn.Down&&L<=k.y||v===Jn.Up&&L>=T.y;if(M&&!p.x){b.scrollTo({top:L,behavior:a});return}M?g.y=b.scrollTop-L:g.y=v===Jn.Down?b.scrollTop-k.y:b.scrollTop-T.y,g.y&&b.scrollBy({top:-g.y,behavior:a});break}}this.handleMove(t,Cg(_2(d,this.referenceCoordinates),g))}}}handleMove(t,n){const{onMove:r}=this.props;t.preventDefault(),r(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}kI.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:r=kue,onActivation:i}=t,{active:o}=n;const{code:s}=e.nativeEvent;if(r.start.includes(s)){const a=o.activatorNode.current;return a&&e.target!==a?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function tJ(e){return!!(e&&"distance"in e)}function nJ(e){return!!(e&&"delay"in e)}class EI{constructor(t,n,r){var i;r===void 0&&(r=Xgt(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:o}=t,{target:s}=o;this.props=t,this.events=n,this.document=P0(s),this.documentListeners=new sb(this.document),this.listeners=new sb(r),this.windowListeners=new sb(Ps(s)),this.initialCoordinates=(i=ZT(o))!=null?i:El,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(ka.Resize,this.handleCancel),this.windowListeners.add(ka.DragStart,eJ),this.windowListeners.add(ka.VisibilityChange,this.handleCancel),this.windowListeners.add(ka.ContextMenu,eJ),this.documentListeners.add(ka.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(nJ(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(tJ(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:r,onPending:i}=this.props;i(r,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(ka.Click,Qgt,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(ka.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:r,initialCoordinates:i,props:o}=this,{onMove:s,options:{activationConstraint:a}}=o;if(!i)return;const l=(n=ZT(t))!=null?n:El,c=_2(i,l);if(!r&&a){if(tJ(a)){if(a.tolerance!=null&&KA(c,a.tolerance))return this.handleCancel();if(KA(c,a.distance))return this.handleStart()}if(nJ(a)&&KA(c,a.tolerance))return this.handleCancel();this.handlePending(a,c);return}t.cancelable&&t.preventDefault(),s(l)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===Jn.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const t0t={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class AI extends EI{constructor(t){const{event:n}=t,r=P0(n.target);super(t,t0t,r)}}AI.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];const n0t={move:{name:"mousemove"},end:{name:"mouseup"}};var QT;(function(e){e[e.RightClick=2]="RightClick"})(QT||(QT={}));class r0t extends EI{constructor(t){super(t,n0t,P0(t.event.target))}}r0t.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===QT.RightClick?!1:(r?.({event:n}),!0)}}];const GA={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class i0t extends EI{constructor(t){super(t,GA)}static setup(){return window.addEventListener(GA.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(GA.move.name,t)};function t(){}}}i0t.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;const{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var ab;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(ab||(ab={}));var c6;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(c6||(c6={}));function o0t(e){let{acceleration:t,activator:n=ab.Pointer,canScroll:r,draggingRect:i,enabled:o,interval:s=5,order:a=c6.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:u,delta:d,threshold:p}=e;const g=a0t({delta:d,disabled:!o}),[y,b]=ygt(),v=A.useRef({x:0,y:0}),S=A.useRef({x:0,y:0}),C=A.useMemo(()=>{switch(n){case ab.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case ab.DraggableRect:return i}},[n,i,l]),w=A.useRef(null),E=A.useCallback(()=>{const T=w.current;if(!T)return;const _=v.current.x*S.current.x,O=v.current.y*S.current.y;T.scrollBy(_,O)},[]),k=A.useMemo(()=>a===c6.TreeOrder?[...c].reverse():c,[a,c]);A.useEffect(()=>{if(!o||!c.length||!C){b();return}for(const T of k){if(r?.(T)===!1)continue;const _=c.indexOf(T),O=u[_];if(!O)continue;const{direction:R,speed:P}=qgt(T,O,C,t,p);for(const L of["x","y"])g[L][R[L]]||(P[L]=0,R[L]=0);if(P.x>0||P.y>0){b(),w.current=T,y(E,s),v.current=P,S.current=R;return}}v.current={x:0,y:0},S.current={x:0,y:0},b()},[t,E,r,b,o,s,JSON.stringify(C),JSON.stringify(g),y,c,k,u,JSON.stringify(p)])}const s0t={x:{[io.Backward]:!1,[io.Forward]:!1},y:{[io.Backward]:!1,[io.Forward]:!1}};function a0t(e){let{delta:t,disabled:n}=e;const r=JT(t);return Pv(i=>{if(n||!r||!i)return s0t;const o={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[io.Backward]:i.x[io.Backward]||o.x===-1,[io.Forward]:i.x[io.Forward]||o.x===1},y:{[io.Backward]:i.y[io.Backward]||o.y===-1,[io.Forward]:i.y[io.Forward]||o.y===1}}},[n,t,r])}function l0t(e,t){const n=t!=null?e.get(t):void 0,r=n?n.node.current:null;return Pv(i=>{var o;return t==null?null:(o=r??i)!=null?o:null},[r,t])}function c0t(e,t){return A.useMemo(()=>e.reduce((n,r)=>{const{sensor:i}=r,o=i.activators.map(s=>({eventName:s.eventName,handler:t(s.handler,r)}));return[...n,...o]},[]),[e,t])}var O2;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(O2||(O2={}));var eO;(function(e){e.Optimized="optimized"})(eO||(eO={}));const rJ=new Map;function u0t(e,t){let{dragging:n,dependencies:r,config:i}=t;const[o,s]=A.useState(null),{frequency:a,measure:l,strategy:c}=i,u=A.useRef(e),d=v(),p=D2(d),g=A.useCallback(function(S){S===void 0&&(S=[]),!p.current&&s(C=>C===null?S:C.concat(S.filter(w=>!C.includes(w))))},[p]),y=A.useRef(null),b=Pv(S=>{if(d&&!n)return rJ;if(!S||S===rJ||u.current!==e||o!=null){const C=new Map;for(let w of e){if(!w)continue;if(o&&o.length>0&&!o.includes(w.id)&&w.rect.current){C.set(w.id,w.rect.current);continue}const E=w.node.current,k=E?new CI(l(E),E):null;w.rect.current=k,k&&C.set(w.id,k)}return C}return S},[e,o,n,d,l]);return A.useEffect(()=>{u.current=e},[e]),A.useEffect(()=>{d||g()},[n,d]),A.useEffect(()=>{o&&o.length>0&&s(null)},[JSON.stringify(o)]),A.useEffect(()=>{d||typeof a!="number"||y.current!==null||(y.current=setTimeout(()=>{g(),y.current=null},a))},[a,d,g,...r]),{droppableRects:b,measureDroppableContainers:g,measuringScheduled:o!=null};function v(){switch(c){case O2.Always:return!1;case O2.BeforeDragging:return n;default:return!n}}}function Eue(e,t){return Pv(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function d0t(e,t){return Eue(e,t)}function f0t(e){let{callback:t,disabled:n}=e;const r=SI(t),i=A.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(r)},[r,n]);return A.useEffect(()=>()=>i?.disconnect(),[i]),i}function I8(e){let{callback:t,disabled:n}=e;const r=SI(t),i=A.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(r)},[n]);return A.useEffect(()=>()=>i?.disconnect(),[i]),i}function h0t(e){return new CI(N0(e),e)}function iJ(e,t,n){t===void 0&&(t=h0t);const[r,i]=A.useState(null);function o(){i(l=>{if(!e)return null;if(e.isConnected===!1){var c;return(c=l??n)!=null?c:null}const u=t(e);return JSON.stringify(l)===JSON.stringify(u)?l:u})}const s=f0t({callback(l){if(e)for(const c of l){const{type:u,target:d}=c;if(u==="childList"&&d instanceof HTMLElement&&d.contains(e)){o();break}}}}),a=I8({callback:o});return Nc(()=>{o(),e?(a?.observe(e),s?.observe(document.body,{childList:!0,subtree:!0})):(a?.disconnect(),s?.disconnect())},[e]),r}function p0t(e){const t=Eue(e);return yue(e,t)}const oJ=[];function m0t(e){const t=A.useRef(e),n=Pv(r=>e?r&&r!==oJ&&e&&t.current&&e.parentNode===t.current.parentNode?r:R8(e):oJ,[e]);return A.useEffect(()=>{t.current=e},[e]),n}function g0t(e){const[t,n]=A.useState(null),r=A.useRef(e),i=A.useCallback(o=>{const s=qA(o.target);s&&n(a=>a?(a.set(s,XT(s)),new Map(a)):null)},[]);return A.useEffect(()=>{const o=r.current;if(e!==o){s(o);const a=e.map(l=>{const c=qA(l);return c?(c.addEventListener("scroll",i,{passive:!0}),[c,XT(c)]):null}).filter(l=>l!=null);n(a.length?new Map(a):null),r.current=e}return()=>{s(e),s(o)};function s(a){a.forEach(l=>{const c=qA(l);c?.removeEventListener("scroll",i)})}},[i,e]),A.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,s)=>Cg(o,s),El):Cue(e):El,[e,t])}function sJ(e,t){t===void 0&&(t=[]);const n=A.useRef(null);return A.useEffect(()=>{n.current=null},t),A.useEffect(()=>{const r=e!==El;r&&!n.current&&(n.current=e),!r&&n.current&&(n.current=null)},[e]),n.current?_2(e,n.current):El}function y0t(e){A.useEffect(()=>{if(!j8)return;const t=e.map(n=>{let{sensor:r}=n;return r.setup==null?void 0:r.setup()});return()=>{for(const n of t)n?.()}},e.map(t=>{let{sensor:n}=t;return n}))}function b0t(e,t){return A.useMemo(()=>e.reduce((n,r)=>{let{eventName:i,handler:o}=r;return n[i]=s=>{o(s,t)},n},{}),[e,t])}function Aue(e){return A.useMemo(()=>e?Hgt(e):null,[e])}const aJ=[];function v0t(e,t){t===void 0&&(t=N0);const[n]=e,r=Aue(n?Ps(n):null),[i,o]=A.useState(aJ);function s(){o(()=>e.length?e.map(l=>Sue(l)?r:new CI(t(l),l)):aJ)}const a=I8({callback:s});return Nc(()=>{a?.disconnect(),s(),e.forEach(l=>a?.observe(l))},[e]),i}function x0t(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Iv(t)?t:e}function S0t(e){let{measure:t}=e;const[n,r]=A.useState(null),i=A.useCallback(c=>{for(const{target:u}of c)if(Iv(u)){r(d=>{const p=t(u);return d?{...d,width:p.width,height:p.height}:p});break}},[t]),o=I8({callback:i}),s=A.useCallback(c=>{const u=x0t(c);o?.disconnect(),u&&o?.observe(u),r(u?t(u):null)},[t,o]),[a,l]=a6(s);return A.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const w0t=[{sensor:AI,options:{}},{sensor:kI,options:{}}],C0t={current:{}},s4={draggable:{measure:QY},droppable:{measure:QY,strategy:O2.WhileDragging,frequency:eO.Optimized},dragOverlay:{measure:N0}};class lb extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,r;return(n=(r=this.get(t))==null?void 0:r.node.current)!=null?n:void 0}}const k0t={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new lb,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:l6},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:s4,measureDroppableContainers:l6,windowRect:null,measuringScheduled:!1},E0t={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:l6,draggableNodes:new Map,over:null,measureDroppableContainers:l6},P8=A.createContext(E0t),Due=A.createContext(k0t);function A0t(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new lb}}}function D0t(e,t){switch(t.type){case Wi.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Wi.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Wi.DragEnd:case Wi.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Wi.RegisterDroppable:{const{element:n}=t,{id:r}=n,i=new lb(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case Wi.SetDroppableDisabled:{const{id:n,key:r,disabled:i}=t,o=e.droppable.containers.get(n);if(!o||r!==o.key)return e;const s=new lb(e.droppable.containers);return s.set(n,{...o,disabled:i}),{...e,droppable:{...e.droppable,containers:s}}}case Wi.UnregisterDroppable:{const{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;const o=new lb(e.droppable.containers);return o.delete(n),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function _0t(e){let{disabled:t}=e;const{active:n,activatorEvent:r,draggableNodes:i}=A.useContext(P8),o=JT(r),s=JT(n?.id);return A.useEffect(()=>{if(!t&&!r&&o&&s!=null){if(!wI(o)||document.activeElement===o.target)return;const a=i.get(s);if(!a)return;const{activatorNode:l,node:c}=a;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const u of[l.current,c.current]){if(!u)continue;const d=xgt(u);if(d){d.focus();break}}})}},[r,t,i,s,o]),null}function T0t(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((i,o)=>o({transform:i,...r}),n):n}function O0t(e){return A.useMemo(()=>({draggable:{...s4.draggable,...e?.draggable},droppable:{...s4.droppable,...e?.droppable},dragOverlay:{...s4.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function M0t(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e;const o=A.useRef(!1),{x:s,y:a}=typeof i=="boolean"?{x:i,y:i}:i;Nc(()=>{if(!s&&!a||!t){o.current=!1;return}if(o.current||!r)return;const c=t?.node.current;if(!c||c.isConnected===!1)return;const u=n(c),d=yue(u,r);if(s||(d.x=0),a||(d.y=0),o.current=!0,Math.abs(d.x)>0||Math.abs(d.y)>0){const p=bue(c);p&&p.scrollBy({top:d.y,left:d.x})}},[t,s,a,r,n])}const _ue=A.createContext({...El,scaleX:1,scaleY:1});var Ld;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Ld||(Ld={}));const j0t=A.memo(function(t){var n,r,i,o;let{id:s,accessibility:a,autoScroll:l=!0,children:c,sensors:u=w0t,collisionDetection:d=Pgt,measuring:p,modifiers:g,...y}=t;const b=A.useReducer(D0t,void 0,A0t),[v,S]=b,[C,w]=Agt(),[E,k]=A.useState(Ld.Uninitialized),T=E===Ld.Initialized,{draggable:{active:_,nodes:O,translate:R},droppable:{containers:P}}=v,L=_!=null?O.get(_):null,M=A.useRef({initial:null,translated:null}),N=A.useMemo(()=>{var We;return _!=null?{id:_,data:(We=L?.data)!=null?We:C0t,rect:M}:null},[_,L]),$=A.useRef(null),[B,F]=A.useState(null),[V,W]=A.useState(null),q=D2(y,Object.values(y)),Z=Nv("DndDescribedBy",s),z=A.useMemo(()=>P.getEnabled(),[P]),U=O0t(p),{droppableRects:Y,measureDroppableContainers:H,measuringScheduled:K}=u0t(z,{dragging:T,dependencies:[R.x,R.y],config:U.droppable}),Q=l0t(O,_),ie=A.useMemo(()=>V?ZT(V):null,[V]),te=Ge(),ce=d0t(Q,U.draggable.measure);M0t({activeNode:_!=null?O.get(_):null,config:te.layoutShiftCompensation,initialRect:ce,measure:U.draggable.measure});const ee=iJ(Q,U.draggable.measure,ce),J=iJ(Q?Q.parentElement:null),X=A.useRef({activatorEvent:null,active:null,activeNode:Q,collisionRect:null,collisions:null,droppableRects:Y,draggableNodes:O,draggingNode:null,draggingNodeRect:null,droppableContainers:P,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),oe=P.getNodeFor((n=X.current.over)==null?void 0:n.id),le=S0t({measure:U.dragOverlay.measure}),fe=(r=le.nodeRef.current)!=null?r:Q,ye=T?(i=le.rect)!=null?i:ee:null,Me=!!(le.nodeRef.current&&le.rect),ue=p0t(Me?null:ee),we=Aue(fe?Ps(fe):null),Oe=m0t(T?oe??Q:null),He=v0t(Oe),ze=T0t(g,{transform:{x:R.x-ue.x,y:R.y-ue.y,scaleX:1,scaleY:1},activatorEvent:V,active:N,activeNodeRect:ee,containerNodeRect:J,draggingNodeRect:ye,over:X.current.over,overlayNodeRect:le.rect,scrollableAncestors:Oe,scrollableAncestorRects:He,windowRect:we}),At=ie?Cg(ie,R):null,gt=g0t(Oe),$e=sJ(gt),je=sJ(gt,[ee]),Ve=Cg(ze,$e),Ke=ye?Lgt(ye,ze):null,at=N&&Ke?d({active:N,collisionRect:Ke,droppableRects:Y,droppableContainers:z,pointerCoordinates:At}):null,ut=gue(at,"id"),[Qe,Bt]=A.useState(null),Ht=Me?ze:Cg(ze,je),Pt=Ngt(Ht,(o=Qe?.rect)!=null?o:null,ee),Dn=A.useRef(null),tn=A.useCallback((We,Je)=>{let{sensor:St,options:In}=Je;if($.current==null)return;const dn=O.get($.current);if(!dn)return;const _t=We.nativeEvent,yn=new St({active:$.current,activeNode:dn,event:_t,options:In,context:X,onAbort(yt){if(!O.get(yt))return;const{onDragAbort:ae}=q.current,pe={id:yt};ae?.(pe),C({type:"onDragAbort",event:pe})},onPending(yt,Kt,ae,pe){if(!O.get(yt))return;const{onDragPending:Pe}=q.current,qe={id:yt,constraint:Kt,initialCoordinates:ae,offset:pe};Pe?.(qe),C({type:"onDragPending",event:qe})},onStart(yt){const Kt=$.current;if(Kt==null)return;const ae=O.get(Kt);if(!ae)return;const{onDragStart:pe}=q.current,xe={activatorEvent:_t,active:{id:Kt,data:ae.data,rect:M}};qd.unstable_batchedUpdates(()=>{pe?.(xe),k(Ld.Initializing),S({type:Wi.DragStart,initialCoordinates:yt,active:Kt}),C({type:"onDragStart",event:xe}),F(Dn.current),W(_t)})},onMove(yt){S({type:Wi.DragMove,coordinates:yt})},onEnd:dt(Wi.DragEnd),onCancel:dt(Wi.DragCancel)});Dn.current=yn;function dt(yt){return async function(){const{active:ae,collisions:pe,over:xe,scrollAdjustedTranslate:Pe}=X.current;let qe=null;if(ae&&Pe){const{cancelDrop:wt}=q.current;qe={activatorEvent:_t,active:ae,collisions:pe,delta:Pe,over:xe},yt===Wi.DragEnd&&typeof wt=="function"&&await Promise.resolve(wt(qe))&&(yt=Wi.DragCancel)}$.current=null,qd.unstable_batchedUpdates(()=>{S({type:yt}),k(Ld.Uninitialized),Bt(null),F(null),W(null),Dn.current=null;const wt=yt===Wi.DragEnd?"onDragEnd":"onDragCancel";if(qe){const lt=q.current[wt];lt?.(qe),C({type:wt,event:qe})}})}}},[O]),pt=A.useCallback((We,Je)=>(St,In)=>{const dn=St.nativeEvent,_t=O.get(In);if($.current!==null||!_t||dn.dndKit||dn.defaultPrevented)return;const yn={active:_t};We(St,Je.options,yn)===!0&&(dn.dndKit={capturedBy:Je.sensor},$.current=In,tn(St,Je))},[O,tn]),Yt=c0t(u,pt);y0t(u),Nc(()=>{ee&&E===Ld.Initializing&&k(Ld.Initialized)},[ee,E]),A.useEffect(()=>{const{onDragMove:We}=q.current,{active:Je,activatorEvent:St,collisions:In,over:dn}=X.current;if(!Je||!St)return;const _t={active:Je,activatorEvent:St,collisions:In,delta:{x:Ve.x,y:Ve.y},over:dn};qd.unstable_batchedUpdates(()=>{We?.(_t),C({type:"onDragMove",event:_t})})},[Ve.x,Ve.y]),A.useEffect(()=>{const{active:We,activatorEvent:Je,collisions:St,droppableContainers:In,scrollAdjustedTranslate:dn}=X.current;if(!We||$.current==null||!Je||!dn)return;const{onDragOver:_t}=q.current,yn=In.get(ut),dt=yn&&yn.rect.current?{id:yn.id,rect:yn.rect.current,data:yn.data,disabled:yn.disabled}:null,yt={active:We,activatorEvent:Je,collisions:St,delta:{x:dn.x,y:dn.y},over:dt};qd.unstable_batchedUpdates(()=>{Bt(dt),_t?.(yt),C({type:"onDragOver",event:yt})})},[ut]),Nc(()=>{X.current={activatorEvent:V,active:N,activeNode:Q,collisionRect:Ke,collisions:at,droppableRects:Y,draggableNodes:O,draggingNode:fe,draggingNodeRect:ye,droppableContainers:P,over:Qe,scrollableAncestors:Oe,scrollAdjustedTranslate:Ve},M.current={initial:ye,translated:Ke}},[N,Q,at,Ke,O,fe,ye,Y,P,Qe,Oe,Ve]),o0t({...te,delta:R,draggingRect:Ke,pointerCoordinates:At,scrollableAncestors:Oe,scrollableAncestorRects:He});const an=A.useMemo(()=>({active:N,activeNode:Q,activeNodeRect:ee,activatorEvent:V,collisions:at,containerNodeRect:J,dragOverlay:le,draggableNodes:O,droppableContainers:P,droppableRects:Y,over:Qe,measureDroppableContainers:H,scrollableAncestors:Oe,scrollableAncestorRects:He,measuringConfiguration:U,measuringScheduled:K,windowRect:we}),[N,Q,ee,V,at,J,le,O,P,Y,Qe,H,Oe,He,U,K,we]),wn=A.useMemo(()=>({activatorEvent:V,activators:Yt,active:N,activeNodeRect:ee,ariaDescribedById:{draggable:Z},dispatch:S,draggableNodes:O,over:Qe,measureDroppableContainers:H}),[V,Yt,N,ee,S,Z,O,Qe,H]);return on.createElement(hue.Provider,{value:w},on.createElement(P8.Provider,{value:wn},on.createElement(Due.Provider,{value:an},on.createElement(_ue.Provider,{value:Pt},c)),on.createElement(_0t,{disabled:a?.restoreFocus===!1})),on.createElement(Tgt,{...a,hiddenTextDescribedById:Z}));function Ge(){const We=B?.autoScrollEnabled===!1,Je=typeof l=="object"?l.enabled===!1:l===!1,St=T&&!We&&!Je;return typeof l=="object"?{...l,enabled:St}:{enabled:St}}}),R0t=A.createContext(null),lJ="button",I0t="Draggable";function P0t(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e;const o=Nv(I0t),{activators:s,activatorEvent:a,active:l,activeNodeRect:c,ariaDescribedById:u,draggableNodes:d,over:p}=A.useContext(P8),{role:g=lJ,roleDescription:y="draggable",tabIndex:b=0}=i??{},v=l?.id===t,S=A.useContext(v?_ue:R0t),[C,w]=a6(),[E,k]=a6(),T=b0t(s,t),_=D2(n);Nc(()=>(d.set(t,{id:t,key:o,node:C,activatorNode:E,data:_}),()=>{const R=d.get(t);R&&R.key===o&&d.delete(t)}),[d,t]);const O=A.useMemo(()=>({role:g,tabIndex:b,"aria-disabled":r,"aria-pressed":v&&g===lJ?!0:void 0,"aria-roledescription":y,"aria-describedby":u.draggable}),[r,g,b,v,y,u.draggable]);return{active:l,activatorEvent:a,activeNodeRect:c,attributes:O,isDragging:v,listeners:r?void 0:T,node:C,over:p,setNodeRef:w,setActivatorNodeRef:k,transform:S}}function N0t(){return A.useContext(Due)}const $0t="Droppable",L0t={timeout:25};function F0t(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e;const o=Nv($0t),{active:s,dispatch:a,over:l,measureDroppableContainers:c}=A.useContext(P8),u=A.useRef({disabled:n}),d=A.useRef(!1),p=A.useRef(null),g=A.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:v}={...L0t,...i},S=D2(b??r),C=A.useCallback(()=>{if(!d.current){d.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{c(Array.isArray(S.current)?S.current:[S.current]),g.current=null},v)},[v]),w=I8({callback:C,disabled:y||!s}),E=A.useCallback((O,R)=>{w&&(R&&(w.unobserve(R),d.current=!1),O&&w.observe(O))},[w]),[k,T]=a6(E),_=D2(t);return A.useEffect(()=>{!w||!k.current||(w.disconnect(),d.current=!1,w.observe(k.current))},[k,w]),A.useEffect(()=>(a({type:Wi.RegisterDroppable,element:{id:r,key:o,disabled:n,node:k,rect:p,data:_}}),()=>a({type:Wi.UnregisterDroppable,key:o,id:r})),[r]),A.useEffect(()=>{n!==u.current.disabled&&(a({type:Wi.SetDroppableDisabled,id:r,key:o,disabled:n}),u.current.disabled=n)},[r,o,n,a]),{active:s,rect:p,isOver:l?.id===r,node:k,over:l,setNodeRef:T}}function DI(e,t,n){const r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function z0t(e,t){return e.reduce((n,r,i)=>{const o=t.get(r);return o&&(n[i]=o),n},Array(e.length))}function rS(e){return e!==null&&e>=0}function B0t(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function H0t(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const Tue=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e;const o=DI(t,r,n),s=t[i],a=o[i];return!a||!s?null:{x:a.left-s.left,y:a.top-s.top,scaleX:a.width/s.width,scaleY:a.height/s.height}},iS={scaleX:1,scaleY:1},U0t=e=>{var t;let{activeIndex:n,activeNodeRect:r,index:i,rects:o,overIndex:s}=e;const a=(t=o[n])!=null?t:r;if(!a)return null;if(i===n){const c=o[s];return c?{x:0,y:n<s?c.top+c.height-(a.top+a.height):c.top-a.top,...iS}:null}const l=V0t(o,i,n);return i>n&&i<=s?{x:0,y:-a.height-l,...iS}:i<n&&i>=s?{x:0,y:a.height+l,...iS}:{x:0,y:0,...iS}};function V0t(e,t,n){const r=e[t],i=e[t-1],o=e[t+1];return r?n<t?i?r.top-(i.top+i.height):o?o.top-(r.top+r.height):0:o?o.top-(r.top+r.height):i?r.top-(i.top+i.height):0:0}const Oue="Sortable",Mue=on.createContext({activeIndex:-1,containerId:Oue,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Tue,disabled:{draggable:!1,droppable:!1}});function W0t(e){let{children:t,id:n,items:r,strategy:i=Tue,disabled:o=!1}=e;const{active:s,dragOverlay:a,droppableRects:l,over:c,measureDroppableContainers:u}=N0t(),d=Nv(Oue,n),p=a.rect!==null,g=A.useMemo(()=>r.map(T=>typeof T=="object"&&"id"in T?T.id:T),[r]),y=s!=null,b=s?g.indexOf(s.id):-1,v=c?g.indexOf(c.id):-1,S=A.useRef(g),C=!B0t(g,S.current),w=v!==-1&&b===-1||C,E=H0t(o);Nc(()=>{C&&y&&u(g)},[C,g,y,u]),A.useEffect(()=>{S.current=g},[g]);const k=A.useMemo(()=>({activeIndex:b,containerId:d,disabled:E,disableTransforms:w,items:g,overIndex:v,useDragOverlay:p,sortedRects:z0t(g,l),strategy:i}),[b,d,E.draggable,E.droppable,w,g,v,l,p,i]);return on.createElement(Mue.Provider,{value:k},t)}const q0t=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return DI(n,r,i).indexOf(t)},K0t=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:o,newIndex:s,previousItems:a,previousContainerId:l,transition:c}=e;return!c||!r||a!==o&&i===s?!1:n?!0:s!==i&&t===l},G0t={duration:200,easing:"ease"},jue="transform",Y0t=T2.Transition.toString({property:jue,duration:0,easing:"linear"}),J0t={roleDescription:"sortable"};function Z0t(e){let{disabled:t,index:n,node:r,rect:i}=e;const[o,s]=A.useState(null),a=A.useRef(n);return Nc(()=>{if(!t&&n!==a.current&&r.current){const l=i.current;if(l){const c=N0(r.current,{ignoreTransform:!0}),u={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(u.x||u.y)&&s(u)}}n!==a.current&&(a.current=n)},[t,n,r,i]),A.useEffect(()=>{o&&s(null)},[o]),o}function X0t(e){let{animateLayoutChanges:t=K0t,attributes:n,disabled:r,data:i,getNewIndex:o=q0t,id:s,strategy:a,resizeObserverConfig:l,transition:c=G0t}=e;const{items:u,containerId:d,activeIndex:p,disabled:g,disableTransforms:y,sortedRects:b,overIndex:v,useDragOverlay:S,strategy:C}=A.useContext(Mue),w=Q0t(r,g),E=u.indexOf(s),k=A.useMemo(()=>({sortable:{containerId:d,index:E,items:u},...i}),[d,i,E,u]),T=A.useMemo(()=>u.slice(u.indexOf(s)),[u,s]),{rect:_,node:O,isOver:R,setNodeRef:P}=F0t({id:s,data:k,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:T,...l}}),{active:L,activatorEvent:M,activeNodeRect:N,attributes:$,setNodeRef:B,listeners:F,isDragging:V,over:W,setActivatorNodeRef:q,transform:Z}=P0t({id:s,data:k,attributes:{...J0t,...n},disabled:w.draggable}),z=ggt(P,B),U=!!L,Y=U&&!y&&rS(p)&&rS(v),H=!S&&V,K=H&&Y?Z:null,ie=Y?K??(a??C)({rects:b,activeNodeRect:N,activeIndex:p,overIndex:v,index:E}):null,te=rS(p)&&rS(v)?o({id:s,items:u,activeIndex:p,overIndex:v}):E,ce=L?.id,ee=A.useRef({activeId:ce,items:u,newIndex:te,containerId:d}),J=u!==ee.current.items,X=t({active:L,containerId:d,isDragging:V,isSorting:U,id:s,index:E,items:u,newIndex:ee.current.newIndex,previousItems:ee.current.items,previousContainerId:ee.current.containerId,transition:c,wasDragging:ee.current.activeId!=null}),oe=Z0t({disabled:!X,index:E,node:O,rect:_});return A.useEffect(()=>{U&&ee.current.newIndex!==te&&(ee.current.newIndex=te),d!==ee.current.containerId&&(ee.current.containerId=d),u!==ee.current.items&&(ee.current.items=u)},[U,te,d,u]),A.useEffect(()=>{if(ce===ee.current.activeId)return;if(ce!=null&&ee.current.activeId==null){ee.current.activeId=ce;return}const fe=setTimeout(()=>{ee.current.activeId=ce},50);return()=>clearTimeout(fe)},[ce]),{active:L,activeIndex:p,attributes:$,data:k,rect:_,index:E,newIndex:te,items:u,isOver:R,isSorting:U,isDragging:V,listeners:F,node:O,overIndex:v,over:W,setNodeRef:z,setActivatorNodeRef:q,setDroppableNodeRef:P,setDraggableNodeRef:B,transform:oe??ie,transition:le()};function le(){if(oe||J&&ee.current.newIndex===E)return Y0t;if(!(H&&!wI(M)||!c)&&(U||X))return T2.Transition.toString({...c,property:jue})}}function Q0t(e,t){var n,r;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e?.draggable)!=null?n:t.draggable,droppable:(r=e?.droppable)!=null?r:t.droppable}}function u6(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const e1t=[Jn.Down,Jn.Right,Jn.Up,Jn.Left],t1t=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:o,over:s,scrollableAncestors:a}}=t;if(e1t.includes(e.code)){if(e.preventDefault(),!n||!r)return;const l=[];o.getEnabled().forEach(d=>{if(!d||d!=null&&d.disabled)return;const p=i.get(d.id);if(p)switch(e.code){case Jn.Down:r.top<p.top&&l.push(d);break;case Jn.Up:r.top>p.top&&l.push(d);break;case Jn.Left:r.left>p.left&&l.push(d);break;case Jn.Right:r.left<p.left&&l.push(d);break}});const c=Rgt({collisionRect:r,droppableRects:i,droppableContainers:l});let u=gue(c,"id");if(u===s?.id&&c.length>1&&(u=c[1].id),u!=null){const d=o.get(n.id),p=o.get(u),g=p?i.get(p.id):null,y=p?.node.current;if(y&&g&&d&&p){const v=R8(y).some((T,_)=>a[_]!==T),S=Rue(d,p),C=n1t(d,p),w=v||!S?{x:0,y:0}:{x:C?r.width-g.width:0,y:C?r.height-g.height:0},E={x:g.left,y:g.top};return w.x&&w.y?E:_2(E,w)}}}};function Rue(e,t){return!u6(e)||!u6(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function n1t(e,t){return!u6(e)||!u6(t)||!Rue(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const r1t=({bridge:e,index:t})=>{const{attributes:n,listeners:r,setNodeRef:i,transform:o,transition:s,isDragging:a}=X0t({id:e.id}),[l,c]=A.useState(!1);A.useEffect(()=>{hC(e.id).then(c)},[e.id]);const u={transform:T2.Transform.toString(o),transition:s,opacity:a?.5:1};return h.jsx(Mn,{ref:i,style:u,variant:"outlined",sx:{cursor:"grab","&:active":{cursor:"grabbing"},bgcolor:a?"action.selected":"background.paper",width:"fit-content"},children:h.jsxs(Qn,{sx:{display:"flex",alignItems:"center",gap:1.5,py:1,"&:last-child":{pb:1}},children:[h.jsx(se,{...n,...r,sx:{display:"flex",alignItems:"center",color:"text.secondary"},children:h.jsx(q_e,{})}),h.jsx(ot,{label:t+1,size:"small",color:"primary",sx:{minWidth:32,fontWeight:"bold"}}),l?h.jsx(se,{component:"img",src:Db(e.id),alt:e.name,sx:{width:40,height:40,borderRadius:"50%",objectFit:"cover",boxShadow:2}}):h.jsx(wl,{sx:{bgcolor:jM(e),width:40,height:40,boxShadow:2},children:(()=>{const d=MM(e);return h.jsx(d,{sx:{fontSize:24}})})()}),h.jsxs(se,{sx:{flex:1},children:[h.jsx(re,{variant:"subtitle1",fontWeight:500,children:e.name}),h.jsxs(re,{variant:"caption",color:"text.secondary",children:["Port: ",e.port," • Priority: ",e.priority??100]})]})]})})},i1t=()=>{const{t:e}=en(),t=Fc(),{content:n,isLoading:r}=h0(),i=h_e(),[o,s]=A.useState([]),[a,l]=A.useState(!1);A.useEffect(()=>{if(n){const g=[...n].sort((y,b)=>{const v=y.priority??100,S=b.priority??100;return v-S});s(g),l(!1)}},[n]);const c=Ogt(JY(AI),JY(kI,{coordinateGetter:t1t})),u=A.useCallback(g=>{const{active:y,over:b}=g;b&&y.id!==b.id&&(s(v=>{const S=v.findIndex(w=>w.id===y.id),C=v.findIndex(w=>w.id===b.id);return DI(v,S,C)}),l(!0))},[]),d=A.useCallback(async()=>{const g=o.map((y,b)=>({id:y.id,priority:(b+1)*10}));try{await i(g),t.show({message:e("startup.saveSuccess"),severity:"success"}),l(!1)}catch(y){t.show({message:y instanceof Error?y.message:e("startup.saveFailed"),severity:"error"})}},[o,i,t,e]),p=A.useMemo(()=>o.map(g=>g.id),[o]);return r?h.jsxs(re,{children:[e("common.loading"),"..."]}):h.jsxs(Wt,{spacing:3,children:[h.jsx(W2,{items:[{name:e("nav.bridges"),to:Ot.bridges},{name:e("startup.title"),to:Ot.startup}]}),h.jsxs(se,{display:"flex",alignItems:"center",gap:2,children:[h.jsx(c0,{color:"primary",fontSize:"large"}),h.jsxs(se,{children:[h.jsx(re,{variant:"h5",fontWeight:600,children:e("startup.title")}),h.jsx(re,{variant:"body2",color:"text.secondary",children:e("startup.description")})]})]}),a&&h.jsx(zt,{severity:"info",action:h.jsx(Ue,{color:"inherit",size:"small",startIcon:h.jsx(F4,{}),onClick:d,children:e("startup.saveChanges")}),children:e("startup.unsavedChanges")}),h.jsx(j0t,{sensors:c,collisionDetection:jgt,onDragEnd:u,children:h.jsx(W0t,{items:p,strategy:U0t,children:h.jsx(Wt,{spacing:1,children:o.map((g,y)=>h.jsx(r1t,{bridge:g,index:y},g.id))})})}),o.length===0&&h.jsx(re,{color:"text.secondary",textAlign:"center",py:4,children:e("startup.noBridges")}),a&&o.length>0&&h.jsx(se,{display:"flex",justifyContent:"flex-end",children:h.jsx(Ue,{variant:"contained",startIcon:h.jsx(F4,{}),onClick:d,children:e("startup.saveOrder")})})]})},oS="https://riddix.github.io/home-assistant-matter-hub",Ot={dashboard:"/",bridges:"/bridges",bridge:e=>`/bridges/${e}`,createBridge:"/bridges/create",areaSetup:"/bridges/area-setup",editBridge:e=>`/bridges/${e}/edit`,devices:"/devices",networkMap:"/network-map",health:"/health",labels:"/labels",lockCredentials:"/lock-credentials",plugins:"/plugins",settings:"/settings",startup:"/startup",githubRepository:"https://github.com/riddix/home-assistant-matter-hub/",documentation:oS,support:`${oS}/support`,faq:{multiFabric:`${oS}/connect-multiple-fabrics`,bridgeConfig:`${oS}/bridge-configuration`}},o1t=[{path:"",element:h.jsx(fwe,{}),children:[{path:"",element:h.jsx(uOe,{})},{path:Ot.bridges,element:h.jsx(iOe,{})},{path:Ot.createBridge,element:h.jsx(elt,{})},{path:Ot.areaSetup,element:h.jsx(H6e,{})},{path:Ot.bridge(":bridgeId"),element:h.jsx(T_e,{})},{path:Ot.editBridge(":bridgeId"),element:h.jsx(tlt,{})},{path:Ot.devices,element:h.jsx(_Oe,{})},{path:Ot.networkMap,element:h.jsx(Bmt,{})},{path:Ot.health,element:h.jsx(xlt,{})},{path:Ot.labels,element:h.jsx(klt,{})},{path:Ot.lockCredentials,element:h.jsx(Olt,{})},{path:Ot.plugins,element:h.jsx(ugt,{})},{path:Ot.settings,element:h.jsx(mgt,{})},{path:Ot.startup,element:h.jsx(i1t,{})},{path:"*",element:h.jsx(Mlt,{})}]}],s1t={items:{isInitialized:!1,isLoading:!1}},a1t=FO(s1t,e=>{e.addCase(Lo.pending,t=>{t.items.isLoading=!0}).addCase(Lo.rejected,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=void 0,t.items.error=n.error}).addCase(Lo.fulfilled,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(AX.fulfilled,(t,n)=>{t.items.content?.push(n.payload)}).addCase(_X.fulfilled,(t,n)=>{const r=t.items.content?.findIndex(i=>i.id===n.payload.id)??-1;r!==-1&&(t.items.content[r]=n.payload)}).addCase(TX.fulfilled,(t,n)=>{const r=t.items.content?.findIndex(i=>i.id===n.payload.id)??-1;r!==-1&&(t.items.content[r]=n.payload)}).addCase(DX.fulfilled,(t,n)=>{if(t.items.content){const r=t.items.content.findIndex(i=>i.id===n.meta.arg);r!==-1&&t.items.content.splice(r,1)}}).addCase(OX,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(MX,(t,n)=>{if(t.items.content){const r=t.items.content.findIndex(i=>i.id===n.payload.id);r!==-1?t.items.content[r]=n.payload:t.items.content.push(n.payload)}})}),l1t={byBridge:{}},c1t=FO(l1t,e=>{e.addCase(Ru.pending,(t,n)=>{t.byBridge[n.meta.arg]=YA(t.byBridge[n.meta.arg],n)}).addCase(Ru.rejected,(t,n)=>{t.byBridge[n.meta.arg]=YA(t.byBridge[n.meta.arg],n)}).addCase(Ru.fulfilled,(t,n)=>{t.byBridge[n.meta.arg]=YA(t.byBridge[n.meta.arg],n)})}),u1t={isInitialized:!1,isLoading:!1,content:void 0,error:void 0},YA=FO(u1t,e=>{e.addCase(Ru.pending,t=>{t.isLoading=!0}).addCase(Ru.rejected,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=void 0,t.error=n.error}).addCase(Ru.fulfilled,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=n.payload,t.error=void 0})}),d1t=K4e({reducer:{bridges:a1t,devices:c1t}}),_I=M3e({createStyledComponent:ge("div",{name:"MuiContainer",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`maxWidth${ve(String(n.maxWidth))}`],n.fixed&&t.fixed,n.disableGutters&&t.disableGutters]}}),useThemeProps:e=>ct({props:e,name:"MuiContainer"})});function f1t(e){return tt("MuiToolbar",e)}st("MuiToolbar",["root","gutters","regular","dense"]);const h1t=e=>{const{classes:t,disableGutters:n,variant:r}=e;return nt({root:["root",!n&&"gutters",r]},f1t,t)},p1t=ge("div",{name:"MuiToolbar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,!n.disableGutters&&t.gutters,t[n.variant]]}})(Ye(({theme:e})=>({position:"relative",display:"flex",alignItems:"center",variants:[{props:({ownerState:t})=>!t.disableGutters,style:{paddingLeft:e.spacing(2),paddingRight:e.spacing(2),[e.breakpoints.up("sm")]:{paddingLeft:e.spacing(3),paddingRight:e.spacing(3)}}},{props:{variant:"dense"},style:{minHeight:48}},{props:{variant:"regular"},style:e.mixins.toolbar}]}))),Iue=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiToolbar"}),{className:i,component:o="div",disableGutters:s=!1,variant:a="regular",...l}=r,c={...r,component:o,disableGutters:s,variant:a},u=h1t(c);return h.jsx(p1t,{as:o,className:_e(u.root,i),ref:n,ownerState:c,...l})});class m1t extends A.Component{constructor(t){super(t),this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){console.error("ErrorBoundary caught:",t,n.componentStack)}render(){return this.state.hasError?h.jsxs(se,{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",gap:2,p:4,children:[h.jsx(QO,{color:"error",sx:{fontSize:64}}),h.jsx(re,{variant:"h5",fontWeight:600,children:pi.t("errorBoundary.title")}),h.jsx(re,{variant:"body2",color:"text.secondary",textAlign:"center",maxWidth:480,children:this.state.error?.message??pi.t("errorBoundary.fallbackMessage")}),h.jsx(Ue,{variant:"contained",onClick:()=>{this.setState({hasError:!1,error:null}),window.location.reload()},children:pi.t("errorBoundary.reload")})]}):this.props.children}}function g1t(e){return tt("MuiFab",e)}const cJ=st("MuiFab",["root","primary","secondary","extended","circular","focusVisible","disabled","colorInherit","sizeSmall","sizeMedium","sizeLarge","info","error","warning","success"]),y1t=e=>{const{color:t,variant:n,classes:r,size:i}=e,o={root:["root",n,`size${ve(i)}`,t==="inherit"?"colorInherit":t]},s=nt(o,g1t,r);return{...r,...s}},b1t=ge(ss,{name:"MuiFab",slot:"Root",shouldForwardProp:e=>Li(e)||e==="classes",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[n.variant],t[`size${ve(n.size)}`],n.color==="inherit"&&t.colorInherit,t[ve(n.size)],t[n.color]]}})(Ye(({theme:e})=>({...e.typography.button,minHeight:36,transition:e.transitions.create(["background-color","box-shadow","border-color"],{duration:e.transitions.duration.short}),borderRadius:"50%",padding:0,minWidth:0,width:56,height:56,zIndex:(e.vars||e).zIndex.fab,boxShadow:(e.vars||e).shadows[6],"&:active":{boxShadow:(e.vars||e).shadows[12]},color:e.vars?e.vars.palette.grey[900]:e.palette.getContrastText?.(e.palette.grey[300]),backgroundColor:(e.vars||e).palette.grey[300],"&:hover":{backgroundColor:(e.vars||e).palette.grey.A100,"@media (hover: none)":{backgroundColor:(e.vars||e).palette.grey[300]},textDecoration:"none"},[`&.${cJ.focusVisible}`]:{boxShadow:(e.vars||e).shadows[6]},variants:[{props:{size:"small"},style:{width:40,height:40}},{props:{size:"medium"},style:{width:48,height:48}},{props:{variant:"extended"},style:{borderRadius:48/2,padding:"0 16px",width:"auto",minHeight:"auto",minWidth:48,height:48}},{props:{variant:"extended",size:"small"},style:{width:"auto",padding:"0 8px",borderRadius:34/2,minWidth:34,height:34}},{props:{variant:"extended",size:"medium"},style:{width:"auto",padding:"0 16px",borderRadius:40/2,minWidth:40,height:40}},{props:{color:"inherit"},style:{color:"inherit"}}]})),Ye(({theme:e})=>({variants:[...Object.entries(e.palette).filter(Gn(["dark","contrastText"])).map(([t])=>({props:{color:t},style:{color:(e.vars||e).palette[t].contrastText,backgroundColor:(e.vars||e).palette[t].main,"&:hover":{backgroundColor:(e.vars||e).palette[t].dark,"@media (hover: none)":{backgroundColor:(e.vars||e).palette[t].main}}}}))]})),Ye(({theme:e})=>({[`&.${cJ.disabled}`]:{color:(e.vars||e).palette.action.disabled,boxShadow:(e.vars||e).shadows[0],backgroundColor:(e.vars||e).palette.action.disabledBackground}}))),v1t=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiFab"}),{children:i,className:o,color:s="default",component:a="button",disabled:l=!1,disableFocusRipple:c=!1,focusVisibleClassName:u,size:d="large",variant:p="circular",...g}=r,y={...r,color:s,component:a,disabled:l,disableFocusRipple:c,size:d,variant:p},b=y1t(y);return h.jsx(b1t,{className:_e(b.root,o),component:a,disabled:l,focusRipple:!c,focusVisibleClassName:_e(b.focusVisible,u),ownerState:y,ref:n,...g,classes:b,children:i})}),x1t=[{code:"en",flag:"🇬🇧",name:"English"},{code:"de",flag:"🇩🇪",name:"Deutsch"},{code:"fr",flag:"🇫🇷",name:"Français"},{code:"es",flag:"🇪🇸",name:"Español"},{code:"it",flag:"🇮🇹",name:"Italiano"},{code:"zh",flag:"🇨🇳",name:"中文"},{code:"zh-TW",flag:"🇹🇼",name:"繁體中文"},{code:"th",flag:"🇹🇭",name:"ไทย"},{code:"sv",flag:"🇸🇪",name:"Svenska"},{code:"tr",flag:"🇹🇷",name:"Türkçe"},{code:"ru",flag:"🇷🇺",name:"Русский"}],S1t="hamh-custom-languages";function w1t(){try{const e=localStorage.getItem(S1t);return e?JSON.parse(e).map(n=>({code:n.code,flag:"🌐",name:n.name})):[]}catch{return[]}}const C1t="https://github.com/RiDDiX/home-assistant-matter-hub/issues/new?labels=translation&title=Translation+improvement";function k1t(){const{t:e,i18n:t}=en(),[n,r]=A.useState(!1),i=A.useRef(null),o=A.useMemo(()=>[...x1t,...w1t()],[]),s=t.language??"en",a=o.some(d=>d.code===s)?s:s.split("-")[0]??"en",l=A.useCallback(()=>{r(d=>!d)},[]),c=A.useCallback(d=>{t.changeLanguage(d),r(!1)},[t]),u=A.useCallback(()=>{r(!1)},[]);return h.jsx(rX,{onClickAway:u,children:h.jsxs(se,{children:[h.jsx(v1t,{ref:i,size:"small",color:"primary",onClick:l,"aria-label":"Change language",sx:{position:"fixed",bottom:24,right:24,zIndex:1300},children:h.jsx(Q_e,{})}),h.jsx(G2,{open:n,anchorEl:i.current,placement:"top-end",transition:!0,sx:{zIndex:1300},children:({TransitionProps:d})=>h.jsx(M4,{...d,timeout:200,children:h.jsxs(zr,{elevation:8,sx:{mb:1,py:.5,minWidth:160,borderRadius:2,overflow:"hidden"},children:[o.map(p=>h.jsxs(se,{onClick:()=>c(p.code),sx:{display:"flex",alignItems:"center",gap:1.5,px:2,py:1,cursor:"pointer",bgcolor:a===p.code?"action.selected":"transparent","&:hover":{bgcolor:"action.hover"},transition:"background-color 0.15s"},children:[h.jsx(re,{sx:{fontSize:"1.4rem",lineHeight:1,userSelect:"none"},children:p.flag}),h.jsx(re,{variant:"body2",fontWeight:a===p.code?600:400,children:p.name})]},p.code)),h.jsx(Dr,{}),h.jsxs(se,{sx:{display:"flex",alignItems:"flex-start",gap:.75,px:2,py:1},children:[h.jsx(VO,{sx:{fontSize:14,mt:.25,color:"text.secondary"}}),h.jsxs(re,{variant:"caption",color:"text.secondary",sx:{lineHeight:1.4},children:[e("languageSwitcher.disclaimer")," ",h.jsx(V2,{href:C1t,target:"_blank",rel:"noopener",sx:{fontSize:"inherit"},children:e("languageSwitcher.contribute")})]})]})]})})})]})})}const E1t="home-assistant-matter-hub",A1t={name:E1t};function Pue(){const e="2.1.0-alpha.604",[t,n]=A.useState(null);A.useEffect(()=>{fetch("api/health").then(i=>i.ok?i.json():null).then(i=>{i?.version&&n(i.version)}).catch(()=>{})},[]);const r=A.useMemo(()=>!t||e==="0.0.0-dev"?!1:e!==t,[t]);return A.useMemo(()=>({name:A1t.name,version:t??e,frontendVersion:e,backendVersion:t,versionMismatch:r}),[t,r])}const D1t=()=>{const{t:e}=en(),t=[{name:e("footer.github"),url:Ot.githubRepository},{name:e("footer.documentation"),url:Ot.documentation},{name:e("footer.support"),url:Ot.support}];return h.jsxs(_I,{sx:{mt:16,mb:4},children:[h.jsx(Dr,{sx:{mt:4,mb:4}}),h.jsx(ht,{container:!0,spacing:2,justifyContent:"center",children:t.map((n,r)=>h.jsx(ht,{size:{xs:12,sm:"auto"},children:h.jsx(Ue,{fullWidth:!0,size:"small",variant:"outlined",component:V2,href:n.url,target:"_blank",children:n.name})},r.toString()))})]})};function _1t(e){return tt("MuiAppBar",e)}st("MuiAppBar",["root","positionFixed","positionAbsolute","positionSticky","positionStatic","positionRelative","colorDefault","colorPrimary","colorSecondary","colorInherit","colorTransparent","colorError","colorInfo","colorSuccess","colorWarning"]);const T1t=e=>{const{color:t,position:n,classes:r}=e,i={root:["root",`color${ve(t)}`,`position${ve(n)}`]};return nt(i,_1t,r)},uJ=(e,t)=>e?`${e.replace(")","")}, ${t})`:t,O1t=ge(zr,{name:"MuiAppBar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`position${ve(n.position)}`],t[`color${ve(n.color)}`]]}})(Ye(({theme:e})=>({display:"flex",flexDirection:"column",width:"100%",boxSizing:"border-box",flexShrink:0,variants:[{props:{position:"fixed"},style:{position:"fixed",zIndex:(e.vars||e).zIndex.appBar,top:0,left:"auto",right:0,"@media print":{position:"absolute"}}},{props:{position:"absolute"},style:{position:"absolute",zIndex:(e.vars||e).zIndex.appBar,top:0,left:"auto",right:0}},{props:{position:"sticky"},style:{position:"sticky",zIndex:(e.vars||e).zIndex.appBar,top:0,left:"auto",right:0}},{props:{position:"static"},style:{position:"static"}},{props:{position:"relative"},style:{position:"relative"}},{props:{color:"inherit"},style:{"--AppBar-color":"inherit",color:"var(--AppBar-color)"}},{props:{color:"default"},style:{"--AppBar-background":e.vars?e.vars.palette.AppBar.defaultBg:e.palette.grey[100],"--AppBar-color":e.vars?e.vars.palette.text.primary:e.palette.getContrastText(e.palette.grey[100]),...e.applyStyles("dark",{"--AppBar-background":e.vars?e.vars.palette.AppBar.defaultBg:e.palette.grey[900],"--AppBar-color":e.vars?e.vars.palette.text.primary:e.palette.getContrastText(e.palette.grey[900])})}},...Object.entries(e.palette).filter(Gn(["contrastText"])).map(([t])=>({props:{color:t},style:{"--AppBar-background":(e.vars??e).palette[t].main,"--AppBar-color":(e.vars??e).palette[t].contrastText}})),{props:t=>t.enableColorOnDark===!0&&!["inherit","transparent"].includes(t.color),style:{backgroundColor:"var(--AppBar-background)",color:"var(--AppBar-color)"}},{props:t=>t.enableColorOnDark===!1&&!["inherit","transparent"].includes(t.color),style:{backgroundColor:"var(--AppBar-background)",color:"var(--AppBar-color)",...e.applyStyles("dark",{backgroundColor:e.vars?uJ(e.vars.palette.AppBar.darkBg,"var(--AppBar-background)"):null,color:e.vars?uJ(e.vars.palette.AppBar.darkColor,"var(--AppBar-color)"):null})}},{props:{color:"transparent"},style:{"--AppBar-background":"transparent","--AppBar-color":"inherit",backgroundColor:"var(--AppBar-background)",color:"var(--AppBar-color)",...e.applyStyles("dark",{backgroundImage:"none"})}}]}))),M1t=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiAppBar"}),{className:i,color:o="primary",enableColorOnDark:s=!1,position:a="fixed",...l}=r,c={...r,color:o,position:a,enableColorOnDark:s},u=T1t(c);return h.jsx(O1t,{square:!0,component:"header",ownerState:c,elevation:4,className:_e(u.root,i,a==="fixed"&&"mui-fixed"),ref:n,...l})});function j1t(e,t,n){const r=t.getBoundingClientRect(),i=n&&n.getBoundingClientRect(),o=oa(t);let s;if(t.fakeTransform)s=t.fakeTransform;else{const c=o.getComputedStyle(t);s=c.getPropertyValue("-webkit-transform")||c.getPropertyValue("transform")}let a=0,l=0;if(s&&s!=="none"&&typeof s=="string"){const c=s.split("(")[1].split(")")[0].split(",");a=parseInt(c[4],10),l=parseInt(c[5],10)}return e==="left"?i?`translateX(${i.right+a-r.left}px)`:`translateX(${o.innerWidth+a-r.left}px)`:e==="right"?i?`translateX(-${r.right-i.left-a}px)`:`translateX(-${r.left+r.width-a}px)`:e==="up"?i?`translateY(${i.bottom+l-r.top}px)`:`translateY(${o.innerHeight+l-r.top}px)`:i?`translateY(-${r.top-i.top+r.height-l}px)`:`translateY(-${r.top+r.height-l}px)`}function R1t(e){return typeof e=="function"?e():e}function sS(e,t,n){const r=R1t(n),i=j1t(e,t,r);i&&(t.style.webkitTransform=i,t.style.transform=i)}const I1t=A.forwardRef(function(t,n){const r=Ki(),i={enter:r.transitions.easing.easeOut,exit:r.transitions.easing.sharp},o={enter:r.transitions.duration.enteringScreen,exit:r.transitions.duration.leavingScreen},{addEndListener:s,appear:a=!0,children:l,container:c,direction:u="down",easing:d=i,in:p,onEnter:g,onEntered:y,onEntering:b,onExit:v,onExited:S,onExiting:C,style:w,timeout:E=o,TransitionComponent:k=Ja,...T}=t,_=A.useRef(null),O=Br(Rf(l),_,n),R=W=>q=>{W&&(q===void 0?W(_.current):W(_.current,q))},P=R((W,q)=>{sS(u,W,c),IO(W),g&&g(W,q)}),L=R((W,q)=>{const Z=gf({timeout:E,style:w,easing:d},{mode:"enter"});W.style.webkitTransition=r.transitions.create("-webkit-transform",{...Z}),W.style.transition=r.transitions.create("transform",{...Z}),W.style.webkitTransform="none",W.style.transform="none",b&&b(W,q)}),M=R(y),N=R(C),$=R(W=>{const q=gf({timeout:E,style:w,easing:d},{mode:"exit"});W.style.webkitTransition=r.transitions.create("-webkit-transform",q),W.style.transition=r.transitions.create("transform",q),sS(u,W,c),v&&v(W)}),B=R(W=>{W.style.webkitTransition="",W.style.transition="",S&&S(W)}),F=W=>{s&&s(_.current,W)},V=A.useCallback(()=>{_.current&&sS(u,_.current,c)},[u,c]);return A.useEffect(()=>{if(p||u==="down"||u==="right")return;const W=H2(()=>{_.current&&sS(u,_.current,c)}),q=oa(_.current);return q.addEventListener("resize",W),()=>{W.clear(),q.removeEventListener("resize",W)}},[u,p,c]),A.useEffect(()=>{p||V()},[p,V]),h.jsx(k,{nodeRef:_,onEnter:P,onEntered:M,onEntering:L,onExit:$,onExited:B,onExiting:N,addEndListener:F,appear:a,in:p,timeout:E,...T,children:(W,{ownerState:q,...Z})=>A.cloneElement(l,{ref:O,style:{visibility:W==="exited"&&!p?"hidden":void 0,...w,...l.props.style},...Z})})});function P1t(e){return tt("MuiDrawer",e)}st("MuiDrawer",["root","docked","paper","anchorLeft","anchorRight","anchorTop","anchorBottom","paperAnchorLeft","paperAnchorRight","paperAnchorTop","paperAnchorBottom","paperAnchorDockedLeft","paperAnchorDockedRight","paperAnchorDockedTop","paperAnchorDockedBottom","modal"]);const Nue=(e,t)=>{const{ownerState:n}=e;return[t.root,(n.variant==="permanent"||n.variant==="persistent")&&t.docked,n.variant==="temporary"&&t.modal]},N1t=e=>{const{classes:t,anchor:n,variant:r}=e,i={root:["root",`anchor${ve(n)}`],docked:[(r==="permanent"||r==="persistent")&&"docked"],modal:["modal"],paper:["paper",`paperAnchor${ve(n)}`,r!=="temporary"&&`paperAnchorDocked${ve(n)}`]};return nt(i,P1t,t)},$1t=ge(nM,{name:"MuiDrawer",slot:"Root",overridesResolver:Nue})(Ye(({theme:e})=>({zIndex:(e.vars||e).zIndex.drawer}))),L1t=ge("div",{shouldForwardProp:Li,name:"MuiDrawer",slot:"Docked",skipVariantsResolver:!1,overridesResolver:Nue})({flex:"0 0 auto"}),F1t=ge(zr,{name:"MuiDrawer",slot:"Paper",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.paper,t[`paperAnchor${ve(n.anchor)}`],n.variant!=="temporary"&&t[`paperAnchorDocked${ve(n.anchor)}`]]}})(Ye(({theme:e})=>({overflowY:"auto",display:"flex",flexDirection:"column",height:"100%",flex:"1 0 auto",zIndex:(e.vars||e).zIndex.drawer,WebkitOverflowScrolling:"touch",position:"fixed",top:0,outline:0,variants:[{props:{anchor:"left"},style:{left:0}},{props:{anchor:"top"},style:{top:0,left:0,right:0,height:"auto",maxHeight:"100%"}},{props:{anchor:"right"},style:{right:0}},{props:{anchor:"bottom"},style:{top:"auto",left:0,bottom:0,right:0,height:"auto",maxHeight:"100%"}},{props:({ownerState:t})=>t.anchor==="left"&&t.variant!=="temporary",style:{borderRight:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:t})=>t.anchor==="top"&&t.variant!=="temporary",style:{borderBottom:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:t})=>t.anchor==="right"&&t.variant!=="temporary",style:{borderLeft:`1px solid ${(e.vars||e).palette.divider}`}},{props:({ownerState:t})=>t.anchor==="bottom"&&t.variant!=="temporary",style:{borderTop:`1px solid ${(e.vars||e).palette.divider}`}}]}))),$ue={left:"right",right:"left",top:"down",bottom:"up"};function z1t(e){return["left","right"].includes(e)}function B1t({direction:e},t){return e==="rtl"&&z1t(t)?$ue[t]:t}const H1t=A.forwardRef(function(t,n){const r=ct({props:t,name:"MuiDrawer"}),i=Ki(),o=Lc(),s={enter:i.transitions.duration.enteringScreen,exit:i.transitions.duration.leavingScreen},{anchor:a="left",BackdropProps:l,children:c,className:u,elevation:d=16,hideBackdrop:p=!1,ModalProps:{BackdropProps:g,...y}={},onClose:b,open:v=!1,PaperProps:S={},SlideProps:C,TransitionComponent:w,transitionDuration:E=s,variant:k="temporary",slots:T={},slotProps:_={},...O}=r,R=A.useRef(!1);A.useEffect(()=>{R.current=!0},[]);const P=B1t({direction:o?"rtl":"ltr"},a),M={...r,anchor:a,elevation:d,open:v,variant:k,...O},N=N1t(M),$={slots:{transition:w,...T},slotProps:{paper:S,transition:C,..._,backdrop:MO(_.backdrop||{...l,...g},{transitionDuration:E})}},[B,F]=ft("root",{ref:n,elementType:$1t,className:_e(N.root,N.modal,u),shouldForwardComponentProp:!0,ownerState:M,externalForwardedProps:{...$,...O,...y},additionalProps:{open:v,onClose:b,hideBackdrop:p,slots:{backdrop:$.slots.backdrop},slotProps:{backdrop:$.slotProps.backdrop}}}),[V,W]=ft("paper",{elementType:F1t,shouldForwardComponentProp:!0,className:_e(N.paper,S.className),ownerState:M,externalForwardedProps:$,additionalProps:{elevation:k==="temporary"?d:0,square:!0,...k==="temporary"&&{role:"dialog","aria-modal":"true"}}}),[q,Z]=ft("docked",{elementType:L1t,ref:n,className:_e(N.root,N.docked,u),ownerState:M,externalForwardedProps:$,additionalProps:O}),[z,U]=ft("transition",{elementType:I1t,ownerState:M,externalForwardedProps:$,additionalProps:{in:v,direction:$ue[P],timeout:E,appear:R.current}}),Y=h.jsx(V,{...W,children:c});if(k==="permanent")return h.jsx(q,{...Z,children:Y});const H=h.jsx(z,{...U,children:Y});return k==="persistent"?h.jsx(q,{...Z,children:H}):h.jsx(B,{...F,children:H})}),U1t=PZ({themeId:ja}),V1t={error:Nf,warn:u0,info:eM,debug:dC},W1t=({open:e,onClose:t})=>{const{t:n}=en(),r=Ki(),i=A.useMemo(()=>({error:r.palette.error.main,warn:r.palette.warning.main,info:r.palette.info.main,debug:r.palette.secondary.main}),[r]),[o,s]=A.useState([]),[a,l]=A.useState(!0),[c,u]=A.useState("error,warn,info".split(",")),[d,p]=A.useState(""),[g,y]=A.useState(!0),b=A.useCallback(async()=>{try{const E=new URLSearchParams({level:c.join(","),limit:"500",...d&&{search:d}}),k=await fetch(`api/logs?${E}`);if(k.ok){const T=await k.json();s(T.entries)}}catch(E){console.error("Failed to fetch logs:",E)}finally{l(!1)}},[c,d]);A.useEffect(()=>{e&&b()},[e,b]),A.useEffect(()=>{if(!g||!e)return;const E=setInterval(b,5e3);return()=>clearInterval(E)},[g,e,b]);const v=E=>{u(Array.isArray(E.target.value)?E.target.value:[E.target.value])},S=E=>{p(E.target.value)},C=async()=>{try{await fetch("api/logs",{method:"DELETE"}),s([])}catch(E){console.error("Failed to clear logs:",E)}},w=E=>{const k=V1t[E]||eM;return h.jsx(k,{sx:{fontSize:16,color:i[E]}})};return h.jsxs(Po,{open:e,onClose:t,maxWidth:"lg",fullWidth:!0,children:[h.jsxs($o,{sx:{display:"flex",alignItems:"center",gap:1},children:[h.jsx(dC,{}),n("logs.title"),h.jsx(se,{sx:{flexGrow:1}}),h.jsx(Lt,{title:n("logs.autoRefresh"),children:h.jsx(ot,{label:g?"Auto":"Manual",color:g?"success":"default",size:"small",onClick:()=>y(!g),sx:{cursor:"pointer"}})}),h.jsx(qt,{onClick:t,children:h.jsx(L4,{})})]}),h.jsxs(No,{children:[h.jsx(Wt,{spacing:2,sx:{mb:2},children:h.jsxs(Wt,{direction:"row",spacing:2,alignItems:"center",children:[h.jsxs(rs,{size:"small",sx:{minWidth:200},children:[h.jsx(Ia,{children:n("logs.logLevel")}),h.jsxs(ts,{value:c,label:n("logs.logLevel"),onChange:v,multiple:!0,renderValue:E=>h.jsx(se,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:(Array.isArray(E)?E:[E]).map(k=>h.jsx(ot,{label:k.toUpperCase(),size:"small",sx:{backgroundColor:i[k],color:"white"}},k))}),children:[h.jsx(Bn,{value:"error",children:n("logs.error")}),h.jsx(Bn,{value:"warn",children:n("logs.warning")}),h.jsx(Bn,{value:"info",children:n("logs.info")}),h.jsx(Bn,{value:"debug",children:n("logs.debug")})]})]}),h.jsx(zn,{size:"small",placeholder:n("logs.searchPlaceholder"),value:d,onChange:S,sx:{flexGrow:1}}),h.jsx(Ue,{variant:"outlined",onClick:b,children:n("common.refresh")}),h.jsx(Ue,{variant:"outlined",color:"error",onClick:C,children:n("common.delete")})]})}),h.jsx(se,{sx:{height:400,overflow:"auto",backgroundColor:"background.paper",border:1,borderColor:"divider",borderRadius:1,p:1},children:a?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsxs(re,{children:[n("common.loading"),"..."]})}):o.length===0?h.jsx(se,{sx:{display:"flex",justifyContent:"center",p:4},children:h.jsx(re,{color:"text.secondary",children:n("logs.noResults")})}):h.jsx(Wt,{spacing:1,children:o.map((E,k)=>h.jsxs(se,{sx:{p:1,borderRadius:1,backgroundColor:"action.hover",fontFamily:"monospace",fontSize:"0.875rem",wordBreak:"break-all"},children:[h.jsxs(se,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[w(E.level),h.jsx(re,{variant:"caption",color:"text.secondary",children:new Date(E.timestamp).toLocaleString()}),h.jsx(ot,{label:E.level.toUpperCase(),size:"small",sx:{backgroundColor:i[E.level],color:r.palette.getContrastText(i[E.level]??r.palette.grey[500]),fontSize:"0.7rem",height:20}})]}),h.jsx(re,{sx:{ml:3},children:E.message}),E.context&&h.jsx(re,{sx:{ml:3,color:"text.secondary",fontSize:"0.8rem"},children:JSON.stringify(E.context,null,2)})]},`${E.timestamp}-${E.level}-${k}`))})})]}),h.jsx(es,{children:h.jsx(Ue,{onClick:t,children:n("common.close")})})]})};function dJ(){const{t:e}=en(),{isConnected:t}=RX(),[n,r]=A.useState(null),[i,o]=A.useState(!1);A.useEffect(()=>{const b=async()=>{try{const S=await fetch("api/health");if(S.ok){const C=await S.json();r(C),o(!1)}else o(!0)}catch{o(!0)}};b();const v=setInterval(b,3e4);return()=>clearInterval(v)},[]);const s=b=>{const v=Math.floor(b/3600),S=Math.floor(b%3600/60);return v>0?`${v}h ${S}m`:`${S}m`},a=n?.status==="healthy"&&!i,l=n?.services?.bridges,c=l&&l.total>0&&l.running===l.total,u=l&&l.total===0,d=n?h.jsxs(se,{sx:{p:.5},children:[h.jsxs("div",{children:[h.jsxs("strong",{children:[e("health.version"),":"]})," ",n.version??e("status.unknown")]}),h.jsxs("div",{children:[h.jsxs("strong",{children:[e("health.uptime"),":"]})," ",s(n.uptime??0)]}),n.services?.bridges&&h.jsxs("div",{children:[h.jsxs("strong",{children:[e("nav.bridges"),":"]})," ",n.services.bridges.running??0,"/",n.services.bridges.total??0," ",e("common.running").toLowerCase(),(n.services.bridges.stopped??0)>0&&` (${n.services.bridges.stopped} ${e("common.stopped").toLowerCase()})`]}),n.services?.homeAssistant&&h.jsxs("div",{children:[h.jsxs("strong",{children:[e("health.homeAssistant"),":"]})," ",n.services.homeAssistant.connected?e("health.connected"):e("health.disconnected")]}),h.jsxs("div",{children:[h.jsx("strong",{children:"WebSocket:"})," ",e(t?"health.connected":"health.disconnected")]})]}):e("status.loadingHealth"),p=()=>i||!a?h.jsx(Nf,{fontSize:"small"}):c?h.jsx(Za,{fontSize:"small"}):h.jsx(Y6,{fontSize:"small"}),g=()=>i||!a?"error":!c||!t?"warning":"success",y=()=>e(i?"status.error":a?t?u?"status.noBridges":c?"common.online":"common.starting":"common.offline":"status.unhealthy");return h.jsx(Lt,{title:d,arrow:!0,children:h.jsx(ot,{icon:p(),label:y(),color:g(),size:"small",variant:"filled",sx:{borderRadius:1,fontWeight:600,"& .MuiChip-icon":{color:"inherit"}}})})}const q1t=e=>A.createElement("svg",{viewBox:"0 0 91 89",xmlSpace:"preserve",xmlns:"http://www.w3.org/2000/svg",...e},A.createElement("g",{style:{display:"inline"}},A.createElement("path",{style:{fill:"#18bcf2",fillOpacity:1,strokeWidth:.266194},d:"m 49.149143,1.473171 38.513568,38.536435 c 0,0 1.248354,1.186052 2.207681,3.092371 0.959329,1.906323 1.10864,4.600698 1.10864,4.600698 v 36.786372 c 0,0 -0.01549,1.748506 -1.49842,3.050572 -1.482931,1.302064 -3.333077,1.362947 -3.333077,1.362947 l -81.325658,7.7e-5 c 0,0 -1.7523855,-0.0091 -3.17112,-1.352526 C -0.07808495,85.913164 0.05953025,84.487808 0.05953025,84.487808 V 47.704546 c 0,0 -0.0018381,-2.218618 0.95921785,-4.315832 0.9610554,-2.097209 2.3010618,-3.355005 2.3010618,-3.355005 L 41.545959,1.4719546 c 0,0 1.465224,-1.46837077 3.753488,-1.46837077 2.288268,0 3.849696,1.46958717 3.849696,1.46958717 z"}),A.createElement("path",{style:{fill:"#ffffff",fillOpacity:1,strokeWidth:.175841},d:"m 31.689717,32.051124 c 2.813363,2.331095 6.157331,3.89845 9.721813,4.556421 V 17.180647 l 3.873694,-2.282955 3.870527,2.282955 V 36.60772 c 3.565364,-0.658847 6.910387,-2.226204 9.725159,-4.556417 l 7.032345,4.154609 c -11.437354,11.557779 -29.852321,11.557779 -41.290025,0 z m 8.546732,49.60988 C 44.314996,65.760441 35.09933,49.470196 19.574984,45.139543 v 8.312381 c 3.383916,1.32244 6.386113,3.496288 8.728705,6.320026 L 11.83076,69.485301 v 4.56907 l 3.873697,2.270836 16.469936,-9.713534 c 1.224356,3.48294 1.56683,7.225375 0.996449,10.879778 z M 70.977694,45.139543 c -15.515726,4.34014 -24.72189,20.626696 -20.643519,36.521461 l 7.047658,-4.15742 c -0.569325,-3.654411 -0.2265,-7.3965 0.996449,-10.87979 l 16.457611,9.701233 3.870711,-2.283125 v -4.55677 L 62.233673,59.77195 c 2.342772,-2.822684 5.34497,-4.996533 8.728708,-6.320026 z"}))),K1t=e=>{const t=Pue();return h.jsxs(se,{component:Oc,to:Ot.dashboard,sx:{display:"flex",alignItems:"center",justifyContent:e.large?"flex-start":"center",flexGrow:1,textDecoration:"none",color:"inherit"},children:[h.jsx(q1t,{style:{height:"40px"}}),h.jsx(re,{variant:"inherit",component:"span",sx:{mr:1,ml:1},children:t.name.split("-").map(ve).join("-")}),e.large&&h.jsx(re,{variant:"caption",component:"span",children:t.version})]})},G1t=()=>{const e=U1t("(min-width:600px)"),{mode:t,setMode:n}=I6(),[r,i]=A.useState(!1),[o,s]=A.useState(!1),a=$c(),l=Yu(),c=y=>y?y==="/"?l.pathname==="/":l.pathname.startsWith(y):!1,u=()=>{n(t==="dark"?"light":"dark")},{t:d}=en(),p=[{label:d("dashboard.title"),icon:h.jsx(kM,{}),to:Ot.dashboard},{label:d("nav.bridges"),icon:h.jsx(Ly,{}),to:Ot.bridges},{label:d("nav.devices"),icon:h.jsx(aa,{}),to:Ot.devices},{label:d("nav.networkMap"),icon:h.jsx(SM,{}),to:Ot.networkMap},{label:d("nav.startupOrder"),icon:h.jsx(c0,{}),to:Ot.startup},{label:d("nav.lockCredentials"),icon:h.jsx(ju,{}),to:Ot.lockCredentials},{label:d("nav.filterReference"),icon:h.jsx(EM,{}),to:Ot.labels},{label:"Plugins",icon:h.jsx($y,{}),to:Ot.plugins},{label:d("nav.settings"),icon:h.jsx(f0,{}),to:Ot.settings},{label:d(t==="dark"?"nav.lightMode":"nav.darkMode"),icon:t==="dark"?h.jsx(tTe,{}):h.jsx(U_e,{}),onClick:u},{label:d("nav.systemLogs"),icon:h.jsx(dC,{}),onClick:()=>i(!0)},{label:d("nav.health"),icon:h.jsx(iM,{}),to:Ot.health}],g=y=>{s(!1),y.onClick?y.onClick():y.to&&a(y.to)};return h.jsxs(se,{children:[h.jsx(M1t,{sx:{height:"72px"},children:h.jsx(Iue,{sx:{paddingLeft:"0 !important",paddingRight:"0 !important"},children:h.jsxs(_I,{sx:{padding:2,height:"100%",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[h.jsx(K1t,{large:e}),e?h.jsxs(se,{sx:{display:"flex",alignItems:"center",gap:1},children:[p.map(y=>y.to?h.jsx(Lt,{title:y.label,children:h.jsx(qt,{component:Oc,to:y.to,sx:{color:"inherit",bgcolor:c(y.to)?"rgba(255,255,255,0.15)":"transparent",borderRadius:1},children:y.icon})},y.label):h.jsx(Lt,{title:y.label,children:h.jsx(qt,{onClick:y.onClick,sx:{color:"inherit"},children:y.icon})},y.label)),h.jsx(dJ,{})]}):h.jsxs(se,{sx:{display:"flex",alignItems:"center",gap:.5},children:[h.jsx(dJ,{}),h.jsx(qt,{onClick:()=>s(!0),sx:{color:"inherit"},children:h.jsx(nTe,{})})]})]})})}),h.jsx(H1t,{anchor:"right",open:o,onClose:()=>s(!1),children:h.jsx(Fo,{sx:{width:250},children:p.map(y=>h.jsxs(oCe,{selected:c(y.to),onClick:()=>g(y),children:[h.jsx(Io,{children:y.icon}),h.jsx(ao,{primary:y.label})]},y.label))})}),h.jsx(W1t,{open:r,onClose:()=>i(!1)})]})},Y1t=()=>{const{versionMismatch:e,frontendVersion:t,backendVersion:n}=Pue(),{isConnected:r}=RX();return h.jsxs(se,{children:[h.jsx(G1t,{}),h.jsx(Iue,{}),e&&h.jsxs(zt,{severity:"warning",variant:"filled",sx:{borderRadius:0},action:h.jsx(Ue,{color:"inherit",size:"small",onClick:()=>window.location.reload(),children:"Reload"}),children:["Version mismatch: frontend ",t,", backend ",n,". Please reload to get the latest UI."]}),!r&&h.jsx(zt,{severity:"error",variant:"filled",sx:{borderRadius:0},children:"Connection lost — data may be outdated. Reconnecting…"}),h.jsx(_I,{sx:{p:2},children:h.jsx(m1t,{children:h.jsx(HJ,{})})}),h.jsx(D1t,{}),h.jsx(k1t,{})]})},J1t=M6({colorSchemes:{light:{palette:{primary:{main:"#1976d2",light:"#42a5f5",dark:"#1565c0"},secondary:{main:"#9c27b0",light:"#ba68c8",dark:"#7b1fa2"},background:{default:"#f5f5f5",paper:"#ffffff"}}},dark:{palette:{primary:{main:"#90caf9",light:"#e3f2fd",dark:"#42a5f5"},secondary:{main:"#ce93d8",light:"#f3e5f5",dark:"#ab47bc"},background:{default:"#121212",paper:"#1e1e1e"}}}},typography:{fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',h1:{fontSize:"2.5rem",fontWeight:500},h2:{fontSize:"2rem",fontWeight:500},h3:{fontSize:"1.75rem",fontWeight:500},h4:{fontSize:"1.5rem",fontWeight:500},h5:{fontSize:"1.25rem",fontWeight:500},h6:{fontSize:"1rem",fontWeight:500}},shape:{borderRadius:8},components:{MuiCard:{styleOverrides:{root:{transition:"transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out","&:hover":{transform:"translateY(-2px)",boxShadow:"0 4px 20px rgba(0,0,0,0.12)"}}}},MuiButton:{styleOverrides:{root:{textTransform:"none",fontWeight:500}}},MuiChip:{styleOverrides:{root:{fontWeight:500}}},MuiAppBar:{styleOverrides:{root:{backgroundImage:"none"}}}}});let a4=document.getElementsByTagName("base")[0]?.href?.replace(/\/$/,"");a4?.startsWith("http")&&(a4=new URL(a4).pathname);const Z1t=Pme([{path:"/",element:h.jsx(Y1t,{}),children:o1t}],{basename:a4});Xfe.createRoot(document.getElementById("root")).render(h.jsx(A.StrictMode,{children:h.jsx(mhe,{store:d1t,children:h.jsxs(H5e,{theme:J1t,children:[h.jsx($5e,{}),h.jsx(JZ,{styles:{".rjsf-field-array > .MuiFormControl-root > .MuiPaper-root > .MuiBox-root > .MuiGrid-root > .MuiGrid-root:has(> .MuiBox-root > .MuiPaper-root > .MuiBox-root > .rjsf-field)":{overflow:"initial !important",flexGrow:1}}}),h.jsx(dwe,{children:h.jsx(n4e,{children:h.jsx(Gme,{router:Z1t})})})]})})}));
|