@riddix/hamh 2.1.0-alpha.421 → 2.1.0-alpha.422
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(vd(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(_se(n.key)&&!vd(n.sep,"newline")){const s=r0(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(vd(n.start,"newline"))Object.assign(n,{key:null,sep:[this.sourceToken]});else{const s=r0(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]}):vd(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&&!vd(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||vd(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=g5(r),o=r0(i);pG(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=g5(t),r=r0(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=g5(t),r=r0(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 Dse(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new kse||null,prettyErrors:t}}function gQe(e,t={}){const{lineCounter:n,prettyErrors:r}=Dse(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(fS(e,n)),a.warnings.forEach(fS(e,n));return s.length>0?s:Object.assign([],{empty:!0},o.streamInfo())}function Ose(e,t={}){const{lineCounter:n,prettyErrors:r}=Dse(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 Sh(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return r&&n&&(s.errors.forEach(fS(e,n)),s.warnings.forEach(fS(e,n))),s}function yQe(e,t,n){let r;typeof t=="function"?r=t:n===void 0&&t&&typeof t=="object"&&(n=t);const i=Ose(e,n);if(!i)return null;if(i.warnings.forEach(o=>Yoe(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 bQe(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 cp(e)&&!r?e.toString(n):new hg(e,r,n).toString(n)}const vQe=Object.freeze(Object.defineProperty({__proto__:null,Alias:CC,CST:hQe,Composer:QR,Document:hg,Lexer:Ase,LineCounter:kse,Pair:Ao,Parser:eI,Scalar:Gt,Schema:RC,YAMLError:ZR,YAMLMap:Ms,YAMLParseError:Sh,YAMLSeq:df,YAMLWarning:pse,isAlias:Cf,isCollection:Zr,isDocument:cp,isMap:cg,isNode:Jr,isPair:Vr,isScalar:Cr,isSeq:ug,parse:yQe,parseAllDocuments:gQe,parseDocument:Ose,stringify:bQe,visit:up,visitAsync:wC},Symbol.toStringTag,{value:"Module"}));function xQe(e){let t=null;try{t=vQe.parse(e.doc.toString())}catch{}const n=pR(e,zr.YAML);return{data:t,pointers:n}}const Tse=e=>{switch(e){case zr.JSON:return ZZe;case zr.JSON5:return uJe;case zr.YAML:return xQe}};function SQe(e){return Object.entries(e)}function ty(e,t){if(typeof e=="string"||typeof e!="object"||e===null)return e;if(Array.isArray(e))return e.map(i=>ty(i,t));if(e instanceof Map){const i=new Map;for(const[o,s]of e){const a=o,l=ty(s,t);i.set(a,l)}return i}if(e instanceof Set){const i=new Set;for(const o of e){const s=ty(o,t);i.add(s)}return i}const n={};function r(i,o,s,a){s===i&&a===o?n[s]=ty(o,t):n[s]=a}for(const[i,o]of SQe(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 wQe=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 CQe{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 Iy(e){return!(!e||ko(e)||e.name==="UnknownPropertyError"||e.type==="undefined")}class EQe{constructor(t){var n,r,i;this.opts=t,this.originalSchema=null,this.schema=null,this.laxSchema=null,this.mode=zr.JSON,this.mode=(n=t.mode)!==null&&n!==void 0?n:zr.JSON,this.parser=(i=(r=this.opts)===null||r===void 0?void 0:r.jsonParser)!==null&&i!==void 0?i:Tse(this.mode)}doComplete(t){var n;const r=mR(t.state);if(this.originalSchema!==r&&(this.schema=(n=ih(r,r))!==null&&n!==void 0?n:r,this.laxSchema=kQe(this.schema)),!this.schema||!this.laxSchema)return[];Kr.log("xxx","trying with original schema");const i=this.doCompleteForSchema(t,this.schema);return i.options.length!==0?i:(Kr.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=cA(t.state,t.pos),l=t.state.sliceDoc(a.from,t.pos).replace(/^(["'])/,"");if(Kr.log("xxx","node",a,"prefix",l,"ctx",t),!(d4(a,this.mode)||e5(a,this.mode))&&!t.explicit)return Kr.log("xxx","no completions for non-word/primitive",a),o;const c=m0(t.state.doc,a),u=m0(t.state.doc,a,!1);if(a&&(d4(a,this.mode)||e5(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;Kr.log("xxx","overwriteStart after",b,"ctx.pos",t.pos,"word",y,"currentWord",c,"=>",s[b-1],"..",s[b],"..",s),o.from=a.name===Xt.INVALID?(r=y?.from)!==null&&r!==void 0?r:t.pos:b,o.to=t.pos}const f=new CQe;let h=!0;const g=HW(a,Xt.PROPERTY_NAME,this.mode);if(g&&(Kr.log("xxx","closestPropertyNameNode",g,"node",a),a=g),e5(a,this.mode)){Kr.log("xxx","isPropertyNameNode",a);const y=a.parent;if(y){const b=zW(y,this.mode);h=!b||b.name===Xt.INVALID&&b.from-b.to===0||(b.parent?Ub(b.parent).length<=1:!1),Kr.log("xxx","addValue",h,zW(y,this.mode),a),a=(i=HW(y,Xt.OBJECT,this.mode))!==null&&i!==void 0?i:null}}if(Kr.log("xxx",a,c,t,"node at pos",cA(t.state,t.pos)),a&&[Xt.OBJECT,Xt.JSON_TEXT].includes(pi(a.name,this.mode))&&(e5(cA(t.state,t.pos),this.mode)||g)){if(a.from===t.pos)return Kr.log("xxx","no completions for just before opening brace"),o;this.getPropertyCompletions(n,t,a,f,h,u)}else{const y={},b=this.getValueCompletions(n,t,y,f);Kr.log("xxx","getValueCompletions res",b)}return o.options=Array.from(f.completions.values()).filter(y=>u4(y.label).startsWith(l)),Kr.log("xxx","result",o,"prefix",l,"collector.completions",f.completions,"reservedKeys",f.reservedKeys),o}applySnippetCompletion(t){return GHe(typeof t.apply!="string"?t.label:t.apply,t)}getPropertyCompletions(t,n,r,i,o,s){const a=jUe(r,Xt.PROPERTY,this.mode);Kr.log("xxx","getPropertyCompletions",r,n,a),a.forEach(c=>{const u=m0(n.state.doc,dD(c,Xt.PROPERTY_NAME,this.mode));i.reserve(u4(u))});const l=this.getSchemas(t,n);Kr.log("xxx","propertyCompletion schemas",l),l.forEach(c=>{if(typeof c!="object")return;const u=c.properties;u&&Object.entries(u).forEach(([h,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:h,apply:this.getInsertTextForProperty(h,o,s,t,g),type:"property",detail:C,info:()=>Ml("div",{inner:Z0(v)})};i.add(this.applySnippetCompletion(w))}});const f=c.propertyNames;if(typeof f=="object"&&(f.enum&&f.enum.forEach(h=>{const g=h?.toString();if(g){const y={label:g,apply:this.getInsertTextForProperty(g,o,s,t),type:"property"};i.add(this.applySnippetCompletion(y))}}),f.const)){const h=f.const.toString(),g={label:h,apply:this.getInsertTextForProperty(h,o,s,t),type:"property"};i.add(this.applySnippetCompletion(g))}})}getInsertTextForProperty(t,n,r,i,o){o=o&&ih(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 zr.JSON5:a="{#{}}";break;case zr.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)&&(Kr.log("xxx","value",a,"nValueProposals",l,o),a="#{}"),s+a}getInsertTextForPropertyName(t,n){switch(this.mode){case zr.JSON5:case zr.YAML:return n.startsWith('"')?`"${t}"`:n.startsWith("'")?`'${t}'`:t;default:return`"${t}"`}}getInsertTextForString(t,n="#"){switch(this.mode){case zr.JSON5:return`'${n}{${t}}'`;case zr.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=Ti(n.state).resolveInner(n.pos,-1),s=null,a;if(Kr.log("xxx","getValueCompletions",o,n),o&&d4(o,this.mode)&&(s=o,o=o.parent),!o){this.addSchemaValueCompletions(t,r,i);return}if(pi(o.name,this.mode)===Xt.PROPERTY){const c=dD(o,Xt.PROPERTY_NAME,this.mode);c&&(a=m0(n.state.doc,c),o=o.parent)}if(Kr.log("xxx","node",o,"parentKey",a),o&&(a!==void 0||pi(o.name,this.mode)===Xt.ARRAY)){const c=this.getSchemas(t,n);for(const u of c){if(typeof u!="object")return;if(pi(o.name,this.mode)===Xt.ARRAY&&u.items){let f=i;if(u.uniqueItems&&(f=Object.assign(Object.assign({},f),{add(h){f.completions.has(h.label)||i.add(h)},reserve(h){i.reserve(h)}})),Array.isArray(u.items)){let h=0;if(s){const y=Fre(o,s,this.mode);y>=0&&(h=y)}const g=u.items[h];g&&this.addSchemaValueCompletions(g,r,f)}else this.addSchemaValueCompletions(u.items,r,f)}if((u.type==null||u.type!=="object")&&this.addSchemaValueCompletions(u,r,i),a!==void 0){let f=!1;if(u.properties){const h=u.properties[a];h&&(f=!0,this.addSchemaValueCompletions(h,r,i))}if(u.patternProperties&&!f)for(const h of Object.keys(u.patternProperties)){const g=this.extendedRegExp(h);if(g?.test(a)){f=!0;const y=u.patternProperties[h];y&&this.addSchemaValueCompletions(y,r,i)}}if(u.additionalProperties&&!f){const h=u.additionalProperties;this.addSchemaValueCompletions(h,r,i)}}r.boolean&&(this.addBooleanValueCompletion(!0,i),this.addBooleanValueCompletion(!1,i)),r.null&&this.addNullValueCompletion(i)}}return{valuePrefix:s?m0(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 Aie(t);let l=Lre(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=mG(t,s,l);if(y!=null)return[y]}let c=l?.replace(/\/[^/]*$/,"");c===""&&(c=void 0);const u=mG(t,s,c),f=l?.split("/").pop(),h=f==null||f in((r=u?.properties)!==null&&r!==void 0?r:{});let g=a.getSchema({pointer:l,data:s??void 0});return!h&&g?.type==="null"&&this.mode==="yaml"&&(g=void 0),Kr.log("xxxx","draft.getSchema",g,"data",s,"pointer",l,"pointerPointsToKnownProperty",h),ko(g)&&(g=(i=g.data)===null||i===void 0?void 0:i.schema),!Iy(g)&&u?[u]:(Iy(g)||(g=a.getSchema({pointer:c}),l=c),Kr.log("xxx","pointer..",JSON.stringify(l)),!Iy(g)&&(!l||l==="/")&&(g=(o=ih(t,t))!==null&&o!==void 0?o:t),Kr.log("xxx","subSchema..",g),g?Array.isArray(g.allOf)?[g,...g.allOf.map(y=>ih(y,t))]:Array.isArray(g.oneOf)?[g,...g.oneOf.map(y=>ih(y,t))]:Array.isArray(g.anyOf)?[g,...g.anyOf.map(y=>ih(y,t))]:[g]:[])}getAppliedValue(t){const n=u4(JSON.stringify(t));switch(this.mode){case zr.JSON5:return{label:n,apply:IUe(JSON.stringify(t))};case zr.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 AQe(e={}){const t=new EQe(e);return function(r){return t.doComplete(r)}}function kQe(e){return ty(e,(t,n)=>t==="additionalProperties"&&n===!1?[]:t==="required"&&Array.isArray(n)?[]:t==="unevaluatedProperties"&&n===!1?[]:t==="unevaluatedItems"&&n===!1?[]:[t,n])}function mG(e,t,n){const r=new Aie(e),i=r.getSchema({pointer:n,data:t??void 0});if(!Iy(i))return;const o=Mse(r,i),s={};for(let h of o){let g=DQe(n,h);const y=r.getSchema({pointer:g,data:t??void 0});Iy(y)&&Object.assign(s,{[h]:y})}if(o.length===0||Object.keys(s).length===0)return;const a=i,{allOf:l,anyOf:c,oneOf:u}=a,f=wQe(a,["allOf","anyOf","oneOf"]);return Object.assign(Object.assign({},f),{properties:s})}function Mse(e,t){if(t=ih(t,e.rootSchema),typeof t!="object"||t==null)return[];const n=[];function r(i){const o=Mse(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 ih(e,t){if(typeof e=="object"&&e.$ref){const n=_Qe(t,e.$ref);if(typeof n=="object"){const r=Object.assign(Object.assign({},e),n);return Reflect.deleteProperty(r,"$ref"),r}}return e}function _Qe(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 DQe(e,t){return e===void 0?`/${t}`:`${e}/${t}`}const K2=(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(" ")},OQe=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}`:""},TQe=e=>e.startState.field(H6)!==e.state.field(H6);function MQe(e){const t=new IQe(e);return n=>t.doValidation(n)}const RQe=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class IQe{constructor(t){var n,r,i,o;this.options=t,this.schema=null,this.mode=zr.JSON,this.rewriteError=s=>{var a,l,c,u,f;const h=s?.data,g=h?.errors;return s.code==="one-of-error"&&g?.length?`Expected one of ${K2(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)?K2((c=s?.data)===null||c===void 0?void 0:c.expected):(u=s?.data)===null||u===void 0?void 0:u.expected}\` but received \`${(f=s?.data)===null||f===void 0?void 0:f.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:zr.JSON,this.parser=(o=(i=this.options)===null||i===void 0?void 0:i.jsonParser)!==null&&o!==void 0?o:Tse(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 Cie(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 Kr.log("xxx","validation errors",o,i.data),o.length?o.reduce((s,a)=>{const l=()=>{const f=this.rewriteError(a);s.push({from:0,to:0,message:f,severity:"error",source:this.schemaTitle,renderMessage:()=>{const h=Ml("div",{});return h.innerHTML=Z0(f),h}})},c=OQe(a),u=i.pointers.get(c);if(a.name==="MaxPropertiesError"||a.name==="MinPropertiesError"||c==="")l();else if(u){const f=RQe.includes(a.name),h=this.rewriteError(a),g=f?u.keyFrom:u.valueFrom,y=f?u.keyTo:u.valueTo;y!==void 0&&g!==void 0&&s.push({from:g,to:y,message:h,renderMessage:()=>{const b=Ml("div",{});return b.innerHTML=Z0(h),b},severity:"error",source:this.schemaTitle})}else l();return s},[]):[]}}function PQe(e){const t=new jQe(e);return async function(r,i,o){return t.doHover(r,i,o)}}function gG(e){if(e.type)return e.$ref?`${e.$ref} (${e.type})`:e.type;if(e.$ref)return`${e.$ref}`}function zA(e,t,n){return`${t}: ${K2(e[t].map(r=>{try{const{data:i}=n.resolveRef({data:r,pointer:r.$ref});return gG(i||r)}catch{return r.type}}))}`}class jQe{constructor(t){var n,r;this.opts=t,this.schema=null,this.mode=zr.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:zr.JSON}getDataForCursor(t,n,r){const i=mR(t.state);if(!i)return null;this.schema=new Cie(i);const o=Lre(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 ko(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?Ml("div",{class:"cm6-json-schema-hover"},[Ml("div",{class:"cm6-json-schema-hover--description",inner:Z0(n,!1)}),Ml("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ml("div",{class:"cm6-json-schema-hover--code",inner:Z0(r,!1)})])]):Ml("div",{class:"cm6-json-schema-hover"},[Ml("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ml("code",{class:"cm6-json-schema-hover--code",inner:Z0(r,!1)})])])}getHoverTexts(t,n){let r="",i=null;const{schema:o}=t;return o.oneOf&&(r=zA(o,"oneOf",n)),o.anyOf&&(r=zA(o,"anyOf",n)),o.allOf&&(r=zA(o,"allOf",n)),o.type&&(r=Array.isArray(o.type)?K2(o.type):o.type),o.$ref&&(r=` Reference: ${o.$ref}`),o.enum&&(r=`\`enum\`: ${K2(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(Kr.log("cursorData",u),!u?.schema)return null;const h=((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)(h);return{pos:l,end:c,arrow:!0,above:!0,create:b=>({dom:y})}}catch(u){return Kr.log(u),null}}}const $Qe=e=>m.jsx(vc,{disablePadding:!0,children:e.validationErrors.map((t,n)=>m.jsx(gf,{disableGutters:!0,disablePadding:!0,children:m.jsxs(zt,{direction:"row",spacing:1,children:[m.jsx(ie,{variant:"body2",children:"•"}),m.jsx(ie,{variant:"caption",children:t.instancePath.length===0?"/":t.instancePath}),m.jsx(ie,{variant:"body2",children:t.message})]})},n.toString()))}),yG=e=>{let t;try{t=JSON.parse(e)}catch{t=void 0}return t};function LQe({schema:e,customValidate:t}){const n=_.useMemo(()=>new Oee({allErrors:!0}),[]);return _.useCallback(r=>{const i=[];return n.validate(e,r),i.push(...n.errors??[]),i.push(...t?.(r)??[]),i},[n,e,t])}const NQe=e=>{const t=FQe(),[n,r]=_.useState(()=>JSON.stringify(e.value,null,2)),i=LQe(e),[o,s]=_.useState([]);_.useEffect(()=>{s(i(e.value))},[i,e.value]);const a=e.onChange,l=_.useCallback(u=>{const f=yG(u),h=i(f);a(f,h.length===0),r(u),s(h)},[i,a]),c=()=>{const u=yG(n);u&&r(JSON.stringify(u,null,2))};return m.jsxs(zt,{spacing:2,children:[m.jsxs(le,{position:"relative",children:[m.jsx(Ire,{value:n,onChange:u=>l(u),extensions:[eBe(),cW(JFe(),{delay:100}),cW(MQe(),{delay:100,needsRefresh:TQe}),_ne.data.of({autocomplete:AQe({mode:"json4"})}),ane(PQe()),NUe(e.schema)],theme:t,height:"400px"}),m.jsx(kt,{sx:{position:"absolute",right:"0",bottom:"0"},onClick:()=>c(),children:"Prettify"})]}),o.length>0&&m.jsx(kn,{severity:"error",variant:"outlined",children:m.jsx($Qe,{validationErrors:o})})]})};function FQe(){return Oa().palette.mode==="dark"?CBe:vBe}const BQe=[{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"}],zQe=({bridgeId:e,selectedIcon:t,onIconChange:n})=>{const r=_.useRef(null),[i,o]=_.useState(!1),[s,a]=_.useState(null),[l,c]=_.useState(!1),[u,f]=_.useState(null);_.useEffect(()=>{e&&Tw(e).then(b=>{o(b),b&&a(`${i2(e)}?t=${Date.now()}`)}).catch(()=>{o(!1)})},[e]);const h=_.useCallback(async b=>{const v=b.target.files?.[0];if(!(!v||!e)){f(null),c(!0);try{await D8e(e,v),o(!0),a(`${i2(e)}?t=${Date.now()}`),n(void 0)}catch(S){f(S instanceof Error?S.message:"Upload failed")}finally{c(!1),r.current&&(r.current.value="")}}},[e,n]),g=_.useCallback(async()=>{if(e){f(null);try{await O8e(e),o(!1),a(null)}catch(b){f(b instanceof Error?b.message:"Delete failed")}}},[e]),y=_.useCallback(b=>{n(b===""?void 0:b)},[n]);return m.jsxs(zt,{spacing:2,children:[m.jsxs(ha,{fullWidth:!0,size:"small",children:[m.jsx(sc,{id:"icon-select-label",children:"Bridge Icon"}),m.jsx(oa,{labelId:"icon-select-label",value:t??"",label:"Bridge Icon",onChange:b=>y(b.target.value),disabled:i,children:BQe.map(b=>m.jsx(er,{value:b.value,children:b.label},b.value))}),m.jsx(Sw,{children:i?"Custom icon is set. Delete it to use preset icons.":"Select a preset icon or upload a custom image"})]}),e&&m.jsxs(le,{children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"Custom Icon"}),m.jsxs(zt,{direction:"row",spacing:2,alignItems:"center",children:[i&&s&&m.jsx(le,{component:"img",src:s,alt:"Custom bridge icon",sx:{width:48,height:48,objectFit:"contain",borderRadius:1,border:"1px solid",borderColor:"divider"}}),m.jsx("input",{ref:r,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp,image/svg+xml",style:{display:"none"},onChange:h}),m.jsx(kt,{variant:"outlined",size:"small",startIcon:m.jsx(GCe,{}),onClick:()=>r.current?.click(),disabled:l,children:l?"Uploading...":"Upload Image"}),i&&m.jsx(kt,{variant:"outlined",size:"small",color:"error",startIcon:m.jsx(Zd,{}),onClick:g,children:"Delete"})]}),u&&m.jsx(ie,{variant:"caption",color:"error",sx:{mt:1},children:u}),m.jsx(ie,{variant:"caption",color:"text.secondary",sx:{mt:1,display:"block"},children:"Supported formats: PNG, JPG, GIF, WebP, SVG (max 5MB)"})]}),!e&&m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Save the bridge first to upload a custom icon."})]})},i0={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"},bG=e=>{try{return JSON.parse(e)}catch{return}};function HQe({filter:e}){const[t,n]=_.useState(!1),[r,i]=_.useState(null),[o,s]=_.useState(null),[a,l]=_.useState(!1),c=_.useRef(null),u=_.useRef(""),f=_.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=bG(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??bG(b);i(S),l(!0)}catch(y){s(y instanceof Error?y.message:"Unknown error")}finally{n(!1)}},[e]);_.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(()=>{f()},800),()=>{c.current&&clearTimeout(c.current)}},[e,f]);const h=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(h).filter(v=>!i0[v]);b.length>0&&g.push(`Unsupported domains will be skipped: ${b.join(", ")}`)}return m.jsxs(le,{sx:{mt:2},children:[m.jsx(kt,{variant:"outlined",startIcon:t?m.jsx(Hr,{size:16}):m.jsx(u8e,{}),onClick:f,disabled:t,size:"small",children:t?"Loading...":"Preview Matching Entities"}),o&&m.jsx(kn,{severity:"error",sx:{mt:1},children:o}),m.jsx(da,{in:a&&r!==null,children:r&&m.jsxs(le,{sx:{mt:2},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsxs(ie,{variant:"subtitle1",fontWeight:"bold",children:[r.total," entities match"]}),r.truncated&&m.jsx(Et,{label:"Showing first 100",size:"small",color:"warning",variant:"outlined"})]}),g.length>0&&m.jsx(zt,{spacing:.5,sx:{mb:1.5},children:g.map(y=>m.jsx(kn,{severity:"warning",variant:"outlined",icon:y.includes("vacuum")?m.jsx(sm,{fontSize:"small"}):m.jsx(Yd,{fontSize:"small"}),sx:{py:0},children:m.jsx(ie,{variant:"caption",children:y})},y))}),m.jsx(le,{display:"flex",gap:.5,flexWrap:"wrap",mb:2,children:Object.entries(h).sort((y,b)=>b[1]-y[1]).map(([y,b])=>m.jsx(Et,{label:`${y}: ${b}${i0[y]?` → ${i0[y]}`:""}`,size:"small",variant:"outlined",color:i0[y]?"default":"warning"},y))}),m.jsx(vc,{dense:!0,sx:{maxHeight:200,overflow:"auto",bgcolor:"background.paper",borderRadius:1,border:1,borderColor:"divider"},children:r.entities.map(y=>m.jsx(gf,{divider:!0,children:m.jsx(Va,{primary:y.friendly_name||y.entity_id,secondary:`${y.entity_id}${i0[y.domain]?` → ${i0[y.domain]}`:""}`,primaryTypographyProps:{variant:"body2"},secondaryTypographyProps:{variant:"caption",fontFamily:"monospace"}})},y.entity_id))}),m.jsx(kt,{size:"small",onClick:()=>l(!1),sx:{mt:1},children:"Hide Preview"})]})})]})}const UQe=Mee(),VQe=UQe.ObjectFieldTemplate;function WQe(e){return(e.fieldPathId?.$id??"")==="root_filter"?m.jsx(qQe,{...e}):m.jsx(VQe,{...e})}function qQe(e){const t=e.formData?.include?.length??0,n=e.formData?.exclude?.length??0,r=t+n,[i,o]=_.useState(r>0);return m.jsxs(hd,{expanded:i,onChange:(s,a)=>o(a),variant:"outlined",disableGutters:!0,sx:{borderRadius:2,"&::before":{display:"none"},overflow:"hidden"},children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),sx:{px:2,"& .MuiAccordionSummary-content":{alignItems:"center",gap:1.5}},children:[m.jsx(hw,{fontSize:"small",color:"action"}),m.jsx(ie,{variant:"subtitle1",fontWeight:600,children:"Entity Filters"}),m.jsx(jZ,{badgeContent:r,color:"primary",sx:{ml:1},max:99,children:m.jsx(le,{})}),m.jsx(ie,{variant:"caption",color:"text.secondary",sx:{ml:1},children:i?"Click to collapse":`${r} rule${r!==1?"s":""} configured`})]}),m.jsx(pd,{sx:{px:2,pb:2},children:e.properties.map(s=>m.jsx("div",{children:s.content},s.name))})]})}function GQe(e){const t=_.useRef(e),n=t.current;return t.current=e,n}function vG(e){const{items:t,canAdd:n,onAddClick:r,title:i,formData:o}=e,s=o??[],[a,l]=_.useState(()=>new Set),[c,u]=_.useState(""),f=GQe(s.length);_.useEffect(()=>{if(s.length>f){const b=s.length-1,v=s[b];!v?.type&&!v?.value&&l(S=>new Set([...S,b]))}},[s,f]);const h=_.useCallback(b=>{l(v=>{const S=new Set(v);return S.has(b)?S.delete(b):S.add(b),S})},[]),g=_.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??"",A=C?.value??"";(w.toLowerCase().includes(b)||A.toLowerCase().includes(b))&&v.push(S)}return new Set(v)},[c,s]),y=_.useMemo(()=>{const b=Array.from({length:t.length},(v,S)=>S);return g?b.filter(v=>g.has(v)):b},[t.length,g]);return m.jsxs(le,{children:[m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1,children:[m.jsx(ie,{variant:"subtitle2",fontWeight:600,children:i}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(Et,{label:t.length,size:"small",color:"default",sx:{height:22,fontSize:"0.75rem"}}),n&&m.jsx(kt,{size:"small",startIcon:m.jsx(hc,{}),onClick:r,children:"Add"})]})]}),t.length>3&&m.jsx(Lr,{size:"small",fullWidth:!0,placeholder:"Search rules...",value:c,onChange:b=>u(b.target.value),slotProps:{input:{startAdornment:m.jsx(AM,{position:"start",children:m.jsx(xJ,{fontSize:"small",color:"action"})})}},sx:{mb:1}}),g&&y.length===0&&m.jsx(ie,{variant:"body2",color:"text.secondary",textAlign:"center",py:2,children:"No matching rules"}),m.jsx(zt,{spacing:.5,children:y.map(b=>{const v=s[b],S=v?.type??"",C=v?.value??"",w=a.has(b),A=S||C;return m.jsxs(le,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:[m.jsxs(le,{display:"flex",alignItems:"center",sx:{px:1.5,py:.75,cursor:"pointer","&:hover":{bgcolor:"action.hover"},bgcolor:w?"action.selected":"transparent"},onClick:()=>h(b),children:[w?m.jsx($Ce,{fontSize:"small",color:"action"}):m.jsx(NCe,{fontSize:"small",color:"action"}),A?m.jsxs(le,{display:"flex",alignItems:"center",gap:1,ml:.5,flex:1,minWidth:0,children:[m.jsx(Et,{label:S,size:"small",variant:"outlined",sx:{height:22,fontSize:"0.75rem",flexShrink:0}}),m.jsx(ie,{variant:"body2",noWrap:!0,sx:{flex:1,minWidth:0},children:C})]}):m.jsx(ie,{variant:"body2",color:"text.secondary",ml:.5,fontStyle:"italic",children:"New rule (click to configure)"})]}),m.jsx(da,{in:w,children:m.jsx(le,{sx:{px:2,pb:1.5,pt:.5},children:t[b]})})]},b)})})]})}function KQe(e){const{schema:t,formData:n={},onChange:r,disabled:i,readonly:o,fieldPathId:s}=e,a=t.properties??{},l=_.useCallback((c,u)=>{r({...n,[c]:u},s.path)},[n,r,s]);return m.jsxs(le,{children:[m.jsx(ie,{variant:"h6",sx:{mb:2},children:"Feature Flags"}),m.jsx(Qe,{container:!0,spacing:2,children:Object.entries(a).map(([c,u])=>{const f=n[c]??u.default??!1,h=u.title?.toLowerCase().includes("deprecated")??!1;return m.jsx(Qe,{size:{xs:12,sm:6,lg:4},children:m.jsx(tr,{variant:"outlined",sx:{height:"100%",opacity:h?.6:1,transition:"border-color 0.2s, box-shadow 0.2s",borderColor:f?"primary.main":"divider","&:hover":{transform:"none",boxShadow:"none"}},children:m.jsx(Gm,{onClick:()=>{!i&&!o&&l(c,!f)},disabled:i||o,sx:{height:"100%"},children:m.jsxs(gr,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[m.jsxs(le,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:1,children:[m.jsxs(le,{sx:{flex:1,minWidth:0},children:[m.jsx(ie,{variant:"subtitle2",fontWeight:600,sx:{lineHeight:1.3},children:u.title??c}),f&&m.jsx(Et,{label:"Active",size:"small",color:"primary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]}),m.jsx(Ph,{checked:f,size:"small",disabled:i||o,tabIndex:-1,onClick:g=>g.stopPropagation(),onChange:g=>l(c,g.target.checked)})]}),m.jsx(ie,{variant:"caption",color:"text.secondary",sx:{mt:1,lineHeight:1.4,flex:1},children:u.description})]})})})},c)})})]})}const Rse=e=>{const[t,n]=_.useState("FIELDS_EDITOR"),r=()=>{n(t==="FIELDS_EDITOR"?"JSON_EDITOR":"FIELDS_EDITOR")},[i,o]=_.useState(e.bridge),[s,a]=_.useState(!0),l=_.useCallback(g=>{const y=g;if(!y?.port)return[];const b=e.usedPorts[y.port];return b!==void 0&&b!==e.bridgeId?[{instancePath:"/port",message:`Port is already used by bridge with id ${b}`}]:[]},[e.bridgeId,e.usedPorts]),c=(g,y)=>{o(b=>({...g,icon:b?.icon})),a(y)},u=_.useCallback(g=>{o(y=>({...y,icon:g}))},[]),f=_.useMemo(()=>{const y=i?.featureFlags,b=[];return y?.serverMode&&b.push({severity:"warning",message:"Server Mode is enabled. Only ONE device should be in this bridge. Multiple devices will cause errors."}),y?.serverMode&&y?.vacuumOnOff===!1&&b.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."}),!y?.serverMode&&y?.vacuumOnOff&&b.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."}),y?.autoForceSync&&y?.autoComposedDevices&&b.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."}),b},[i]),h=async()=>{s&&await e.onSave(i)};return m.jsxs(m.Fragment,{children:[m.jsxs(kn,{severity:"warning",variant:"outlined",children:["Please consult"," ",m.jsx(uw,{href:jt.faq.bridgeConfig,target:"_blank",children:"the documentation"})," ","for proper bridge configurations."," ",m.jsx("strong",{children:'Especially if you are using labels, see the "Labels" section.'})]}),m.jsxs(kn,{severity:"info",variant:"outlined",children:[m.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."]}),f.map(g=>m.jsx(kn,{severity:g.severity,variant:"outlined",children:g.message},g.message)),m.jsxs(zt,{spacing:2,children:[m.jsx(le,{display:"flex",justifyContent:"flex-end",children:m.jsx(kt,{onClick:()=>r(),title:t==="FIELDS_EDITOR"?"JSON editor":"Form editor",children:t==="FIELDS_EDITOR"?m.jsx(h8e,{}):m.jsx(s8e,{})})}),t==="FIELDS_EDITOR"&&m.jsx(Eje,{value:i??{},onChange:c,schema:dy,uiSchema:{icon:{"ui:widget":"hidden"},featureFlags:{"ui:field":"featureFlags"},filter:{include:{"ui:options":{ArrayFieldTemplate:vG}},exclude:{"ui:options":{ArrayFieldTemplate:vG}}}},customValidate:l,templates:{ObjectFieldTemplate:WQe},fields:{featureFlags:KQe}}),t==="JSON_EDITOR"&&m.jsx(NQe,{value:i??{},onChange:c,schema:dy,customValidate:l}),i?.filter&&m.jsx(HQe,{filter:i.filter}),m.jsx(tr,{variant:"outlined",children:m.jsxs(gr,{children:[m.jsx(ie,{variant:"subtitle1",gutterBottom:!0,fontWeight:600,children:"Bridge Icon"}),m.jsx(zQe,{bridgeId:e.bridgeId,selectedIcon:i?.icon,onIconChange:u})]})}),m.jsxs(Qe,{container:!0,children:[m.jsx(Qe,{size:{xs:6,sm:4,md:3},children:m.jsx(kt,{fullWidth:!0,variant:"outlined",color:"error",onClick:e.onCancel,children:"Cancel"})}),m.jsx(Qe,{size:{xs:0,sm:4,md:6},sx:{display:{xs:"none",sm:"block"}}}),m.jsx(Qe,{size:{xs:6,sm:4,md:3},children:m.jsx(kt,{fullWidth:!0,variant:"outlined",disabled:!s,onClick:h,children:"Save"})})]})]})]})},YQe={name:"",featureFlags:{},filter:{include:[],exclude:[]}};function XQe(e){let t=5540;for(;e[t];)t++;return t}const ZQe=()=>{const e=Tu(),t=Jh(),[n,r]=_.useState(),i=!!qm().content?.length,o=pJ(),s=_.useCallback(f=>{r(f?.id)},[]),a=_.useMemo(()=>{if(!o)return;const f=XQe(o);if(n){const h=OZ.find(g=>g.id===n);if(h)return{name:h.name,port:f,filter:{...h.filter},featureFlags:{...h.featureFlags},icon:h.icon}}return{...YQe,port:f}},[o,n]),l=yCe(),c=()=>{t(-1)},u=async f=>{await l({...f}).then(()=>e.show({message:"Bridge saved",severity:"success"})).then(()=>c()).catch(h=>e.show({message:h.message,severity:"error"}))};return!a||!o?"Loading":m.jsxs(zt,{spacing:4,children:[m.jsx(dw,{items:[{name:"Bridges",to:jt.bridges},{name:"Create New",to:jt.createBridge}]}),i&&m.jsx(kn,{severity:"info",variant:"outlined",children:m.jsxs(ie,{children:["Did you know that you can connect the same bridge with multiple assistants?"," ",m.jsx(uw,{href:jt.faq.multiFabric,target:"_blank",children:"Learn more."})]})}),m.jsx(AJ,{selectedTemplate:n,onSelect:s}),m.jsx(Rse,{bridge:a,usedPorts:o,onSave:u,onCancel:c},n??"custom")]})},JQe=()=>{const e=Tu(),t=Jh(),{bridgeId:n}=hY(),{content:r,isLoading:i}=mJ(n),o=pJ(),s=bCe(),a=_.useMemo(()=>{if(!(i||!r))return{name:r.name,port:r.port,countryCode:r.countryCode,filter:r.filter,featureFlags:r.featureFlags,icon:r.icon,priority:r.priority}},[i,r]),l=()=>{t(-1)},c=async u=>{await s({...u,id:n}).then(()=>e.show({message:"Update completed",severity:"success"})).then(()=>l()).catch(f=>e.show({message:f.message,severity:"error"}))};return i||!o?"Loading":!r||!a?"Not found":m.jsxs(zt,{spacing:4,children:[m.jsx(dw,{items:[{name:"Bridges",to:jt.bridges},{name:r.name,to:jt.bridge(n)},{name:"Edit",to:jt.editBridge(n)}]}),m.jsx(Rse,{bridgeId:n,bridge:a,usedPorts:o,onSave:c,onCancel:l})]})};function QQe(){const[e,t]=_.useState(!1),[n,r]=_.useState(null),[i,o]=_.useState(null),[s,a]=_.useState(null),[l,c]=_.useState(new Set),[u,f]=_.useState(!1),[h,g]=_.useState(!0),[y,b]=_.useState(!0),[v,S]=_.useState(!1),[C,w]=_.useState(!1),[A,E]=_.useState(null),O=_.useRef(null),D=async(R=!1)=>{t(!0),r(null);try{const j=await fetch(R?"api/backup/download?includeIdentity=true":"api/backup/download");if(!j.ok)throw new Error("Failed to create backup");const z=await j.blob(),N=window.URL.createObjectURL(z),W=document.createElement("a");W.href=N,W.download=j.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]||"hamh-backup.zip",document.body.appendChild(W),W.click(),window.URL.revokeObjectURL(N),document.body.removeChild(W),o("Backup downloaded successfully!")}catch($){r($ instanceof Error?$.message:"Unknown error")}finally{t(!1)}},T=async R=>{const $=R.target.files?.[0];if($){E($),t(!0),r(null);try{const j=new FormData;j.append("file",$);const z=await fetch("api/backup/restore/preview",{method:"POST",body:j});if(!z.ok){const W=await z.json();throw new Error(W.error||"Failed to parse backup")}const N=await z.json();a(N),c(new Set(N.bridges.map(W=>W.id))),S(!0)}catch(j){r(j instanceof Error?j.message:"Unknown error")}finally{t(!1),O.current&&(O.current.value="")}}},I=async()=>{if(A){t(!0),r(null);try{const R=new FormData;R.append("file",A),R.append("options",JSON.stringify({bridgeIds:Array.from(l),overwriteExisting:u,includeMappings:h,restoreIdentity:y&&s?.includesIdentity}));const $=await fetch("api/backup/restore",{method:"POST",body:R});if(!$.ok){const z=await $.json();throw new Error(z.error||"Failed to restore backup")}const j=await $.json();if(j.errors.length>0)r(`Restored ${j.bridgesRestored} bridges with ${j.errors.length} errors`);else{const z=[`Restored ${j.bridgesRestored} bridges`];j.mappingsRestored>0&&z.push(`${j.mappingsRestored} entity mappings`),j.identitiesRestored>0&&z.push(`${j.identitiesRestored} identities`),o(`${z.join(", ")}!`)}S(!1),a(null),E(null),j.restartRequired&&w(!0)}catch(R){r(R instanceof Error?R.message:"Unknown error")}finally{t(!1)}}},F=R=>{const $=new Set(l);$.has(R)?$.delete(R):$.add(R),c($)},L=async()=>{t(!0);try{await fetch("api/backup/restart",{method:"POST"}),o("Application is restarting...")}catch(R){r(R instanceof Error?R.message:"Failed to restart")}finally{t(!1),w(!1)}};return m.jsxs(tr,{children:[m.jsxs(gr,{children:[m.jsxs(ie,{variant:"h6",gutterBottom:!0,children:[m.jsx($x,{sx:{mr:1,verticalAlign:"middle"}}),"Backup & Restore"]}),m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Create a full backup of your bridges and entity mappings, or restore from a previous backup."}),n&&m.jsx(kn,{severity:"error",sx:{mb:2},onClose:()=>r(null),children:n}),i&&m.jsx(kn,{severity:"success",sx:{mb:2},onClose:()=>o(null),children:i}),m.jsxs(Qe,{container:!0,spacing:2,children:[m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx($x,{color:"primary"}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",children:"Config Backup"})]}),m.jsxs(le,{sx:{flexGrow:1},children:[m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Export bridge configurations and entity mappings."}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Bridges will need to be re-commissioned after restore."})]}),m.jsx(kt,{variant:"contained",startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):m.jsx($x,{}),onClick:()=>D(!1),disabled:e,fullWidth:!0,sx:{mt:2},children:"Config Backup"})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx(SJ,{color:"warning"}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",children:"Full Backup (with Identity)"})]}),m.jsxs(le,{sx:{flexGrow:1},children:[m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Includes Matter identity files (keypairs, fabric credentials)."}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Preserves commissioning state across restores. DONT SHARE!"})]}),m.jsx(kt,{variant:"contained",color:"warning",startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):m.jsx($x,{}),onClick:()=>D(!0),disabled:e,fullWidth:!0,sx:{mt:2},children:"Full Backup (with Identity)"})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx(FB,{color:"info"}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",children:"Restore from Backup"})]}),m.jsx(le,{sx:{flexGrow:1},children:m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Upload a previously created backup file to restore bridges and configurations."})}),m.jsxs(kt,{variant:"outlined",color:"info",startIcon:m.jsx(FB,{}),component:"label",disabled:e,fullWidth:!0,sx:{mt:2},children:["Restore from Backup",m.jsx("input",{ref:O,type:"file",accept:".zip",hidden:!0,onChange:T})]})]})})]})]}),m.jsxs(vu,{open:v,onClose:()=>S(!1),maxWidth:"sm",fullWidth:!0,children:[m.jsx(Su,{children:"Restore Backup"}),m.jsx(xu,{children:s&&m.jsxs(m.Fragment,{children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Backup created: ",new Date(s.createdAt).toLocaleString()]}),s.includesIdentity&&m.jsx(kn,{severity:"info",sx:{mt:1},children:"This backup includes Matter identity data (keypairs, fabric credentials). Restoring identities allows bridges to reconnect without re-commissioning."}),m.jsx(ie,{variant:"subtitle2",sx:{mt:2,mb:1},children:"Select bridges to restore:"}),m.jsx(vc,{dense:!0,children:s.bridges.map(R=>m.jsxs(gf,{onClick:()=>F(R.id),sx:{cursor:"pointer"},children:[m.jsx(Ul,{children:m.jsx(Wl,{edge:"start",checked:l.has(R.id),tabIndex:-1,disableRipple:!0})}),m.jsx(Va,{primary:R.name,secondary:m.jsxs(m.Fragment,{children:["Port: ",R.port,R.hasMappings&&` • ${R.mappingCount} entity mappings`,R.exists&&m.jsx(ie,{component:"span",color:"warning.main",sx:{ml:1},children:"(exists)"})]})})]},R.id))}),m.jsxs(le,{sx:{mt:2},children:[m.jsx(Ls,{control:m.jsx(Wl,{checked:u,onChange:R=>f(R.target.checked)}),label:"Overwrite existing bridges"}),m.jsx(Ls,{control:m.jsx(Wl,{checked:h,onChange:R=>g(R.target.checked)}),label:"Include entity mappings"}),s?.includesIdentity&&m.jsx(Ls,{control:m.jsx(Wl,{checked:y,onChange:R=>b(R.target.checked)}),label:"Restore Matter identities (no re-commissioning needed)"})]})]})}),m.jsxs(Xd,{children:[m.jsx(kt,{onClick:()=>S(!1),children:"Cancel"}),m.jsx(kt,{variant:"contained",onClick:I,disabled:e||l.size===0,startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):null,children:"Restore"})]})]}),m.jsxs(vu,{open:C,onClose:()=>w(!1),children:[m.jsxs(Su,{children:[m.jsx(n2,{sx:{mr:1,verticalAlign:"middle"}}),"Restart Required"]}),m.jsxs(xu,{children:[m.jsx(ie,{children:"Bridges have been restored from backup. A restart is required for the changes to take effect."}),m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{mt:1},children:"The application will restart and you may need to refresh this page."})]}),m.jsxs(Xd,{children:[m.jsx(kt,{onClick:()=>w(!1),children:"Later"}),m.jsx(kt,{variant:"contained",color:"warning",onClick:L,disabled:e,startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):m.jsx(n2,{}),children:"Restart Now"})]})]})]})}const eet=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 tet(e={}){const[t,n]=_.useState(null),[r,i]=_.useState(!0),[o,s]=_.useState(null),[a,l]=_.useState("name"),[c,u]=_.useState("asc"),f=e.sortField??a,h=e.sortDirection??c,g=e.onSortFieldChange??l,y=e.onSortDirectionChange??u,b=_.useCallback(async()=>{try{const w=await fetch("api/health/detailed");if(w.ok){const A=await w.json();n(A),s(null)}else s("Failed to fetch health status")}catch{s("Connection error")}finally{i(!1)}},[]);_.useEffect(()=>{b();const w=setInterval(b,1e4);return()=>clearInterval(w)},[b]);const v=_.useCallback(async()=>{try{const w=await fetch("api/diagnostic/export");if(w.ok){const A=await w.blob(),E=URL.createObjectURL(A),O=document.createElement("a");O.href=E;const T=w.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]??`hamh-diagnostic-${new Date().toISOString().replace(/[:.]/g,"-")}.json`;O.download=T,document.body.appendChild(O),O.click(),document.body.removeChild(O),URL.revokeObjectURL(E)}}catch{s("Failed to export diagnostic data")}},[]),S=async w=>{try{await fetch(`api/matter/bridges/${w}/actions/restart`,{method:"POST"}),b()}catch{s("Failed to restart bridge")}};if(r)return m.jsx(le,{display:"flex",justifyContent:"center",p:4,children:m.jsx(Hr,{})});if(o||!t)return m.jsx(kn,{severity:"error",sx:{m:2},children:o??"Unable to load health status"});const C=t.status==="healthy"?m.jsx(Mu,{color:"success"}):t.status==="degraded"?m.jsx(aw,{color:"warning"}):m.jsx(bf,{color:"error"});return m.jsxs(le,{sx:{p:2},children:[m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[C,m.jsx(ie,{variant:"h5",children:"System Health"}),m.jsx(Et,{label:t.status.toUpperCase(),color:t.status==="healthy"?"success":t.status==="degraded"?"warning":"error",size:"small"})]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(kt,{variant:"outlined",size:"small",startIcon:m.jsx(Dw,{}),onClick:v,children:"Export Diagnostic"}),m.jsx(cn,{title:"Refresh",children:m.jsx(_n,{onClick:b,children:m.jsx(kT,{})})})]})]}),m.jsxs(Qe,{container:!0,spacing:2,children:[m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2},children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Version"}),m.jsx(ie,{variant:"h6",children:t.version})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2},children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Uptime"}),m.jsx(ie,{variant:"h6",children:eet(t.uptime)})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2},children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Home Assistant"}),m.jsx(Et,{label:t.services.homeAssistant.connected?"Connected":"Disconnected",color:t.services.homeAssistant.connected?"success":"error",size:"small"})]})})]}),m.jsx(gi,{sx:{my:3}}),m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,flexWrap:"wrap",gap:1,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(t_,{}),m.jsx(ie,{variant:"h6",children:"Bridge Status"}),m.jsx(Et,{label:`${t.services.bridges.running}/${t.services.bridges.total} Running`,size:"small",variant:"outlined"})]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(PZ,{fontSize:"small",color:"action"}),m.jsxs(ha,{size:"small",sx:{minWidth:120},children:[m.jsx(sc,{children:"Sort by"}),m.jsxs(oa,{value:f,label:"Sort by",onChange:w=>g(w.target.value),children:[m.jsx(er,{value:"name",children:"Name"}),m.jsx(er,{value:"created",children:"Created"})]})]}),m.jsx(cn,{title:h==="asc"?"Ascending":"Descending",children:m.jsx(_n,{size:"small",onClick:()=>y(h==="asc"?"desc":"asc"),children:h==="asc"?m.jsx(wT,{fontSize:"small"}):m.jsx(ST,{fontSize:"small"})})})]})]}),m.jsx(Qe,{container:!0,spacing:2,alignItems:"stretch",children:[...t.bridgeDetails].sort((w,A)=>{let E=0;return f==="name"?E=w.name.localeCompare(A.name):E=w.id.localeCompare(A.id),h==="asc"?E:-E}).map(w=>m.jsx(Qe,{size:{xs:12,sm:6,md:6,lg:4,xl:3},sx:{display:"flex"},children:m.jsx(tr,{variant:"outlined",sx:{width:"100%",height:"100%",minWidth:280,maxWidth:480,display:"flex",flexDirection:"column",borderColor:w.status==="running"?"success.main":w.status==="failed"?"error.main":"warning.main"},children:m.jsxs(gr,{sx:{flex:1,display:"flex",flexDirection:"column",p:2,"&:last-child":{pb:2}},children:[m.jsxs(le,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",flexShrink:0,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,minWidth:0,children:[m.jsx(ss,{}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",noWrap:!0,sx:{maxWidth:140},children:w.name})]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:.5,flexShrink:0,children:[m.jsx(Et,{label:w.status.toUpperCase(),color:w.status==="running"?"success":w.status==="failed"?"error":"warning",size:"small"}),w.status==="failed"&&m.jsx(cn,{title:"Restart Bridge",children:m.jsx(_n,{size:"small",onClick:()=>S(w.id),children:m.jsx(LB,{})})})]})]}),w.statusReason&&m.jsx(ie,{variant:"body2",color:"error",sx:{mt:1,flexShrink:0},children:w.statusReason}),m.jsx(le,{sx:{mt:"auto",pt:1,flexShrink:0},children:m.jsxs(le,{display:"flex",flexWrap:"wrap",gap:.5,alignItems:"center",children:[m.jsx(Et,{label:`Port ${w.port}`,size:"small",variant:"outlined",color:"default"}),m.jsx(Et,{label:`${w.deviceCount} Devices`,size:"small",variant:"outlined",color:"default"}),m.jsx(Et,{label:`${w.fabricCount} Fabrics`,size:"small",variant:"outlined",color:"default"}),w.failedEntityCount>0&&m.jsx(Et,{label:`${w.failedEntityCount} failed`,color:"error",size:"small"})]})}),w.connectivity&&w.status==="running"&&m.jsx(le,{sx:{mt:1,flexShrink:0},children:m.jsxs(ie,{variant:"caption",color:"text.secondary",children:["Sessions: ",w.connectivity.totalSessions," | Subs:"," ",w.connectivity.totalSubscriptions]})}),w.fabrics.length>0&&m.jsxs(le,{sx:{mt:1,flexShrink:0},children:[m.jsx(ie,{variant:"caption",color:"text.secondary",children:"Connected to:"}),m.jsx(le,{display:"flex",gap:.5,flexWrap:"wrap",mt:.5,children:w.fabrics.map(A=>m.jsx(Et,{icon:m.jsx(DZ,{fabric:A}),label:A.label||e2(A.rootVendorId),size:"small",variant:"outlined"},A.fabricIndex))})]})]})})},w.id))}),t.recovery.enabled&&m.jsxs(m.Fragment,{children:[m.jsx(gi,{sx:{my:3}}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx(LB,{}),m.jsx(ie,{variant:"h6",children:"Auto Recovery"}),m.jsx(Et,{label:"Enabled",color:"success",size:"small"})]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:["Recovery attempts: ",t.recovery.recoveryCount,t.recovery.lastRecoveryAttempt&&` | Last attempt: ${new Date(t.recovery.lastRecoveryAttempt).toLocaleString()}`]})]}),m.jsx(gi,{sx:{my:3}}),m.jsx(QQe,{})]})}const Jf=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]}`},xG=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`},net=()=>{const[e,t]=_.useState(null),[n,r]=_.useState(!0),[i,o]=_.useState(!0);if(_.useEffect(()=>{let l=null;const c=async()=>{try{const u=await fetch("api/system/info");if(u.ok){const f=await u.json();t(f),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 m.jsx(tr,{children:m.jsx(gr,{children:m.jsx(ie,{children:"Loading system information..."})})});if(!e)return m.jsx(tr,{children:m.jsx(gr,{children:m.jsx(ie,{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 m.jsx(tr,{children:m.jsxs(gr,{children:[m.jsxs(ie,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(KCe,{}),"System Information"]}),m.jsxs(Qe,{container:!0,spacing:3,children:[m.jsx(Qe,{size:{xs:12,md:6},children:m.jsxs(zt,{spacing:2,children:[m.jsxs(le,{children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Application"}),m.jsxs(zt,{spacing:1,sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Version:"}),m.jsx(Et,{label:e.version,size:"small",color:"primary"})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Environment:"}),m.jsx(Et,{label:e.environment,size:"small",variant:"outlined",color:e.environment==="Home Assistant Add-on"?"success":"default"})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Node.js:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:e.nodeVersion})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Process Uptime:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:xG(e.process.uptime)})]})]})]}),m.jsxs(le,{children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"System"}),m.jsxs(zt,{spacing:1,sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Hostname:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:e.hostname})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Platform:"}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:[e.platform," (",e.arch,")"]})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"CPU:"}),m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{maxWidth:200,textAlign:"right"},noWrap:!0,title:e.cpuModel,children:[e.cpuCount,"x"," ",e.cpuModel.split("@")[0].trim()]})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"System Uptime:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:xG(e.uptime)})]})]})]})]})}),m.jsx(Qe,{size:{xs:12,md:6},children:m.jsxs(zt,{spacing:2,children:[m.jsxs(le,{children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(t_,{}),"Memory Usage"]}),m.jsxs(le,{sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[m.jsxs(ie,{variant:"body2",children:[Jf(e.memory.used)," /"," ",Jf(e.memory.total)]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:[s.toFixed(1),"%"]})]}),m.jsx(le,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:m.jsx(le,{sx:{height:"100%",width:`${s}%`,backgroundColor:s>80?"error.main":s>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]}),m.jsxs(le,{children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(t_,{}),"HAMH Process Memory"]}),m.jsxs(le,{sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[m.jsxs(ie,{variant:"body2",children:["RSS: ",Jf(e.process.rss)]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:["Heap: ",Jf(e.process.heapUsed)," /"," ",Jf(e.process.heapSizeLimit)]})]}),m.jsx(le,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:m.jsx(le,{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"}})})]})]}),m.jsxs(le,{children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(f8e,{}),"Storage Usage"]}),m.jsxs(le,{sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[m.jsxs(ie,{variant:"body2",children:[Jf(e.storage.used)," /"," ",Jf(e.storage.total)]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:[a.toFixed(1),"%"]})]}),m.jsx(le,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:m.jsx(le,{sx:{height:"100%",width:`${a}%`,backgroundColor:a>80?"error.main":a>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]})]})}),m.jsxs(Qe,{size:{xs:12},children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(c8e,{}),"Network Interfaces"]}),m.jsx(zt,{spacing:1,sx:{mt:1},children:e.network.interfaces.map(l=>m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[m.jsx(ie,{variant:"body2",children:l.name}),m.jsx(Et,{label:`${l.address} (${l.family})`,size:"small",variant:"outlined"})]},`${l.name}-${l.address}`))})]})]})]})})},SG=200;function ret(){const[e,t]=_.useState([]),[n,r]=_.useState(null),[i,o]=_.useState(!1),s=_.useRef(null),a=_.useRef(void 0),l=_.useCallback(()=>{if(s.current?.readyState===WebSocket.OPEN)return;const u=window.location.protocol==="https:"?"wss:":"ws:",f=document.querySelector("base")?.href||window.location.origin,h=new URL(f),g=`${u}//${h.host}${h.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>SG?w.slice(-SG):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()},[]);_.useEffect(()=>(l(),()=>{clearTimeout(a.current),s.current&&(s.current.send(JSON.stringify({type:"unsubscribe_diagnostics"})),s.current.close())}),[l]);const c=_.useCallback(()=>t([]),[]);return{events:e,snapshot:n,connected:i,clearEvents:c}}const S4={state_update:{color:"#4caf50",label:"State Update"},command_received:{color:"#2196f3",label:"Command"},entity_error:{color:"#f44336",label:"Error"},session_opened:{color:"#ff9800",label:"Session Open"},session_closed:{color:"#9e9e9e",label:"Session Close"},subscription_changed:{color:"#9c27b0",label:"Subscription"},bridge_started:{color:"#00bcd4",label:"Bridge Start"},bridge_stopped:{color:"#795548",label:"Bridge Stop"}};function iet(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 HA=Object.keys(S4);function oet({sortField:e,sortDirection:t}={}){const{events:n,snapshot:r,connected:i,clearEvents:o}=ret(),[s,a]=_.useState(new Set(HA)),[l,c]=_.useState(!1),u=y=>{a(b=>{const v=new Set(b);return v.has(y)?v.delete(y):v.add(y),v})},f=n.filter(y=>s.has(y.type)),h=_.useMemo(()=>{const y=r?.bridges??[];return e?[...y].sort((b,v)=>{let S=0;return e==="name"?S=b.bridgeName.localeCompare(v.bridgeName):S=b.bridgeId.localeCompare(v.bridgeId),t==="desc"?-S:S}):y},[r?.bridges,e,t]),g={};for(const y of n)g[y.type]=(g[y.type]??0)+1;return m.jsx(tr,{children:m.jsxs(gr,{children:[m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(p8e,{}),m.jsx(ie,{variant:"h6",children:"Live Diagnostics"}),m.jsx(Et,{icon:m.jsx(n8e,{sx:{fontSize:10,color:i?"#4caf50":"#f44336"}}),label:i?"Live":"Offline",size:"small",variant:"outlined"})]}),m.jsxs(zt,{direction:"row",spacing:.5,alignItems:"center",children:[m.jsx(cn,{title:"Filter event types",children:m.jsx(_n,{size:"small",onClick:()=>c(y=>!y),color:l?"primary":"default",children:m.jsx(hw,{})})}),m.jsx(cn,{title:"Clear all events",children:m.jsx(_n,{size:"small",onClick:o,children:m.jsx(WCe,{})})})]})]}),m.jsxs(zt,{direction:"row",spacing:.5,flexWrap:"wrap",sx:{mb:2,gap:.5},children:[HA.map(y=>{const b=g[y]??0;if(b===0&&!l)return null;const v=S4[y];return m.jsx(Et,{label:`${v.label}: ${b}`,size:"small",sx:{bgcolor:s.has(y)?v.color:"action.disabledBackground",color:s.has(y)?"#fff":"text.disabled",fontSize:"0.7rem",height:22,cursor:"pointer",opacity:s.has(y)?1:.5},onClick:()=>u(y)},y)}),r?.system&&m.jsx(Et,{label:`Total: ${r.system.eventCount}`,size:"small",variant:"outlined",sx:{fontSize:"0.7rem",height:22}})]}),m.jsx(da,{in:l,children:m.jsx(Nr,{variant:"outlined",sx:{p:1.5,mb:2},children:m.jsx(Qe,{container:!0,spacing:0,children:HA.map(y=>{const b=S4[y];return m.jsx(Qe,{size:{xs:6,sm:4,md:3},children:m.jsx(Ls,{control:m.jsx(Wl,{size:"small",checked:s.has(y),onChange:()=>u(y),sx:{color:b.color,"&.Mui-checked":{color:b.color}}}),label:m.jsx(ie,{variant:"caption",children:b.label})})},y)})})})}),h.length>0&&m.jsxs(m.Fragment,{children:[m.jsx(Qe,{container:!0,spacing:1,sx:{mb:2},children:h.map(y=>m.jsx(Qe,{size:{xs:12,sm:6},children:m.jsxs(Nr,{variant:"outlined",sx:{p:1.5,display:"flex",justifyContent:"space-between",alignItems:"center",overflow:"hidden",minWidth:0},children:[m.jsxs(le,{sx:{minWidth:0,overflow:"hidden"},children:[m.jsx(ie,{variant:"body2",fontWeight:500,noWrap:!0,children:y.bridgeName}),m.jsxs(ie,{variant:"caption",color:"text.secondary",noWrap:!0,children:[y.entityCount," devices · ",y.sessionCount," ","sessions"]})]}),m.jsxs(zt,{direction:"row",spacing:.5,alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end",sx:{flexShrink:0,ml:1},children:[Object.entries(y.featureFlags).filter(([,b])=>b).map(([b])=>m.jsx(Et,{label:b.replace(/^auto/,"").replace(/([A-Z])/g," $1").trim(),size:"small",variant:"outlined",sx:{fontSize:"0.6rem",height:18}},b)),m.jsx(Et,{label:y.status,size:"small",color:y.status==="running"?"success":y.status==="failed"?"error":"default",sx:{height:20}})]})]})},y.bridgeId))}),m.jsx(gi,{sx:{mb:2}})]}),m.jsx(le,{sx:{maxHeight:400,overflow:"auto",bgcolor:"background.default",borderRadius:1,p:1},children:f.length===0?m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:4},children:n.length===0?"Waiting for diagnostic events…":"No events match the current filters."}):f.map(y=>{const b=S4[y.type];return m.jsxs(le,{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:[m.jsx(ie,{variant:"caption",sx:{color:"text.secondary",whiteSpace:"nowrap",fontFamily:"monospace",fontSize:"0.72rem",minWidth:85,pt:.1},children:iet(y.timestamp)}),m.jsx(Et,{label:b?.label??y.type,size:"small",sx:{bgcolor:b?.color??"#757575",color:"#fff",fontSize:"0.62rem",fontWeight:600,height:18,minWidth:90}}),y.bridgeName&&m.jsxs(ie,{variant:"caption",sx:{color:"primary.main",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:140,flexShrink:0},children:["[",y.bridgeName,"]"]}),y.entityId&&m.jsx(ie,{variant:"caption",sx:{color:"warning.main",fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:220,flexShrink:1},children:y.entityId}),m.jsx(ie,{variant:"caption",sx:{color:"text.primary",flex:1,wordBreak:"break-word",fontSize:"0.72rem"},children:y.message})]},y.id)})})]})})}const set=()=>{const[e,t]=_.useState("name"),[n,r]=_.useState("asc");return m.jsxs(le,{sx:{display:"flex",flexDirection:"column",gap:3},children:[m.jsx(tet,{sortField:e,sortDirection:n,onSortFieldChange:t,onSortDirectionChange:r}),m.jsx(le,{sx:{px:2},children:m.jsx(oet,{sortField:e,sortDirection:n})}),m.jsx(le,{sx:{px:2,pb:2},children:m.jsx(net,{})})]})};async function aet(){const e=await fetch(`api/matter/labels?_s=${Date.now()}`);if(!e.ok)throw new Error("Failed to fetch labels");return e.json()}async function cet(){const e=await fetch(`api/matter/areas?_s=${Date.now()}`);if(!e.ok)throw new Error("Failed to fetch areas");return e.json()}async function uet(){const e=await fetch(`api/matter/filter-values?_s=${Date.now()}`);if(!e.ok)throw new Error("Failed to fetch filter values");return e.json()}const o0=({values:e,copiedId:t,onCopy:n,searchable:r})=>{const[i,o]=_.useState(""),s=_.useMemo(()=>{if(!i)return e;const a=i.toLowerCase();return e.filter(l=>l.toLowerCase().includes(a))},[e,i]);return e.length===0?m.jsx(le,{sx:{p:2,textAlign:"center"},children:m.jsx(ie,{color:"text.secondary",variant:"body2",children:"No values found."})}):m.jsxs(le,{children:[r&&e.length>10&&m.jsx(le,{sx:{px:2,pt:1,pb:.5},children:m.jsx(Lr,{size:"small",fullWidth:!0,placeholder:"Search...",value:i,onChange:a=>o(a.target.value),slotProps:{input:{startAdornment:m.jsx(AM,{position:"start",children:m.jsx(xJ,{fontSize:"small"})})}}})}),m.jsxs(le,{sx:{p:1.5,display:"flex",flexWrap:"wrap",gap:.75},children:[s.map(a=>m.jsx(Et,{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&&m.jsxs(ie,{color:"text.secondary",variant:"body2",sx:{p:1},children:['No matches for "',i,'"']})]})]})},det=()=>{const[e,t]=_.useState([]),[n,r]=_.useState([]),[i,o]=_.useState(null),[s,a]=_.useState(!0),[l,c]=_.useState(null),[u,f]=_.useState(null),h=_.useCallback(async()=>{a(!0);try{const[y,b,v]=await Promise.all([aet(),cet(),uet()]);t(y),r(b),o(v),c(null)}catch(y){c(y instanceof Error?y.message:"Failed to load data")}finally{a(!1)}},[]);_.useEffect(()=>{h()},[h]);const g=y=>{navigator.clipboard.writeText(y),f(y),setTimeout(()=>f(null),2e3)};return s?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(Hr,{})}):m.jsxs(le,{sx:{p:2},children:[m.jsxs(ie,{variant:"h5",component:"h1",sx:{mb:3},children:[m.jsx(hw,{sx:{mr:1,verticalAlign:"middle"}}),"Filter Reference"]}),m.jsx(kn,{severity:"info",sx:{mb:3},children:"Browse all available filter values for your bridge configuration. Click any value to copy it to your clipboard."}),l&&m.jsx(kn,{severity:"error",sx:{mb:2},children:l}),m.jsxs(ie,{variant:"h6",sx:{mb:1},children:[m.jsx(i6,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),"Labels (",e.length,")"]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:["Use with filter type ",m.jsx("b",{children:'"entity_label"'})," or"," ",m.jsx("b",{children:'"device_label"'}),". You can use either the display name or the label_id."]}),m.jsx(tr,{sx:{mb:4},children:e.length===0?m.jsx(le,{sx:{p:3,textAlign:"center"},children:m.jsx(ie,{color:"text.secondary",children:"No labels found in Home Assistant. Create labels under Settings > Labels."})}):m.jsx(hm,{children:m.jsxs(dm,{size:"small",children:[m.jsx(J4,{children:m.jsxs(Ts,{children:[m.jsx(Rn,{sx:{fontWeight:"bold"},children:"Display Name"}),m.jsx(Rn,{sx:{fontWeight:"bold"},children:"label_id"}),m.jsx(Rn,{width:48})]})}),m.jsx(fm,{children:e.map(y=>m.jsxs(Ts,{hover:!0,children:[m.jsxs(Rn,{children:[y.color&&m.jsx(le,{component:"span",sx:{display:"inline-block",width:12,height:12,borderRadius:"50%",backgroundColor:y.color,mr:1,verticalAlign:"middle"}}),y.name]}),m.jsx(Rn,{children:m.jsx("code",{children:y.label_id})}),m.jsx(Rn,{children:m.jsx(cn,{title:u===y.label_id?"Copied!":"Copy ID",children:m.jsx(_n,{size:"small",onClick:()=>g(y.label_id),children:m.jsx(Eh,{fontSize:"small"})})})})]},y.label_id))})]})})}),m.jsxs(ie,{variant:"h6",sx:{mb:1},children:[m.jsx(fJ,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),"Areas (",n.length,")"]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:["Use with filter type ",m.jsx("b",{children:'"area"'}),". Areas are also used for automatic room assignment in Matter controllers."]}),m.jsx(tr,{sx:{mb:4},children:n.length===0?m.jsx(le,{sx:{p:3,textAlign:"center"},children:m.jsx(ie,{color:"text.secondary",children:"No areas found in Home Assistant. Create areas under Settings > Areas."})}):m.jsx(hm,{children:m.jsxs(dm,{size:"small",children:[m.jsx(J4,{children:m.jsxs(Ts,{children:[m.jsx(Rn,{sx:{fontWeight:"bold"},children:"Display Name"}),m.jsx(Rn,{sx:{fontWeight:"bold"},children:"area_id"}),m.jsx(Rn,{width:48})]})}),m.jsx(fm,{children:n.map(y=>m.jsxs(Ts,{hover:!0,children:[m.jsx(Rn,{children:y.name}),m.jsx(Rn,{children:m.jsx("code",{children:y.area_id})}),m.jsx(Rn,{children:m.jsx(cn,{title:u===y.area_id?"Copied!":"Copy ID",children:m.jsx(_n,{size:"small",onClick:()=>g(y.area_id),children:m.jsx(Eh,{fontSize:"small"})})})})]},y.area_id))})]})})}),i&&m.jsxs(m.Fragment,{children:[m.jsx(ie,{variant:"h6",sx:{mb:2},children:"Other Filter Values"}),m.jsxs(hd,{defaultExpanded:!0,children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(y8e,{sx:{mr:1}}),m.jsxs(ie,{children:["Domains (",i.domains.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"domain"'}),"."]}),m.jsx(o0,{values:i.domains,copiedId:u,onCopy:g})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(t8e,{sx:{mr:1}}),m.jsxs(ie,{children:["Platforms / Integrations (",i.platforms.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"platform"'}),"."]}),m.jsx(o0,{values:i.platforms,copiedId:u,onCopy:g})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(NB,{sx:{mr:1}}),m.jsxs(ie,{children:["Entity Categories (",i.entityCategories.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"entity_category"'}),"."]}),m.jsx(o0,{values:i.entityCategories,copiedId:u,onCopy:g})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(NB,{sx:{mr:1}}),m.jsxs(ie,{children:["Device Classes (",i.deviceClasses.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"device_class"'}),"."]}),m.jsx(o0,{values:i.deviceClasses,copiedId:u,onCopy:g,searchable:!0})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(ss,{sx:{mr:1}}),m.jsxs(ie,{children:["Device Names (",i.deviceNames.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"device_name"'}),"."]}),m.jsx(o0,{values:i.deviceNames,copiedId:u,onCopy:g,searchable:!0})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(ss,{sx:{mr:1}}),m.jsxs(ie,{children:["Product Names (",i.productNames.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"product_name"'}),"."]}),m.jsx(o0,{values:i.productNames,copiedId:u,onCopy:g,searchable:!0})]})]})]})]})};async function fet(){const e=await fetch("api/lock-credentials");if(!e.ok)throw new Error(`Failed to fetch lock credentials: ${e.statusText}`);return e.json()}async function het(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`Failed to update lock credential: ${n.statusText}`)}return n.json()}async function pet(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}/enabled`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`Failed to toggle credential: ${n.statusText}`)}return n.json()}async function met(e){const t=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"DELETE"});if(!t.ok)throw new Error(`Failed to delete lock credential: ${t.statusText}`)}const get=({open:e,onClose:t,onSave:n,initialEntityId:r="",initialName:i="",isEdit:o=!1})=>{const[s,a]=_.useState(r),[l,c]=_.useState(""),[u,f]=_.useState(i),[h,g]=_.useState(""),[y,b]=_.useState(!1);_.useEffect(()=>{e&&(a(r),f(i),c(""),g(""))},[e,r,i]);const v=async()=>{if(!s.trim()){g("Entity ID is required");return}if(!l||l.length<4||l.length>8){g("PIN must be 4-8 digits");return}if(!/^\d+$/.test(l)){g("PIN must contain only digits");return}b(!0);try{await n(s.trim(),l,u.trim()),t()}catch(S){g(S instanceof Error?S.message:"Failed to save")}finally{b(!1)}};return m.jsxs(vu,{open:e,onClose:t,maxWidth:"sm",fullWidth:!0,children:[m.jsx(Su,{children:o?"Edit Lock Credential":"Add Lock Credential"}),m.jsx(xu,{children:m.jsxs(le,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[h&&m.jsx(kn,{severity:"error",children:h}),m.jsx(Lr,{label:"Lock Entity ID",placeholder:"lock.front_door",value:s,onChange:S=>a(S.target.value),disabled:o,fullWidth:!0,helperText:"The Home Assistant entity ID of the lock"}),m.jsx(Lr,{label:"PIN Code",type:"password",placeholder:"1234",value:l,onChange:S=>c(S.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]*"}}),m.jsx(Lr,{label:"Name (optional)",placeholder:"Front Door",value:u,onChange:S=>f(S.target.value),fullWidth:!0,helperText:"Friendly name for this credential"})]})}),m.jsxs(Xd,{children:[m.jsx(kt,{onClick:t,disabled:y,children:"Cancel"}),m.jsx(kt,{onClick:v,variant:"contained",disabled:y,startIcon:y?m.jsx(Hr,{size:16}):m.jsx(o6,{}),children:"Save"})]})]})},yet=()=>{const[e,t]=_.useState([]),[n,r]=_.useState(!0),[i,o]=_.useState(null),[s,a]=_.useState(!1),[l,c]=_.useState(null),u=_.useCallback(async()=>{r(!0);try{const v=await fet();t(v.credentials),o(null)}catch(v){o(v instanceof Error?v.message:"Failed to load credentials")}finally{r(!1)}},[]);_.useEffect(()=>{u()},[u]);const f=async(v,S,C)=>{await het(v,{entityId:v,pinCode:S,name:C||void 0,enabled:!0}),await u()},h=async v=>{if(confirm("Are you sure you want to delete this credential?"))try{await met(v),await u()}catch(S){o(S instanceof Error?S.message:"Failed to delete")}},g=async v=>{try{await pet(v.entityId,!v.enabled),await u()}catch(S){o(S instanceof Error?S.message:"Failed to update")}},y=v=>{c(v),a(!0)},b=()=>{c(null),a(!0)};return m.jsxs(le,{sx:{p:2},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[m.jsxs(ie,{variant:"h5",component:"h1",children:[m.jsx(ac,{sx:{mr:1,verticalAlign:"middle"}}),"Lock Credentials"]}),m.jsx(kt,{variant:"contained",startIcon:m.jsx(hc,{}),onClick:b,children:"Add Credential"})]}),m.jsx(kn,{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."}),i&&m.jsx(kn,{severity:"error",sx:{mb:2},children:i}),n?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(Hr,{})}):e.length===0?m.jsx(tr,{children:m.jsxs(gr,{sx:{textAlign:"center",py:4},children:[m.jsx(ac,{sx:{fontSize:48,color:"text.secondary",mb:2}}),m.jsx(ie,{variant:"h6",color:"text.secondary",children:"No lock credentials configured"}),m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Add a PIN code for your Matter locks to enable remote lock/unlock"}),m.jsx(kt,{variant:"outlined",startIcon:m.jsx(hc,{}),onClick:b,children:"Add Your First Credential"})]})}):m.jsx(tr,{children:m.jsx(vc,{children:e.map((v,S)=>m.jsxs(gf,{divider:S<e.length-1,onClick:()=>y(v),sx:{cursor:"pointer","&:hover":{bgcolor:"action.hover"}},children:[m.jsx(Ul,{children:m.jsx(ac,{color:v.enabled?"primary":"disabled"})}),m.jsx(Va,{primary:v.name||v.entityId,secondary:m.jsxs(m.Fragment,{children:[v.name&&m.jsx(ie,{component:"span",variant:"body2",color:"text.secondary",children:v.entityId}),m.jsx(ie,{component:"span",variant:"body2",color:"text.secondary",sx:{ml:v.name?2:0},children:"PIN: ****"})]})}),m.jsxs(WO,{children:[m.jsx(cn,{title:v.enabled?"Disable":"Enable",children:m.jsx(Ph,{edge:"end",checked:v.enabled,onChange:C=>{C.stopPropagation(),g(v)}})}),m.jsx(cn,{title:"Delete",children:m.jsx(_n,{edge:"end",onClick:C=>{C.stopPropagation(),h(v.entityId)},sx:{ml:1},children:m.jsx(Zd,{})})})]})]},v.entityId))})}),m.jsx(get,{open:s,onClose:()=>a(!1),onSave:f,initialEntityId:l?.entityId,initialName:l?.name,isEdit:!!l})]})};function Mi(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=Mi(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var bet={value:()=>{}};function $C(){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 w4(n)}function w4(e){this._=e}function vet(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}})}w4.prototype=$C.prototype={constructor:w4,on:function(e,t){var n=this._,r=vet(e+"",n),i,o=-1,s=r.length;if(arguments.length<2){for(;++o<s;)if((i=(e=r[o]).type)&&(i=xet(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]=wG(n[i],e.name,t);else if(t==null)for(i in n)n[i]=wG(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 w4(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 xet(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function wG(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=bet,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var FD="http://www.w3.org/1999/xhtml";const CG={svg:"http://www.w3.org/2000/svg",xhtml:FD,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function LC(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),CG.hasOwnProperty(t)?{space:CG[t],local:e}:e}function wet(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===FD&&t.documentElement.namespaceURI===FD?t.createElement(e):t.createElementNS(n,e)}}function Cet(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Ise(e){var t=LC(e);return(t.local?Cet:wet)(t)}function Eet(){}function tI(e){return e==null?Eet:function(){return this.querySelector(e)}}function Aet(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 Bs(r,this._parents)}function ket(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function _et(){return[]}function Pse(e){return e==null?_et:function(){return this.querySelectorAll(e)}}function Det(e){return function(){return ket(e.apply(this,arguments))}}function Oet(e){typeof e=="function"?e=Det(e):e=Pse(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 Bs(r,i)}function jse(e){return function(){return this.matches(e)}}function $se(e){return function(t){return t.matches(e)}}var Tet=Array.prototype.find;function Met(e){return function(){return Tet.call(this.children,e)}}function Ret(){return this.firstElementChild}function Iet(e){return this.select(e==null?Ret:Met(typeof e=="function"?e:$se(e)))}var Pet=Array.prototype.filter;function jet(){return Array.from(this.children)}function $et(e){return function(){return Pet.call(this.children,e)}}function Let(e){return this.selectAll(e==null?jet:$et(typeof e=="function"?e:$se(e)))}function Net(e){typeof e!="function"&&(e=jse(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 Bs(r,this._parents)}function Lse(e){return new Array(e.length)}function Fet(){return new Bs(this._enter||this._groups.map(Lse),this._parents)}function pS(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}pS.prototype={constructor:pS,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 Bet(e){return function(){return e}}function zet(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 pS(e,o[s]);for(;s<l;++s)(a=t[s])&&(i[s]=a)}function Het(e,t,n,r,i,o,s){var a,l,c=new Map,u=t.length,f=o.length,h=new Array(u),g;for(a=0;a<u;++a)(l=t[a])&&(h[a]=g=s.call(l,l.__data__,a,t)+"",c.has(g)?i[a]=l:c.set(g,l));for(a=0;a<f;++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 pS(e,o[a]);for(a=0;a<u;++a)(l=t[a])&&c.get(h[a])===l&&(i[a]=l)}function Uet(e){return e.__data__}function Vet(e,t){if(!arguments.length)return Array.from(this,Uet);var n=t?Het:zet,r=this._parents,i=this._groups;typeof e!="function"&&(e=Bet(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],f=i[c],h=f.length,g=Wet(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(h);n(u,f,b,v,S,g,t);for(var C=0,w=0,A,E;C<y;++C)if(A=b[C]){for(C>=w&&(w=C+1);!(E=v[w])&&++w<y;);A._next=E||null}}return s=new Bs(s,r),s._enter=a,s._exit=l,s}function Wet(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function qet(){return new Bs(this._exit||this._groups.map(Lse),this._parents)}function Get(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 Ket(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],f=c.length,h=a[l]=new Array(f),g,y=0;y<f;++y)(g=c[y]||u[y])&&(h[y]=g);for(;l<i;++l)a[l]=n[l];return new Bs(a,this._parents)}function Yet(){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 Xet(e){e||(e=Zet);function t(f,h){return f&&h?e(f.__data__,h.__data__):!f-!h}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 Bs(i,this._parents).order()}function Zet(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Jet(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Qet(){return Array.from(this)}function ett(){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 ttt(){let e=0;for(const t of this)++e;return e}function ntt(){return!this.node()}function rtt(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 itt(e){return function(){this.removeAttribute(e)}}function ott(e){return function(){this.removeAttributeNS(e.space,e.local)}}function stt(e,t){return function(){this.setAttribute(e,t)}}function att(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function ltt(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function ctt(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 utt(e,t){var n=LC(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?ott:itt:typeof t=="function"?n.local?ctt:ltt:n.local?att:stt)(n,t))}function Nse(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function dtt(e){return function(){this.style.removeProperty(e)}}function ftt(e,t,n){return function(){this.style.setProperty(e,t,n)}}function htt(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function ptt(e,t,n){return arguments.length>1?this.each((t==null?dtt:typeof t=="function"?htt:ftt)(e,t,n??"")):Mm(this.node(),e)}function Mm(e,t){return e.style.getPropertyValue(t)||Nse(e).getComputedStyle(e,null).getPropertyValue(t)}function mtt(e){return function(){delete this[e]}}function gtt(e,t){return function(){this[e]=t}}function ytt(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function btt(e,t){return arguments.length>1?this.each((t==null?mtt:typeof t=="function"?ytt:gtt)(e,t)):this.node()[e]}function Fse(e){return e.trim().split(/^|\s+/)}function nI(e){return e.classList||new Bse(e)}function Bse(e){this._node=e,this._names=Fse(e.getAttribute("class")||"")}Bse.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 zse(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Hse(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function vtt(e){return function(){zse(this,e)}}function xtt(e){return function(){Hse(this,e)}}function Stt(e,t){return function(){(t.apply(this,arguments)?zse:Hse)(this,e)}}function wtt(e,t){var n=Fse(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"?Stt:t?vtt:xtt)(n,t))}function Ctt(){this.textContent=""}function Ett(e){return function(){this.textContent=e}}function Att(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function ktt(e){return arguments.length?this.each(e==null?Ctt:(typeof e=="function"?Att:Ett)(e)):this.node().textContent}function _tt(){this.innerHTML=""}function Dtt(e){return function(){this.innerHTML=e}}function Ott(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function Ttt(e){return arguments.length?this.each(e==null?_tt:(typeof e=="function"?Ott:Dtt)(e)):this.node().innerHTML}function Mtt(){this.nextSibling&&this.parentNode.appendChild(this)}function Rtt(){return this.each(Mtt)}function Itt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Ptt(){return this.each(Itt)}function jtt(e){var t=typeof e=="function"?e:Ise(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function $tt(){return null}function Ltt(e,t){var n=typeof e=="function"?e:Ise(e),r=t==null?$tt:typeof t=="function"?t:tI(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Ntt(){var e=this.parentNode;e&&e.removeChild(this)}function Ftt(){return this.each(Ntt)}function Btt(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ztt(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Htt(e){return this.select(e?ztt:Btt)}function Utt(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Vtt(e){return function(t){e.call(this,t,this.__data__)}}function Wtt(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 qtt(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 Gtt(e,t,n){return function(){var r=this.__on,i,o=Vtt(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 Ktt(e,t,n){var r=Wtt(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?Gtt:qtt,i=0;i<o;++i)this.each(a(r[i],t,n));return this}function Use(e,t,n){var r=Nse(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 Ytt(e,t){return function(){return Use(this,e,t)}}function Xtt(e,t){return function(){return Use(this,e,t.apply(this,arguments))}}function Ztt(e,t){return this.each((typeof t=="function"?Xtt:Ytt)(e,t))}function*Jtt(){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 Vse=[null];function Bs(e,t){this._groups=e,this._parents=t}function ev(){return new Bs([[document.documentElement]],Vse)}function Qtt(){return this}Bs.prototype=ev.prototype={constructor:Bs,select:Aet,selectAll:Oet,selectChild:Iet,selectChildren:Let,filter:Net,data:Vet,enter:Fet,exit:qet,join:Get,merge:Ket,selection:Qtt,order:Yet,sort:Xet,call:Jet,nodes:Qet,node:ett,size:ttt,empty:ntt,each:rtt,attr:utt,style:ptt,property:btt,classed:wtt,text:ktt,html:Ttt,raise:Rtt,lower:Ptt,append:jtt,insert:Ltt,remove:Ftt,clone:Htt,datum:Utt,on:Ktt,dispatch:Ztt,[Symbol.iterator]:Jtt};function Rs(e){return typeof e=="string"?new Bs([[document.querySelector(e)]],[document.documentElement]):new Bs([[e]],Vse)}function ent(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Fa(e,t){if(e=ent(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 tnt={passive:!1},Y2={capture:!0,passive:!1};function UA(e){e.stopImmediatePropagation()}function em(e){e.preventDefault(),e.stopImmediatePropagation()}function Wse(e){var t=e.document.documentElement,n=Rs(e).on("dragstart.drag",em,Y2);"onselectstart"in t?n.on("selectstart.drag",em,Y2):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function qse(e,t){var n=e.document.documentElement,r=Rs(e).on("dragstart.drag",null);t&&(r.on("click.drag",em,Y2),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 y5=e=>()=>e;function BD(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}})}BD.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function nnt(e){return!e.ctrlKey&&!e.button}function rnt(){return this.parentNode}function int(e,t){return t??{x:e.x,y:e.y}}function ont(){return navigator.maxTouchPoints||"ontouchstart"in this}function Gse(){var e=nnt,t=rnt,n=int,r=ont,i={},o=$C("start","drag","end"),s=0,a,l,c,u,f=0;function h(A){A.on("mousedown.drag",g).filter(r).on("touchstart.drag",v).on("touchmove.drag",S,tnt).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(A,E){if(!(u||!e.call(this,A,E))){var O=w(this,t.call(this,A,E),A,E,"mouse");O&&(Rs(A.view).on("mousemove.drag",y,Y2).on("mouseup.drag",b,Y2),Wse(A.view),UA(A),c=!1,a=A.clientX,l=A.clientY,O("start",A))}}function y(A){if(em(A),!c){var E=A.clientX-a,O=A.clientY-l;c=E*E+O*O>f}i.mouse("drag",A)}function b(A){Rs(A.view).on("mousemove.drag mouseup.drag",null),qse(A.view,c),em(A),i.mouse("end",A)}function v(A,E){if(e.call(this,A,E)){var O=A.changedTouches,D=t.call(this,A,E),T=O.length,I,F;for(I=0;I<T;++I)(F=w(this,D,A,E,O[I].identifier,O[I]))&&(UA(A),F("start",A,O[I]))}}function S(A){var E=A.changedTouches,O=E.length,D,T;for(D=0;D<O;++D)(T=i[E[D].identifier])&&(em(A),T("drag",A,E[D]))}function C(A){var E=A.changedTouches,O=E.length,D,T;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),D=0;D<O;++D)(T=i[E[D].identifier])&&(UA(A),T("end",A,E[D]))}function w(A,E,O,D,T,I){var F=o.copy(),L=Fa(I||O,E),R,$,j;if((j=n.call(A,new BD("beforestart",{sourceEvent:O,target:h,identifier:T,active:s,x:L[0],y:L[1],dx:0,dy:0,dispatch:F}),D))!=null)return R=j.x-L[0]||0,$=j.y-L[1]||0,function z(N,W,H){var U=L,K;switch(N){case"start":i[T]=z,K=s++;break;case"end":delete i[T],--s;case"drag":L=Fa(H||W,E),K=s;break}F.call(N,A,new BD(N,{sourceEvent:W,subject:j,target:h,identifier:T,active:K,x:L[0]+R,y:L[1]+$,dx:L[0]-U[0],dy:L[1]-U[1],dispatch:F}),D)}}return h.filter=function(A){return arguments.length?(e=typeof A=="function"?A:y5(!!A),h):e},h.container=function(A){return arguments.length?(t=typeof A=="function"?A:y5(A),h):t},h.subject=function(A){return arguments.length?(n=typeof A=="function"?A:y5(A),h):n},h.touchable=function(A){return arguments.length?(r=typeof A=="function"?A:y5(!!A),h):r},h.on=function(){var A=o.on.apply(o,arguments);return A===o?h:A},h.clickDistance=function(A){return arguments.length?(f=(A=+A)*A,h):Math.sqrt(f)},h}function rI(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Kse(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function tv(){}var X2=.7,mS=1/X2,tm="\\s*([+-]?\\d+)\\s*",Z2="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",uc="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",snt=/^#([0-9a-f]{3,8})$/,ant=new RegExp(`^rgb\\(${tm},${tm},${tm}\\)$`),lnt=new RegExp(`^rgb\\(${uc},${uc},${uc}\\)$`),cnt=new RegExp(`^rgba\\(${tm},${tm},${tm},${Z2}\\)$`),unt=new RegExp(`^rgba\\(${uc},${uc},${uc},${Z2}\\)$`),dnt=new RegExp(`^hsl\\(${Z2},${uc},${uc}\\)$`),fnt=new RegExp(`^hsla\\(${Z2},${uc},${uc},${Z2}\\)$`),EG={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,qh,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:AG,formatHex:AG,formatHex8:hnt,formatHsl:pnt,formatRgb:kG,toString:kG});function AG(){return this.rgb().formatHex()}function hnt(){return this.rgb().formatHex8()}function pnt(){return Yse(this).formatHsl()}function kG(){return this.rgb().formatRgb()}function qh(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=snt.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?_G(t):n===3?new rs(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?b5(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?b5(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=ant.exec(e))?new rs(t[1],t[2],t[3],1):(t=lnt.exec(e))?new rs(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=cnt.exec(e))?b5(t[1],t[2],t[3],t[4]):(t=unt.exec(e))?b5(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=dnt.exec(e))?TG(t[1],t[2]/100,t[3]/100,1):(t=fnt.exec(e))?TG(t[1],t[2]/100,t[3]/100,t[4]):EG.hasOwnProperty(e)?_G(EG[e]):e==="transparent"?new rs(NaN,NaN,NaN,0):null}function _G(e){return new rs(e>>16&255,e>>8&255,e&255,1)}function b5(e,t,n,r){return r<=0&&(e=t=n=NaN),new rs(e,t,n,r)}function mnt(e){return e instanceof tv||(e=qh(e)),e?(e=e.rgb(),new rs(e.r,e.g,e.b,e.opacity)):new rs}function zD(e,t,n,r){return arguments.length===1?mnt(e):new rs(e,t,n,r??1)}function rs(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}rI(rs,zD,Kse(tv,{brighter(e){return e=e==null?mS:Math.pow(mS,e),new rs(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?X2:Math.pow(X2,e),new rs(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new rs(Dh(this.r),Dh(this.g),Dh(this.b),gS(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:DG,formatHex:DG,formatHex8:gnt,formatRgb:OG,toString:OG}));function DG(){return`#${wh(this.r)}${wh(this.g)}${wh(this.b)}`}function gnt(){return`#${wh(this.r)}${wh(this.g)}${wh(this.b)}${wh((isNaN(this.opacity)?1:this.opacity)*255)}`}function OG(){const e=gS(this.opacity);return`${e===1?"rgb(":"rgba("}${Dh(this.r)}, ${Dh(this.g)}, ${Dh(this.b)}${e===1?")":`, ${e})`}`}function gS(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Dh(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function wh(e){return e=Dh(e),(e<16?"0":"")+e.toString(16)}function TG(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ua(e,t,n,r)}function Yse(e){if(e instanceof Ua)return new Ua(e.h,e.s,e.l,e.opacity);if(e instanceof tv||(e=qh(e)),!e)return new Ua;if(e instanceof Ua)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 Ua(s,a,l,e.opacity)}function ynt(e,t,n,r){return arguments.length===1?Yse(e):new Ua(e,t,n,r??1)}function Ua(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}rI(Ua,ynt,Kse(tv,{brighter(e){return e=e==null?mS:Math.pow(mS,e),new Ua(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?X2:Math.pow(X2,e),new Ua(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 rs(VA(e>=240?e-240:e+120,i,r),VA(e,i,r),VA(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new Ua(MG(this.h),v5(this.s),v5(this.l),gS(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=gS(this.opacity);return`${e===1?"hsl(":"hsla("}${MG(this.h)}, ${v5(this.s)*100}%, ${v5(this.l)*100}%${e===1?")":`, ${e})`}`}}));function MG(e){return e=(e||0)%360,e<0?e+360:e}function v5(e){return Math.max(0,Math.min(1,e||0))}function VA(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 bnt(e,t){return function(n){return e+n*t}}function vnt(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 xnt(e){return(e=+e)==1?Xse:function(t,n){return n-t?vnt(t,n,e):iI(isNaN(t)?n:t)}}function Xse(e,t){var n=t-e;return n?bnt(e,n):iI(isNaN(e)?t:e)}const yS=(function e(t){var n=xnt(t);function r(i,o){var s=n((i=zD(i)).r,(o=zD(o)).r),a=n(i.g,o.g),l=n(i.b,o.b),c=Xse(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 Snt(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 wnt(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Cnt(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]=Py(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 Ent(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function $l(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Ant(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]=Py(e[i],t[i]):r[i]=t[i];return function(o){for(i in n)r[i]=n[i](o);return r}}var HD=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,WA=new RegExp(HD.source,"g");function knt(e){return function(){return e}}function _nt(e){return function(t){return e(t)+""}}function Zse(e,t){var n=HD.lastIndex=WA.lastIndex=0,r,i,o,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=HD.exec(e))&&(i=WA.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:$l(r,i)})),n=WA.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?l[0]?_nt(l[0].x):knt(t):(t=l.length,function(c){for(var u=0,f;u<t;++u)a[(f=l[u]).i]=f.x(c);return a.join("")})}function Py(e,t){var n=typeof t,r;return t==null||n==="boolean"?iI(t):(n==="number"?$l:n==="string"?(r=qh(t))?(t=r,yS):Zse:t instanceof qh?yS:t instanceof Date?Ent:wnt(t)?Snt:Array.isArray(t)?Cnt:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Ant:$l)(e,t)}var RG=180/Math.PI,UD={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Jse(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)*RG,skewX:Math.atan(l)*RG,scaleX:s,scaleY:a}}var x5;function Dnt(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?UD:Jse(t.a,t.b,t.c,t.d,t.e,t.f)}function Ont(e){return e==null||(x5||(x5=document.createElementNS("http://www.w3.org/2000/svg","g")),x5.setAttribute("transform",e),!(e=x5.transform.baseVal.consolidate()))?UD:(e=e.matrix,Jse(e.a,e.b,e.c,e.d,e.e,e.f))}function Qse(e,t,n,r){function i(c){return c.length?c.pop()+" ":""}function o(c,u,f,h,g,y){if(c!==f||u!==h){var b=g.push("translate(",null,t,null,n);y.push({i:b-4,x:$l(c,f)},{i:b-2,x:$l(u,h)})}else(f||h)&&g.push("translate("+f+t+h+n)}function s(c,u,f,h){c!==u?(c-u>180?u+=360:u-c>180&&(c+=360),h.push({i:f.push(i(f)+"rotate(",null,r)-2,x:$l(c,u)})):u&&f.push(i(f)+"rotate("+u+r)}function a(c,u,f,h){c!==u?h.push({i:f.push(i(f)+"skewX(",null,r)-2,x:$l(c,u)}):u&&f.push(i(f)+"skewX("+u+r)}function l(c,u,f,h,g,y){if(c!==f||u!==h){var b=g.push(i(g)+"scale(",null,",",null,")");y.push({i:b-4,x:$l(c,f)},{i:b-2,x:$l(u,h)})}else(f!==1||h!==1)&&g.push(i(g)+"scale("+f+","+h+")")}return function(c,u){var f=[],h=[];return c=e(c),u=e(u),o(c.translateX,c.translateY,u.translateX,u.translateY,f,h),s(c.rotate,u.rotate,f,h),a(c.skewX,u.skewX,f,h),l(c.scaleX,c.scaleY,u.scaleX,u.scaleY,f,h),c=u=null,function(g){for(var y=-1,b=h.length,v;++y<b;)f[(v=h[y]).i]=v.x(g);return f.join("")}}}var Tnt=Qse(Dnt,"px, ","px)","deg)"),Mnt=Qse(Ont,", ",")",")"),Rnt=1e-12;function IG(e){return((e=Math.exp(e))+1/e)/2}function Int(e){return((e=Math.exp(e))-1/e)/2}function Pnt(e){return((e=Math.exp(2*e))-1)/(e+1)}const C4=(function e(t,n,r){function i(o,s){var a=o[0],l=o[1],c=o[2],u=s[0],f=s[1],h=s[2],g=u-a,y=f-l,b=g*g+y*y,v,S;if(b<Rnt)S=Math.log(h/c)/t,v=function(D){return[a+D*g,l+D*y,c*Math.exp(t*D*S)]};else{var C=Math.sqrt(b),w=(h*h-c*c+r*b)/(2*c*n*C),A=(h*h-c*c-r*b)/(2*h*n*C),E=Math.log(Math.sqrt(w*w+1)-w),O=Math.log(Math.sqrt(A*A+1)-A);S=(O-E)/t,v=function(D){var T=D*S,I=IG(E),F=c/(n*C)*(I*Pnt(t*T+E)-Int(E));return[a+F*g,l+F*y,c*I/IG(t*T+E)]}}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 Rm=0,ny=0,j1=0,eae=1e3,bS,ry,vS=0,Gh=0,NC=0,J2=typeof performance=="object"&&performance.now?performance:Date,tae=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function oI(){return Gh||(tae(jnt),Gh=J2.now()+NC)}function jnt(){Gh=0}function xS(){this._call=this._time=this._next=null}xS.prototype=nae.prototype={constructor:xS,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&&ry!==this&&(ry?ry._next=this:bS=this,ry=this),this._call=e,this._time=n,VD()},stop:function(){this._call&&(this._call=null,this._time=1/0,VD())}};function nae(e,t,n){var r=new xS;return r.restart(e,t,n),r}function $nt(){oI(),++Rm;for(var e=bS,t;e;)(t=Gh-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Rm}function PG(){Gh=(vS=J2.now())+NC,Rm=ny=0;try{$nt()}finally{Rm=0,Nnt(),Gh=0}}function Lnt(){var e=J2.now(),t=e-vS;t>eae&&(NC-=t,vS=e)}function Nnt(){for(var e,t=bS,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:bS=n);ry=e,VD(r)}function VD(e){if(!Rm){ny&&(ny=clearTimeout(ny));var t=e-Gh;t>24?(e<1/0&&(ny=setTimeout(PG,e-J2.now()-NC)),j1&&(j1=clearInterval(j1))):(j1||(vS=J2.now(),j1=setInterval(Lnt,eae)),Rm=1,tae(PG))}}function jG(e,t,n){var r=new xS;return t=t==null?0:+t,r.restart(i=>{r.stop(),e(i+t)},t,n),r}var Fnt=$C("start","end","cancel","interrupt"),Bnt=[],rae=0,$G=1,WD=2,E4=3,LG=4,qD=5,A4=6;function FC(e,t,n,r,i,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;znt(e,n,{name:t,index:r,group:i,on:Fnt,tween:Bnt,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:rae})}function sI(e,t){var n=ml(e,t);if(n.state>rae)throw new Error("too late; already scheduled");return n}function Ac(e,t){var n=ml(e,t);if(n.state>E4)throw new Error("too late; already running");return n}function ml(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function znt(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=nae(o,0,n.time);function o(c){n.state=$G,n.timer.restart(s,n.delay,n.time),n.delay<=c&&s(c-n.delay)}function s(c){var u,f,h,g;if(n.state!==$G)return l();for(u in r)if(g=r[u],g.name===n.name){if(g.state===E4)return jG(s);g.state===LG?(g.state=A4,g.timer.stop(),g.on.call("interrupt",e,e.__data__,g.index,g.group),delete r[u]):+u<t&&(g.state=A4,g.timer.stop(),g.on.call("cancel",e,e.__data__,g.index,g.group),delete r[u])}if(jG(function(){n.state===E4&&(n.state=LG,n.timer.restart(a,n.delay,n.time),a(c))}),n.state=WD,n.on.call("start",e,e.__data__,n.index,n.group),n.state===WD){for(n.state=E4,i=new Array(h=n.tween.length),u=0,f=-1;u<h;++u)(g=n.tween[u].value.call(e,e.__data__,n.index,n.group))&&(i[++f]=g);i.length=f+1}}function a(c){for(var u=c<n.duration?n.ease.call(null,c/n.duration):(n.timer.restart(l),n.state=qD,1),f=-1,h=i.length;++f<h;)i[f].call(e,u);n.state===qD&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=A4,n.timer.stop(),delete r[t];for(var c in r)return;delete e.__transition}}function k4(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>WD&&r.state<qD,r.state=A4,r.timer.stop(),r.on.call(i?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}o&&delete e.__transition}}function Hnt(e){return this.each(function(){k4(this,e)})}function Unt(e,t){var n,r;return function(){var i=Ac(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 Vnt(e,t,n){var r,i;if(typeof n!="function")throw new Error;return function(){var o=Ac(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 Wnt(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=ml(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?Unt:Vnt)(n,e,t))}function aI(e,t,n){var r=e._id;return e.each(function(){var i=Ac(this,r);(i.value||(i.value={}))[t]=n.apply(this,arguments)}),function(i){return ml(i,r).value[t]}}function iae(e,t){var n;return(typeof t=="number"?$l:t instanceof qh?yS:(n=qh(t))?(t=n,yS):Zse)(e,t)}function qnt(e){return function(){this.removeAttribute(e)}}function Gnt(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Knt(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 Ynt(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 Xnt(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 Znt(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 Jnt(e,t){var n=LC(e),r=n==="transform"?Mnt:iae;return this.attrTween(e,typeof t=="function"?(n.local?Znt:Xnt)(n,r,aI(this,"attr."+e,t)):t==null?(n.local?Gnt:qnt)(n):(n.local?Ynt:Knt)(n,r,t))}function Qnt(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function ert(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function trt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&ert(e,o)),n}return i._value=t,i}function nrt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&Qnt(e,o)),n}return i._value=t,i}function rrt(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=LC(e);return this.tween(n,(r.local?trt:nrt)(r,t))}function irt(e,t){return function(){sI(this,e).delay=+t.apply(this,arguments)}}function ort(e,t){return t=+t,function(){sI(this,e).delay=t}}function srt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?irt:ort)(t,e)):ml(this.node(),t).delay}function art(e,t){return function(){Ac(this,e).duration=+t.apply(this,arguments)}}function lrt(e,t){return t=+t,function(){Ac(this,e).duration=t}}function crt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?art:lrt)(t,e)):ml(this.node(),t).duration}function urt(e,t){if(typeof t!="function")throw new Error;return function(){Ac(this,e).ease=t}}function drt(e){var t=this._id;return arguments.length?this.each(urt(t,e)):ml(this.node(),t).ease}function frt(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ac(this,e).ease=n}}function hrt(e){if(typeof e!="function")throw new Error;return this.each(frt(this._id,e))}function prt(e){typeof e!="function"&&(e=jse(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 _u(r,this._parents,this._name,this._id)}function mrt(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,f=s[a]=new Array(u),h,g=0;g<u;++g)(h=l[g]||c[g])&&(f[g]=h);for(;a<r;++a)s[a]=t[a];return new _u(s,this._parents,this._name,this._id)}function grt(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 yrt(e,t,n){var r,i,o=grt(t)?sI:Ac;return function(){var s=o(this,e),a=s.on;a!==r&&(i=(r=a).copy()).on(t,n),s.on=i}}function brt(e,t){var n=this._id;return arguments.length<2?ml(this.node(),n).on.on(e):this.each(yrt(n,e,t))}function vrt(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function xrt(){return this.on("end.remove",vrt(this._id))}function Srt(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,f,h=0;h<l;++h)(u=a[h])&&(f=e.call(u,u.__data__,h,a))&&("__data__"in u&&(f.__data__=u.__data__),c[h]=f,FC(c[h],t,n,h,c,ml(u,n)));return new _u(o,this._parents,t,n)}function wrt(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Pse(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,f=0;f<c;++f)if(u=l[f]){for(var h=e.call(u,u.__data__,f,l),g,y=ml(u,n),b=0,v=h.length;b<v;++b)(g=h[b])&&FC(g,t,n,b,h,y);o.push(h),s.push(u)}return new _u(o,s,t,n)}var Crt=ev.prototype.constructor;function Ert(){return new Crt(this._groups,this._parents)}function Art(e,t){var n,r,i;return function(){var o=Mm(this,e),s=(this.style.removeProperty(e),Mm(this,e));return o===s?null:o===n&&s===r?i:i=t(n=o,r=s)}}function oae(e){return function(){this.style.removeProperty(e)}}function krt(e,t,n){var r,i=n+"",o;return function(){var s=Mm(this,e);return s===i?null:s===r?o:o=t(r=s,n)}}function _rt(e,t,n){var r,i,o;return function(){var s=Mm(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),Mm(this,e))),s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a))}}function Drt(e,t){var n,r,i,o="style."+t,s="end."+o,a;return function(){var l=Ac(this,e),c=l.on,u=l.value[o]==null?a||(a=oae(t)):void 0;(c!==n||i!==u)&&(r=(n=c).copy()).on(s,i=u),l.on=r}}function Ort(e,t,n){var r=(e+="")=="transform"?Tnt:iae;return t==null?this.styleTween(e,Art(e,r)).on("end.style."+e,oae(e)):typeof t=="function"?this.styleTween(e,_rt(e,r,aI(this,"style."+e,t))).each(Drt(this._id,e)):this.styleTween(e,krt(e,r,t),n).on("end.style."+e,null)}function Trt(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Mrt(e,t,n){var r,i;function o(){var s=t.apply(this,arguments);return s!==i&&(r=(i=s)&&Trt(e,s,n)),r}return o._value=t,o}function Rrt(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,Mrt(e,t,n??""))}function Irt(e){return function(){this.textContent=e}}function Prt(e){return function(){var t=e(this);this.textContent=t??""}}function jrt(e){return this.tween("text",typeof e=="function"?Prt(aI(this,"text",e)):Irt(e==null?"":e+""))}function $rt(e){return function(t){this.textContent=e.call(this,t)}}function Lrt(e){var t,n;function r(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&$rt(i)),t}return r._value=e,r}function Nrt(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,Lrt(e))}function Frt(){for(var e=this._name,t=this._id,n=sae(),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=ml(l,t);FC(l,e,n,c,s,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new _u(r,this._parents,e,n)}function Brt(){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=Ac(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 zrt=0;function _u(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function sae(){return++zrt}var Zc=ev.prototype;_u.prototype={constructor:_u,select:Srt,selectAll:wrt,selectChild:Zc.selectChild,selectChildren:Zc.selectChildren,filter:prt,merge:mrt,selection:Ert,transition:Frt,call:Zc.call,nodes:Zc.nodes,node:Zc.node,size:Zc.size,empty:Zc.empty,each:Zc.each,on:brt,attr:Jnt,attrTween:rrt,style:Ort,styleTween:Rrt,text:jrt,textTween:Nrt,remove:xrt,tween:Wnt,delay:srt,duration:crt,ease:drt,easeVarying:hrt,end:Brt,[Symbol.iterator]:Zc[Symbol.iterator]};function Hrt(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Urt={time:null,delay:0,duration:250,ease:Hrt};function Vrt(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 Wrt(e){var t,n;e instanceof _u?(t=e._id,e=e._name):(t=sae(),(n=Urt).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])&&FC(l,e,t,c,s,n||Vrt(l,t));return new _u(r,this._parents,e,t)}ev.prototype.interrupt=Hnt;ev.prototype.transition=Wrt;const S5=e=>()=>e;function qrt(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 uu(e,t,n){this.k=e,this.x=t,this.y=n}uu.prototype={constructor:uu,scale:function(e){return e===1?this:new uu(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new uu(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 BC=new uu(1,0,0);aae.prototype=uu.prototype;function aae(e){for(;!e.__zoom;)if(!(e=e.parentNode))return BC;return e.__zoom}function qA(e){e.stopImmediatePropagation()}function $1(e){e.preventDefault(),e.stopImmediatePropagation()}function Grt(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Krt(){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 NG(){return this.__zoom||BC}function Yrt(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Xrt(){return navigator.maxTouchPoints||"ontouchstart"in this}function Zrt(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 lae(){var e=Grt,t=Krt,n=Zrt,r=Yrt,i=Xrt,o=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,l=C4,c=$C("start","zoom","end"),u,f,h,g=500,y=150,b=0,v=10;function S(j){j.property("__zoom",NG).on("wheel.zoom",T,{passive:!1}).on("mousedown.zoom",I).on("dblclick.zoom",F).filter(i).on("touchstart.zoom",L).on("touchmove.zoom",R).on("touchend.zoom touchcancel.zoom",$).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}S.transform=function(j,z,N,W){var H=j.selection?j.selection():j;H.property("__zoom",NG),j!==H?E(j,z,N,W):H.interrupt().each(function(){O(this,arguments).event(W).start().zoom(null,typeof z=="function"?z.apply(this,arguments):z).end()})},S.scaleBy=function(j,z,N,W){S.scaleTo(j,function(){var H=this.__zoom.k,U=typeof z=="function"?z.apply(this,arguments):z;return H*U},N,W)},S.scaleTo=function(j,z,N,W){S.transform(j,function(){var H=t.apply(this,arguments),U=this.__zoom,K=N==null?A(H):typeof N=="function"?N.apply(this,arguments):N,B=U.invert(K),q=typeof z=="function"?z.apply(this,arguments):z;return n(w(C(U,q),K,B),H,s)},N,W)},S.translateBy=function(j,z,N,W){S.transform(j,function(){return n(this.__zoom.translate(typeof z=="function"?z.apply(this,arguments):z,typeof N=="function"?N.apply(this,arguments):N),t.apply(this,arguments),s)},null,W)},S.translateTo=function(j,z,N,W,H){S.transform(j,function(){var U=t.apply(this,arguments),K=this.__zoom,B=W==null?A(U):typeof W=="function"?W.apply(this,arguments):W;return n(BC.translate(B[0],B[1]).scale(K.k).translate(typeof z=="function"?-z.apply(this,arguments):-z,typeof N=="function"?-N.apply(this,arguments):-N),U,s)},W,H)};function C(j,z){return z=Math.max(o[0],Math.min(o[1],z)),z===j.k?j:new uu(z,j.x,j.y)}function w(j,z,N){var W=z[0]-N[0]*j.k,H=z[1]-N[1]*j.k;return W===j.x&&H===j.y?j:new uu(j.k,W,H)}function A(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function E(j,z,N,W){j.on("start.zoom",function(){O(this,arguments).event(W).start()}).on("interrupt.zoom end.zoom",function(){O(this,arguments).event(W).end()}).tween("zoom",function(){var H=this,U=arguments,K=O(H,U).event(W),B=t.apply(H,U),q=N==null?A(B):typeof N=="function"?N.apply(H,U):N,X=Math.max(B[1][0]-B[0][0],B[1][1]-B[0][1]),V=H.__zoom,Y=typeof z=="function"?z.apply(H,U):z,J=l(V.invert(q).concat(X/V.k),Y.invert(q).concat(X/Y.k));return function(ne){if(ne===1)ne=Y;else{var ee=J(ne),se=X/ee[2];ne=new uu(se,q[0]-ee[0]*se,q[1]-ee[1]*se)}K.zoom(null,ne)}})}function O(j,z,N){return!N&&j.__zooming||new D(j,z)}function D(j,z){this.that=j,this.args=z,this.active=0,this.sourceEvent=null,this.extent=t.apply(j,z),this.taps=0}D.prototype={event:function(j){return j&&(this.sourceEvent=j),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(j,z){return this.mouse&&j!=="mouse"&&(this.mouse[1]=z.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=z.invert(this.touch0[0])),this.touch1&&j!=="touch"&&(this.touch1[1]=z.invert(this.touch1[0])),this.that.__zoom=z,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(j){var z=Rs(this.that).datum();c.call(j,this.that,new qrt(j,{sourceEvent:this.sourceEvent,target:S,transform:this.that.__zoom,dispatch:c}),z)}};function T(j,...z){if(!e.apply(this,arguments))return;var N=O(this,z).event(j),W=this.__zoom,H=Math.max(o[0],Math.min(o[1],W.k*Math.pow(2,r.apply(this,arguments)))),U=Fa(j);if(N.wheel)(N.mouse[0][0]!==U[0]||N.mouse[0][1]!==U[1])&&(N.mouse[1]=W.invert(N.mouse[0]=U)),clearTimeout(N.wheel);else{if(W.k===H)return;N.mouse=[U,W.invert(U)],k4(this),N.start()}$1(j),N.wheel=setTimeout(K,y),N.zoom("mouse",n(w(C(W,H),N.mouse[0],N.mouse[1]),N.extent,s));function K(){N.wheel=null,N.end()}}function I(j,...z){if(h||!e.apply(this,arguments))return;var N=j.currentTarget,W=O(this,z,!0).event(j),H=Rs(j.view).on("mousemove.zoom",q,!0).on("mouseup.zoom",X,!0),U=Fa(j,N),K=j.clientX,B=j.clientY;Wse(j.view),qA(j),W.mouse=[U,this.__zoom.invert(U)],k4(this),W.start();function q(V){if($1(V),!W.moved){var Y=V.clientX-K,J=V.clientY-B;W.moved=Y*Y+J*J>b}W.event(V).zoom("mouse",n(w(W.that.__zoom,W.mouse[0]=Fa(V,N),W.mouse[1]),W.extent,s))}function X(V){H.on("mousemove.zoom mouseup.zoom",null),qse(V.view,W.moved),$1(V),W.event(V).end()}}function F(j,...z){if(e.apply(this,arguments)){var N=this.__zoom,W=Fa(j.changedTouches?j.changedTouches[0]:j,this),H=N.invert(W),U=N.k*(j.shiftKey?.5:2),K=n(w(C(N,U),W,H),t.apply(this,z),s);$1(j),a>0?Rs(this).transition().duration(a).call(E,K,W,j):Rs(this).call(S.transform,K,W,j)}}function L(j,...z){if(e.apply(this,arguments)){var N=j.touches,W=N.length,H=O(this,z,j.changedTouches.length===W).event(j),U,K,B,q;for(qA(j),K=0;K<W;++K)B=N[K],q=Fa(B,this),q=[q,this.__zoom.invert(q),B.identifier],H.touch0?!H.touch1&&H.touch0[2]!==q[2]&&(H.touch1=q,H.taps=0):(H.touch0=q,U=!0,H.taps=1+!!u);u&&(u=clearTimeout(u)),U&&(H.taps<2&&(f=q[0],u=setTimeout(function(){u=null},g)),k4(this),H.start())}}function R(j,...z){if(this.__zooming){var N=O(this,z).event(j),W=j.changedTouches,H=W.length,U,K,B,q;for($1(j),U=0;U<H;++U)K=W[U],B=Fa(K,this),N.touch0&&N.touch0[2]===K.identifier?N.touch0[0]=B:N.touch1&&N.touch1[2]===K.identifier&&(N.touch1[0]=B);if(K=N.that.__zoom,N.touch1){var X=N.touch0[0],V=N.touch0[1],Y=N.touch1[0],J=N.touch1[1],ne=(ne=Y[0]-X[0])*ne+(ne=Y[1]-X[1])*ne,ee=(ee=J[0]-V[0])*ee+(ee=J[1]-V[1])*ee;K=C(K,Math.sqrt(ne/ee)),B=[(X[0]+Y[0])/2,(X[1]+Y[1])/2],q=[(V[0]+J[0])/2,(V[1]+J[1])/2]}else if(N.touch0)B=N.touch0[0],q=N.touch0[1];else return;N.zoom("touch",n(w(K,B,q),N.extent,s))}}function $(j,...z){if(this.__zooming){var N=O(this,z).event(j),W=j.changedTouches,H=W.length,U,K;for(qA(j),h&&clearTimeout(h),h=setTimeout(function(){h=null},g),U=0;U<H;++U)K=W[U],N.touch0&&N.touch0[2]===K.identifier?delete N.touch0:N.touch1&&N.touch1[2]===K.identifier&&delete N.touch1;if(N.touch1&&!N.touch0&&(N.touch0=N.touch1,delete N.touch1),N.touch0)N.touch0[1]=this.__zoom.invert(N.touch0[0]);else if(N.end(),N.taps===2&&(K=Fa(K,this),Math.hypot(f[0]-K[0],f[1]-K[1])<v)){var B=Rs(this).on("dblclick.zoom");B&&B.apply(this,arguments)}}}return S.wheelDelta=function(j){return arguments.length?(r=typeof j=="function"?j:S5(+j),S):r},S.filter=function(j){return arguments.length?(e=typeof j=="function"?j:S5(!!j),S):e},S.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:S5(!!j),S):i},S.extent=function(j){return arguments.length?(t=typeof j=="function"?j:S5([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),S):t},S.scaleExtent=function(j){return arguments.length?(o[0]=+j[0],o[1]=+j[1],S):[o[0],o[1]]},S.translateExtent=function(j){return arguments.length?(s[0][0]=+j[0][0],s[1][0]=+j[1][0],s[0][1]=+j[0][1],s[1][1]=+j[1][1],S):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},S.constrain=function(j){return arguments.length?(n=j,S):n},S.duration=function(j){return arguments.length?(a=+j,S):a},S.interpolate=function(j){return arguments.length?(l=j,S):l},S.on=function(){var j=c.on.apply(c,arguments);return j===c?S:j},S.clickDistance=function(j){return arguments.length?(b=(j=+j)*j,S):Math.sqrt(b)},S.tapDistance=function(j){return arguments.length?(v=+j,S):v},S}const yc={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."},Q2=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],cae=["Enter"," ","Escape"],uae={"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 Im;(function(e){e.Strict="strict",e.Loose="loose"})(Im||(Im={}));var Oh;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Oh||(Oh={}));var eb;(function(e){e.Partial="partial",e.Full="full"})(eb||(eb={}));const dae={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var kd;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(kd||(kd={}));var SS;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(SS||(SS={}));var xt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(xt||(xt={}));const FG={[xt.Left]:xt.Right,[xt.Right]:xt.Left,[xt.Top]:xt.Bottom,[xt.Bottom]:xt.Top};function fae(e){return e===null?null:e?"valid":"invalid"}const hae=e=>"id"in e&&"source"in e&&"target"in e,Jrt=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),nv=(e,t=[0,0])=>{const{width:n,height:r}=ju(e),i=e.origin??t,o=n*i[0],s=r*i[1];return{x:e.position.x-o,y:e.position.y-s}},Qrt=(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?wS(s,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return zC(r,a)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return HC(n)},rv=(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=zC(n,wS(i)),r=!0)}),r?HC(n):{x:0,y:0,width:0,height:0}},cI=(e,t,[n,r,i]=[0,0,1],o=!1,s=!1)=>{const a={...ov(t,[n,r,i]),width:t.width/i,height:t.height/i},l=[];for(const c of e.values()){const{measured:u,selectable:f=!0,hidden:h=!1}=c;if(s&&!f||h)continue;const g=u.width??c.width??c.initialWidth??null,y=u.height??c.height??c.initialHeight??null,b=tb(a,jm(c)),v=(g??0)*(y??0),S=o&&b>0;(!c.internals.handleBounds||S||b>=v||c.dragging)&&l.push(c)}return l},eit=(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 tit(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 nit({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:o},s){if(e.size===0)return Promise.resolve(!0);const a=tit(e,s),l=rv(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 pae({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 f=s.extent||i;if(s.extent==="parent"&&!s.expandParent)if(!a)o?.("005",yc.error005());else{const g=a.measured.width,y=a.measured.height;g&&y&&(f=[[l,c],[l+g,c+y]])}else a&&$m(s.extent)&&(f=[[s.extent[0][0]+l,s.extent[0][1]+c],[s.extent[1][0]+l,s.extent[1][1]+c]]);const h=$m(f)?Kh(t,f,s.measured):t;return(s.measured.width===void 0||s.measured.height===void 0)&&o?.("015",yc.error015()),{position:{x:h.x-l+(s.measured.width??0)*u[0],y:h.y-c+(s.measured.height??0)*u[1]},positionAbsolute:h}}async function rit({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){const o=new Set(e.map(h=>h.id)),s=[];for(const h of n){if(h.deletable===!1)continue;const g=o.has(h.id),y=!g&&h.parentId&&s.find(b=>b.id===h.parentId);(g||y)&&s.push(h)}const a=new Set(t.map(h=>h.id)),l=r.filter(h=>h.deletable!==!1),u=eit(s,l);for(const h of l)a.has(h.id)&&!u.find(y=>y.id===h.id)&&u.push(h);if(!i)return{edges:u,nodes:s};const f=await i({nodes:s,edges:u});return typeof f=="boolean"?f?{edges:u,nodes:s}:{edges:[],nodes:[]}:f}const Pm=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Kh=(e={x:0,y:0},t,n)=>({x:Pm(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Pm(e.y,t[0][1],t[1][1]-(n?.height??0))});function mae(e,t,n){const{width:r,height:i}=ju(n),{x:o,y:s}=n.internals.positionAbsolute;return Kh(e,[[o,s],[o+r,s+i]],t)}const BG=(e,t,n)=>e<t?Pm(Math.abs(e-t),1,t)/t:e>n?-Pm(Math.abs(e-n),1,t)/t:0,gae=(e,t,n=15,r=40)=>{const i=BG(e.x,r,t.width-r)*n,o=BG(e.y,r,t.height-r)*n;return[i,o]},zC=(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)}),GD=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),HC=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),jm=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:nv(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}},wS=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:nv(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)}},yae=(e,t)=>HC(zC(GD(e),GD(t))),tb=(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)},zG=e=>Ga(e.width)&&Ga(e.height)&&Ga(e.x)&&Ga(e.y),Ga=e=>!isNaN(e)&&isFinite(e),iit=(e,t)=>{},iv=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),ov=({x:e,y:t},[n,r,i],o=!1,s=[1,1])=>{const a={x:(e-n)/i,y:(t-r)/i};return o?iv(a,s):a},CS=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function s0(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 oit(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=s0(e,n),i=s0(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=s0(e.top??e.y??0,n),i=s0(e.bottom??e.y??0,n),o=s0(e.left??e.x??0,t),s=s0(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 sit(e,t,n,r,i,o){const{x:s,y:a}=CS(e,[t,n,r]),{x:l,y:c}=CS({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-l,f=o-c;return{left:Math.floor(s),top:Math.floor(a),right:Math.floor(u),bottom:Math.floor(f)}}const uI=(e,t,n,r,i,o)=>{const s=oit(o,t,n),a=(t-s.x)/e.width,l=(n-s.y)/e.height,c=Math.min(a,l),u=Pm(c,r,i),f=e.x+e.width/2,h=e.y+e.height/2,g=t/2-f*u,y=n/2-h*u,b=sit(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}},nb=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function $m(e){return e!=null&&e!=="parent"}function ju(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function bae(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function vae(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 HG(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function ait(){let e,t;return{promise:new Promise((r,i)=>{e=r,t=i}),resolve:e,reject:t}}function lit(e){return{...uae,...e||{}}}function jy(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){const{x:o,y:s}=Ka(e),a=ov({x:o-(i?.left??0),y:s-(i?.top??0)},r),{x:l,y:c}=n?iv(a,t):a;return{xSnapped:l,ySnapped:c,...a}}const dI=e=>({width:e.offsetWidth,height:e.offsetHeight}),xae=e=>e?.getRootNode?.()||window?.document,cit=["INPUT","SELECT","TEXTAREA"];function Sae(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:cit.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const wae=e=>"clientX"in e,Ka=(e,t)=>{const n=wae(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)}},UG=(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 Cae({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),f=Math.abs(c-t);return[l,c,u,f]}function w5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function VG({pos:e,x1:t,y1:n,x2:r,y2:i,c:o}){switch(e){case xt.Left:return[t-w5(t-r,o),n];case xt.Right:return[t+w5(r-t,o),n];case xt.Top:return[t,n-w5(n-i,o)];case xt.Bottom:return[t,n+w5(i-n,o)]}}function Eae({sourceX:e,sourceY:t,sourcePosition:n=xt.Bottom,targetX:r,targetY:i,targetPosition:o=xt.Top,curvature:s=.25}){const[a,l]=VG({pos:n,x1:e,y1:t,x2:r,y2:i,c:s}),[c,u]=VG({pos:o,x1:r,y1:i,x2:e,y2:t,c:s}),[f,h,g,y]=Cae({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}`,f,h,g,y]}function Aae({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 uit({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 dit({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){const o=zC(wS(e),wS(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 tb(s,HC(o))>0}const fit=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,hit=(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)),pit=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||fit;let i;return hae(e)?i={...e}:i={...e,id:r(e)},hit(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function kae({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[i,o,s,a]=Aae({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,o,s,a]}const WG={[xt.Left]:{x:-1,y:0},[xt.Right]:{x:1,y:0},[xt.Top]:{x:0,y:-1},[xt.Bottom]:{x:0,y:1}},mit=({source:e,sourcePosition:t=xt.Bottom,target:n})=>t===xt.Left||t===xt.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},qG=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function git({source:e,sourcePosition:t=xt.Bottom,target:n,targetPosition:r=xt.Top,center:i,offset:o,stepPosition:s}){const a=WG[t],l=WG[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},f=mit({source:c,sourcePosition:t,target:u}),h=f.x!==0?"x":"y",g=f[h];let y=[],b,v;const S={x:0,y:0},C={x:0,y:0},[,,w,A]=Aae({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[h]*l[h]===-1){h==="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 O=[{x:b,y:c.y},{x:b,y:u.y}],D=[{x:c.x,y:v},{x:u.x,y:v}];a[h]===g?y=h==="x"?O:D:y=h==="x"?D:O}else{const O=[{x:c.x,y:u.y}],D=[{x:u.x,y:c.y}];if(h==="x"?y=a.x===g?D:O:y=a.y===g?O:D,t===r){const R=Math.abs(e[h]-n[h]);if(R<=o){const $=Math.min(o-1,o-R);a[h]===g?S[h]=(c[h]>e[h]?-1:1)*$:C[h]=(u[h]>n[h]?-1:1)*$}}if(t!==r){const R=h==="x"?"y":"x",$=a[h]===l[R],j=c[R]>u[R],z=c[R]<u[R];(a[h]===1&&(!$&&j||$&&z)||a[h]!==1&&(!$&&z||$&&j))&&(y=h==="x"?O:D)}const T={x:c.x+S.x,y:c.y+S.y},I={x:u.x+C.x,y:u.y+C.y},F=Math.max(Math.abs(T.x-y[0].x),Math.abs(I.x-y[0].x)),L=Math.max(Math.abs(T.y-y[0].y),Math.abs(I.y-y[0].y));F>=L?(b=(T.x+I.x)/2,v=y[0].y):(b=y[0].x,v=(T.y+I.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,A]}function yit(e,t,n,r){const i=Math.min(qG(e,t)/2,qG(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 KD({sourceX:e,sourceY:t,sourcePosition:n=xt.Bottom,targetX:r,targetY:i,targetPosition:o=xt.Top,borderRadius:s=5,centerX:a,centerY:l,offset:c=20,stepPosition:u=.5}){const[f,h,g,y,b]=git({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:o,center:{x:a,y:l},offset:c,stepPosition:u});return[f.reduce((S,C,w)=>{let A="";return w>0&&w<f.length-1?A=yit(f[w-1],C,f[w+1],s):A=`${w===0?"M":"L"}${C.x} ${C.y}`,S+=A,S},""),h,g,y,b]}function GG(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function bit(e){const{sourceNode:t,targetNode:n}=e;if(!GG(t)||!GG(n))return null;const r=t.internals.handleBounds||KG(t.handles),i=n.internals.handleBounds||KG(n.handles),o=YG(r?.source??[],e.sourceHandle),s=YG(e.connectionMode===Im.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!s)return e.onError?.("008",yc.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const a=o?.position||xt.Bottom,l=s?.position||xt.Top,c=Yh(t,o,a),u=Yh(n,s,l);return{sourceX:c.x,sourceY:c.y,targetX:u.x,targetY:u.y,sourcePosition:a,targetPosition:l}}function KG(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 Yh(e,t,n=xt.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??ju(e);if(r)return{x:i+s/2,y:o+a/2};switch(t?.position??n){case xt.Top:return{x:i+s/2,y:o};case xt.Right:return{x:i+s,y:o+a/2};case xt.Bottom:return{x:i+s/2,y:o+a};case xt.Left:return{x:i,y:o+a/2}}}function YG(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function YD(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function vit(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=YD(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 _ae=1e3,xit=10,fI={nodeOrigin:[0,0],nodeExtent:Q2,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Sit={...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 wit(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=nv(i,r.nodeOrigin),s=$m(i.extent)?i.extent:r.nodeExtent,a=Kh(o,s,ju(i));i.internals.positionAbsolute=a}}function Cit(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 XD(e,t,n,r={}){const i=hI(Sit,r),o={i:0},s=new Map(t),a=i?.elevateNodesOnSelect&&!pI(i.zIndexMode)?_ae: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 f=nv(c,i.nodeOrigin),h=$m(c.extent)?c.extent:i.nodeExtent,g=Kh(f,h,ju(c));u={...i.defaults,...c,measured:{width:c.measured?.width,height:c.measured?.height},internals:{positionAbsolute:g,handleBounds:Cit(c,u),z:Dae(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 Eit(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}Eit(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*xit),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);const f=o&&!pI(l)?_ae:0,{x:h,y:g,z:y}=Ait(e,u,s,a,f,l),{positionAbsolute:b}=e.internals,v=h!==b.x||g!==b.y;(v||y!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:v?{x:h,y:g}:b,z:y}})}function Dae(e,t,n){const r=Ga(e.zIndex)?e.zIndex:0;return pI(n)?r:r+(e.selected?t:0)}function Ait(e,t,n,r,i,o){const{x:s,y:a}=t.internals.positionAbsolute,l=ju(e),c=nv(e,n),u=$m(e.extent)?Kh(c,e.extent,l):c;let f=Kh({x:s+u.x,y:a+u.y},r,l);e.extent==="parent"&&(f=mae(f,l,t));const h=Dae(e,i,o),g=t.internals.z??0;return{x:f.x,y:f.y,z:g>=h?g+1:h}}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??jm(a),c=yae(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=ju(a),f=a.origin??r,h=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)*f[0],S=(b-u.height)*f[1];(h>0||g>0||v||S)&&(i.push({id:l,type:"position",position:{x:a.position.x-h+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+h,y:C.position.y+g}})})),(u.width<s.width||u.height<s.height||h||g)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:y+(h?f[0]*h-v:0),height:b+(g?f[1]*g-S:0)}})}),i}function kit(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:f}=new window.DOMMatrixReadOnly(u.transform),h=[];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=$m(y.extent)?y.extent:o;let{positionAbsolute:A}=y.internals;y.parentId&&y.extent==="parent"?A=mae(A,b,t.get(y.parentId)):w&&(A=Kh(A,w,b));const E={...y,measured:b,internals:{...y.internals,positionAbsolute:A,handleBounds:{source:UG("source",g.nodeElement,C,f,y.id),target:UG("target",g.nodeElement,C,f,y.id)}}};t.set(y.id,E),y.parentId&&mI(E,t,n,{nodeOrigin:i,zIndexMode:s}),l=!0,v&&(c.push({id:y.id,type:"dimensions",dimensions:b}),y.expandParent&&y.parentId&&h.push({id:y.id,parentId:y.parentId,rect:jm(E,i)}))}}if(h.length>0){const g=gI(h,t,n,i);c.push(...g)}return{changes:c,updatedInternals:l}}async function _it({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 XG(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 Oae(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}`;XG("source",l,u,e,i,s),XG("target",l,c,e,o,a),t.set(r.id,r)}}function Tae(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Tae(n,t):!1}function ZG(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 Dit(e,t,n,r){const i=new Map;for(const[o,s]of e)if((s.selected||s.id===r)&&(!s.parentId||!Tae(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 GA({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 Oit({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=iv(o,t);return{x:s.x-o.x,y:s.y-o.y}}function Tit({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,f=!1,h=null,g=!1,y=!1,b=null;function v({noDragClassName:C,handleSelector:w,domNode:A,isSelectable:E,nodeId:O,nodeClickDistance:D=0}){h=Rs(A);function T({x:R,y:$}){const{nodeLookup:j,nodeExtent:z,snapGrid:N,snapToGrid:W,nodeOrigin:H,onNodeDrag:U,onSelectionDrag:K,onError:B,updateNodePositions:q}=t();o={x:R,y:$};let X=!1;const V=a.size>1,Y=V&&z?GD(rv(a)):null,J=V&&W?Oit({dragItems:a,snapGrid:N,x:R,y:$}):null;for(const[ne,ee]of a){if(!j.has(ne))continue;let se={x:R-ee.distance.x,y:$-ee.distance.y};W&&(se=J?{x:Math.round(se.x+J.x),y:Math.round(se.y+J.y)}:iv(se,N));let ue=null;if(V&&z&&!ee.extent&&Y){const{positionAbsolute:re}=ee.internals,oe=re.x-Y.x+z[0][0],de=re.x+ee.measured.width-Y.x2+z[1][0],be=re.y-Y.y+z[0][1],je=re.y+ee.measured.height-Y.y2+z[1][1];ue=[[oe,be],[de,je]]}const{position:te,positionAbsolute:Z}=pae({nodeId:ne,nextPosition:se,nodeLookup:j,nodeExtent:ue||z,nodeOrigin:H,onError:B});X=X||ee.position.x!==te.x||ee.position.y!==te.y,ee.position=te,ee.internals.positionAbsolute=Z}if(y=y||X,!!X&&(q(a,!0),b&&(r||U||!O&&K))){const[ne,ee]=GA({nodeId:O,dragItems:a,nodeLookup:j});r?.(b,a,ne,ee),U?.(b,ne,ee),O||K?.(b,ee)}}async function I(){if(!u)return;const{transform:R,panBy:$,autoPanSpeed:j,autoPanOnNodeDrag:z}=t();if(!z){l=!1,cancelAnimationFrame(s);return}const[N,W]=gae(c,u,j);(N!==0||W!==0)&&(o.x=(o.x??0)-N/R[2],o.y=(o.y??0)-W/R[2],await $({x:N,y:W})&&T(o)),s=requestAnimationFrame(I)}function F(R){const{nodeLookup:$,multiSelectionActive:j,nodesDraggable:z,transform:N,snapGrid:W,snapToGrid:H,selectNodesOnDrag:U,onNodeDragStart:K,onSelectionDragStart:B,unselectNodesAndEdges:q}=t();f=!0,(!U||!E)&&!j&&O&&($.get(O)?.selected||q()),E&&U&&O&&e?.(O);const X=jy(R.sourceEvent,{transform:N,snapGrid:W,snapToGrid:H,containerBounds:u});if(o=X,a=Dit($,z,X,O),a.size>0&&(n||K||!O&&B)){const[V,Y]=GA({nodeId:O,dragItems:a,nodeLookup:$});n?.(R.sourceEvent,a,V,Y),K?.(R.sourceEvent,V,Y),O||B?.(R.sourceEvent,Y)}}const L=Gse().clickDistance(D).on("start",R=>{const{domNode:$,nodeDragThreshold:j,transform:z,snapGrid:N,snapToGrid:W}=t();u=$?.getBoundingClientRect()||null,g=!1,y=!1,b=R.sourceEvent,j===0&&F(R),o=jy(R.sourceEvent,{transform:z,snapGrid:N,snapToGrid:W,containerBounds:u}),c=Ka(R.sourceEvent,u)}).on("drag",R=>{const{autoPanOnNodeDrag:$,transform:j,snapGrid:z,snapToGrid:N,nodeDragThreshold:W,nodeLookup:H}=t(),U=jy(R.sourceEvent,{transform:j,snapGrid:z,snapToGrid:N,containerBounds:u});if(b=R.sourceEvent,(R.sourceEvent.type==="touchmove"&&R.sourceEvent.touches.length>1||O&&!H.has(O))&&(g=!0),!g){if(!l&&$&&f&&(l=!0,I()),!f){const K=Ka(R.sourceEvent,u),B=K.x-c.x,q=K.y-c.y;Math.sqrt(B*B+q*q)>W&&F(R)}(o.x!==U.xSnapped||o.y!==U.ySnapped)&&a&&f&&(c=Ka(R.sourceEvent,u),T(U))}}).on("end",R=>{if(!(!f||g)&&(l=!1,f=!1,cancelAnimationFrame(s),a.size>0)){const{nodeLookup:$,updateNodePositions:j,onNodeDragStop:z,onSelectionDragStop:N}=t();if(y&&(j(a,!1),y=!1),i||z||!O&&N){const[W,H]=GA({nodeId:O,dragItems:a,nodeLookup:$,dragging:!1});i?.(R.sourceEvent,a,W,H),z?.(R.sourceEvent,W,H),O||N?.(R.sourceEvent,H)}}}).filter(R=>{const $=R.target;return!R.button&&(!C||!ZG($,`.${C}`,A))&&(!w||ZG($,w,A))});h.call(L)}function S(){h?.on(".drag",null)}return{update:v,destroy:S}}function Mit(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())tb(i,jm(o))>0&&r.push(o);return r}const Rit=250;function Iit(e,t,n,r){let i=[],o=1/0;const s=Mit(e,n,t+Rit);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:f}=Yh(a,c,c.position,!0),h=Math.sqrt(Math.pow(u-e.x,2)+Math.pow(f-e.y,2));h>t||(h<o?(i=[{...c,x:u,y:f}],o=h):h===o&&i.push({...c,x:u,y:f}))}}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 Mae(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,...Yh(s,l,l.position,!0)}:l}function Rae(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Pit(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const Iae=()=>!0;function jit(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:s,domNode:a,nodeLookup:l,lib:c,autoPanOnConnect:u,flowId:f,panBy:h,cancelConnection:g,onConnectStart:y,onConnect:b,onConnectEnd:v,isValidConnection:S=Iae,onReconnectEnd:C,updateConnection:w,getTransform:A,getFromHandle:E,autoPanSpeed:O,dragThreshold:D=1,handleDomNode:T}){const I=xae(e.target);let F=0,L;const{x:R,y:$}=Ka(e),j=Rae(o,T),z=a?.getBoundingClientRect();let N=!1;if(!z||!j)return;const W=Mae(i,j,r,l,t);if(!W)return;let H=Ka(e,z),U=!1,K=null,B=!1,q=null;function X(){if(!u||!z)return;const[te,Z]=gae(H,z,O);h({x:te,y:Z}),F=requestAnimationFrame(X)}const V={...W,nodeId:i,type:j,position:W.position},Y=l.get(i);let ne={inProgress:!0,isValid:null,from:Yh(Y,V,xt.Left,!0),fromHandle:V,fromPosition:V.position,fromNode:Y,to:H,toHandle:null,toPosition:FG[V.position],toNode:null,pointer:H};function ee(){N=!0,w(ne),y?.(e,{nodeId:i,handleId:r,handleType:j})}D===0&&ee();function se(te){if(!N){const{x:je,y:De}=Ka(te),Ke=je-R,xe=De-$;if(!(Ke*Ke+xe*xe>D*D))return;ee()}if(!E()||!V){ue(te);return}const Z=A();H=Ka(te,z),L=Iit(ov(H,Z,!1,[1,1]),n,l,V),U||(X(),U=!0);const re=Pae(te,{handle:L,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:s?"target":"source",isValidConnection:S,doc:I,lib:c,flowId:f,nodeLookup:l});q=re.handleDomNode,K=re.connection,B=Pit(!!L,re.isValid);const oe=l.get(i),de=oe?Yh(oe,V,xt.Left,!0):ne.from,be={...ne,from:de,isValid:B,to:re.toHandle&&B?CS({x:re.toHandle.x,y:re.toHandle.y},Z):H,toHandle:re.toHandle,toPosition:B&&re.toHandle?re.toHandle.position:FG[V.position],toNode:re.toHandle?l.get(re.toHandle.nodeId):null,pointer:H};w(be),ne=be}function ue(te){if(!("touches"in te&&te.touches.length>0)){if(N){(L||q)&&K&&B&&b?.(K);const{inProgress:Z,...re}=ne,oe={...re,toPosition:ne.toHandle?ne.toPosition:null};v?.(te,oe),o&&C?.(te,oe)}g(),cancelAnimationFrame(F),U=!1,B=!1,K=null,q=null,I.removeEventListener("mousemove",se),I.removeEventListener("mouseup",ue),I.removeEventListener("touchmove",se),I.removeEventListener("touchend",ue)}}I.addEventListener("mousemove",se),I.addEventListener("mouseup",ue),I.addEventListener("touchmove",se),I.addEventListener("touchend",ue)}function Pae(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:o,doc:s,lib:a,flowId:l,isValidConnection:c=Iae,nodeLookup:u}){const f=o==="target",h=t?s.querySelector(`.${a}-flow__handle[data-id="${l}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y}=Ka(e),b=s.elementFromPoint(g,y),v=b?.classList.contains(`${a}-flow__handle`)?b:h,S={handleDomNode:v,isValid:!1,connection:null,toHandle:null};if(v){const C=Rae(void 0,v),w=v.getAttribute("data-nodeid"),A=v.getAttribute("data-handleid"),E=v.classList.contains("connectable"),O=v.classList.contains("connectableend");if(!w||!C)return S;const D={source:f?w:r,sourceHandle:f?A:i,target:f?r:w,targetHandle:f?i:A};S.connection=D;const I=E&&O&&(n===Im.Strict?f&&C==="source"||!f&&C==="target":w!==r||A!==i);S.isValid=I&&c(D),S.toHandle=Mae(w,C,A,u,n,!0)}return S}const ZD={onPointerDown:jit,isValid:Pae};function $it({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const i=Rs(e);function o({translateExtent:a,width:l,height:c,zoomStep:u=1,pannable:f=!0,zoomable:h=!0,inversePan:g=!1}){const y=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const A=n(),E=w.sourceEvent.ctrlKey&&nb()?10:1,O=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*u,D=A[2]*Math.pow(2,O*E);t.scaleTo(D)};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 A=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const E=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],O=[E[0]-b[0],E[1]-b[1]];b=E;const D=r()*Math.max(A[2],Math.log(A[2]))*(g?-1:1),T={x:A[0]-O[0]*D,y:A[1]-O[1]*D},I=[[0,0],[l,c]];t.setViewportConstrained({x:T.x,y:T.y,zoom:A[2]},I,a)},C=lae().on("start",v).on("zoom",f?S:null).on("zoom.wheel",h?y:null);i.call(C,{})}function s(){i.on("zoom",null)}return{update:o,destroy:s,pointer:Fa}}const UC=e=>({x:e.x,y:e.y,zoom:e.k}),KA=({x:e,y:t,zoom:n})=>BC.translate(e,t).scale(n),M0=(e,t)=>e.target.closest(`.${t}`),jae=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Lit=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,YA=(e,t=0,n=Lit,r=()=>{})=>{const i=typeof t=="number"&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on("end",r):e},$ae=e=>{const t=e.ctrlKey&&nb()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Nit({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:s,onPanZoomStart:a,onPanZoom:l,onPanZoomEnd:c}){return u=>{if(M0(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(u.ctrlKey&&s){const v=Fa(u),S=$ae(u),C=f*Math.pow(2,S);r.scaleTo(n,C,v,u);return}const h=u.deltaMode===1?20:1;let g=i===Oh.Vertical?0:u.deltaX*h,y=i===Oh.Horizontal?0:u.deltaY*h;!nb()&&u.shiftKey&&i!==Oh.Vertical&&(g=u.deltaY*h,y=0),r.translateBy(n,-(g/f)*o,-(y/f)*o,{internal:!0});const b=UC(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 Fit({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){const o=r.type==="wheel",s=!t&&o&&!r.ctrlKey,a=M0(r,e);if(r.ctrlKey&&o&&a&&r.preventDefault(),s||a)return null;r.preventDefault(),n.call(this,r,i)}}function Bit({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const i=UC(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 zit({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(n&&jae(t,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,UC(o.transform))}}function Hit({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return s=>{if(!s.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&jae(t,e.mouseButton??0)&&!e.usedRightMouseButton&&s.sourceEvent&&o(s.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const a=UC(s.transform);e.prevViewport=a,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(s.sourceEvent,a)},n?150:0)}}}function Uit({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:s,noWheelClassName:a,noPanClassName:l,lib:c,connectionInProgress:u}){return f=>{const h=e||t,g=n&&f.ctrlKey,y=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(M0(f,`${c}-flow__node`)||M0(f,`${c}-flow__edge`)))return!0;if(!r&&!h&&!i&&!o&&!n||s||u&&!y||M0(f,a)&&y||M0(f,l)&&(!y||i&&y&&!e)||!n&&f.ctrlKey&&y)return!1;if(!n&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!h&&!i&&!g&&y||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const b=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||y)&&b}}function Vit({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(),f=lae().scaleExtent([t,n]).translateExtent(r),h=Rs(e).call(f);C({x:i.x,y:i.y,zoom:Pm(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);const g=h.on("wheel.zoom"),y=h.on("dblclick.zoom");f.wheelDelta($ae);function b(L,R){return h?new Promise($=>{f?.interpolate(R?.interpolate==="linear"?Py:C4).transform(YA(h,R?.duration,R?.ease,()=>$(!0)),L)}):Promise.resolve(!1)}function v({noWheelClassName:L,noPanClassName:R,onPaneContextMenu:$,userSelectionActive:j,panOnScroll:z,panOnDrag:N,panOnScrollMode:W,panOnScrollSpeed:H,preventScrolling:U,zoomOnPinch:K,zoomOnScroll:B,zoomOnDoubleClick:q,zoomActivationKeyPressed:X,lib:V,onTransformChange:Y,connectionInProgress:J,paneClickDistance:ne,selectionOnDrag:ee}){j&&!c.isZoomingOrPanning&&S();const se=z&&!X&&!j;f.clickDistance(ee?1/0:!Ga(ne)||ne<0?0:ne);const ue=se?Nit({zoomPanValues:c,noWheelClassName:L,d3Selection:h,d3Zoom:f,panOnScrollMode:W,panOnScrollSpeed:H,zoomOnPinch:K,onPanZoomStart:s,onPanZoom:o,onPanZoomEnd:a}):Fit({noWheelClassName:L,preventScrolling:U,d3ZoomHandler:g});if(h.on("wheel.zoom",ue,{passive:!1}),!j){const Z=Bit({zoomPanValues:c,onDraggingChange:l,onPanZoomStart:s});f.on("start",Z);const re=zit({zoomPanValues:c,panOnDrag:N,onPaneContextMenu:!!$,onPanZoom:o,onTransformChange:Y});f.on("zoom",re);const oe=Hit({zoomPanValues:c,panOnDrag:N,panOnScroll:z,onPaneContextMenu:$,onPanZoomEnd:a,onDraggingChange:l});f.on("end",oe)}const te=Uit({zoomActivationKeyPressed:X,panOnDrag:N,zoomOnScroll:B,panOnScroll:z,zoomOnDoubleClick:q,zoomOnPinch:K,userSelectionActive:j,noPanClassName:R,noWheelClassName:L,lib:V,connectionInProgress:J});f.filter(te),q?h.on("dblclick.zoom",y):h.on("dblclick.zoom",null)}function S(){f.on("zoom",null)}async function C(L,R,$){const j=KA(L),z=f?.constrain()(j,R,$);return z&&await b(z),new Promise(N=>N(z))}async function w(L,R){const $=KA(L);return await b($,R),new Promise(j=>j($))}function A(L){if(h){const R=KA(L),$=h.property("__zoom");($.k!==L.zoom||$.x!==L.x||$.y!==L.y)&&f?.transform(h,R,null,{sync:!0})}}function E(){const L=h?aae(h.node()):{x:0,y:0,k:1};return{x:L.x,y:L.y,zoom:L.k}}function O(L,R){return h?new Promise($=>{f?.interpolate(R?.interpolate==="linear"?Py:C4).scaleTo(YA(h,R?.duration,R?.ease,()=>$(!0)),L)}):Promise.resolve(!1)}function D(L,R){return h?new Promise($=>{f?.interpolate(R?.interpolate==="linear"?Py:C4).scaleBy(YA(h,R?.duration,R?.ease,()=>$(!0)),L)}):Promise.resolve(!1)}function T(L){f?.scaleExtent(L)}function I(L){f?.translateExtent(L)}function F(L){const R=!Ga(L)||L<0?0:L;f?.clickDistance(R)}return{update:v,destroy:S,setViewport:w,setViewportConstrained:C,getViewport:E,scaleTo:O,scaleBy:D,setScaleExtent:T,setTranslateExtent:I,syncViewport:A,setClickDistance:F}}var Lm;(function(e){e.Line="line",e.Handle="handle"})(Lm||(Lm={}));function Wit({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 JG(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 cd(e,t){return Math.max(0,t-e)}function ud(e,t){return Math.max(0,e-t)}function C5(e,t,n){return Math.max(0,t-e,e-n)}function QG(e,t){return e?!t:t}function qit(e,t,n,r,i,o,s,a){let{affectsX:l,affectsY:c}=t;const{isHorizontal:u,isVertical:f}=t,h=u&&f,{xSnapped:g,ySnapped:y}=n,{minWidth:b,maxWidth:v,minHeight:S,maxHeight:C}=r,{x:w,y:A,width:E,height:O,aspectRatio:D}=e;let T=Math.floor(u?g-e.pointerX:0),I=Math.floor(f?y-e.pointerY:0);const F=E+(l?-T:T),L=O+(c?-I:I),R=-o[0]*E,$=-o[1]*O;let j=C5(F,b,v),z=C5(L,S,C);if(s){let H=0,U=0;l&&T<0?H=cd(w+T+R,s[0][0]):!l&&T>0&&(H=ud(w+F+R,s[1][0])),c&&I<0?U=cd(A+I+$,s[0][1]):!c&&I>0&&(U=ud(A+L+$,s[1][1])),j=Math.max(j,H),z=Math.max(z,U)}if(a){let H=0,U=0;l&&T>0?H=ud(w+T,a[0][0]):!l&&T<0&&(H=cd(w+F,a[1][0])),c&&I>0?U=ud(A+I,a[0][1]):!c&&I<0&&(U=cd(A+L,a[1][1])),j=Math.max(j,H),z=Math.max(z,U)}if(i){if(u){const H=C5(F/D,S,C)*D;if(j=Math.max(j,H),s){let U=0;!l&&!c||l&&!c&&h?U=ud(A+$+F/D,s[1][1])*D:U=cd(A+$+(l?T:-T)/D,s[0][1])*D,j=Math.max(j,U)}if(a){let U=0;!l&&!c||l&&!c&&h?U=cd(A+F/D,a[1][1])*D:U=ud(A+(l?T:-T)/D,a[0][1])*D,j=Math.max(j,U)}}if(f){const H=C5(L*D,b,v)/D;if(z=Math.max(z,H),s){let U=0;!l&&!c||c&&!l&&h?U=ud(w+L*D+R,s[1][0])/D:U=cd(w+(c?I:-I)*D+R,s[0][0])/D,z=Math.max(z,U)}if(a){let U=0;!l&&!c||c&&!l&&h?U=cd(w+L*D,a[1][0])/D:U=ud(w+(c?I:-I)*D,a[0][0])/D,z=Math.max(z,U)}}}I=I+(I<0?z:-z),T=T+(T<0?j:-j),i&&(h?F>L*D?I=(QG(l,c)?-T:T)/D:T=(QG(l,c)?-I:I)*D:u?(I=T/D,c=l):(T=I*D,l=c));const N=l?w+T:w,W=c?A+I:A;return{width:E+(l?-T:T),height:O+(c?-I:I),x:o[0]*T*(l?-1:1)+N,y:o[1]*I*(c?-1:1)+W}}const Lae={width:0,height:0,x:0,y:0},Git={...Lae,pointerX:0,pointerY:0,aspectRatio:1};function Kit(e){return[[0,0],[e.measured.width,e.measured.height]]}function Yit(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 Xit({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){const o=Rs(e);let s={controlDirection:JG("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:f,resizeDirection:h,onResizeStart:g,onResize:y,onResizeEnd:b,shouldResize:v}){let S={...Lae},C={...Git};s={boundaries:u,resizeDirection:h,keepAspectRatio:f,controlDirection:JG(c)};let w,A=null,E=[],O,D,T,I=!1;const F=Gse().on("start",L=>{const{nodeLookup:R,transform:$,snapGrid:j,snapToGrid:z,nodeOrigin:N,paneDomNode:W}=n();if(w=R.get(t),!w)return;A=W?.getBoundingClientRect()??null;const{xSnapped:H,ySnapped:U}=jy(L.sourceEvent,{transform:$,snapGrid:j,snapToGrid:z,containerBounds:A});S={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},C={...S,pointerX:H,pointerY:U,aspectRatio:S.width/S.height},O=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(O=R.get(w.parentId),D=O&&w.extent==="parent"?Kit(O):void 0),E=[],T=void 0;for(const[K,B]of R)if(B.parentId===t&&(E.push({id:K,position:{...B.position},extent:B.extent}),B.extent==="parent"||B.expandParent)){const q=Yit(B,w,B.origin??N);T?T=[[Math.min(q[0][0],T[0][0]),Math.min(q[0][1],T[0][1])],[Math.max(q[1][0],T[1][0]),Math.max(q[1][1],T[1][1])]]:T=q}g?.(L,{...S})}).on("drag",L=>{const{transform:R,snapGrid:$,snapToGrid:j,nodeOrigin:z}=n(),N=jy(L.sourceEvent,{transform:R,snapGrid:$,snapToGrid:j,containerBounds:A}),W=[];if(!w)return;const{x:H,y:U,width:K,height:B}=S,q={},X=w.origin??z,{width:V,height:Y,x:J,y:ne}=qit(C,s.controlDirection,N,s.boundaries,s.keepAspectRatio,X,D,T),ee=V!==K,se=Y!==B,ue=J!==H&&ee,te=ne!==U&&se;if(!ue&&!te&&!ee&&!se)return;if((ue||te||X[0]===1||X[1]===1)&&(q.x=ue?J:S.x,q.y=te?ne:S.y,S.x=q.x,S.y=q.y,E.length>0)){const de=J-H,be=ne-U;for(const je of E)je.position={x:je.position.x-de+X[0]*(V-K),y:je.position.y-be+X[1]*(Y-B)},W.push(je)}if((ee||se)&&(q.width=ee&&(!s.resizeDirection||s.resizeDirection==="horizontal")?V:S.width,q.height=se&&(!s.resizeDirection||s.resizeDirection==="vertical")?Y:S.height,S.width=q.width,S.height=q.height),O&&w.expandParent){const de=X[0]*(q.width??0);q.x&&q.x<de&&(S.x=de,C.x=C.x-(q.x-de));const be=X[1]*(q.height??0);q.y&&q.y<be&&(S.y=be,C.y=C.y-(q.y-be))}const Z=Wit({width:S.width,prevWidth:K,height:S.height,prevHeight:B,affectsX:s.controlDirection.affectsX,affectsY:s.controlDirection.affectsY}),re={...S,direction:Z};v?.(L,re)!==!1&&(I=!0,y?.(L,re),r(q,W))}).on("end",L=>{I&&(b?.(L,{...S}),i?.({...S}),I=!1)});o.call(F)}function l(){o.on(".drag",null)}return{update:a,destroy:l}}const Zit={},eK=e=>{let t;const n=new Set,r=(u,f)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const g=t;t=f??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(y=>y(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(Zit?"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},Jit=e=>e?eK(e):eK,{useDebugValue:Qit}=qt,{useSyncExternalStoreWithSelector:eot}=RSe,tot=e=>e;function Nae(e,t=tot,n){const r=eot(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Qit(r),r}const tK=(e,t)=>{const n=Jit(e),r=(i,o=t)=>Nae(n,i,o);return Object.assign(r,n),r},not=(e,t)=>e?tK(e,t):tK;function Wr(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 VC=_.createContext(null),rot=VC.Provider,Fae=yc.error001();function zn(e,t){const n=_.useContext(VC);if(n===null)throw new Error(Fae);return Nae(n,e,t)}function qr(){const e=_.useContext(VC);if(e===null)throw new Error(Fae);return _.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const nK={display:"none"},iot={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Bae="react-flow__node-desc",zae="react-flow__edge-desc",oot="react-flow__aria-live",sot=e=>e.ariaLiveMessage,aot=e=>e.ariaLabelConfig;function lot({rfId:e}){const t=zn(sot);return m.jsx("div",{id:`${oot}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:iot,children:t})}function cot({rfId:e,disableKeyboardA11y:t}){const n=zn(aot);return m.jsxs(m.Fragment,{children:[m.jsx("div",{id:`${Bae}-${e}`,style:nK,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),m.jsx("div",{id:`${zae}-${e}`,style:nK,children:n["edge.a11yDescription.default"]}),!t&&m.jsx(lot,{rfId:e})]})}const WC=_.forwardRef(({position:e="top-left",children:t,className:n,style:r,...i},o)=>{const s=`${e}`.split("-");return m.jsx("div",{className:Mi(["react-flow__panel",n,...s]),style:r,ref:o,...i,children:t})});WC.displayName="Panel";function uot({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:m.jsx(WC,{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:m.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const dot=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}},E5=e=>e.id;function fot(e,t){return Wr(e.selectedNodes.map(E5),t.selectedNodes.map(E5))&&Wr(e.selectedEdges.map(E5),t.selectedEdges.map(E5))}function hot({onSelectionChange:e}){const t=qr(),{selectedNodes:n,selectedEdges:r}=zn(dot,fot);return _.useEffect(()=>{const i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[n,r,e]),null}const pot=e=>!!e.onSelectionChangeHandlers;function mot({onSelectionChange:e}){const t=zn(pot);return e||t?m.jsx(hot,{onSelectionChange:e}):null}const Hae=[0,0],got={x:0,y:0,zoom:1},yot=["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"],rK=[...yot,"rfId"],bot=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}),iK={translateExtent:Q2,nodeOrigin:Hae,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function vot(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:s,reset:a,setDefaultNodesAndEdges:l}=zn(bot,Wr),c=qr();_.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{u.current=iK,a()}),[]);const u=_.useRef(iK);return _.useEffect(()=>{for(const f of rK){const h=e[f],g=u.current[f];h!==g&&(typeof e[f]>"u"||(f==="nodes"?t(h):f==="edges"?n(h):f==="minZoom"?r(h):f==="maxZoom"?i(h):f==="translateExtent"?o(h):f==="nodeExtent"?s(h):f==="ariaLabelConfig"?c.setState({ariaLabelConfig:lit(h)}):f==="fitView"?c.setState({fitViewQueued:h}):f==="fitViewOptions"?c.setState({fitViewOptions:h}):c.setState({[f]:h})))}u.current=e},rK.map(f=>e[f])),null}function oK(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function xot(e){const[t,n]=_.useState(e==="system"?null:e);return _.useEffect(()=>{if(e!=="system"){n(e);return}const r=oK(),i=()=>n(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),t!==null?t:oK()?.matches?"dark":"light"}const sK=typeof document<"u"?document:null;function rb(e=null,t={target:sK,actInsideInputWithModifier:!0}){const[n,r]=_.useState(!1),i=_.useRef(!1),o=_.useRef(new Set([])),[s,a]=_.useMemo(()=>{if(e!==null){const c=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.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=g5(t),r=r0(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=g5(t),r=r0(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 Dse(e){const t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new kse||null,prettyErrors:t}}function gQe(e,t={}){const{lineCounter:n,prettyErrors:r}=Dse(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(fS(e,n)),a.warnings.forEach(fS(e,n));return s.length>0?s:Object.assign([],{empty:!0},o.streamInfo())}function Ose(e,t={}){const{lineCounter:n,prettyErrors:r}=Dse(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 Sh(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return r&&n&&(s.errors.forEach(fS(e,n)),s.warnings.forEach(fS(e,n))),s}function yQe(e,t,n){let r;typeof t=="function"?r=t:n===void 0&&t&&typeof t=="object"&&(n=t);const i=Ose(e,n);if(!i)return null;if(i.warnings.forEach(o=>Yoe(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 bQe(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 cp(e)&&!r?e.toString(n):new hg(e,r,n).toString(n)}const vQe=Object.freeze(Object.defineProperty({__proto__:null,Alias:CC,CST:hQe,Composer:QR,Document:hg,Lexer:Ase,LineCounter:kse,Pair:Ao,Parser:eI,Scalar:Gt,Schema:RC,YAMLError:ZR,YAMLMap:Ms,YAMLParseError:Sh,YAMLSeq:df,YAMLWarning:pse,isAlias:Cf,isCollection:Zr,isDocument:cp,isMap:cg,isNode:Jr,isPair:Vr,isScalar:Cr,isSeq:ug,parse:yQe,parseAllDocuments:gQe,parseDocument:Ose,stringify:bQe,visit:up,visitAsync:wC},Symbol.toStringTag,{value:"Module"}));function xQe(e){let t=null;try{t=vQe.parse(e.doc.toString())}catch{}const n=pR(e,zr.YAML);return{data:t,pointers:n}}const Tse=e=>{switch(e){case zr.JSON:return ZZe;case zr.JSON5:return uJe;case zr.YAML:return xQe}};function SQe(e){return Object.entries(e)}function ty(e,t){if(typeof e=="string"||typeof e!="object"||e===null)return e;if(Array.isArray(e))return e.map(i=>ty(i,t));if(e instanceof Map){const i=new Map;for(const[o,s]of e){const a=o,l=ty(s,t);i.set(a,l)}return i}if(e instanceof Set){const i=new Set;for(const o of e){const s=ty(o,t);i.add(s)}return i}const n={};function r(i,o,s,a){s===i&&a===o?n[s]=ty(o,t):n[s]=a}for(const[i,o]of SQe(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 wQe=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 CQe{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 Iy(e){return!(!e||ko(e)||e.name==="UnknownPropertyError"||e.type==="undefined")}class EQe{constructor(t){var n,r,i;this.opts=t,this.originalSchema=null,this.schema=null,this.laxSchema=null,this.mode=zr.JSON,this.mode=(n=t.mode)!==null&&n!==void 0?n:zr.JSON,this.parser=(i=(r=this.opts)===null||r===void 0?void 0:r.jsonParser)!==null&&i!==void 0?i:Tse(this.mode)}doComplete(t){var n;const r=mR(t.state);if(this.originalSchema!==r&&(this.schema=(n=ih(r,r))!==null&&n!==void 0?n:r,this.laxSchema=kQe(this.schema)),!this.schema||!this.laxSchema)return[];Kr.log("xxx","trying with original schema");const i=this.doCompleteForSchema(t,this.schema);return i.options.length!==0?i:(Kr.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=cA(t.state,t.pos),l=t.state.sliceDoc(a.from,t.pos).replace(/^(["'])/,"");if(Kr.log("xxx","node",a,"prefix",l,"ctx",t),!(d4(a,this.mode)||e5(a,this.mode))&&!t.explicit)return Kr.log("xxx","no completions for non-word/primitive",a),o;const c=m0(t.state.doc,a),u=m0(t.state.doc,a,!1);if(a&&(d4(a,this.mode)||e5(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;Kr.log("xxx","overwriteStart after",b,"ctx.pos",t.pos,"word",y,"currentWord",c,"=>",s[b-1],"..",s[b],"..",s),o.from=a.name===Xt.INVALID?(r=y?.from)!==null&&r!==void 0?r:t.pos:b,o.to=t.pos}const f=new CQe;let h=!0;const g=HW(a,Xt.PROPERTY_NAME,this.mode);if(g&&(Kr.log("xxx","closestPropertyNameNode",g,"node",a),a=g),e5(a,this.mode)){Kr.log("xxx","isPropertyNameNode",a);const y=a.parent;if(y){const b=zW(y,this.mode);h=!b||b.name===Xt.INVALID&&b.from-b.to===0||(b.parent?Ub(b.parent).length<=1:!1),Kr.log("xxx","addValue",h,zW(y,this.mode),a),a=(i=HW(y,Xt.OBJECT,this.mode))!==null&&i!==void 0?i:null}}if(Kr.log("xxx",a,c,t,"node at pos",cA(t.state,t.pos)),a&&[Xt.OBJECT,Xt.JSON_TEXT].includes(pi(a.name,this.mode))&&(e5(cA(t.state,t.pos),this.mode)||g)){if(a.from===t.pos)return Kr.log("xxx","no completions for just before opening brace"),o;this.getPropertyCompletions(n,t,a,f,h,u)}else{const y={},b=this.getValueCompletions(n,t,y,f);Kr.log("xxx","getValueCompletions res",b)}return o.options=Array.from(f.completions.values()).filter(y=>u4(y.label).startsWith(l)),Kr.log("xxx","result",o,"prefix",l,"collector.completions",f.completions,"reservedKeys",f.reservedKeys),o}applySnippetCompletion(t){return GHe(typeof t.apply!="string"?t.label:t.apply,t)}getPropertyCompletions(t,n,r,i,o,s){const a=jUe(r,Xt.PROPERTY,this.mode);Kr.log("xxx","getPropertyCompletions",r,n,a),a.forEach(c=>{const u=m0(n.state.doc,dD(c,Xt.PROPERTY_NAME,this.mode));i.reserve(u4(u))});const l=this.getSchemas(t,n);Kr.log("xxx","propertyCompletion schemas",l),l.forEach(c=>{if(typeof c!="object")return;const u=c.properties;u&&Object.entries(u).forEach(([h,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:h,apply:this.getInsertTextForProperty(h,o,s,t,g),type:"property",detail:C,info:()=>Ml("div",{inner:Z0(v)})};i.add(this.applySnippetCompletion(w))}});const f=c.propertyNames;if(typeof f=="object"&&(f.enum&&f.enum.forEach(h=>{const g=h?.toString();if(g){const y={label:g,apply:this.getInsertTextForProperty(g,o,s,t),type:"property"};i.add(this.applySnippetCompletion(y))}}),f.const)){const h=f.const.toString(),g={label:h,apply:this.getInsertTextForProperty(h,o,s,t),type:"property"};i.add(this.applySnippetCompletion(g))}})}getInsertTextForProperty(t,n,r,i,o){o=o&&ih(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 zr.JSON5:a="{#{}}";break;case zr.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)&&(Kr.log("xxx","value",a,"nValueProposals",l,o),a="#{}"),s+a}getInsertTextForPropertyName(t,n){switch(this.mode){case zr.JSON5:case zr.YAML:return n.startsWith('"')?`"${t}"`:n.startsWith("'")?`'${t}'`:t;default:return`"${t}"`}}getInsertTextForString(t,n="#"){switch(this.mode){case zr.JSON5:return`'${n}{${t}}'`;case zr.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=Ti(n.state).resolveInner(n.pos,-1),s=null,a;if(Kr.log("xxx","getValueCompletions",o,n),o&&d4(o,this.mode)&&(s=o,o=o.parent),!o){this.addSchemaValueCompletions(t,r,i);return}if(pi(o.name,this.mode)===Xt.PROPERTY){const c=dD(o,Xt.PROPERTY_NAME,this.mode);c&&(a=m0(n.state.doc,c),o=o.parent)}if(Kr.log("xxx","node",o,"parentKey",a),o&&(a!==void 0||pi(o.name,this.mode)===Xt.ARRAY)){const c=this.getSchemas(t,n);for(const u of c){if(typeof u!="object")return;if(pi(o.name,this.mode)===Xt.ARRAY&&u.items){let f=i;if(u.uniqueItems&&(f=Object.assign(Object.assign({},f),{add(h){f.completions.has(h.label)||i.add(h)},reserve(h){i.reserve(h)}})),Array.isArray(u.items)){let h=0;if(s){const y=Fre(o,s,this.mode);y>=0&&(h=y)}const g=u.items[h];g&&this.addSchemaValueCompletions(g,r,f)}else this.addSchemaValueCompletions(u.items,r,f)}if((u.type==null||u.type!=="object")&&this.addSchemaValueCompletions(u,r,i),a!==void 0){let f=!1;if(u.properties){const h=u.properties[a];h&&(f=!0,this.addSchemaValueCompletions(h,r,i))}if(u.patternProperties&&!f)for(const h of Object.keys(u.patternProperties)){const g=this.extendedRegExp(h);if(g?.test(a)){f=!0;const y=u.patternProperties[h];y&&this.addSchemaValueCompletions(y,r,i)}}if(u.additionalProperties&&!f){const h=u.additionalProperties;this.addSchemaValueCompletions(h,r,i)}}r.boolean&&(this.addBooleanValueCompletion(!0,i),this.addBooleanValueCompletion(!1,i)),r.null&&this.addNullValueCompletion(i)}}return{valuePrefix:s?m0(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 Aie(t);let l=Lre(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=mG(t,s,l);if(y!=null)return[y]}let c=l?.replace(/\/[^/]*$/,"");c===""&&(c=void 0);const u=mG(t,s,c),f=l?.split("/").pop(),h=f==null||f in((r=u?.properties)!==null&&r!==void 0?r:{});let g=a.getSchema({pointer:l,data:s??void 0});return!h&&g?.type==="null"&&this.mode==="yaml"&&(g=void 0),Kr.log("xxxx","draft.getSchema",g,"data",s,"pointer",l,"pointerPointsToKnownProperty",h),ko(g)&&(g=(i=g.data)===null||i===void 0?void 0:i.schema),!Iy(g)&&u?[u]:(Iy(g)||(g=a.getSchema({pointer:c}),l=c),Kr.log("xxx","pointer..",JSON.stringify(l)),!Iy(g)&&(!l||l==="/")&&(g=(o=ih(t,t))!==null&&o!==void 0?o:t),Kr.log("xxx","subSchema..",g),g?Array.isArray(g.allOf)?[g,...g.allOf.map(y=>ih(y,t))]:Array.isArray(g.oneOf)?[g,...g.oneOf.map(y=>ih(y,t))]:Array.isArray(g.anyOf)?[g,...g.anyOf.map(y=>ih(y,t))]:[g]:[])}getAppliedValue(t){const n=u4(JSON.stringify(t));switch(this.mode){case zr.JSON5:return{label:n,apply:IUe(JSON.stringify(t))};case zr.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 AQe(e={}){const t=new EQe(e);return function(r){return t.doComplete(r)}}function kQe(e){return ty(e,(t,n)=>t==="additionalProperties"&&n===!1?[]:t==="required"&&Array.isArray(n)?[]:t==="unevaluatedProperties"&&n===!1?[]:t==="unevaluatedItems"&&n===!1?[]:[t,n])}function mG(e,t,n){const r=new Aie(e),i=r.getSchema({pointer:n,data:t??void 0});if(!Iy(i))return;const o=Mse(r,i),s={};for(let h of o){let g=DQe(n,h);const y=r.getSchema({pointer:g,data:t??void 0});Iy(y)&&Object.assign(s,{[h]:y})}if(o.length===0||Object.keys(s).length===0)return;const a=i,{allOf:l,anyOf:c,oneOf:u}=a,f=wQe(a,["allOf","anyOf","oneOf"]);return Object.assign(Object.assign({},f),{properties:s})}function Mse(e,t){if(t=ih(t,e.rootSchema),typeof t!="object"||t==null)return[];const n=[];function r(i){const o=Mse(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 ih(e,t){if(typeof e=="object"&&e.$ref){const n=_Qe(t,e.$ref);if(typeof n=="object"){const r=Object.assign(Object.assign({},e),n);return Reflect.deleteProperty(r,"$ref"),r}}return e}function _Qe(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 DQe(e,t){return e===void 0?`/${t}`:`${e}/${t}`}const K2=(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(" ")},OQe=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}`:""},TQe=e=>e.startState.field(H6)!==e.state.field(H6);function MQe(e){const t=new IQe(e);return n=>t.doValidation(n)}const RQe=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class IQe{constructor(t){var n,r,i,o;this.options=t,this.schema=null,this.mode=zr.JSON,this.rewriteError=s=>{var a,l,c,u,f;const h=s?.data,g=h?.errors;return s.code==="one-of-error"&&g?.length?`Expected one of ${K2(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)?K2((c=s?.data)===null||c===void 0?void 0:c.expected):(u=s?.data)===null||u===void 0?void 0:u.expected}\` but received \`${(f=s?.data)===null||f===void 0?void 0:f.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:zr.JSON,this.parser=(o=(i=this.options)===null||i===void 0?void 0:i.jsonParser)!==null&&o!==void 0?o:Tse(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 Cie(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 Kr.log("xxx","validation errors",o,i.data),o.length?o.reduce((s,a)=>{const l=()=>{const f=this.rewriteError(a);s.push({from:0,to:0,message:f,severity:"error",source:this.schemaTitle,renderMessage:()=>{const h=Ml("div",{});return h.innerHTML=Z0(f),h}})},c=OQe(a),u=i.pointers.get(c);if(a.name==="MaxPropertiesError"||a.name==="MinPropertiesError"||c==="")l();else if(u){const f=RQe.includes(a.name),h=this.rewriteError(a),g=f?u.keyFrom:u.valueFrom,y=f?u.keyTo:u.valueTo;y!==void 0&&g!==void 0&&s.push({from:g,to:y,message:h,renderMessage:()=>{const b=Ml("div",{});return b.innerHTML=Z0(h),b},severity:"error",source:this.schemaTitle})}else l();return s},[]):[]}}function PQe(e){const t=new jQe(e);return async function(r,i,o){return t.doHover(r,i,o)}}function gG(e){if(e.type)return e.$ref?`${e.$ref} (${e.type})`:e.type;if(e.$ref)return`${e.$ref}`}function zA(e,t,n){return`${t}: ${K2(e[t].map(r=>{try{const{data:i}=n.resolveRef({data:r,pointer:r.$ref});return gG(i||r)}catch{return r.type}}))}`}class jQe{constructor(t){var n,r;this.opts=t,this.schema=null,this.mode=zr.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:zr.JSON}getDataForCursor(t,n,r){const i=mR(t.state);if(!i)return null;this.schema=new Cie(i);const o=Lre(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 ko(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?Ml("div",{class:"cm6-json-schema-hover"},[Ml("div",{class:"cm6-json-schema-hover--description",inner:Z0(n,!1)}),Ml("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ml("div",{class:"cm6-json-schema-hover--code",inner:Z0(r,!1)})])]):Ml("div",{class:"cm6-json-schema-hover"},[Ml("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ml("code",{class:"cm6-json-schema-hover--code",inner:Z0(r,!1)})])])}getHoverTexts(t,n){let r="",i=null;const{schema:o}=t;return o.oneOf&&(r=zA(o,"oneOf",n)),o.anyOf&&(r=zA(o,"anyOf",n)),o.allOf&&(r=zA(o,"allOf",n)),o.type&&(r=Array.isArray(o.type)?K2(o.type):o.type),o.$ref&&(r=` Reference: ${o.$ref}`),o.enum&&(r=`\`enum\`: ${K2(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(Kr.log("cursorData",u),!u?.schema)return null;const h=((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)(h);return{pos:l,end:c,arrow:!0,above:!0,create:b=>({dom:y})}}catch(u){return Kr.log(u),null}}}const $Qe=e=>m.jsx(vc,{disablePadding:!0,children:e.validationErrors.map((t,n)=>m.jsx(gf,{disableGutters:!0,disablePadding:!0,children:m.jsxs(zt,{direction:"row",spacing:1,children:[m.jsx(ie,{variant:"body2",children:"•"}),m.jsx(ie,{variant:"caption",children:t.instancePath.length===0?"/":t.instancePath}),m.jsx(ie,{variant:"body2",children:t.message})]})},n.toString()))}),yG=e=>{let t;try{t=JSON.parse(e)}catch{t=void 0}return t};function LQe({schema:e,customValidate:t}){const n=_.useMemo(()=>new Oee({allErrors:!0}),[]);return _.useCallback(r=>{const i=[];return n.validate(e,r),i.push(...n.errors??[]),i.push(...t?.(r)??[]),i},[n,e,t])}const NQe=e=>{const t=FQe(),[n,r]=_.useState(()=>JSON.stringify(e.value,null,2)),i=LQe(e),[o,s]=_.useState([]);_.useEffect(()=>{s(i(e.value))},[i,e.value]);const a=e.onChange,l=_.useCallback(u=>{const f=yG(u),h=i(f);a(f,h.length===0),r(u),s(h)},[i,a]),c=()=>{const u=yG(n);u&&r(JSON.stringify(u,null,2))};return m.jsxs(zt,{spacing:2,children:[m.jsxs(le,{position:"relative",children:[m.jsx(Ire,{value:n,onChange:u=>l(u),extensions:[eBe(),cW(JFe(),{delay:100}),cW(MQe(),{delay:100,needsRefresh:TQe}),_ne.data.of({autocomplete:AQe({mode:"json4"})}),ane(PQe()),NUe(e.schema)],theme:t,height:"400px"}),m.jsx(kt,{sx:{position:"absolute",right:"0",bottom:"0"},onClick:()=>c(),children:"Prettify"})]}),o.length>0&&m.jsx(kn,{severity:"error",variant:"outlined",children:m.jsx($Qe,{validationErrors:o})})]})};function FQe(){return Oa().palette.mode==="dark"?CBe:vBe}const BQe=[{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"}],zQe=({bridgeId:e,selectedIcon:t,onIconChange:n})=>{const r=_.useRef(null),[i,o]=_.useState(!1),[s,a]=_.useState(null),[l,c]=_.useState(!1),[u,f]=_.useState(null);_.useEffect(()=>{e&&Tw(e).then(b=>{o(b),b&&a(`${i2(e)}?t=${Date.now()}`)}).catch(()=>{o(!1)})},[e]);const h=_.useCallback(async b=>{const v=b.target.files?.[0];if(!(!v||!e)){f(null),c(!0);try{await D8e(e,v),o(!0),a(`${i2(e)}?t=${Date.now()}`),n(void 0)}catch(S){f(S instanceof Error?S.message:"Upload failed")}finally{c(!1),r.current&&(r.current.value="")}}},[e,n]),g=_.useCallback(async()=>{if(e){f(null);try{await O8e(e),o(!1),a(null)}catch(b){f(b instanceof Error?b.message:"Delete failed")}}},[e]),y=_.useCallback(b=>{n(b===""?void 0:b)},[n]);return m.jsxs(zt,{spacing:2,children:[m.jsxs(ha,{fullWidth:!0,size:"small",children:[m.jsx(sc,{id:"icon-select-label",children:"Bridge Icon"}),m.jsx(oa,{labelId:"icon-select-label",value:t??"",label:"Bridge Icon",onChange:b=>y(b.target.value),disabled:i,children:BQe.map(b=>m.jsx(er,{value:b.value,children:b.label},b.value))}),m.jsx(Sw,{children:i?"Custom icon is set. Delete it to use preset icons.":"Select a preset icon or upload a custom image"})]}),e&&m.jsxs(le,{children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",gutterBottom:!0,children:"Custom Icon"}),m.jsxs(zt,{direction:"row",spacing:2,alignItems:"center",children:[i&&s&&m.jsx(le,{component:"img",src:s,alt:"Custom bridge icon",sx:{width:48,height:48,objectFit:"contain",borderRadius:1,border:"1px solid",borderColor:"divider"}}),m.jsx("input",{ref:r,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp,image/svg+xml",style:{display:"none"},onChange:h}),m.jsx(kt,{variant:"outlined",size:"small",startIcon:m.jsx(GCe,{}),onClick:()=>r.current?.click(),disabled:l,children:l?"Uploading...":"Upload Image"}),i&&m.jsx(kt,{variant:"outlined",size:"small",color:"error",startIcon:m.jsx(Zd,{}),onClick:g,children:"Delete"})]}),u&&m.jsx(ie,{variant:"caption",color:"error",sx:{mt:1},children:u}),m.jsx(ie,{variant:"caption",color:"text.secondary",sx:{mt:1,display:"block"},children:"Supported formats: PNG, JPG, GIF, WebP, SVG (max 5MB)"})]}),!e&&m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Save the bridge first to upload a custom icon."})]})},i0={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"},bG=e=>{try{return JSON.parse(e)}catch{return}};function HQe({filter:e}){const[t,n]=_.useState(!1),[r,i]=_.useState(null),[o,s]=_.useState(null),[a,l]=_.useState(!1),c=_.useRef(null),u=_.useRef(""),f=_.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=bG(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??bG(b);i(S),l(!0)}catch(y){s(y instanceof Error?y.message:"Unknown error")}finally{n(!1)}},[e]);_.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(()=>{f()},800),()=>{c.current&&clearTimeout(c.current)}},[e,f]);const h=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(h).filter(v=>!i0[v]);b.length>0&&g.push(`Unsupported domains will be skipped: ${b.join(", ")}`)}return m.jsxs(le,{sx:{mt:2},children:[m.jsx(kt,{variant:"outlined",startIcon:t?m.jsx(Hr,{size:16}):m.jsx(u8e,{}),onClick:f,disabled:t,size:"small",children:t?"Loading...":"Preview Matching Entities"}),o&&m.jsx(kn,{severity:"error",sx:{mt:1},children:o}),m.jsx(da,{in:a&&r!==null,children:r&&m.jsxs(le,{sx:{mt:2},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsxs(ie,{variant:"subtitle1",fontWeight:"bold",children:[r.total," entities match"]}),r.truncated&&m.jsx(Et,{label:"Showing first 100",size:"small",color:"warning",variant:"outlined"})]}),g.length>0&&m.jsx(zt,{spacing:.5,sx:{mb:1.5},children:g.map(y=>m.jsx(kn,{severity:"warning",variant:"outlined",icon:y.includes("vacuum")?m.jsx(sm,{fontSize:"small"}):m.jsx(Yd,{fontSize:"small"}),sx:{py:0},children:m.jsx(ie,{variant:"caption",children:y})},y))}),m.jsx(le,{display:"flex",gap:.5,flexWrap:"wrap",mb:2,children:Object.entries(h).sort((y,b)=>b[1]-y[1]).map(([y,b])=>m.jsx(Et,{label:`${y}: ${b}${i0[y]?` → ${i0[y]}`:""}`,size:"small",variant:"outlined",color:i0[y]?"default":"warning"},y))}),m.jsx(vc,{dense:!0,sx:{maxHeight:200,overflow:"auto",bgcolor:"background.paper",borderRadius:1,border:1,borderColor:"divider"},children:r.entities.map(y=>m.jsx(gf,{divider:!0,children:m.jsx(Va,{primary:y.friendly_name||y.entity_id,secondary:`${y.entity_id}${i0[y.domain]?` → ${i0[y.domain]}`:""}`,primaryTypographyProps:{variant:"body2"},secondaryTypographyProps:{variant:"caption",fontFamily:"monospace"}})},y.entity_id))}),m.jsx(kt,{size:"small",onClick:()=>l(!1),sx:{mt:1},children:"Hide Preview"})]})})]})}const UQe=Mee(),VQe=UQe.ObjectFieldTemplate;function WQe(e){return(e.fieldPathId?.$id??"")==="root_filter"?m.jsx(qQe,{...e}):m.jsx(VQe,{...e})}function qQe(e){const t=e.formData?.include?.length??0,n=e.formData?.exclude?.length??0,r=t+n,[i,o]=_.useState(r>0);return m.jsxs(hd,{expanded:i,onChange:(s,a)=>o(a),variant:"outlined",disableGutters:!0,sx:{borderRadius:2,"&::before":{display:"none"},overflow:"hidden"},children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),sx:{px:2,"& .MuiAccordionSummary-content":{alignItems:"center",gap:1.5}},children:[m.jsx(hw,{fontSize:"small",color:"action"}),m.jsx(ie,{variant:"subtitle1",fontWeight:600,children:"Entity Filters"}),m.jsx(jZ,{badgeContent:r,color:"primary",sx:{ml:1},max:99,children:m.jsx(le,{})}),m.jsx(ie,{variant:"caption",color:"text.secondary",sx:{ml:1},children:i?"Click to collapse":`${r} rule${r!==1?"s":""} configured`})]}),m.jsx(pd,{sx:{px:2,pb:2},children:e.properties.map(s=>m.jsx("div",{children:s.content},s.name))})]})}function GQe(e){const t=_.useRef(e),n=t.current;return t.current=e,n}function vG(e){const{items:t,canAdd:n,onAddClick:r,title:i,formData:o}=e,s=o??[],[a,l]=_.useState(()=>new Set),[c,u]=_.useState(""),f=GQe(s.length);_.useEffect(()=>{if(s.length>f){const b=s.length-1,v=s[b];!v?.type&&!v?.value&&l(S=>new Set([...S,b]))}},[s,f]);const h=_.useCallback(b=>{l(v=>{const S=new Set(v);return S.has(b)?S.delete(b):S.add(b),S})},[]),g=_.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??"",A=C?.value??"";(w.toLowerCase().includes(b)||A.toLowerCase().includes(b))&&v.push(S)}return new Set(v)},[c,s]),y=_.useMemo(()=>{const b=Array.from({length:t.length},(v,S)=>S);return g?b.filter(v=>g.has(v)):b},[t.length,g]);return m.jsxs(le,{children:[m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1,children:[m.jsx(ie,{variant:"subtitle2",fontWeight:600,children:i}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(Et,{label:t.length,size:"small",color:"default",sx:{height:22,fontSize:"0.75rem"}}),n&&m.jsx(kt,{size:"small",startIcon:m.jsx(hc,{}),onClick:r,children:"Add"})]})]}),t.length>3&&m.jsx(Lr,{size:"small",fullWidth:!0,placeholder:"Search rules...",value:c,onChange:b=>u(b.target.value),slotProps:{input:{startAdornment:m.jsx(AM,{position:"start",children:m.jsx(xJ,{fontSize:"small",color:"action"})})}},sx:{mb:1}}),g&&y.length===0&&m.jsx(ie,{variant:"body2",color:"text.secondary",textAlign:"center",py:2,children:"No matching rules"}),m.jsx(zt,{spacing:.5,children:y.map(b=>{const v=s[b],S=v?.type??"",C=v?.value??"",w=a.has(b),A=S||C;return m.jsxs(le,{sx:{border:1,borderColor:"divider",borderRadius:1,overflow:"hidden"},children:[m.jsxs(le,{display:"flex",alignItems:"center",sx:{px:1.5,py:.75,cursor:"pointer","&:hover":{bgcolor:"action.hover"},bgcolor:w?"action.selected":"transparent"},onClick:()=>h(b),children:[w?m.jsx($Ce,{fontSize:"small",color:"action"}):m.jsx(NCe,{fontSize:"small",color:"action"}),A?m.jsxs(le,{display:"flex",alignItems:"center",gap:1,ml:.5,flex:1,minWidth:0,children:[m.jsx(Et,{label:S,size:"small",variant:"outlined",sx:{height:22,fontSize:"0.75rem",flexShrink:0}}),m.jsx(ie,{variant:"body2",noWrap:!0,sx:{flex:1,minWidth:0},children:C})]}):m.jsx(ie,{variant:"body2",color:"text.secondary",ml:.5,fontStyle:"italic",children:"New rule (click to configure)"})]}),m.jsx(da,{in:w,children:m.jsx(le,{sx:{px:2,pb:1.5,pt:.5},children:t[b]})})]},b)})})]})}function KQe(e){const{schema:t,formData:n={},onChange:r,disabled:i,readonly:o,fieldPathId:s}=e,a=t.properties??{},l=_.useCallback((c,u)=>{r({...n,[c]:u},s.path)},[n,r,s]);return m.jsxs(le,{children:[m.jsx(ie,{variant:"h6",sx:{mb:2},children:"Feature Flags"}),m.jsx(Qe,{container:!0,spacing:2,children:Object.entries(a).map(([c,u])=>{const f=n[c]??u.default??!1,h=u.title?.toLowerCase().includes("deprecated")??!1;return m.jsx(Qe,{size:{xs:12,sm:6,lg:4},children:m.jsx(tr,{variant:"outlined",sx:{height:"100%",opacity:h?.6:1,transition:"border-color 0.2s, box-shadow 0.2s",borderColor:f?"primary.main":"divider","&:hover":{transform:"none",boxShadow:"none"}},children:m.jsx(Gm,{onClick:()=>{!i&&!o&&l(c,!f)},disabled:i||o,sx:{height:"100%"},children:m.jsxs(gr,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[m.jsxs(le,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:1,children:[m.jsxs(le,{sx:{flex:1,minWidth:0},children:[m.jsx(ie,{variant:"subtitle2",fontWeight:600,sx:{lineHeight:1.3},children:u.title??c}),f&&m.jsx(Et,{label:"Active",size:"small",color:"primary",variant:"outlined",sx:{mt:.5,height:20,fontSize:"0.7rem"}})]}),m.jsx(Ph,{checked:f,size:"small",disabled:i||o,tabIndex:-1,onClick:g=>g.stopPropagation(),onChange:g=>l(c,g.target.checked)})]}),m.jsx(ie,{variant:"caption",color:"text.secondary",sx:{mt:1,lineHeight:1.4,flex:1},children:u.description})]})})})},c)})})]})}const Rse=e=>{const[t,n]=_.useState("FIELDS_EDITOR"),r=()=>{n(t==="FIELDS_EDITOR"?"JSON_EDITOR":"FIELDS_EDITOR")},[i,o]=_.useState(e.bridge),[s,a]=_.useState(!0),l=_.useCallback(g=>{const y=g;if(!y?.port)return[];const b=e.usedPorts[y.port];return b!==void 0&&b!==e.bridgeId?[{instancePath:"/port",message:`Port is already used by bridge with id ${b}`}]:[]},[e.bridgeId,e.usedPorts]),c=(g,y)=>{const b=v=>v?.icon;o(v=>{const S=b(v);return S!=null?{...g,icon:S}:{...g}}),a(y)},u=_.useCallback(g=>{o(y=>{if(g!=null)return{...y,icon:g};const{icon:b,...v}=y??{};return v})},[]),f=_.useMemo(()=>{const y=i?.featureFlags,b=[];return y?.serverMode&&b.push({severity:"warning",message:"Server Mode is enabled. Only ONE device should be in this bridge. Multiple devices will cause errors."}),y?.serverMode&&y?.vacuumOnOff===!1&&b.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."}),!y?.serverMode&&y?.vacuumOnOff&&b.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."}),y?.autoForceSync&&y?.autoComposedDevices&&b.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."}),b},[i]),h=async()=>{s&&await e.onSave(i)};return m.jsxs(m.Fragment,{children:[m.jsxs(kn,{severity:"warning",variant:"outlined",children:["Please consult"," ",m.jsx(uw,{href:jt.faq.bridgeConfig,target:"_blank",children:"the documentation"})," ","for proper bridge configurations."," ",m.jsx("strong",{children:'Especially if you are using labels, see the "Labels" section.'})]}),m.jsxs(kn,{severity:"info",variant:"outlined",children:[m.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."]}),f.map(g=>m.jsx(kn,{severity:g.severity,variant:"outlined",children:g.message},g.message)),m.jsxs(zt,{spacing:2,children:[m.jsx(le,{display:"flex",justifyContent:"flex-end",children:m.jsx(kt,{onClick:()=>r(),title:t==="FIELDS_EDITOR"?"JSON editor":"Form editor",children:t==="FIELDS_EDITOR"?m.jsx(h8e,{}):m.jsx(s8e,{})})}),t==="FIELDS_EDITOR"&&m.jsx(Eje,{value:i??{},onChange:c,schema:dy,uiSchema:{icon:{"ui:widget":"hidden"},featureFlags:{"ui:field":"featureFlags"},filter:{include:{"ui:options":{ArrayFieldTemplate:vG}},exclude:{"ui:options":{ArrayFieldTemplate:vG}}}},customValidate:l,templates:{ObjectFieldTemplate:WQe},fields:{featureFlags:KQe}}),t==="JSON_EDITOR"&&m.jsx(NQe,{value:i??{},onChange:c,schema:dy,customValidate:l}),i?.filter&&m.jsx(HQe,{filter:i.filter}),m.jsx(tr,{variant:"outlined",children:m.jsxs(gr,{children:[m.jsx(ie,{variant:"subtitle1",gutterBottom:!0,fontWeight:600,children:"Bridge Icon"}),m.jsx(zQe,{bridgeId:e.bridgeId,selectedIcon:i?.icon,onIconChange:u})]})}),m.jsxs(Qe,{container:!0,children:[m.jsx(Qe,{size:{xs:6,sm:4,md:3},children:m.jsx(kt,{fullWidth:!0,variant:"outlined",color:"error",onClick:e.onCancel,children:"Cancel"})}),m.jsx(Qe,{size:{xs:0,sm:4,md:6},sx:{display:{xs:"none",sm:"block"}}}),m.jsx(Qe,{size:{xs:6,sm:4,md:3},children:m.jsx(kt,{fullWidth:!0,variant:"outlined",disabled:!s,onClick:h,children:"Save"})})]})]})]})},YQe={name:"",featureFlags:{},filter:{include:[],exclude:[]}};function XQe(e){let t=5540;for(;e[t];)t++;return t}const ZQe=()=>{const e=Tu(),t=Jh(),[n,r]=_.useState(),i=!!qm().content?.length,o=pJ(),s=_.useCallback(f=>{r(f?.id)},[]),a=_.useMemo(()=>{if(!o)return;const f=XQe(o);if(n){const h=OZ.find(g=>g.id===n);if(h)return{name:h.name,port:f,filter:{...h.filter},featureFlags:{...h.featureFlags},icon:h.icon}}return{...YQe,port:f}},[o,n]),l=yCe(),c=()=>{t(-1)},u=async f=>{await l({...f}).then(()=>e.show({message:"Bridge saved",severity:"success"})).then(()=>c()).catch(h=>e.show({message:h.message,severity:"error"}))};return!a||!o?"Loading":m.jsxs(zt,{spacing:4,children:[m.jsx(dw,{items:[{name:"Bridges",to:jt.bridges},{name:"Create New",to:jt.createBridge}]}),i&&m.jsx(kn,{severity:"info",variant:"outlined",children:m.jsxs(ie,{children:["Did you know that you can connect the same bridge with multiple assistants?"," ",m.jsx(uw,{href:jt.faq.multiFabric,target:"_blank",children:"Learn more."})]})}),m.jsx(AJ,{selectedTemplate:n,onSelect:s}),m.jsx(Rse,{bridge:a,usedPorts:o,onSave:u,onCancel:c},n??"custom")]})},JQe=()=>{const e=Tu(),t=Jh(),{bridgeId:n}=hY(),{content:r,isLoading:i}=mJ(n),o=pJ(),s=bCe(),a=_.useMemo(()=>{if(!(i||!r))return{name:r.name,port:r.port,filter:r.filter,...r.countryCode!=null&&{countryCode:r.countryCode},...r.featureFlags!=null&&{featureFlags:r.featureFlags},...r.icon!=null&&{icon:r.icon},...r.priority!=null&&{priority:r.priority}}},[i,r]),l=()=>{t(-1)},c=async u=>{await s({...u,id:n}).then(()=>e.show({message:"Update completed",severity:"success"})).then(()=>l()).catch(f=>e.show({message:f.message,severity:"error"}))};return i||!o?"Loading":!r||!a?"Not found":m.jsxs(zt,{spacing:4,children:[m.jsx(dw,{items:[{name:"Bridges",to:jt.bridges},{name:r.name,to:jt.bridge(n)},{name:"Edit",to:jt.editBridge(n)}]}),m.jsx(Rse,{bridgeId:n,bridge:a,usedPorts:o,onSave:c,onCancel:l})]})};function QQe(){const[e,t]=_.useState(!1),[n,r]=_.useState(null),[i,o]=_.useState(null),[s,a]=_.useState(null),[l,c]=_.useState(new Set),[u,f]=_.useState(!1),[h,g]=_.useState(!0),[y,b]=_.useState(!0),[v,S]=_.useState(!1),[C,w]=_.useState(!1),[A,E]=_.useState(null),O=_.useRef(null),D=async(R=!1)=>{t(!0),r(null);try{const j=await fetch(R?"api/backup/download?includeIdentity=true":"api/backup/download");if(!j.ok)throw new Error("Failed to create backup");const z=await j.blob(),N=window.URL.createObjectURL(z),W=document.createElement("a");W.href=N,W.download=j.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]||"hamh-backup.zip",document.body.appendChild(W),W.click(),window.URL.revokeObjectURL(N),document.body.removeChild(W),o("Backup downloaded successfully!")}catch($){r($ instanceof Error?$.message:"Unknown error")}finally{t(!1)}},T=async R=>{const $=R.target.files?.[0];if($){E($),t(!0),r(null);try{const j=new FormData;j.append("file",$);const z=await fetch("api/backup/restore/preview",{method:"POST",body:j});if(!z.ok){const W=await z.json();throw new Error(W.error||"Failed to parse backup")}const N=await z.json();a(N),c(new Set(N.bridges.map(W=>W.id))),S(!0)}catch(j){r(j instanceof Error?j.message:"Unknown error")}finally{t(!1),O.current&&(O.current.value="")}}},I=async()=>{if(A){t(!0),r(null);try{const R=new FormData;R.append("file",A),R.append("options",JSON.stringify({bridgeIds:Array.from(l),overwriteExisting:u,includeMappings:h,restoreIdentity:y&&s?.includesIdentity}));const $=await fetch("api/backup/restore",{method:"POST",body:R});if(!$.ok){const z=await $.json();throw new Error(z.error||"Failed to restore backup")}const j=await $.json();if(j.errors.length>0)r(`Restored ${j.bridgesRestored} bridges with ${j.errors.length} errors`);else{const z=[`Restored ${j.bridgesRestored} bridges`];j.mappingsRestored>0&&z.push(`${j.mappingsRestored} entity mappings`),j.identitiesRestored>0&&z.push(`${j.identitiesRestored} identities`),o(`${z.join(", ")}!`)}S(!1),a(null),E(null),j.restartRequired&&w(!0)}catch(R){r(R instanceof Error?R.message:"Unknown error")}finally{t(!1)}}},F=R=>{const $=new Set(l);$.has(R)?$.delete(R):$.add(R),c($)},L=async()=>{t(!0);try{await fetch("api/backup/restart",{method:"POST"}),o("Application is restarting...")}catch(R){r(R instanceof Error?R.message:"Failed to restart")}finally{t(!1),w(!1)}};return m.jsxs(tr,{children:[m.jsxs(gr,{children:[m.jsxs(ie,{variant:"h6",gutterBottom:!0,children:[m.jsx($x,{sx:{mr:1,verticalAlign:"middle"}}),"Backup & Restore"]}),m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Create a full backup of your bridges and entity mappings, or restore from a previous backup."}),n&&m.jsx(kn,{severity:"error",sx:{mb:2},onClose:()=>r(null),children:n}),i&&m.jsx(kn,{severity:"success",sx:{mb:2},onClose:()=>o(null),children:i}),m.jsxs(Qe,{container:!0,spacing:2,children:[m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx($x,{color:"primary"}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",children:"Config Backup"})]}),m.jsxs(le,{sx:{flexGrow:1},children:[m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Export bridge configurations and entity mappings."}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Bridges will need to be re-commissioned after restore."})]}),m.jsx(kt,{variant:"contained",startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):m.jsx($x,{}),onClick:()=>D(!1),disabled:e,fullWidth:!0,sx:{mt:2},children:"Config Backup"})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx(SJ,{color:"warning"}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",children:"Full Backup (with Identity)"})]}),m.jsxs(le,{sx:{flexGrow:1},children:[m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Includes Matter identity files (keypairs, fabric credentials)."}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Preserves commissioning state across restores. DONT SHARE!"})]}),m.jsx(kt,{variant:"contained",color:"warning",startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):m.jsx($x,{}),onClick:()=>D(!0),disabled:e,fullWidth:!0,sx:{mt:2},children:"Full Backup (with Identity)"})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2,height:"100%",display:"flex",flexDirection:"column"},children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx(FB,{color:"info"}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",children:"Restore from Backup"})]}),m.jsx(le,{sx:{flexGrow:1},children:m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Upload a previously created backup file to restore bridges and configurations."})}),m.jsxs(kt,{variant:"outlined",color:"info",startIcon:m.jsx(FB,{}),component:"label",disabled:e,fullWidth:!0,sx:{mt:2},children:["Restore from Backup",m.jsx("input",{ref:O,type:"file",accept:".zip",hidden:!0,onChange:T})]})]})})]})]}),m.jsxs(vu,{open:v,onClose:()=>S(!1),maxWidth:"sm",fullWidth:!0,children:[m.jsx(Su,{children:"Restore Backup"}),m.jsx(xu,{children:s&&m.jsxs(m.Fragment,{children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Backup created: ",new Date(s.createdAt).toLocaleString()]}),s.includesIdentity&&m.jsx(kn,{severity:"info",sx:{mt:1},children:"This backup includes Matter identity data (keypairs, fabric credentials). Restoring identities allows bridges to reconnect without re-commissioning."}),m.jsx(ie,{variant:"subtitle2",sx:{mt:2,mb:1},children:"Select bridges to restore:"}),m.jsx(vc,{dense:!0,children:s.bridges.map(R=>m.jsxs(gf,{onClick:()=>F(R.id),sx:{cursor:"pointer"},children:[m.jsx(Ul,{children:m.jsx(Wl,{edge:"start",checked:l.has(R.id),tabIndex:-1,disableRipple:!0})}),m.jsx(Va,{primary:R.name,secondary:m.jsxs(m.Fragment,{children:["Port: ",R.port,R.hasMappings&&` • ${R.mappingCount} entity mappings`,R.exists&&m.jsx(ie,{component:"span",color:"warning.main",sx:{ml:1},children:"(exists)"})]})})]},R.id))}),m.jsxs(le,{sx:{mt:2},children:[m.jsx(Ls,{control:m.jsx(Wl,{checked:u,onChange:R=>f(R.target.checked)}),label:"Overwrite existing bridges"}),m.jsx(Ls,{control:m.jsx(Wl,{checked:h,onChange:R=>g(R.target.checked)}),label:"Include entity mappings"}),s?.includesIdentity&&m.jsx(Ls,{control:m.jsx(Wl,{checked:y,onChange:R=>b(R.target.checked)}),label:"Restore Matter identities (no re-commissioning needed)"})]})]})}),m.jsxs(Xd,{children:[m.jsx(kt,{onClick:()=>S(!1),children:"Cancel"}),m.jsx(kt,{variant:"contained",onClick:I,disabled:e||l.size===0,startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):null,children:"Restore"})]})]}),m.jsxs(vu,{open:C,onClose:()=>w(!1),children:[m.jsxs(Su,{children:[m.jsx(n2,{sx:{mr:1,verticalAlign:"middle"}}),"Restart Required"]}),m.jsxs(xu,{children:[m.jsx(ie,{children:"Bridges have been restored from backup. A restart is required for the changes to take effect."}),m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{mt:1},children:"The application will restart and you may need to refresh this page."})]}),m.jsxs(Xd,{children:[m.jsx(kt,{onClick:()=>w(!1),children:"Later"}),m.jsx(kt,{variant:"contained",color:"warning",onClick:L,disabled:e,startIcon:e?m.jsx(Hr,{size:20,color:"inherit"}):m.jsx(n2,{}),children:"Restart Now"})]})]})]})}const eet=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 tet(e={}){const[t,n]=_.useState(null),[r,i]=_.useState(!0),[o,s]=_.useState(null),[a,l]=_.useState("name"),[c,u]=_.useState("asc"),f=e.sortField??a,h=e.sortDirection??c,g=e.onSortFieldChange??l,y=e.onSortDirectionChange??u,b=_.useCallback(async()=>{try{const w=await fetch("api/health/detailed");if(w.ok){const A=await w.json();n(A),s(null)}else s("Failed to fetch health status")}catch{s("Connection error")}finally{i(!1)}},[]);_.useEffect(()=>{b();const w=setInterval(b,1e4);return()=>clearInterval(w)},[b]);const v=_.useCallback(async()=>{try{const w=await fetch("api/diagnostic/export");if(w.ok){const A=await w.blob(),E=URL.createObjectURL(A),O=document.createElement("a");O.href=E;const T=w.headers.get("Content-Disposition")?.match(/filename="(.+)"/)?.[1]??`hamh-diagnostic-${new Date().toISOString().replace(/[:.]/g,"-")}.json`;O.download=T,document.body.appendChild(O),O.click(),document.body.removeChild(O),URL.revokeObjectURL(E)}}catch{s("Failed to export diagnostic data")}},[]),S=async w=>{try{await fetch(`api/matter/bridges/${w}/actions/restart`,{method:"POST"}),b()}catch{s("Failed to restart bridge")}};if(r)return m.jsx(le,{display:"flex",justifyContent:"center",p:4,children:m.jsx(Hr,{})});if(o||!t)return m.jsx(kn,{severity:"error",sx:{m:2},children:o??"Unable to load health status"});const C=t.status==="healthy"?m.jsx(Mu,{color:"success"}):t.status==="degraded"?m.jsx(aw,{color:"warning"}):m.jsx(bf,{color:"error"});return m.jsxs(le,{sx:{p:2},children:[m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[C,m.jsx(ie,{variant:"h5",children:"System Health"}),m.jsx(Et,{label:t.status.toUpperCase(),color:t.status==="healthy"?"success":t.status==="degraded"?"warning":"error",size:"small"})]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(kt,{variant:"outlined",size:"small",startIcon:m.jsx(Dw,{}),onClick:v,children:"Export Diagnostic"}),m.jsx(cn,{title:"Refresh",children:m.jsx(_n,{onClick:b,children:m.jsx(kT,{})})})]})]}),m.jsxs(Qe,{container:!0,spacing:2,children:[m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2},children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Version"}),m.jsx(ie,{variant:"h6",children:t.version})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2},children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Uptime"}),m.jsx(ie,{variant:"h6",children:eet(t.uptime)})]})}),m.jsx(Qe,{size:{xs:12,md:4},children:m.jsxs(Nr,{sx:{p:2},children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Home Assistant"}),m.jsx(Et,{label:t.services.homeAssistant.connected?"Connected":"Disconnected",color:t.services.homeAssistant.connected?"success":"error",size:"small"})]})})]}),m.jsx(gi,{sx:{my:3}}),m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,flexWrap:"wrap",gap:1,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(t_,{}),m.jsx(ie,{variant:"h6",children:"Bridge Status"}),m.jsx(Et,{label:`${t.services.bridges.running}/${t.services.bridges.total} Running`,size:"small",variant:"outlined"})]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(PZ,{fontSize:"small",color:"action"}),m.jsxs(ha,{size:"small",sx:{minWidth:120},children:[m.jsx(sc,{children:"Sort by"}),m.jsxs(oa,{value:f,label:"Sort by",onChange:w=>g(w.target.value),children:[m.jsx(er,{value:"name",children:"Name"}),m.jsx(er,{value:"created",children:"Created"})]})]}),m.jsx(cn,{title:h==="asc"?"Ascending":"Descending",children:m.jsx(_n,{size:"small",onClick:()=>y(h==="asc"?"desc":"asc"),children:h==="asc"?m.jsx(wT,{fontSize:"small"}):m.jsx(ST,{fontSize:"small"})})})]})]}),m.jsx(Qe,{container:!0,spacing:2,alignItems:"stretch",children:[...t.bridgeDetails].sort((w,A)=>{let E=0;return f==="name"?E=w.name.localeCompare(A.name):E=w.id.localeCompare(A.id),h==="asc"?E:-E}).map(w=>m.jsx(Qe,{size:{xs:12,sm:6,md:6,lg:4,xl:3},sx:{display:"flex"},children:m.jsx(tr,{variant:"outlined",sx:{width:"100%",height:"100%",minWidth:280,maxWidth:480,display:"flex",flexDirection:"column",borderColor:w.status==="running"?"success.main":w.status==="failed"?"error.main":"warning.main"},children:m.jsxs(gr,{sx:{flex:1,display:"flex",flexDirection:"column",p:2,"&:last-child":{pb:2}},children:[m.jsxs(le,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",flexShrink:0,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,minWidth:0,children:[m.jsx(ss,{}),m.jsx(ie,{variant:"subtitle1",fontWeight:"bold",noWrap:!0,sx:{maxWidth:140},children:w.name})]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:.5,flexShrink:0,children:[m.jsx(Et,{label:w.status.toUpperCase(),color:w.status==="running"?"success":w.status==="failed"?"error":"warning",size:"small"}),w.status==="failed"&&m.jsx(cn,{title:"Restart Bridge",children:m.jsx(_n,{size:"small",onClick:()=>S(w.id),children:m.jsx(LB,{})})})]})]}),w.statusReason&&m.jsx(ie,{variant:"body2",color:"error",sx:{mt:1,flexShrink:0},children:w.statusReason}),m.jsx(le,{sx:{mt:"auto",pt:1,flexShrink:0},children:m.jsxs(le,{display:"flex",flexWrap:"wrap",gap:.5,alignItems:"center",children:[m.jsx(Et,{label:`Port ${w.port}`,size:"small",variant:"outlined",color:"default"}),m.jsx(Et,{label:`${w.deviceCount} Devices`,size:"small",variant:"outlined",color:"default"}),m.jsx(Et,{label:`${w.fabricCount} Fabrics`,size:"small",variant:"outlined",color:"default"}),w.failedEntityCount>0&&m.jsx(Et,{label:`${w.failedEntityCount} failed`,color:"error",size:"small"})]})}),w.connectivity&&w.status==="running"&&m.jsx(le,{sx:{mt:1,flexShrink:0},children:m.jsxs(ie,{variant:"caption",color:"text.secondary",children:["Sessions: ",w.connectivity.totalSessions," | Subs:"," ",w.connectivity.totalSubscriptions]})}),w.fabrics.length>0&&m.jsxs(le,{sx:{mt:1,flexShrink:0},children:[m.jsx(ie,{variant:"caption",color:"text.secondary",children:"Connected to:"}),m.jsx(le,{display:"flex",gap:.5,flexWrap:"wrap",mt:.5,children:w.fabrics.map(A=>m.jsx(Et,{icon:m.jsx(DZ,{fabric:A}),label:A.label||e2(A.rootVendorId),size:"small",variant:"outlined"},A.fabricIndex))})]})]})})},w.id))}),t.recovery.enabled&&m.jsxs(m.Fragment,{children:[m.jsx(gi,{sx:{my:3}}),m.jsxs(le,{display:"flex",alignItems:"center",gap:1,mb:1,children:[m.jsx(LB,{}),m.jsx(ie,{variant:"h6",children:"Auto Recovery"}),m.jsx(Et,{label:"Enabled",color:"success",size:"small"})]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:["Recovery attempts: ",t.recovery.recoveryCount,t.recovery.lastRecoveryAttempt&&` | Last attempt: ${new Date(t.recovery.lastRecoveryAttempt).toLocaleString()}`]})]}),m.jsx(gi,{sx:{my:3}}),m.jsx(QQe,{})]})}const Jf=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]}`},xG=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`},net=()=>{const[e,t]=_.useState(null),[n,r]=_.useState(!0),[i,o]=_.useState(!0);if(_.useEffect(()=>{let l=null;const c=async()=>{try{const u=await fetch("api/system/info");if(u.ok){const f=await u.json();t(f),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 m.jsx(tr,{children:m.jsx(gr,{children:m.jsx(ie,{children:"Loading system information..."})})});if(!e)return m.jsx(tr,{children:m.jsx(gr,{children:m.jsx(ie,{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 m.jsx(tr,{children:m.jsxs(gr,{children:[m.jsxs(ie,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(KCe,{}),"System Information"]}),m.jsxs(Qe,{container:!0,spacing:3,children:[m.jsx(Qe,{size:{xs:12,md:6},children:m.jsxs(zt,{spacing:2,children:[m.jsxs(le,{children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"Application"}),m.jsxs(zt,{spacing:1,sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Version:"}),m.jsx(Et,{label:e.version,size:"small",color:"primary"})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Environment:"}),m.jsx(Et,{label:e.environment,size:"small",variant:"outlined",color:e.environment==="Home Assistant Add-on"?"success":"default"})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Node.js:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:e.nodeVersion})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Process Uptime:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:xG(e.process.uptime)})]})]})]}),m.jsxs(le,{children:[m.jsx(ie,{variant:"subtitle2",color:"text.secondary",children:"System"}),m.jsxs(zt,{spacing:1,sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Hostname:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:e.hostname})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"Platform:"}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:[e.platform," (",e.arch,")"]})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"CPU:"}),m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{maxWidth:200,textAlign:"right"},noWrap:!0,title:e.cpuModel,children:[e.cpuCount,"x"," ",e.cpuModel.split("@")[0].trim()]})]}),m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between"},children:[m.jsx(ie,{variant:"body2",children:"System Uptime:"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:xG(e.uptime)})]})]})]})]})}),m.jsx(Qe,{size:{xs:12,md:6},children:m.jsxs(zt,{spacing:2,children:[m.jsxs(le,{children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(t_,{}),"Memory Usage"]}),m.jsxs(le,{sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[m.jsxs(ie,{variant:"body2",children:[Jf(e.memory.used)," /"," ",Jf(e.memory.total)]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:[s.toFixed(1),"%"]})]}),m.jsx(le,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:m.jsx(le,{sx:{height:"100%",width:`${s}%`,backgroundColor:s>80?"error.main":s>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]}),m.jsxs(le,{children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(t_,{}),"HAMH Process Memory"]}),m.jsxs(le,{sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",mb:.5},children:[m.jsxs(ie,{variant:"body2",children:["RSS: ",Jf(e.process.rss)]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:["Heap: ",Jf(e.process.heapUsed)," /"," ",Jf(e.process.heapSizeLimit)]})]}),m.jsx(le,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:m.jsx(le,{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"}})})]})]}),m.jsxs(le,{children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(f8e,{}),"Storage Usage"]}),m.jsxs(le,{sx:{mt:1},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[m.jsxs(ie,{variant:"body2",children:[Jf(e.storage.used)," /"," ",Jf(e.storage.total)]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",children:[a.toFixed(1),"%"]})]}),m.jsx(le,{sx:{height:8,backgroundColor:"action.hover",borderRadius:4,overflow:"hidden"},children:m.jsx(le,{sx:{height:"100%",width:`${a}%`,backgroundColor:a>80?"error.main":a>60?"warning.main":"success.main",transition:"width 0.3s ease"}})})]})]})]})}),m.jsxs(Qe,{size:{xs:12},children:[m.jsxs(ie,{variant:"subtitle2",color:"text.secondary",sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(c8e,{}),"Network Interfaces"]}),m.jsx(zt,{spacing:1,sx:{mt:1},children:e.network.interfaces.map(l=>m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[m.jsx(ie,{variant:"body2",children:l.name}),m.jsx(Et,{label:`${l.address} (${l.family})`,size:"small",variant:"outlined"})]},`${l.name}-${l.address}`))})]})]})]})})},SG=200;function ret(){const[e,t]=_.useState([]),[n,r]=_.useState(null),[i,o]=_.useState(!1),s=_.useRef(null),a=_.useRef(void 0),l=_.useCallback(()=>{if(s.current?.readyState===WebSocket.OPEN)return;const u=window.location.protocol==="https:"?"wss:":"ws:",f=document.querySelector("base")?.href||window.location.origin,h=new URL(f),g=`${u}//${h.host}${h.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>SG?w.slice(-SG):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()},[]);_.useEffect(()=>(l(),()=>{clearTimeout(a.current),s.current&&(s.current.send(JSON.stringify({type:"unsubscribe_diagnostics"})),s.current.close())}),[l]);const c=_.useCallback(()=>t([]),[]);return{events:e,snapshot:n,connected:i,clearEvents:c}}const S4={state_update:{color:"#4caf50",label:"State Update"},command_received:{color:"#2196f3",label:"Command"},entity_error:{color:"#f44336",label:"Error"},session_opened:{color:"#ff9800",label:"Session Open"},session_closed:{color:"#9e9e9e",label:"Session Close"},subscription_changed:{color:"#9c27b0",label:"Subscription"},bridge_started:{color:"#00bcd4",label:"Bridge Start"},bridge_stopped:{color:"#795548",label:"Bridge Stop"}};function iet(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 HA=Object.keys(S4);function oet({sortField:e,sortDirection:t}={}){const{events:n,snapshot:r,connected:i,clearEvents:o}=ret(),[s,a]=_.useState(new Set(HA)),[l,c]=_.useState(!1),u=y=>{a(b=>{const v=new Set(b);return v.has(y)?v.delete(y):v.add(y),v})},f=n.filter(y=>s.has(y.type)),h=_.useMemo(()=>{const y=r?.bridges??[];return e?[...y].sort((b,v)=>{let S=0;return e==="name"?S=b.bridgeName.localeCompare(v.bridgeName):S=b.bridgeId.localeCompare(v.bridgeId),t==="desc"?-S:S}):y},[r?.bridges,e,t]),g={};for(const y of n)g[y.type]=(g[y.type]??0)+1;return m.jsx(tr,{children:m.jsxs(gr,{children:[m.jsxs(le,{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2,children:[m.jsxs(le,{display:"flex",alignItems:"center",gap:1,children:[m.jsx(p8e,{}),m.jsx(ie,{variant:"h6",children:"Live Diagnostics"}),m.jsx(Et,{icon:m.jsx(n8e,{sx:{fontSize:10,color:i?"#4caf50":"#f44336"}}),label:i?"Live":"Offline",size:"small",variant:"outlined"})]}),m.jsxs(zt,{direction:"row",spacing:.5,alignItems:"center",children:[m.jsx(cn,{title:"Filter event types",children:m.jsx(_n,{size:"small",onClick:()=>c(y=>!y),color:l?"primary":"default",children:m.jsx(hw,{})})}),m.jsx(cn,{title:"Clear all events",children:m.jsx(_n,{size:"small",onClick:o,children:m.jsx(WCe,{})})})]})]}),m.jsxs(zt,{direction:"row",spacing:.5,flexWrap:"wrap",sx:{mb:2,gap:.5},children:[HA.map(y=>{const b=g[y]??0;if(b===0&&!l)return null;const v=S4[y];return m.jsx(Et,{label:`${v.label}: ${b}`,size:"small",sx:{bgcolor:s.has(y)?v.color:"action.disabledBackground",color:s.has(y)?"#fff":"text.disabled",fontSize:"0.7rem",height:22,cursor:"pointer",opacity:s.has(y)?1:.5},onClick:()=>u(y)},y)}),r?.system&&m.jsx(Et,{label:`Total: ${r.system.eventCount}`,size:"small",variant:"outlined",sx:{fontSize:"0.7rem",height:22}})]}),m.jsx(da,{in:l,children:m.jsx(Nr,{variant:"outlined",sx:{p:1.5,mb:2},children:m.jsx(Qe,{container:!0,spacing:0,children:HA.map(y=>{const b=S4[y];return m.jsx(Qe,{size:{xs:6,sm:4,md:3},children:m.jsx(Ls,{control:m.jsx(Wl,{size:"small",checked:s.has(y),onChange:()=>u(y),sx:{color:b.color,"&.Mui-checked":{color:b.color}}}),label:m.jsx(ie,{variant:"caption",children:b.label})})},y)})})})}),h.length>0&&m.jsxs(m.Fragment,{children:[m.jsx(Qe,{container:!0,spacing:1,sx:{mb:2},children:h.map(y=>m.jsx(Qe,{size:{xs:12,sm:6},children:m.jsxs(Nr,{variant:"outlined",sx:{p:1.5,display:"flex",justifyContent:"space-between",alignItems:"center",overflow:"hidden",minWidth:0},children:[m.jsxs(le,{sx:{minWidth:0,overflow:"hidden"},children:[m.jsx(ie,{variant:"body2",fontWeight:500,noWrap:!0,children:y.bridgeName}),m.jsxs(ie,{variant:"caption",color:"text.secondary",noWrap:!0,children:[y.entityCount," devices · ",y.sessionCount," ","sessions"]})]}),m.jsxs(zt,{direction:"row",spacing:.5,alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end",sx:{flexShrink:0,ml:1},children:[Object.entries(y.featureFlags).filter(([,b])=>b).map(([b])=>m.jsx(Et,{label:b.replace(/^auto/,"").replace(/([A-Z])/g," $1").trim(),size:"small",variant:"outlined",sx:{fontSize:"0.6rem",height:18}},b)),m.jsx(Et,{label:y.status,size:"small",color:y.status==="running"?"success":y.status==="failed"?"error":"default",sx:{height:20}})]})]})},y.bridgeId))}),m.jsx(gi,{sx:{mb:2}})]}),m.jsx(le,{sx:{maxHeight:400,overflow:"auto",bgcolor:"background.default",borderRadius:1,p:1},children:f.length===0?m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:4},children:n.length===0?"Waiting for diagnostic events…":"No events match the current filters."}):f.map(y=>{const b=S4[y.type];return m.jsxs(le,{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:[m.jsx(ie,{variant:"caption",sx:{color:"text.secondary",whiteSpace:"nowrap",fontFamily:"monospace",fontSize:"0.72rem",minWidth:85,pt:.1},children:iet(y.timestamp)}),m.jsx(Et,{label:b?.label??y.type,size:"small",sx:{bgcolor:b?.color??"#757575",color:"#fff",fontSize:"0.62rem",fontWeight:600,height:18,minWidth:90}}),y.bridgeName&&m.jsxs(ie,{variant:"caption",sx:{color:"primary.main",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:140,flexShrink:0},children:["[",y.bridgeName,"]"]}),y.entityId&&m.jsx(ie,{variant:"caption",sx:{color:"warning.main",fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontSize:"0.72rem",maxWidth:220,flexShrink:1},children:y.entityId}),m.jsx(ie,{variant:"caption",sx:{color:"text.primary",flex:1,wordBreak:"break-word",fontSize:"0.72rem"},children:y.message})]},y.id)})})]})})}const set=()=>{const[e,t]=_.useState("name"),[n,r]=_.useState("asc");return m.jsxs(le,{sx:{display:"flex",flexDirection:"column",gap:3},children:[m.jsx(tet,{sortField:e,sortDirection:n,onSortFieldChange:t,onSortDirectionChange:r}),m.jsx(le,{sx:{px:2},children:m.jsx(oet,{sortField:e,sortDirection:n})}),m.jsx(le,{sx:{px:2,pb:2},children:m.jsx(net,{})})]})};async function aet(){const e=await fetch(`api/matter/labels?_s=${Date.now()}`);if(!e.ok)throw new Error("Failed to fetch labels");return e.json()}async function cet(){const e=await fetch(`api/matter/areas?_s=${Date.now()}`);if(!e.ok)throw new Error("Failed to fetch areas");return e.json()}async function uet(){const e=await fetch(`api/matter/filter-values?_s=${Date.now()}`);if(!e.ok)throw new Error("Failed to fetch filter values");return e.json()}const o0=({values:e,copiedId:t,onCopy:n,searchable:r})=>{const[i,o]=_.useState(""),s=_.useMemo(()=>{if(!i)return e;const a=i.toLowerCase();return e.filter(l=>l.toLowerCase().includes(a))},[e,i]);return e.length===0?m.jsx(le,{sx:{p:2,textAlign:"center"},children:m.jsx(ie,{color:"text.secondary",variant:"body2",children:"No values found."})}):m.jsxs(le,{children:[r&&e.length>10&&m.jsx(le,{sx:{px:2,pt:1,pb:.5},children:m.jsx(Lr,{size:"small",fullWidth:!0,placeholder:"Search...",value:i,onChange:a=>o(a.target.value),slotProps:{input:{startAdornment:m.jsx(AM,{position:"start",children:m.jsx(xJ,{fontSize:"small"})})}}})}),m.jsxs(le,{sx:{p:1.5,display:"flex",flexWrap:"wrap",gap:.75},children:[s.map(a=>m.jsx(Et,{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&&m.jsxs(ie,{color:"text.secondary",variant:"body2",sx:{p:1},children:['No matches for "',i,'"']})]})]})},det=()=>{const[e,t]=_.useState([]),[n,r]=_.useState([]),[i,o]=_.useState(null),[s,a]=_.useState(!0),[l,c]=_.useState(null),[u,f]=_.useState(null),h=_.useCallback(async()=>{a(!0);try{const[y,b,v]=await Promise.all([aet(),cet(),uet()]);t(y),r(b),o(v),c(null)}catch(y){c(y instanceof Error?y.message:"Failed to load data")}finally{a(!1)}},[]);_.useEffect(()=>{h()},[h]);const g=y=>{navigator.clipboard.writeText(y),f(y),setTimeout(()=>f(null),2e3)};return s?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(Hr,{})}):m.jsxs(le,{sx:{p:2},children:[m.jsxs(ie,{variant:"h5",component:"h1",sx:{mb:3},children:[m.jsx(hw,{sx:{mr:1,verticalAlign:"middle"}}),"Filter Reference"]}),m.jsx(kn,{severity:"info",sx:{mb:3},children:"Browse all available filter values for your bridge configuration. Click any value to copy it to your clipboard."}),l&&m.jsx(kn,{severity:"error",sx:{mb:2},children:l}),m.jsxs(ie,{variant:"h6",sx:{mb:1},children:[m.jsx(i6,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),"Labels (",e.length,")"]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:["Use with filter type ",m.jsx("b",{children:'"entity_label"'})," or"," ",m.jsx("b",{children:'"device_label"'}),". You can use either the display name or the label_id."]}),m.jsx(tr,{sx:{mb:4},children:e.length===0?m.jsx(le,{sx:{p:3,textAlign:"center"},children:m.jsx(ie,{color:"text.secondary",children:"No labels found in Home Assistant. Create labels under Settings > Labels."})}):m.jsx(hm,{children:m.jsxs(dm,{size:"small",children:[m.jsx(J4,{children:m.jsxs(Ts,{children:[m.jsx(Rn,{sx:{fontWeight:"bold"},children:"Display Name"}),m.jsx(Rn,{sx:{fontWeight:"bold"},children:"label_id"}),m.jsx(Rn,{width:48})]})}),m.jsx(fm,{children:e.map(y=>m.jsxs(Ts,{hover:!0,children:[m.jsxs(Rn,{children:[y.color&&m.jsx(le,{component:"span",sx:{display:"inline-block",width:12,height:12,borderRadius:"50%",backgroundColor:y.color,mr:1,verticalAlign:"middle"}}),y.name]}),m.jsx(Rn,{children:m.jsx("code",{children:y.label_id})}),m.jsx(Rn,{children:m.jsx(cn,{title:u===y.label_id?"Copied!":"Copy ID",children:m.jsx(_n,{size:"small",onClick:()=>g(y.label_id),children:m.jsx(Eh,{fontSize:"small"})})})})]},y.label_id))})]})})}),m.jsxs(ie,{variant:"h6",sx:{mb:1},children:[m.jsx(fJ,{sx:{mr:.5,fontSize:20,verticalAlign:"middle"}}),"Areas (",n.length,")"]}),m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:["Use with filter type ",m.jsx("b",{children:'"area"'}),". Areas are also used for automatic room assignment in Matter controllers."]}),m.jsx(tr,{sx:{mb:4},children:n.length===0?m.jsx(le,{sx:{p:3,textAlign:"center"},children:m.jsx(ie,{color:"text.secondary",children:"No areas found in Home Assistant. Create areas under Settings > Areas."})}):m.jsx(hm,{children:m.jsxs(dm,{size:"small",children:[m.jsx(J4,{children:m.jsxs(Ts,{children:[m.jsx(Rn,{sx:{fontWeight:"bold"},children:"Display Name"}),m.jsx(Rn,{sx:{fontWeight:"bold"},children:"area_id"}),m.jsx(Rn,{width:48})]})}),m.jsx(fm,{children:n.map(y=>m.jsxs(Ts,{hover:!0,children:[m.jsx(Rn,{children:y.name}),m.jsx(Rn,{children:m.jsx("code",{children:y.area_id})}),m.jsx(Rn,{children:m.jsx(cn,{title:u===y.area_id?"Copied!":"Copy ID",children:m.jsx(_n,{size:"small",onClick:()=>g(y.area_id),children:m.jsx(Eh,{fontSize:"small"})})})})]},y.area_id))})]})})}),i&&m.jsxs(m.Fragment,{children:[m.jsx(ie,{variant:"h6",sx:{mb:2},children:"Other Filter Values"}),m.jsxs(hd,{defaultExpanded:!0,children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(y8e,{sx:{mr:1}}),m.jsxs(ie,{children:["Domains (",i.domains.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"domain"'}),"."]}),m.jsx(o0,{values:i.domains,copiedId:u,onCopy:g})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(t8e,{sx:{mr:1}}),m.jsxs(ie,{children:["Platforms / Integrations (",i.platforms.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"platform"'}),"."]}),m.jsx(o0,{values:i.platforms,copiedId:u,onCopy:g})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(NB,{sx:{mr:1}}),m.jsxs(ie,{children:["Entity Categories (",i.entityCategories.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"entity_category"'}),"."]}),m.jsx(o0,{values:i.entityCategories,copiedId:u,onCopy:g})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(NB,{sx:{mr:1}}),m.jsxs(ie,{children:["Device Classes (",i.deviceClasses.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"device_class"'}),"."]}),m.jsx(o0,{values:i.deviceClasses,copiedId:u,onCopy:g,searchable:!0})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(ss,{sx:{mr:1}}),m.jsxs(ie,{children:["Device Names (",i.deviceNames.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"device_name"'}),"."]}),m.jsx(o0,{values:i.deviceNames,copiedId:u,onCopy:g,searchable:!0})]})]}),m.jsxs(hd,{children:[m.jsxs(md,{expandIcon:m.jsx(nu,{}),children:[m.jsx(ss,{sx:{mr:1}}),m.jsxs(ie,{children:["Product Names (",i.productNames.length,")"]})]}),m.jsxs(pd,{sx:{p:0},children:[m.jsxs(ie,{variant:"body2",color:"text.secondary",sx:{px:2,pb:1},children:["Use with filter type ",m.jsx("b",{children:'"product_name"'}),"."]}),m.jsx(o0,{values:i.productNames,copiedId:u,onCopy:g,searchable:!0})]})]})]})]})};async function fet(){const e=await fetch("api/lock-credentials");if(!e.ok)throw new Error(`Failed to fetch lock credentials: ${e.statusText}`);return e.json()}async function het(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`Failed to update lock credential: ${n.statusText}`)}return n.json()}async function pet(e,t){const n=await fetch(`api/lock-credentials/${encodeURIComponent(e)}/enabled`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:t})});if(!n.ok){const r=await n.json().catch(()=>({}));throw new Error(r.error||`Failed to toggle credential: ${n.statusText}`)}return n.json()}async function met(e){const t=await fetch(`api/lock-credentials/${encodeURIComponent(e)}`,{method:"DELETE"});if(!t.ok)throw new Error(`Failed to delete lock credential: ${t.statusText}`)}const get=({open:e,onClose:t,onSave:n,initialEntityId:r="",initialName:i="",isEdit:o=!1})=>{const[s,a]=_.useState(r),[l,c]=_.useState(""),[u,f]=_.useState(i),[h,g]=_.useState(""),[y,b]=_.useState(!1);_.useEffect(()=>{e&&(a(r),f(i),c(""),g(""))},[e,r,i]);const v=async()=>{if(!s.trim()){g("Entity ID is required");return}if(!l||l.length<4||l.length>8){g("PIN must be 4-8 digits");return}if(!/^\d+$/.test(l)){g("PIN must contain only digits");return}b(!0);try{await n(s.trim(),l,u.trim()),t()}catch(S){g(S instanceof Error?S.message:"Failed to save")}finally{b(!1)}};return m.jsxs(vu,{open:e,onClose:t,maxWidth:"sm",fullWidth:!0,children:[m.jsx(Su,{children:o?"Edit Lock Credential":"Add Lock Credential"}),m.jsx(xu,{children:m.jsxs(le,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[h&&m.jsx(kn,{severity:"error",children:h}),m.jsx(Lr,{label:"Lock Entity ID",placeholder:"lock.front_door",value:s,onChange:S=>a(S.target.value),disabled:o,fullWidth:!0,helperText:"The Home Assistant entity ID of the lock"}),m.jsx(Lr,{label:"PIN Code",type:"password",placeholder:"1234",value:l,onChange:S=>c(S.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]*"}}),m.jsx(Lr,{label:"Name (optional)",placeholder:"Front Door",value:u,onChange:S=>f(S.target.value),fullWidth:!0,helperText:"Friendly name for this credential"})]})}),m.jsxs(Xd,{children:[m.jsx(kt,{onClick:t,disabled:y,children:"Cancel"}),m.jsx(kt,{onClick:v,variant:"contained",disabled:y,startIcon:y?m.jsx(Hr,{size:16}):m.jsx(o6,{}),children:"Save"})]})]})},yet=()=>{const[e,t]=_.useState([]),[n,r]=_.useState(!0),[i,o]=_.useState(null),[s,a]=_.useState(!1),[l,c]=_.useState(null),u=_.useCallback(async()=>{r(!0);try{const v=await fet();t(v.credentials),o(null)}catch(v){o(v instanceof Error?v.message:"Failed to load credentials")}finally{r(!1)}},[]);_.useEffect(()=>{u()},[u]);const f=async(v,S,C)=>{await het(v,{entityId:v,pinCode:S,name:C||void 0,enabled:!0}),await u()},h=async v=>{if(confirm("Are you sure you want to delete this credential?"))try{await met(v),await u()}catch(S){o(S instanceof Error?S.message:"Failed to delete")}},g=async v=>{try{await pet(v.entityId,!v.enabled),await u()}catch(S){o(S instanceof Error?S.message:"Failed to update")}},y=v=>{c(v),a(!0)},b=()=>{c(null),a(!0)};return m.jsxs(le,{sx:{p:2},children:[m.jsxs(le,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[m.jsxs(ie,{variant:"h5",component:"h1",children:[m.jsx(ac,{sx:{mr:1,verticalAlign:"middle"}}),"Lock Credentials"]}),m.jsx(kt,{variant:"contained",startIcon:m.jsx(hc,{}),onClick:b,children:"Add Credential"})]}),m.jsx(kn,{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."}),i&&m.jsx(kn,{severity:"error",sx:{mb:2},children:i}),n?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(Hr,{})}):e.length===0?m.jsx(tr,{children:m.jsxs(gr,{sx:{textAlign:"center",py:4},children:[m.jsx(ac,{sx:{fontSize:48,color:"text.secondary",mb:2}}),m.jsx(ie,{variant:"h6",color:"text.secondary",children:"No lock credentials configured"}),m.jsx(ie,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"Add a PIN code for your Matter locks to enable remote lock/unlock"}),m.jsx(kt,{variant:"outlined",startIcon:m.jsx(hc,{}),onClick:b,children:"Add Your First Credential"})]})}):m.jsx(tr,{children:m.jsx(vc,{children:e.map((v,S)=>m.jsxs(gf,{divider:S<e.length-1,onClick:()=>y(v),sx:{cursor:"pointer","&:hover":{bgcolor:"action.hover"}},children:[m.jsx(Ul,{children:m.jsx(ac,{color:v.enabled?"primary":"disabled"})}),m.jsx(Va,{primary:v.name||v.entityId,secondary:m.jsxs(m.Fragment,{children:[v.name&&m.jsx(ie,{component:"span",variant:"body2",color:"text.secondary",children:v.entityId}),m.jsx(ie,{component:"span",variant:"body2",color:"text.secondary",sx:{ml:v.name?2:0},children:"PIN: ****"})]})}),m.jsxs(WO,{children:[m.jsx(cn,{title:v.enabled?"Disable":"Enable",children:m.jsx(Ph,{edge:"end",checked:v.enabled,onChange:C=>{C.stopPropagation(),g(v)}})}),m.jsx(cn,{title:"Delete",children:m.jsx(_n,{edge:"end",onClick:C=>{C.stopPropagation(),h(v.entityId)},sx:{ml:1},children:m.jsx(Zd,{})})})]})]},v.entityId))})}),m.jsx(get,{open:s,onClose:()=>a(!1),onSave:f,initialEntityId:l?.entityId,initialName:l?.name,isEdit:!!l})]})};function Mi(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=Mi(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var bet={value:()=>{}};function $C(){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 w4(n)}function w4(e){this._=e}function vet(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}})}w4.prototype=$C.prototype={constructor:w4,on:function(e,t){var n=this._,r=vet(e+"",n),i,o=-1,s=r.length;if(arguments.length<2){for(;++o<s;)if((i=(e=r[o]).type)&&(i=xet(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]=wG(n[i],e.name,t);else if(t==null)for(i in n)n[i]=wG(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 w4(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 xet(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function wG(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=bet,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var FD="http://www.w3.org/1999/xhtml";const CG={svg:"http://www.w3.org/2000/svg",xhtml:FD,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function LC(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),CG.hasOwnProperty(t)?{space:CG[t],local:e}:e}function wet(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===FD&&t.documentElement.namespaceURI===FD?t.createElement(e):t.createElementNS(n,e)}}function Cet(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function Ise(e){var t=LC(e);return(t.local?Cet:wet)(t)}function Eet(){}function tI(e){return e==null?Eet:function(){return this.querySelector(e)}}function Aet(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 Bs(r,this._parents)}function ket(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function _et(){return[]}function Pse(e){return e==null?_et:function(){return this.querySelectorAll(e)}}function Det(e){return function(){return ket(e.apply(this,arguments))}}function Oet(e){typeof e=="function"?e=Det(e):e=Pse(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 Bs(r,i)}function jse(e){return function(){return this.matches(e)}}function $se(e){return function(t){return t.matches(e)}}var Tet=Array.prototype.find;function Met(e){return function(){return Tet.call(this.children,e)}}function Ret(){return this.firstElementChild}function Iet(e){return this.select(e==null?Ret:Met(typeof e=="function"?e:$se(e)))}var Pet=Array.prototype.filter;function jet(){return Array.from(this.children)}function $et(e){return function(){return Pet.call(this.children,e)}}function Let(e){return this.selectAll(e==null?jet:$et(typeof e=="function"?e:$se(e)))}function Net(e){typeof e!="function"&&(e=jse(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 Bs(r,this._parents)}function Lse(e){return new Array(e.length)}function Fet(){return new Bs(this._enter||this._groups.map(Lse),this._parents)}function pS(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}pS.prototype={constructor:pS,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 Bet(e){return function(){return e}}function zet(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 pS(e,o[s]);for(;s<l;++s)(a=t[s])&&(i[s]=a)}function Het(e,t,n,r,i,o,s){var a,l,c=new Map,u=t.length,f=o.length,h=new Array(u),g;for(a=0;a<u;++a)(l=t[a])&&(h[a]=g=s.call(l,l.__data__,a,t)+"",c.has(g)?i[a]=l:c.set(g,l));for(a=0;a<f;++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 pS(e,o[a]);for(a=0;a<u;++a)(l=t[a])&&c.get(h[a])===l&&(i[a]=l)}function Uet(e){return e.__data__}function Vet(e,t){if(!arguments.length)return Array.from(this,Uet);var n=t?Het:zet,r=this._parents,i=this._groups;typeof e!="function"&&(e=Bet(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],f=i[c],h=f.length,g=Wet(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(h);n(u,f,b,v,S,g,t);for(var C=0,w=0,A,E;C<y;++C)if(A=b[C]){for(C>=w&&(w=C+1);!(E=v[w])&&++w<y;);A._next=E||null}}return s=new Bs(s,r),s._enter=a,s._exit=l,s}function Wet(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function qet(){return new Bs(this._exit||this._groups.map(Lse),this._parents)}function Get(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 Ket(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],f=c.length,h=a[l]=new Array(f),g,y=0;y<f;++y)(g=c[y]||u[y])&&(h[y]=g);for(;l<i;++l)a[l]=n[l];return new Bs(a,this._parents)}function Yet(){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 Xet(e){e||(e=Zet);function t(f,h){return f&&h?e(f.__data__,h.__data__):!f-!h}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 Bs(i,this._parents).order()}function Zet(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Jet(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Qet(){return Array.from(this)}function ett(){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 ttt(){let e=0;for(const t of this)++e;return e}function ntt(){return!this.node()}function rtt(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 itt(e){return function(){this.removeAttribute(e)}}function ott(e){return function(){this.removeAttributeNS(e.space,e.local)}}function stt(e,t){return function(){this.setAttribute(e,t)}}function att(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function ltt(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function ctt(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 utt(e,t){var n=LC(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?ott:itt:typeof t=="function"?n.local?ctt:ltt:n.local?att:stt)(n,t))}function Nse(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function dtt(e){return function(){this.style.removeProperty(e)}}function ftt(e,t,n){return function(){this.style.setProperty(e,t,n)}}function htt(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function ptt(e,t,n){return arguments.length>1?this.each((t==null?dtt:typeof t=="function"?htt:ftt)(e,t,n??"")):Mm(this.node(),e)}function Mm(e,t){return e.style.getPropertyValue(t)||Nse(e).getComputedStyle(e,null).getPropertyValue(t)}function mtt(e){return function(){delete this[e]}}function gtt(e,t){return function(){this[e]=t}}function ytt(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function btt(e,t){return arguments.length>1?this.each((t==null?mtt:typeof t=="function"?ytt:gtt)(e,t)):this.node()[e]}function Fse(e){return e.trim().split(/^|\s+/)}function nI(e){return e.classList||new Bse(e)}function Bse(e){this._node=e,this._names=Fse(e.getAttribute("class")||"")}Bse.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 zse(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Hse(e,t){for(var n=nI(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function vtt(e){return function(){zse(this,e)}}function xtt(e){return function(){Hse(this,e)}}function Stt(e,t){return function(){(t.apply(this,arguments)?zse:Hse)(this,e)}}function wtt(e,t){var n=Fse(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"?Stt:t?vtt:xtt)(n,t))}function Ctt(){this.textContent=""}function Ett(e){return function(){this.textContent=e}}function Att(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function ktt(e){return arguments.length?this.each(e==null?Ctt:(typeof e=="function"?Att:Ett)(e)):this.node().textContent}function _tt(){this.innerHTML=""}function Dtt(e){return function(){this.innerHTML=e}}function Ott(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function Ttt(e){return arguments.length?this.each(e==null?_tt:(typeof e=="function"?Ott:Dtt)(e)):this.node().innerHTML}function Mtt(){this.nextSibling&&this.parentNode.appendChild(this)}function Rtt(){return this.each(Mtt)}function Itt(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Ptt(){return this.each(Itt)}function jtt(e){var t=typeof e=="function"?e:Ise(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function $tt(){return null}function Ltt(e,t){var n=typeof e=="function"?e:Ise(e),r=t==null?$tt:typeof t=="function"?t:tI(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Ntt(){var e=this.parentNode;e&&e.removeChild(this)}function Ftt(){return this.each(Ntt)}function Btt(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function ztt(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Htt(e){return this.select(e?ztt:Btt)}function Utt(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Vtt(e){return function(t){e.call(this,t,this.__data__)}}function Wtt(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 qtt(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 Gtt(e,t,n){return function(){var r=this.__on,i,o=Vtt(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 Ktt(e,t,n){var r=Wtt(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?Gtt:qtt,i=0;i<o;++i)this.each(a(r[i],t,n));return this}function Use(e,t,n){var r=Nse(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 Ytt(e,t){return function(){return Use(this,e,t)}}function Xtt(e,t){return function(){return Use(this,e,t.apply(this,arguments))}}function Ztt(e,t){return this.each((typeof t=="function"?Xtt:Ytt)(e,t))}function*Jtt(){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 Vse=[null];function Bs(e,t){this._groups=e,this._parents=t}function ev(){return new Bs([[document.documentElement]],Vse)}function Qtt(){return this}Bs.prototype=ev.prototype={constructor:Bs,select:Aet,selectAll:Oet,selectChild:Iet,selectChildren:Let,filter:Net,data:Vet,enter:Fet,exit:qet,join:Get,merge:Ket,selection:Qtt,order:Yet,sort:Xet,call:Jet,nodes:Qet,node:ett,size:ttt,empty:ntt,each:rtt,attr:utt,style:ptt,property:btt,classed:wtt,text:ktt,html:Ttt,raise:Rtt,lower:Ptt,append:jtt,insert:Ltt,remove:Ftt,clone:Htt,datum:Utt,on:Ktt,dispatch:Ztt,[Symbol.iterator]:Jtt};function Rs(e){return typeof e=="string"?new Bs([[document.querySelector(e)]],[document.documentElement]):new Bs([[e]],Vse)}function ent(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Fa(e,t){if(e=ent(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 tnt={passive:!1},Y2={capture:!0,passive:!1};function UA(e){e.stopImmediatePropagation()}function em(e){e.preventDefault(),e.stopImmediatePropagation()}function Wse(e){var t=e.document.documentElement,n=Rs(e).on("dragstart.drag",em,Y2);"onselectstart"in t?n.on("selectstart.drag",em,Y2):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function qse(e,t){var n=e.document.documentElement,r=Rs(e).on("dragstart.drag",null);t&&(r.on("click.drag",em,Y2),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 y5=e=>()=>e;function BD(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}})}BD.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function nnt(e){return!e.ctrlKey&&!e.button}function rnt(){return this.parentNode}function int(e,t){return t??{x:e.x,y:e.y}}function ont(){return navigator.maxTouchPoints||"ontouchstart"in this}function Gse(){var e=nnt,t=rnt,n=int,r=ont,i={},o=$C("start","drag","end"),s=0,a,l,c,u,f=0;function h(A){A.on("mousedown.drag",g).filter(r).on("touchstart.drag",v).on("touchmove.drag",S,tnt).on("touchend.drag touchcancel.drag",C).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function g(A,E){if(!(u||!e.call(this,A,E))){var O=w(this,t.call(this,A,E),A,E,"mouse");O&&(Rs(A.view).on("mousemove.drag",y,Y2).on("mouseup.drag",b,Y2),Wse(A.view),UA(A),c=!1,a=A.clientX,l=A.clientY,O("start",A))}}function y(A){if(em(A),!c){var E=A.clientX-a,O=A.clientY-l;c=E*E+O*O>f}i.mouse("drag",A)}function b(A){Rs(A.view).on("mousemove.drag mouseup.drag",null),qse(A.view,c),em(A),i.mouse("end",A)}function v(A,E){if(e.call(this,A,E)){var O=A.changedTouches,D=t.call(this,A,E),T=O.length,I,F;for(I=0;I<T;++I)(F=w(this,D,A,E,O[I].identifier,O[I]))&&(UA(A),F("start",A,O[I]))}}function S(A){var E=A.changedTouches,O=E.length,D,T;for(D=0;D<O;++D)(T=i[E[D].identifier])&&(em(A),T("drag",A,E[D]))}function C(A){var E=A.changedTouches,O=E.length,D,T;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),D=0;D<O;++D)(T=i[E[D].identifier])&&(UA(A),T("end",A,E[D]))}function w(A,E,O,D,T,I){var F=o.copy(),L=Fa(I||O,E),R,$,j;if((j=n.call(A,new BD("beforestart",{sourceEvent:O,target:h,identifier:T,active:s,x:L[0],y:L[1],dx:0,dy:0,dispatch:F}),D))!=null)return R=j.x-L[0]||0,$=j.y-L[1]||0,function z(N,W,H){var U=L,K;switch(N){case"start":i[T]=z,K=s++;break;case"end":delete i[T],--s;case"drag":L=Fa(H||W,E),K=s;break}F.call(N,A,new BD(N,{sourceEvent:W,subject:j,target:h,identifier:T,active:K,x:L[0]+R,y:L[1]+$,dx:L[0]-U[0],dy:L[1]-U[1],dispatch:F}),D)}}return h.filter=function(A){return arguments.length?(e=typeof A=="function"?A:y5(!!A),h):e},h.container=function(A){return arguments.length?(t=typeof A=="function"?A:y5(A),h):t},h.subject=function(A){return arguments.length?(n=typeof A=="function"?A:y5(A),h):n},h.touchable=function(A){return arguments.length?(r=typeof A=="function"?A:y5(!!A),h):r},h.on=function(){var A=o.on.apply(o,arguments);return A===o?h:A},h.clickDistance=function(A){return arguments.length?(f=(A=+A)*A,h):Math.sqrt(f)},h}function rI(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Kse(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function tv(){}var X2=.7,mS=1/X2,tm="\\s*([+-]?\\d+)\\s*",Z2="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",uc="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",snt=/^#([0-9a-f]{3,8})$/,ant=new RegExp(`^rgb\\(${tm},${tm},${tm}\\)$`),lnt=new RegExp(`^rgb\\(${uc},${uc},${uc}\\)$`),cnt=new RegExp(`^rgba\\(${tm},${tm},${tm},${Z2}\\)$`),unt=new RegExp(`^rgba\\(${uc},${uc},${uc},${Z2}\\)$`),dnt=new RegExp(`^hsl\\(${Z2},${uc},${uc}\\)$`),fnt=new RegExp(`^hsla\\(${Z2},${uc},${uc},${Z2}\\)$`),EG={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,qh,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:AG,formatHex:AG,formatHex8:hnt,formatHsl:pnt,formatRgb:kG,toString:kG});function AG(){return this.rgb().formatHex()}function hnt(){return this.rgb().formatHex8()}function pnt(){return Yse(this).formatHsl()}function kG(){return this.rgb().formatRgb()}function qh(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=snt.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?_G(t):n===3?new rs(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?b5(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?b5(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=ant.exec(e))?new rs(t[1],t[2],t[3],1):(t=lnt.exec(e))?new rs(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=cnt.exec(e))?b5(t[1],t[2],t[3],t[4]):(t=unt.exec(e))?b5(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=dnt.exec(e))?TG(t[1],t[2]/100,t[3]/100,1):(t=fnt.exec(e))?TG(t[1],t[2]/100,t[3]/100,t[4]):EG.hasOwnProperty(e)?_G(EG[e]):e==="transparent"?new rs(NaN,NaN,NaN,0):null}function _G(e){return new rs(e>>16&255,e>>8&255,e&255,1)}function b5(e,t,n,r){return r<=0&&(e=t=n=NaN),new rs(e,t,n,r)}function mnt(e){return e instanceof tv||(e=qh(e)),e?(e=e.rgb(),new rs(e.r,e.g,e.b,e.opacity)):new rs}function zD(e,t,n,r){return arguments.length===1?mnt(e):new rs(e,t,n,r??1)}function rs(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}rI(rs,zD,Kse(tv,{brighter(e){return e=e==null?mS:Math.pow(mS,e),new rs(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?X2:Math.pow(X2,e),new rs(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new rs(Dh(this.r),Dh(this.g),Dh(this.b),gS(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:DG,formatHex:DG,formatHex8:gnt,formatRgb:OG,toString:OG}));function DG(){return`#${wh(this.r)}${wh(this.g)}${wh(this.b)}`}function gnt(){return`#${wh(this.r)}${wh(this.g)}${wh(this.b)}${wh((isNaN(this.opacity)?1:this.opacity)*255)}`}function OG(){const e=gS(this.opacity);return`${e===1?"rgb(":"rgba("}${Dh(this.r)}, ${Dh(this.g)}, ${Dh(this.b)}${e===1?")":`, ${e})`}`}function gS(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Dh(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function wh(e){return e=Dh(e),(e<16?"0":"")+e.toString(16)}function TG(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ua(e,t,n,r)}function Yse(e){if(e instanceof Ua)return new Ua(e.h,e.s,e.l,e.opacity);if(e instanceof tv||(e=qh(e)),!e)return new Ua;if(e instanceof Ua)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 Ua(s,a,l,e.opacity)}function ynt(e,t,n,r){return arguments.length===1?Yse(e):new Ua(e,t,n,r??1)}function Ua(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}rI(Ua,ynt,Kse(tv,{brighter(e){return e=e==null?mS:Math.pow(mS,e),new Ua(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?X2:Math.pow(X2,e),new Ua(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 rs(VA(e>=240?e-240:e+120,i,r),VA(e,i,r),VA(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new Ua(MG(this.h),v5(this.s),v5(this.l),gS(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=gS(this.opacity);return`${e===1?"hsl(":"hsla("}${MG(this.h)}, ${v5(this.s)*100}%, ${v5(this.l)*100}%${e===1?")":`, ${e})`}`}}));function MG(e){return e=(e||0)%360,e<0?e+360:e}function v5(e){return Math.max(0,Math.min(1,e||0))}function VA(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 bnt(e,t){return function(n){return e+n*t}}function vnt(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 xnt(e){return(e=+e)==1?Xse:function(t,n){return n-t?vnt(t,n,e):iI(isNaN(t)?n:t)}}function Xse(e,t){var n=t-e;return n?bnt(e,n):iI(isNaN(e)?t:e)}const yS=(function e(t){var n=xnt(t);function r(i,o){var s=n((i=zD(i)).r,(o=zD(o)).r),a=n(i.g,o.g),l=n(i.b,o.b),c=Xse(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 Snt(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 wnt(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Cnt(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]=Py(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 Ent(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function $l(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function Ant(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]=Py(e[i],t[i]):r[i]=t[i];return function(o){for(i in n)r[i]=n[i](o);return r}}var HD=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,WA=new RegExp(HD.source,"g");function knt(e){return function(){return e}}function _nt(e){return function(t){return e(t)+""}}function Zse(e,t){var n=HD.lastIndex=WA.lastIndex=0,r,i,o,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=HD.exec(e))&&(i=WA.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:$l(r,i)})),n=WA.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?l[0]?_nt(l[0].x):knt(t):(t=l.length,function(c){for(var u=0,f;u<t;++u)a[(f=l[u]).i]=f.x(c);return a.join("")})}function Py(e,t){var n=typeof t,r;return t==null||n==="boolean"?iI(t):(n==="number"?$l:n==="string"?(r=qh(t))?(t=r,yS):Zse:t instanceof qh?yS:t instanceof Date?Ent:wnt(t)?Snt:Array.isArray(t)?Cnt:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?Ant:$l)(e,t)}var RG=180/Math.PI,UD={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Jse(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)*RG,skewX:Math.atan(l)*RG,scaleX:s,scaleY:a}}var x5;function Dnt(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?UD:Jse(t.a,t.b,t.c,t.d,t.e,t.f)}function Ont(e){return e==null||(x5||(x5=document.createElementNS("http://www.w3.org/2000/svg","g")),x5.setAttribute("transform",e),!(e=x5.transform.baseVal.consolidate()))?UD:(e=e.matrix,Jse(e.a,e.b,e.c,e.d,e.e,e.f))}function Qse(e,t,n,r){function i(c){return c.length?c.pop()+" ":""}function o(c,u,f,h,g,y){if(c!==f||u!==h){var b=g.push("translate(",null,t,null,n);y.push({i:b-4,x:$l(c,f)},{i:b-2,x:$l(u,h)})}else(f||h)&&g.push("translate("+f+t+h+n)}function s(c,u,f,h){c!==u?(c-u>180?u+=360:u-c>180&&(c+=360),h.push({i:f.push(i(f)+"rotate(",null,r)-2,x:$l(c,u)})):u&&f.push(i(f)+"rotate("+u+r)}function a(c,u,f,h){c!==u?h.push({i:f.push(i(f)+"skewX(",null,r)-2,x:$l(c,u)}):u&&f.push(i(f)+"skewX("+u+r)}function l(c,u,f,h,g,y){if(c!==f||u!==h){var b=g.push(i(g)+"scale(",null,",",null,")");y.push({i:b-4,x:$l(c,f)},{i:b-2,x:$l(u,h)})}else(f!==1||h!==1)&&g.push(i(g)+"scale("+f+","+h+")")}return function(c,u){var f=[],h=[];return c=e(c),u=e(u),o(c.translateX,c.translateY,u.translateX,u.translateY,f,h),s(c.rotate,u.rotate,f,h),a(c.skewX,u.skewX,f,h),l(c.scaleX,c.scaleY,u.scaleX,u.scaleY,f,h),c=u=null,function(g){for(var y=-1,b=h.length,v;++y<b;)f[(v=h[y]).i]=v.x(g);return f.join("")}}}var Tnt=Qse(Dnt,"px, ","px)","deg)"),Mnt=Qse(Ont,", ",")",")"),Rnt=1e-12;function IG(e){return((e=Math.exp(e))+1/e)/2}function Int(e){return((e=Math.exp(e))-1/e)/2}function Pnt(e){return((e=Math.exp(2*e))-1)/(e+1)}const C4=(function e(t,n,r){function i(o,s){var a=o[0],l=o[1],c=o[2],u=s[0],f=s[1],h=s[2],g=u-a,y=f-l,b=g*g+y*y,v,S;if(b<Rnt)S=Math.log(h/c)/t,v=function(D){return[a+D*g,l+D*y,c*Math.exp(t*D*S)]};else{var C=Math.sqrt(b),w=(h*h-c*c+r*b)/(2*c*n*C),A=(h*h-c*c-r*b)/(2*h*n*C),E=Math.log(Math.sqrt(w*w+1)-w),O=Math.log(Math.sqrt(A*A+1)-A);S=(O-E)/t,v=function(D){var T=D*S,I=IG(E),F=c/(n*C)*(I*Pnt(t*T+E)-Int(E));return[a+F*g,l+F*y,c*I/IG(t*T+E)]}}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 Rm=0,ny=0,j1=0,eae=1e3,bS,ry,vS=0,Gh=0,NC=0,J2=typeof performance=="object"&&performance.now?performance:Date,tae=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function oI(){return Gh||(tae(jnt),Gh=J2.now()+NC)}function jnt(){Gh=0}function xS(){this._call=this._time=this._next=null}xS.prototype=nae.prototype={constructor:xS,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&&ry!==this&&(ry?ry._next=this:bS=this,ry=this),this._call=e,this._time=n,VD()},stop:function(){this._call&&(this._call=null,this._time=1/0,VD())}};function nae(e,t,n){var r=new xS;return r.restart(e,t,n),r}function $nt(){oI(),++Rm;for(var e=bS,t;e;)(t=Gh-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Rm}function PG(){Gh=(vS=J2.now())+NC,Rm=ny=0;try{$nt()}finally{Rm=0,Nnt(),Gh=0}}function Lnt(){var e=J2.now(),t=e-vS;t>eae&&(NC-=t,vS=e)}function Nnt(){for(var e,t=bS,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:bS=n);ry=e,VD(r)}function VD(e){if(!Rm){ny&&(ny=clearTimeout(ny));var t=e-Gh;t>24?(e<1/0&&(ny=setTimeout(PG,e-J2.now()-NC)),j1&&(j1=clearInterval(j1))):(j1||(vS=J2.now(),j1=setInterval(Lnt,eae)),Rm=1,tae(PG))}}function jG(e,t,n){var r=new xS;return t=t==null?0:+t,r.restart(i=>{r.stop(),e(i+t)},t,n),r}var Fnt=$C("start","end","cancel","interrupt"),Bnt=[],rae=0,$G=1,WD=2,E4=3,LG=4,qD=5,A4=6;function FC(e,t,n,r,i,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;znt(e,n,{name:t,index:r,group:i,on:Fnt,tween:Bnt,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:rae})}function sI(e,t){var n=ml(e,t);if(n.state>rae)throw new Error("too late; already scheduled");return n}function Ac(e,t){var n=ml(e,t);if(n.state>E4)throw new Error("too late; already running");return n}function ml(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function znt(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=nae(o,0,n.time);function o(c){n.state=$G,n.timer.restart(s,n.delay,n.time),n.delay<=c&&s(c-n.delay)}function s(c){var u,f,h,g;if(n.state!==$G)return l();for(u in r)if(g=r[u],g.name===n.name){if(g.state===E4)return jG(s);g.state===LG?(g.state=A4,g.timer.stop(),g.on.call("interrupt",e,e.__data__,g.index,g.group),delete r[u]):+u<t&&(g.state=A4,g.timer.stop(),g.on.call("cancel",e,e.__data__,g.index,g.group),delete r[u])}if(jG(function(){n.state===E4&&(n.state=LG,n.timer.restart(a,n.delay,n.time),a(c))}),n.state=WD,n.on.call("start",e,e.__data__,n.index,n.group),n.state===WD){for(n.state=E4,i=new Array(h=n.tween.length),u=0,f=-1;u<h;++u)(g=n.tween[u].value.call(e,e.__data__,n.index,n.group))&&(i[++f]=g);i.length=f+1}}function a(c){for(var u=c<n.duration?n.ease.call(null,c/n.duration):(n.timer.restart(l),n.state=qD,1),f=-1,h=i.length;++f<h;)i[f].call(e,u);n.state===qD&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=A4,n.timer.stop(),delete r[t];for(var c in r)return;delete e.__transition}}function k4(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>WD&&r.state<qD,r.state=A4,r.timer.stop(),r.on.call(i?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}o&&delete e.__transition}}function Hnt(e){return this.each(function(){k4(this,e)})}function Unt(e,t){var n,r;return function(){var i=Ac(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 Vnt(e,t,n){var r,i;if(typeof n!="function")throw new Error;return function(){var o=Ac(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 Wnt(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=ml(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?Unt:Vnt)(n,e,t))}function aI(e,t,n){var r=e._id;return e.each(function(){var i=Ac(this,r);(i.value||(i.value={}))[t]=n.apply(this,arguments)}),function(i){return ml(i,r).value[t]}}function iae(e,t){var n;return(typeof t=="number"?$l:t instanceof qh?yS:(n=qh(t))?(t=n,yS):Zse)(e,t)}function qnt(e){return function(){this.removeAttribute(e)}}function Gnt(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Knt(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 Ynt(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 Xnt(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 Znt(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 Jnt(e,t){var n=LC(e),r=n==="transform"?Mnt:iae;return this.attrTween(e,typeof t=="function"?(n.local?Znt:Xnt)(n,r,aI(this,"attr."+e,t)):t==null?(n.local?Gnt:qnt)(n):(n.local?Ynt:Knt)(n,r,t))}function Qnt(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function ert(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function trt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&ert(e,o)),n}return i._value=t,i}function nrt(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&Qnt(e,o)),n}return i._value=t,i}function rrt(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=LC(e);return this.tween(n,(r.local?trt:nrt)(r,t))}function irt(e,t){return function(){sI(this,e).delay=+t.apply(this,arguments)}}function ort(e,t){return t=+t,function(){sI(this,e).delay=t}}function srt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?irt:ort)(t,e)):ml(this.node(),t).delay}function art(e,t){return function(){Ac(this,e).duration=+t.apply(this,arguments)}}function lrt(e,t){return t=+t,function(){Ac(this,e).duration=t}}function crt(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?art:lrt)(t,e)):ml(this.node(),t).duration}function urt(e,t){if(typeof t!="function")throw new Error;return function(){Ac(this,e).ease=t}}function drt(e){var t=this._id;return arguments.length?this.each(urt(t,e)):ml(this.node(),t).ease}function frt(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ac(this,e).ease=n}}function hrt(e){if(typeof e!="function")throw new Error;return this.each(frt(this._id,e))}function prt(e){typeof e!="function"&&(e=jse(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 _u(r,this._parents,this._name,this._id)}function mrt(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,f=s[a]=new Array(u),h,g=0;g<u;++g)(h=l[g]||c[g])&&(f[g]=h);for(;a<r;++a)s[a]=t[a];return new _u(s,this._parents,this._name,this._id)}function grt(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 yrt(e,t,n){var r,i,o=grt(t)?sI:Ac;return function(){var s=o(this,e),a=s.on;a!==r&&(i=(r=a).copy()).on(t,n),s.on=i}}function brt(e,t){var n=this._id;return arguments.length<2?ml(this.node(),n).on.on(e):this.each(yrt(n,e,t))}function vrt(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function xrt(){return this.on("end.remove",vrt(this._id))}function Srt(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,f,h=0;h<l;++h)(u=a[h])&&(f=e.call(u,u.__data__,h,a))&&("__data__"in u&&(f.__data__=u.__data__),c[h]=f,FC(c[h],t,n,h,c,ml(u,n)));return new _u(o,this._parents,t,n)}function wrt(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Pse(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,f=0;f<c;++f)if(u=l[f]){for(var h=e.call(u,u.__data__,f,l),g,y=ml(u,n),b=0,v=h.length;b<v;++b)(g=h[b])&&FC(g,t,n,b,h,y);o.push(h),s.push(u)}return new _u(o,s,t,n)}var Crt=ev.prototype.constructor;function Ert(){return new Crt(this._groups,this._parents)}function Art(e,t){var n,r,i;return function(){var o=Mm(this,e),s=(this.style.removeProperty(e),Mm(this,e));return o===s?null:o===n&&s===r?i:i=t(n=o,r=s)}}function oae(e){return function(){this.style.removeProperty(e)}}function krt(e,t,n){var r,i=n+"",o;return function(){var s=Mm(this,e);return s===i?null:s===r?o:o=t(r=s,n)}}function _rt(e,t,n){var r,i,o;return function(){var s=Mm(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),Mm(this,e))),s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a))}}function Drt(e,t){var n,r,i,o="style."+t,s="end."+o,a;return function(){var l=Ac(this,e),c=l.on,u=l.value[o]==null?a||(a=oae(t)):void 0;(c!==n||i!==u)&&(r=(n=c).copy()).on(s,i=u),l.on=r}}function Ort(e,t,n){var r=(e+="")=="transform"?Tnt:iae;return t==null?this.styleTween(e,Art(e,r)).on("end.style."+e,oae(e)):typeof t=="function"?this.styleTween(e,_rt(e,r,aI(this,"style."+e,t))).each(Drt(this._id,e)):this.styleTween(e,krt(e,r,t),n).on("end.style."+e,null)}function Trt(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Mrt(e,t,n){var r,i;function o(){var s=t.apply(this,arguments);return s!==i&&(r=(i=s)&&Trt(e,s,n)),r}return o._value=t,o}function Rrt(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,Mrt(e,t,n??""))}function Irt(e){return function(){this.textContent=e}}function Prt(e){return function(){var t=e(this);this.textContent=t??""}}function jrt(e){return this.tween("text",typeof e=="function"?Prt(aI(this,"text",e)):Irt(e==null?"":e+""))}function $rt(e){return function(t){this.textContent=e.call(this,t)}}function Lrt(e){var t,n;function r(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&$rt(i)),t}return r._value=e,r}function Nrt(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,Lrt(e))}function Frt(){for(var e=this._name,t=this._id,n=sae(),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=ml(l,t);FC(l,e,n,c,s,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new _u(r,this._parents,e,n)}function Brt(){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=Ac(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 zrt=0;function _u(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function sae(){return++zrt}var Zc=ev.prototype;_u.prototype={constructor:_u,select:Srt,selectAll:wrt,selectChild:Zc.selectChild,selectChildren:Zc.selectChildren,filter:prt,merge:mrt,selection:Ert,transition:Frt,call:Zc.call,nodes:Zc.nodes,node:Zc.node,size:Zc.size,empty:Zc.empty,each:Zc.each,on:brt,attr:Jnt,attrTween:rrt,style:Ort,styleTween:Rrt,text:jrt,textTween:Nrt,remove:xrt,tween:Wnt,delay:srt,duration:crt,ease:drt,easeVarying:hrt,end:Brt,[Symbol.iterator]:Zc[Symbol.iterator]};function Hrt(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Urt={time:null,delay:0,duration:250,ease:Hrt};function Vrt(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 Wrt(e){var t,n;e instanceof _u?(t=e._id,e=e._name):(t=sae(),(n=Urt).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])&&FC(l,e,t,c,s,n||Vrt(l,t));return new _u(r,this._parents,e,t)}ev.prototype.interrupt=Hnt;ev.prototype.transition=Wrt;const S5=e=>()=>e;function qrt(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 uu(e,t,n){this.k=e,this.x=t,this.y=n}uu.prototype={constructor:uu,scale:function(e){return e===1?this:new uu(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new uu(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 BC=new uu(1,0,0);aae.prototype=uu.prototype;function aae(e){for(;!e.__zoom;)if(!(e=e.parentNode))return BC;return e.__zoom}function qA(e){e.stopImmediatePropagation()}function $1(e){e.preventDefault(),e.stopImmediatePropagation()}function Grt(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Krt(){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 NG(){return this.__zoom||BC}function Yrt(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Xrt(){return navigator.maxTouchPoints||"ontouchstart"in this}function Zrt(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 lae(){var e=Grt,t=Krt,n=Zrt,r=Yrt,i=Xrt,o=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,l=C4,c=$C("start","zoom","end"),u,f,h,g=500,y=150,b=0,v=10;function S(j){j.property("__zoom",NG).on("wheel.zoom",T,{passive:!1}).on("mousedown.zoom",I).on("dblclick.zoom",F).filter(i).on("touchstart.zoom",L).on("touchmove.zoom",R).on("touchend.zoom touchcancel.zoom",$).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}S.transform=function(j,z,N,W){var H=j.selection?j.selection():j;H.property("__zoom",NG),j!==H?E(j,z,N,W):H.interrupt().each(function(){O(this,arguments).event(W).start().zoom(null,typeof z=="function"?z.apply(this,arguments):z).end()})},S.scaleBy=function(j,z,N,W){S.scaleTo(j,function(){var H=this.__zoom.k,U=typeof z=="function"?z.apply(this,arguments):z;return H*U},N,W)},S.scaleTo=function(j,z,N,W){S.transform(j,function(){var H=t.apply(this,arguments),U=this.__zoom,K=N==null?A(H):typeof N=="function"?N.apply(this,arguments):N,B=U.invert(K),q=typeof z=="function"?z.apply(this,arguments):z;return n(w(C(U,q),K,B),H,s)},N,W)},S.translateBy=function(j,z,N,W){S.transform(j,function(){return n(this.__zoom.translate(typeof z=="function"?z.apply(this,arguments):z,typeof N=="function"?N.apply(this,arguments):N),t.apply(this,arguments),s)},null,W)},S.translateTo=function(j,z,N,W,H){S.transform(j,function(){var U=t.apply(this,arguments),K=this.__zoom,B=W==null?A(U):typeof W=="function"?W.apply(this,arguments):W;return n(BC.translate(B[0],B[1]).scale(K.k).translate(typeof z=="function"?-z.apply(this,arguments):-z,typeof N=="function"?-N.apply(this,arguments):-N),U,s)},W,H)};function C(j,z){return z=Math.max(o[0],Math.min(o[1],z)),z===j.k?j:new uu(z,j.x,j.y)}function w(j,z,N){var W=z[0]-N[0]*j.k,H=z[1]-N[1]*j.k;return W===j.x&&H===j.y?j:new uu(j.k,W,H)}function A(j){return[(+j[0][0]+ +j[1][0])/2,(+j[0][1]+ +j[1][1])/2]}function E(j,z,N,W){j.on("start.zoom",function(){O(this,arguments).event(W).start()}).on("interrupt.zoom end.zoom",function(){O(this,arguments).event(W).end()}).tween("zoom",function(){var H=this,U=arguments,K=O(H,U).event(W),B=t.apply(H,U),q=N==null?A(B):typeof N=="function"?N.apply(H,U):N,X=Math.max(B[1][0]-B[0][0],B[1][1]-B[0][1]),V=H.__zoom,Y=typeof z=="function"?z.apply(H,U):z,J=l(V.invert(q).concat(X/V.k),Y.invert(q).concat(X/Y.k));return function(ne){if(ne===1)ne=Y;else{var ee=J(ne),se=X/ee[2];ne=new uu(se,q[0]-ee[0]*se,q[1]-ee[1]*se)}K.zoom(null,ne)}})}function O(j,z,N){return!N&&j.__zooming||new D(j,z)}function D(j,z){this.that=j,this.args=z,this.active=0,this.sourceEvent=null,this.extent=t.apply(j,z),this.taps=0}D.prototype={event:function(j){return j&&(this.sourceEvent=j),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(j,z){return this.mouse&&j!=="mouse"&&(this.mouse[1]=z.invert(this.mouse[0])),this.touch0&&j!=="touch"&&(this.touch0[1]=z.invert(this.touch0[0])),this.touch1&&j!=="touch"&&(this.touch1[1]=z.invert(this.touch1[0])),this.that.__zoom=z,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(j){var z=Rs(this.that).datum();c.call(j,this.that,new qrt(j,{sourceEvent:this.sourceEvent,target:S,transform:this.that.__zoom,dispatch:c}),z)}};function T(j,...z){if(!e.apply(this,arguments))return;var N=O(this,z).event(j),W=this.__zoom,H=Math.max(o[0],Math.min(o[1],W.k*Math.pow(2,r.apply(this,arguments)))),U=Fa(j);if(N.wheel)(N.mouse[0][0]!==U[0]||N.mouse[0][1]!==U[1])&&(N.mouse[1]=W.invert(N.mouse[0]=U)),clearTimeout(N.wheel);else{if(W.k===H)return;N.mouse=[U,W.invert(U)],k4(this),N.start()}$1(j),N.wheel=setTimeout(K,y),N.zoom("mouse",n(w(C(W,H),N.mouse[0],N.mouse[1]),N.extent,s));function K(){N.wheel=null,N.end()}}function I(j,...z){if(h||!e.apply(this,arguments))return;var N=j.currentTarget,W=O(this,z,!0).event(j),H=Rs(j.view).on("mousemove.zoom",q,!0).on("mouseup.zoom",X,!0),U=Fa(j,N),K=j.clientX,B=j.clientY;Wse(j.view),qA(j),W.mouse=[U,this.__zoom.invert(U)],k4(this),W.start();function q(V){if($1(V),!W.moved){var Y=V.clientX-K,J=V.clientY-B;W.moved=Y*Y+J*J>b}W.event(V).zoom("mouse",n(w(W.that.__zoom,W.mouse[0]=Fa(V,N),W.mouse[1]),W.extent,s))}function X(V){H.on("mousemove.zoom mouseup.zoom",null),qse(V.view,W.moved),$1(V),W.event(V).end()}}function F(j,...z){if(e.apply(this,arguments)){var N=this.__zoom,W=Fa(j.changedTouches?j.changedTouches[0]:j,this),H=N.invert(W),U=N.k*(j.shiftKey?.5:2),K=n(w(C(N,U),W,H),t.apply(this,z),s);$1(j),a>0?Rs(this).transition().duration(a).call(E,K,W,j):Rs(this).call(S.transform,K,W,j)}}function L(j,...z){if(e.apply(this,arguments)){var N=j.touches,W=N.length,H=O(this,z,j.changedTouches.length===W).event(j),U,K,B,q;for(qA(j),K=0;K<W;++K)B=N[K],q=Fa(B,this),q=[q,this.__zoom.invert(q),B.identifier],H.touch0?!H.touch1&&H.touch0[2]!==q[2]&&(H.touch1=q,H.taps=0):(H.touch0=q,U=!0,H.taps=1+!!u);u&&(u=clearTimeout(u)),U&&(H.taps<2&&(f=q[0],u=setTimeout(function(){u=null},g)),k4(this),H.start())}}function R(j,...z){if(this.__zooming){var N=O(this,z).event(j),W=j.changedTouches,H=W.length,U,K,B,q;for($1(j),U=0;U<H;++U)K=W[U],B=Fa(K,this),N.touch0&&N.touch0[2]===K.identifier?N.touch0[0]=B:N.touch1&&N.touch1[2]===K.identifier&&(N.touch1[0]=B);if(K=N.that.__zoom,N.touch1){var X=N.touch0[0],V=N.touch0[1],Y=N.touch1[0],J=N.touch1[1],ne=(ne=Y[0]-X[0])*ne+(ne=Y[1]-X[1])*ne,ee=(ee=J[0]-V[0])*ee+(ee=J[1]-V[1])*ee;K=C(K,Math.sqrt(ne/ee)),B=[(X[0]+Y[0])/2,(X[1]+Y[1])/2],q=[(V[0]+J[0])/2,(V[1]+J[1])/2]}else if(N.touch0)B=N.touch0[0],q=N.touch0[1];else return;N.zoom("touch",n(w(K,B,q),N.extent,s))}}function $(j,...z){if(this.__zooming){var N=O(this,z).event(j),W=j.changedTouches,H=W.length,U,K;for(qA(j),h&&clearTimeout(h),h=setTimeout(function(){h=null},g),U=0;U<H;++U)K=W[U],N.touch0&&N.touch0[2]===K.identifier?delete N.touch0:N.touch1&&N.touch1[2]===K.identifier&&delete N.touch1;if(N.touch1&&!N.touch0&&(N.touch0=N.touch1,delete N.touch1),N.touch0)N.touch0[1]=this.__zoom.invert(N.touch0[0]);else if(N.end(),N.taps===2&&(K=Fa(K,this),Math.hypot(f[0]-K[0],f[1]-K[1])<v)){var B=Rs(this).on("dblclick.zoom");B&&B.apply(this,arguments)}}}return S.wheelDelta=function(j){return arguments.length?(r=typeof j=="function"?j:S5(+j),S):r},S.filter=function(j){return arguments.length?(e=typeof j=="function"?j:S5(!!j),S):e},S.touchable=function(j){return arguments.length?(i=typeof j=="function"?j:S5(!!j),S):i},S.extent=function(j){return arguments.length?(t=typeof j=="function"?j:S5([[+j[0][0],+j[0][1]],[+j[1][0],+j[1][1]]]),S):t},S.scaleExtent=function(j){return arguments.length?(o[0]=+j[0],o[1]=+j[1],S):[o[0],o[1]]},S.translateExtent=function(j){return arguments.length?(s[0][0]=+j[0][0],s[1][0]=+j[1][0],s[0][1]=+j[0][1],s[1][1]=+j[1][1],S):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},S.constrain=function(j){return arguments.length?(n=j,S):n},S.duration=function(j){return arguments.length?(a=+j,S):a},S.interpolate=function(j){return arguments.length?(l=j,S):l},S.on=function(){var j=c.on.apply(c,arguments);return j===c?S:j},S.clickDistance=function(j){return arguments.length?(b=(j=+j)*j,S):Math.sqrt(b)},S.tapDistance=function(j){return arguments.length?(v=+j,S):v},S}const yc={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."},Q2=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],cae=["Enter"," ","Escape"],uae={"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 Im;(function(e){e.Strict="strict",e.Loose="loose"})(Im||(Im={}));var Oh;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Oh||(Oh={}));var eb;(function(e){e.Partial="partial",e.Full="full"})(eb||(eb={}));const dae={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var kd;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(kd||(kd={}));var SS;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(SS||(SS={}));var xt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(xt||(xt={}));const FG={[xt.Left]:xt.Right,[xt.Right]:xt.Left,[xt.Top]:xt.Bottom,[xt.Bottom]:xt.Top};function fae(e){return e===null?null:e?"valid":"invalid"}const hae=e=>"id"in e&&"source"in e&&"target"in e,Jrt=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),nv=(e,t=[0,0])=>{const{width:n,height:r}=ju(e),i=e.origin??t,o=n*i[0],s=r*i[1];return{x:e.position.x-o,y:e.position.y-s}},Qrt=(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?wS(s,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return zC(r,a)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return HC(n)},rv=(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=zC(n,wS(i)),r=!0)}),r?HC(n):{x:0,y:0,width:0,height:0}},cI=(e,t,[n,r,i]=[0,0,1],o=!1,s=!1)=>{const a={...ov(t,[n,r,i]),width:t.width/i,height:t.height/i},l=[];for(const c of e.values()){const{measured:u,selectable:f=!0,hidden:h=!1}=c;if(s&&!f||h)continue;const g=u.width??c.width??c.initialWidth??null,y=u.height??c.height??c.initialHeight??null,b=tb(a,jm(c)),v=(g??0)*(y??0),S=o&&b>0;(!c.internals.handleBounds||S||b>=v||c.dragging)&&l.push(c)}return l},eit=(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 tit(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 nit({nodes:e,width:t,height:n,panZoom:r,minZoom:i,maxZoom:o},s){if(e.size===0)return Promise.resolve(!0);const a=tit(e,s),l=rv(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 pae({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 f=s.extent||i;if(s.extent==="parent"&&!s.expandParent)if(!a)o?.("005",yc.error005());else{const g=a.measured.width,y=a.measured.height;g&&y&&(f=[[l,c],[l+g,c+y]])}else a&&$m(s.extent)&&(f=[[s.extent[0][0]+l,s.extent[0][1]+c],[s.extent[1][0]+l,s.extent[1][1]+c]]);const h=$m(f)?Kh(t,f,s.measured):t;return(s.measured.width===void 0||s.measured.height===void 0)&&o?.("015",yc.error015()),{position:{x:h.x-l+(s.measured.width??0)*u[0],y:h.y-c+(s.measured.height??0)*u[1]},positionAbsolute:h}}async function rit({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:i}){const o=new Set(e.map(h=>h.id)),s=[];for(const h of n){if(h.deletable===!1)continue;const g=o.has(h.id),y=!g&&h.parentId&&s.find(b=>b.id===h.parentId);(g||y)&&s.push(h)}const a=new Set(t.map(h=>h.id)),l=r.filter(h=>h.deletable!==!1),u=eit(s,l);for(const h of l)a.has(h.id)&&!u.find(y=>y.id===h.id)&&u.push(h);if(!i)return{edges:u,nodes:s};const f=await i({nodes:s,edges:u});return typeof f=="boolean"?f?{edges:u,nodes:s}:{edges:[],nodes:[]}:f}const Pm=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Kh=(e={x:0,y:0},t,n)=>({x:Pm(e.x,t[0][0],t[1][0]-(n?.width??0)),y:Pm(e.y,t[0][1],t[1][1]-(n?.height??0))});function mae(e,t,n){const{width:r,height:i}=ju(n),{x:o,y:s}=n.internals.positionAbsolute;return Kh(e,[[o,s],[o+r,s+i]],t)}const BG=(e,t,n)=>e<t?Pm(Math.abs(e-t),1,t)/t:e>n?-Pm(Math.abs(e-n),1,t)/t:0,gae=(e,t,n=15,r=40)=>{const i=BG(e.x,r,t.width-r)*n,o=BG(e.y,r,t.height-r)*n;return[i,o]},zC=(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)}),GD=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),HC=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),jm=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:nv(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}},wS=(e,t=[0,0])=>{const{x:n,y:r}=lI(e)?e.internals.positionAbsolute:nv(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)}},yae=(e,t)=>HC(zC(GD(e),GD(t))),tb=(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)},zG=e=>Ga(e.width)&&Ga(e.height)&&Ga(e.x)&&Ga(e.y),Ga=e=>!isNaN(e)&&isFinite(e),iit=(e,t)=>{},iv=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),ov=({x:e,y:t},[n,r,i],o=!1,s=[1,1])=>{const a={x:(e-n)/i,y:(t-r)/i};return o?iv(a,s):a},CS=({x:e,y:t},[n,r,i])=>({x:e*i+n,y:t*i+r});function s0(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 oit(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=s0(e,n),i=s0(e,t);return{top:r,right:i,bottom:r,left:i,x:i*2,y:r*2}}if(typeof e=="object"){const r=s0(e.top??e.y??0,n),i=s0(e.bottom??e.y??0,n),o=s0(e.left??e.x??0,t),s=s0(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 sit(e,t,n,r,i,o){const{x:s,y:a}=CS(e,[t,n,r]),{x:l,y:c}=CS({x:e.x+e.width,y:e.y+e.height},[t,n,r]),u=i-l,f=o-c;return{left:Math.floor(s),top:Math.floor(a),right:Math.floor(u),bottom:Math.floor(f)}}const uI=(e,t,n,r,i,o)=>{const s=oit(o,t,n),a=(t-s.x)/e.width,l=(n-s.y)/e.height,c=Math.min(a,l),u=Pm(c,r,i),f=e.x+e.width/2,h=e.y+e.height/2,g=t/2-f*u,y=n/2-h*u,b=sit(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}},nb=()=>typeof navigator<"u"&&navigator?.userAgent?.indexOf("Mac")>=0;function $m(e){return e!=null&&e!=="parent"}function ju(e){return{width:e.measured?.width??e.width??e.initialWidth??0,height:e.measured?.height??e.height??e.initialHeight??0}}function bae(e){return(e.measured?.width??e.width??e.initialWidth)!==void 0&&(e.measured?.height??e.height??e.initialHeight)!==void 0}function vae(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 HG(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function ait(){let e,t;return{promise:new Promise((r,i)=>{e=r,t=i}),resolve:e,reject:t}}function lit(e){return{...uae,...e||{}}}function jy(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:i}){const{x:o,y:s}=Ka(e),a=ov({x:o-(i?.left??0),y:s-(i?.top??0)},r),{x:l,y:c}=n?iv(a,t):a;return{xSnapped:l,ySnapped:c,...a}}const dI=e=>({width:e.offsetWidth,height:e.offsetHeight}),xae=e=>e?.getRootNode?.()||window?.document,cit=["INPUT","SELECT","TEXTAREA"];function Sae(e){const t=e.composedPath?.()?.[0]||e.target;return t?.nodeType!==1?!1:cit.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const wae=e=>"clientX"in e,Ka=(e,t)=>{const n=wae(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)}},UG=(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 Cae({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),f=Math.abs(c-t);return[l,c,u,f]}function w5(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function VG({pos:e,x1:t,y1:n,x2:r,y2:i,c:o}){switch(e){case xt.Left:return[t-w5(t-r,o),n];case xt.Right:return[t+w5(r-t,o),n];case xt.Top:return[t,n-w5(n-i,o)];case xt.Bottom:return[t,n+w5(i-n,o)]}}function Eae({sourceX:e,sourceY:t,sourcePosition:n=xt.Bottom,targetX:r,targetY:i,targetPosition:o=xt.Top,curvature:s=.25}){const[a,l]=VG({pos:n,x1:e,y1:t,x2:r,y2:i,c:s}),[c,u]=VG({pos:o,x1:r,y1:i,x2:e,y2:t,c:s}),[f,h,g,y]=Cae({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}`,f,h,g,y]}function Aae({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 uit({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 dit({sourceNode:e,targetNode:t,width:n,height:r,transform:i}){const o=zC(wS(e),wS(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 tb(s,HC(o))>0}const fit=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,hit=(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)),pit=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||fit;let i;return hae(e)?i={...e}:i={...e,id:r(e)},hit(i,t)?t:(i.sourceHandle===null&&delete i.sourceHandle,i.targetHandle===null&&delete i.targetHandle,t.concat(i))};function kae({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[i,o,s,a]=Aae({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,i,o,s,a]}const WG={[xt.Left]:{x:-1,y:0},[xt.Right]:{x:1,y:0},[xt.Top]:{x:0,y:-1},[xt.Bottom]:{x:0,y:1}},mit=({source:e,sourcePosition:t=xt.Bottom,target:n})=>t===xt.Left||t===xt.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},qG=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function git({source:e,sourcePosition:t=xt.Bottom,target:n,targetPosition:r=xt.Top,center:i,offset:o,stepPosition:s}){const a=WG[t],l=WG[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},f=mit({source:c,sourcePosition:t,target:u}),h=f.x!==0?"x":"y",g=f[h];let y=[],b,v;const S={x:0,y:0},C={x:0,y:0},[,,w,A]=Aae({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(a[h]*l[h]===-1){h==="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 O=[{x:b,y:c.y},{x:b,y:u.y}],D=[{x:c.x,y:v},{x:u.x,y:v}];a[h]===g?y=h==="x"?O:D:y=h==="x"?D:O}else{const O=[{x:c.x,y:u.y}],D=[{x:u.x,y:c.y}];if(h==="x"?y=a.x===g?D:O:y=a.y===g?O:D,t===r){const R=Math.abs(e[h]-n[h]);if(R<=o){const $=Math.min(o-1,o-R);a[h]===g?S[h]=(c[h]>e[h]?-1:1)*$:C[h]=(u[h]>n[h]?-1:1)*$}}if(t!==r){const R=h==="x"?"y":"x",$=a[h]===l[R],j=c[R]>u[R],z=c[R]<u[R];(a[h]===1&&(!$&&j||$&&z)||a[h]!==1&&(!$&&z||$&&j))&&(y=h==="x"?O:D)}const T={x:c.x+S.x,y:c.y+S.y},I={x:u.x+C.x,y:u.y+C.y},F=Math.max(Math.abs(T.x-y[0].x),Math.abs(I.x-y[0].x)),L=Math.max(Math.abs(T.y-y[0].y),Math.abs(I.y-y[0].y));F>=L?(b=(T.x+I.x)/2,v=y[0].y):(b=y[0].x,v=(T.y+I.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,A]}function yit(e,t,n,r){const i=Math.min(qG(e,t)/2,qG(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 KD({sourceX:e,sourceY:t,sourcePosition:n=xt.Bottom,targetX:r,targetY:i,targetPosition:o=xt.Top,borderRadius:s=5,centerX:a,centerY:l,offset:c=20,stepPosition:u=.5}){const[f,h,g,y,b]=git({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:i},targetPosition:o,center:{x:a,y:l},offset:c,stepPosition:u});return[f.reduce((S,C,w)=>{let A="";return w>0&&w<f.length-1?A=yit(f[w-1],C,f[w+1],s):A=`${w===0?"M":"L"}${C.x} ${C.y}`,S+=A,S},""),h,g,y,b]}function GG(e){return e&&!!(e.internals.handleBounds||e.handles?.length)&&!!(e.measured.width||e.width||e.initialWidth)}function bit(e){const{sourceNode:t,targetNode:n}=e;if(!GG(t)||!GG(n))return null;const r=t.internals.handleBounds||KG(t.handles),i=n.internals.handleBounds||KG(n.handles),o=YG(r?.source??[],e.sourceHandle),s=YG(e.connectionMode===Im.Strict?i?.target??[]:(i?.target??[]).concat(i?.source??[]),e.targetHandle);if(!o||!s)return e.onError?.("008",yc.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const a=o?.position||xt.Bottom,l=s?.position||xt.Top,c=Yh(t,o,a),u=Yh(n,s,l);return{sourceX:c.x,sourceY:c.y,targetX:u.x,targetY:u.y,sourcePosition:a,targetPosition:l}}function KG(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 Yh(e,t,n=xt.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??ju(e);if(r)return{x:i+s/2,y:o+a/2};switch(t?.position??n){case xt.Top:return{x:i+s/2,y:o};case xt.Right:return{x:i+s,y:o+a/2};case xt.Bottom:return{x:i+s/2,y:o+a};case xt.Left:return{x:i,y:o+a/2}}}function YG(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function YD(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function vit(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=YD(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 _ae=1e3,xit=10,fI={nodeOrigin:[0,0],nodeExtent:Q2,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},Sit={...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 wit(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=nv(i,r.nodeOrigin),s=$m(i.extent)?i.extent:r.nodeExtent,a=Kh(o,s,ju(i));i.internals.positionAbsolute=a}}function Cit(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 XD(e,t,n,r={}){const i=hI(Sit,r),o={i:0},s=new Map(t),a=i?.elevateNodesOnSelect&&!pI(i.zIndexMode)?_ae: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 f=nv(c,i.nodeOrigin),h=$m(c.extent)?c.extent:i.nodeExtent,g=Kh(f,h,ju(c));u={...i.defaults,...c,measured:{width:c.measured?.width,height:c.measured?.height},internals:{positionAbsolute:g,handleBounds:Cit(c,u),z:Dae(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 Eit(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}Eit(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*xit),i&&u.internals.rootParentIndex!==void 0&&(i.i=u.internals.rootParentIndex);const f=o&&!pI(l)?_ae:0,{x:h,y:g,z:y}=Ait(e,u,s,a,f,l),{positionAbsolute:b}=e.internals,v=h!==b.x||g!==b.y;(v||y!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:v?{x:h,y:g}:b,z:y}})}function Dae(e,t,n){const r=Ga(e.zIndex)?e.zIndex:0;return pI(n)?r:r+(e.selected?t:0)}function Ait(e,t,n,r,i,o){const{x:s,y:a}=t.internals.positionAbsolute,l=ju(e),c=nv(e,n),u=$m(e.extent)?Kh(c,e.extent,l):c;let f=Kh({x:s+u.x,y:a+u.y},r,l);e.extent==="parent"&&(f=mae(f,l,t));const h=Dae(e,i,o),g=t.internals.z??0;return{x:f.x,y:f.y,z:g>=h?g+1:h}}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??jm(a),c=yae(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=ju(a),f=a.origin??r,h=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)*f[0],S=(b-u.height)*f[1];(h>0||g>0||v||S)&&(i.push({id:l,type:"position",position:{x:a.position.x-h+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+h,y:C.position.y+g}})})),(u.width<s.width||u.height<s.height||h||g)&&i.push({id:l,type:"dimensions",setAttributes:!0,dimensions:{width:y+(h?f[0]*h-v:0),height:b+(g?f[1]*g-S:0)}})}),i}function kit(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:f}=new window.DOMMatrixReadOnly(u.transform),h=[];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=$m(y.extent)?y.extent:o;let{positionAbsolute:A}=y.internals;y.parentId&&y.extent==="parent"?A=mae(A,b,t.get(y.parentId)):w&&(A=Kh(A,w,b));const E={...y,measured:b,internals:{...y.internals,positionAbsolute:A,handleBounds:{source:UG("source",g.nodeElement,C,f,y.id),target:UG("target",g.nodeElement,C,f,y.id)}}};t.set(y.id,E),y.parentId&&mI(E,t,n,{nodeOrigin:i,zIndexMode:s}),l=!0,v&&(c.push({id:y.id,type:"dimensions",dimensions:b}),y.expandParent&&y.parentId&&h.push({id:y.id,parentId:y.parentId,rect:jm(E,i)}))}}if(h.length>0){const g=gI(h,t,n,i);c.push(...g)}return{changes:c,updatedInternals:l}}async function _it({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 XG(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 Oae(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}`;XG("source",l,u,e,i,s),XG("target",l,c,e,o,a),t.set(r.id,r)}}function Tae(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:Tae(n,t):!1}function ZG(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 Dit(e,t,n,r){const i=new Map;for(const[o,s]of e)if((s.selected||s.id===r)&&(!s.parentId||!Tae(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 GA({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 Oit({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=iv(o,t);return{x:s.x-o.x,y:s.y-o.y}}function Tit({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,f=!1,h=null,g=!1,y=!1,b=null;function v({noDragClassName:C,handleSelector:w,domNode:A,isSelectable:E,nodeId:O,nodeClickDistance:D=0}){h=Rs(A);function T({x:R,y:$}){const{nodeLookup:j,nodeExtent:z,snapGrid:N,snapToGrid:W,nodeOrigin:H,onNodeDrag:U,onSelectionDrag:K,onError:B,updateNodePositions:q}=t();o={x:R,y:$};let X=!1;const V=a.size>1,Y=V&&z?GD(rv(a)):null,J=V&&W?Oit({dragItems:a,snapGrid:N,x:R,y:$}):null;for(const[ne,ee]of a){if(!j.has(ne))continue;let se={x:R-ee.distance.x,y:$-ee.distance.y};W&&(se=J?{x:Math.round(se.x+J.x),y:Math.round(se.y+J.y)}:iv(se,N));let ue=null;if(V&&z&&!ee.extent&&Y){const{positionAbsolute:re}=ee.internals,oe=re.x-Y.x+z[0][0],de=re.x+ee.measured.width-Y.x2+z[1][0],be=re.y-Y.y+z[0][1],je=re.y+ee.measured.height-Y.y2+z[1][1];ue=[[oe,be],[de,je]]}const{position:te,positionAbsolute:Z}=pae({nodeId:ne,nextPosition:se,nodeLookup:j,nodeExtent:ue||z,nodeOrigin:H,onError:B});X=X||ee.position.x!==te.x||ee.position.y!==te.y,ee.position=te,ee.internals.positionAbsolute=Z}if(y=y||X,!!X&&(q(a,!0),b&&(r||U||!O&&K))){const[ne,ee]=GA({nodeId:O,dragItems:a,nodeLookup:j});r?.(b,a,ne,ee),U?.(b,ne,ee),O||K?.(b,ee)}}async function I(){if(!u)return;const{transform:R,panBy:$,autoPanSpeed:j,autoPanOnNodeDrag:z}=t();if(!z){l=!1,cancelAnimationFrame(s);return}const[N,W]=gae(c,u,j);(N!==0||W!==0)&&(o.x=(o.x??0)-N/R[2],o.y=(o.y??0)-W/R[2],await $({x:N,y:W})&&T(o)),s=requestAnimationFrame(I)}function F(R){const{nodeLookup:$,multiSelectionActive:j,nodesDraggable:z,transform:N,snapGrid:W,snapToGrid:H,selectNodesOnDrag:U,onNodeDragStart:K,onSelectionDragStart:B,unselectNodesAndEdges:q}=t();f=!0,(!U||!E)&&!j&&O&&($.get(O)?.selected||q()),E&&U&&O&&e?.(O);const X=jy(R.sourceEvent,{transform:N,snapGrid:W,snapToGrid:H,containerBounds:u});if(o=X,a=Dit($,z,X,O),a.size>0&&(n||K||!O&&B)){const[V,Y]=GA({nodeId:O,dragItems:a,nodeLookup:$});n?.(R.sourceEvent,a,V,Y),K?.(R.sourceEvent,V,Y),O||B?.(R.sourceEvent,Y)}}const L=Gse().clickDistance(D).on("start",R=>{const{domNode:$,nodeDragThreshold:j,transform:z,snapGrid:N,snapToGrid:W}=t();u=$?.getBoundingClientRect()||null,g=!1,y=!1,b=R.sourceEvent,j===0&&F(R),o=jy(R.sourceEvent,{transform:z,snapGrid:N,snapToGrid:W,containerBounds:u}),c=Ka(R.sourceEvent,u)}).on("drag",R=>{const{autoPanOnNodeDrag:$,transform:j,snapGrid:z,snapToGrid:N,nodeDragThreshold:W,nodeLookup:H}=t(),U=jy(R.sourceEvent,{transform:j,snapGrid:z,snapToGrid:N,containerBounds:u});if(b=R.sourceEvent,(R.sourceEvent.type==="touchmove"&&R.sourceEvent.touches.length>1||O&&!H.has(O))&&(g=!0),!g){if(!l&&$&&f&&(l=!0,I()),!f){const K=Ka(R.sourceEvent,u),B=K.x-c.x,q=K.y-c.y;Math.sqrt(B*B+q*q)>W&&F(R)}(o.x!==U.xSnapped||o.y!==U.ySnapped)&&a&&f&&(c=Ka(R.sourceEvent,u),T(U))}}).on("end",R=>{if(!(!f||g)&&(l=!1,f=!1,cancelAnimationFrame(s),a.size>0)){const{nodeLookup:$,updateNodePositions:j,onNodeDragStop:z,onSelectionDragStop:N}=t();if(y&&(j(a,!1),y=!1),i||z||!O&&N){const[W,H]=GA({nodeId:O,dragItems:a,nodeLookup:$,dragging:!1});i?.(R.sourceEvent,a,W,H),z?.(R.sourceEvent,W,H),O||N?.(R.sourceEvent,H)}}}).filter(R=>{const $=R.target;return!R.button&&(!C||!ZG($,`.${C}`,A))&&(!w||ZG($,w,A))});h.call(L)}function S(){h?.on(".drag",null)}return{update:v,destroy:S}}function Mit(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())tb(i,jm(o))>0&&r.push(o);return r}const Rit=250;function Iit(e,t,n,r){let i=[],o=1/0;const s=Mit(e,n,t+Rit);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:f}=Yh(a,c,c.position,!0),h=Math.sqrt(Math.pow(u-e.x,2)+Math.pow(f-e.y,2));h>t||(h<o?(i=[{...c,x:u,y:f}],o=h):h===o&&i.push({...c,x:u,y:f}))}}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 Mae(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,...Yh(s,l,l.position,!0)}:l}function Rae(e,t){return e||(t?.classList.contains("target")?"target":t?.classList.contains("source")?"source":null)}function Pit(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const Iae=()=>!0;function jit(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:i,edgeUpdaterType:o,isTarget:s,domNode:a,nodeLookup:l,lib:c,autoPanOnConnect:u,flowId:f,panBy:h,cancelConnection:g,onConnectStart:y,onConnect:b,onConnectEnd:v,isValidConnection:S=Iae,onReconnectEnd:C,updateConnection:w,getTransform:A,getFromHandle:E,autoPanSpeed:O,dragThreshold:D=1,handleDomNode:T}){const I=xae(e.target);let F=0,L;const{x:R,y:$}=Ka(e),j=Rae(o,T),z=a?.getBoundingClientRect();let N=!1;if(!z||!j)return;const W=Mae(i,j,r,l,t);if(!W)return;let H=Ka(e,z),U=!1,K=null,B=!1,q=null;function X(){if(!u||!z)return;const[te,Z]=gae(H,z,O);h({x:te,y:Z}),F=requestAnimationFrame(X)}const V={...W,nodeId:i,type:j,position:W.position},Y=l.get(i);let ne={inProgress:!0,isValid:null,from:Yh(Y,V,xt.Left,!0),fromHandle:V,fromPosition:V.position,fromNode:Y,to:H,toHandle:null,toPosition:FG[V.position],toNode:null,pointer:H};function ee(){N=!0,w(ne),y?.(e,{nodeId:i,handleId:r,handleType:j})}D===0&&ee();function se(te){if(!N){const{x:je,y:De}=Ka(te),Ke=je-R,xe=De-$;if(!(Ke*Ke+xe*xe>D*D))return;ee()}if(!E()||!V){ue(te);return}const Z=A();H=Ka(te,z),L=Iit(ov(H,Z,!1,[1,1]),n,l,V),U||(X(),U=!0);const re=Pae(te,{handle:L,connectionMode:t,fromNodeId:i,fromHandleId:r,fromType:s?"target":"source",isValidConnection:S,doc:I,lib:c,flowId:f,nodeLookup:l});q=re.handleDomNode,K=re.connection,B=Pit(!!L,re.isValid);const oe=l.get(i),de=oe?Yh(oe,V,xt.Left,!0):ne.from,be={...ne,from:de,isValid:B,to:re.toHandle&&B?CS({x:re.toHandle.x,y:re.toHandle.y},Z):H,toHandle:re.toHandle,toPosition:B&&re.toHandle?re.toHandle.position:FG[V.position],toNode:re.toHandle?l.get(re.toHandle.nodeId):null,pointer:H};w(be),ne=be}function ue(te){if(!("touches"in te&&te.touches.length>0)){if(N){(L||q)&&K&&B&&b?.(K);const{inProgress:Z,...re}=ne,oe={...re,toPosition:ne.toHandle?ne.toPosition:null};v?.(te,oe),o&&C?.(te,oe)}g(),cancelAnimationFrame(F),U=!1,B=!1,K=null,q=null,I.removeEventListener("mousemove",se),I.removeEventListener("mouseup",ue),I.removeEventListener("touchmove",se),I.removeEventListener("touchend",ue)}}I.addEventListener("mousemove",se),I.addEventListener("mouseup",ue),I.addEventListener("touchmove",se),I.addEventListener("touchend",ue)}function Pae(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:o,doc:s,lib:a,flowId:l,isValidConnection:c=Iae,nodeLookup:u}){const f=o==="target",h=t?s.querySelector(`.${a}-flow__handle[data-id="${l}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y}=Ka(e),b=s.elementFromPoint(g,y),v=b?.classList.contains(`${a}-flow__handle`)?b:h,S={handleDomNode:v,isValid:!1,connection:null,toHandle:null};if(v){const C=Rae(void 0,v),w=v.getAttribute("data-nodeid"),A=v.getAttribute("data-handleid"),E=v.classList.contains("connectable"),O=v.classList.contains("connectableend");if(!w||!C)return S;const D={source:f?w:r,sourceHandle:f?A:i,target:f?r:w,targetHandle:f?i:A};S.connection=D;const I=E&&O&&(n===Im.Strict?f&&C==="source"||!f&&C==="target":w!==r||A!==i);S.isValid=I&&c(D),S.toHandle=Mae(w,C,A,u,n,!0)}return S}const ZD={onPointerDown:jit,isValid:Pae};function $it({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const i=Rs(e);function o({translateExtent:a,width:l,height:c,zoomStep:u=1,pannable:f=!0,zoomable:h=!0,inversePan:g=!1}){const y=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const A=n(),E=w.sourceEvent.ctrlKey&&nb()?10:1,O=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*u,D=A[2]*Math.pow(2,O*E);t.scaleTo(D)};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 A=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const E=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],O=[E[0]-b[0],E[1]-b[1]];b=E;const D=r()*Math.max(A[2],Math.log(A[2]))*(g?-1:1),T={x:A[0]-O[0]*D,y:A[1]-O[1]*D},I=[[0,0],[l,c]];t.setViewportConstrained({x:T.x,y:T.y,zoom:A[2]},I,a)},C=lae().on("start",v).on("zoom",f?S:null).on("zoom.wheel",h?y:null);i.call(C,{})}function s(){i.on("zoom",null)}return{update:o,destroy:s,pointer:Fa}}const UC=e=>({x:e.x,y:e.y,zoom:e.k}),KA=({x:e,y:t,zoom:n})=>BC.translate(e,t).scale(n),M0=(e,t)=>e.target.closest(`.${t}`),jae=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),Lit=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,YA=(e,t=0,n=Lit,r=()=>{})=>{const i=typeof t=="number"&&t>0;return i||r(),i?e.transition().duration(t).ease(n).on("end",r):e},$ae=e=>{const t=e.ctrlKey&&nb()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function Nit({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:i,panOnScrollSpeed:o,zoomOnPinch:s,onPanZoomStart:a,onPanZoom:l,onPanZoomEnd:c}){return u=>{if(M0(u,t))return u.ctrlKey&&u.preventDefault(),!1;u.preventDefault(),u.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(u.ctrlKey&&s){const v=Fa(u),S=$ae(u),C=f*Math.pow(2,S);r.scaleTo(n,C,v,u);return}const h=u.deltaMode===1?20:1;let g=i===Oh.Vertical?0:u.deltaX*h,y=i===Oh.Horizontal?0:u.deltaY*h;!nb()&&u.shiftKey&&i!==Oh.Vertical&&(g=u.deltaY*h,y=0),r.translateBy(n,-(g/f)*o,-(y/f)*o,{internal:!0});const b=UC(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 Fit({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,i){const o=r.type==="wheel",s=!t&&o&&!r.ctrlKey,a=M0(r,e);if(r.ctrlKey&&o&&a&&r.preventDefault(),s||a)return null;r.preventDefault(),n.call(this,r,i)}}function Bit({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{if(r.sourceEvent?.internal)return;const i=UC(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 zit({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:i}){return o=>{e.usedRightMouseButton=!!(n&&jae(t,e.mouseButton??0)),o.sourceEvent?.sync||r([o.transform.x,o.transform.y,o.transform.k]),i&&!o.sourceEvent?.internal&&i?.(o.sourceEvent,UC(o.transform))}}function Hit({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:i,onPaneContextMenu:o}){return s=>{if(!s.sourceEvent?.internal&&(e.isZoomingOrPanning=!1,o&&jae(t,e.mouseButton??0)&&!e.usedRightMouseButton&&s.sourceEvent&&o(s.sourceEvent),e.usedRightMouseButton=!1,r(!1),i)){const a=UC(s.transform);e.prevViewport=a,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{i?.(s.sourceEvent,a)},n?150:0)}}}function Uit({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:i,zoomOnDoubleClick:o,userSelectionActive:s,noWheelClassName:a,noPanClassName:l,lib:c,connectionInProgress:u}){return f=>{const h=e||t,g=n&&f.ctrlKey,y=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(M0(f,`${c}-flow__node`)||M0(f,`${c}-flow__edge`)))return!0;if(!r&&!h&&!i&&!o&&!n||s||u&&!y||M0(f,a)&&y||M0(f,l)&&(!y||i&&y&&!e)||!n&&f.ctrlKey&&y)return!1;if(!n&&f.type==="touchstart"&&f.touches?.length>1)return f.preventDefault(),!1;if(!h&&!i&&!g&&y||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const b=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||y)&&b}}function Vit({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(),f=lae().scaleExtent([t,n]).translateExtent(r),h=Rs(e).call(f);C({x:i.x,y:i.y,zoom:Pm(i.zoom,t,n)},[[0,0],[u.width,u.height]],r);const g=h.on("wheel.zoom"),y=h.on("dblclick.zoom");f.wheelDelta($ae);function b(L,R){return h?new Promise($=>{f?.interpolate(R?.interpolate==="linear"?Py:C4).transform(YA(h,R?.duration,R?.ease,()=>$(!0)),L)}):Promise.resolve(!1)}function v({noWheelClassName:L,noPanClassName:R,onPaneContextMenu:$,userSelectionActive:j,panOnScroll:z,panOnDrag:N,panOnScrollMode:W,panOnScrollSpeed:H,preventScrolling:U,zoomOnPinch:K,zoomOnScroll:B,zoomOnDoubleClick:q,zoomActivationKeyPressed:X,lib:V,onTransformChange:Y,connectionInProgress:J,paneClickDistance:ne,selectionOnDrag:ee}){j&&!c.isZoomingOrPanning&&S();const se=z&&!X&&!j;f.clickDistance(ee?1/0:!Ga(ne)||ne<0?0:ne);const ue=se?Nit({zoomPanValues:c,noWheelClassName:L,d3Selection:h,d3Zoom:f,panOnScrollMode:W,panOnScrollSpeed:H,zoomOnPinch:K,onPanZoomStart:s,onPanZoom:o,onPanZoomEnd:a}):Fit({noWheelClassName:L,preventScrolling:U,d3ZoomHandler:g});if(h.on("wheel.zoom",ue,{passive:!1}),!j){const Z=Bit({zoomPanValues:c,onDraggingChange:l,onPanZoomStart:s});f.on("start",Z);const re=zit({zoomPanValues:c,panOnDrag:N,onPaneContextMenu:!!$,onPanZoom:o,onTransformChange:Y});f.on("zoom",re);const oe=Hit({zoomPanValues:c,panOnDrag:N,panOnScroll:z,onPaneContextMenu:$,onPanZoomEnd:a,onDraggingChange:l});f.on("end",oe)}const te=Uit({zoomActivationKeyPressed:X,panOnDrag:N,zoomOnScroll:B,panOnScroll:z,zoomOnDoubleClick:q,zoomOnPinch:K,userSelectionActive:j,noPanClassName:R,noWheelClassName:L,lib:V,connectionInProgress:J});f.filter(te),q?h.on("dblclick.zoom",y):h.on("dblclick.zoom",null)}function S(){f.on("zoom",null)}async function C(L,R,$){const j=KA(L),z=f?.constrain()(j,R,$);return z&&await b(z),new Promise(N=>N(z))}async function w(L,R){const $=KA(L);return await b($,R),new Promise(j=>j($))}function A(L){if(h){const R=KA(L),$=h.property("__zoom");($.k!==L.zoom||$.x!==L.x||$.y!==L.y)&&f?.transform(h,R,null,{sync:!0})}}function E(){const L=h?aae(h.node()):{x:0,y:0,k:1};return{x:L.x,y:L.y,zoom:L.k}}function O(L,R){return h?new Promise($=>{f?.interpolate(R?.interpolate==="linear"?Py:C4).scaleTo(YA(h,R?.duration,R?.ease,()=>$(!0)),L)}):Promise.resolve(!1)}function D(L,R){return h?new Promise($=>{f?.interpolate(R?.interpolate==="linear"?Py:C4).scaleBy(YA(h,R?.duration,R?.ease,()=>$(!0)),L)}):Promise.resolve(!1)}function T(L){f?.scaleExtent(L)}function I(L){f?.translateExtent(L)}function F(L){const R=!Ga(L)||L<0?0:L;f?.clickDistance(R)}return{update:v,destroy:S,setViewport:w,setViewportConstrained:C,getViewport:E,scaleTo:O,scaleBy:D,setScaleExtent:T,setTranslateExtent:I,syncViewport:A,setClickDistance:F}}var Lm;(function(e){e.Line="line",e.Handle="handle"})(Lm||(Lm={}));function Wit({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 JG(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 cd(e,t){return Math.max(0,t-e)}function ud(e,t){return Math.max(0,e-t)}function C5(e,t,n){return Math.max(0,t-e,e-n)}function QG(e,t){return e?!t:t}function qit(e,t,n,r,i,o,s,a){let{affectsX:l,affectsY:c}=t;const{isHorizontal:u,isVertical:f}=t,h=u&&f,{xSnapped:g,ySnapped:y}=n,{minWidth:b,maxWidth:v,minHeight:S,maxHeight:C}=r,{x:w,y:A,width:E,height:O,aspectRatio:D}=e;let T=Math.floor(u?g-e.pointerX:0),I=Math.floor(f?y-e.pointerY:0);const F=E+(l?-T:T),L=O+(c?-I:I),R=-o[0]*E,$=-o[1]*O;let j=C5(F,b,v),z=C5(L,S,C);if(s){let H=0,U=0;l&&T<0?H=cd(w+T+R,s[0][0]):!l&&T>0&&(H=ud(w+F+R,s[1][0])),c&&I<0?U=cd(A+I+$,s[0][1]):!c&&I>0&&(U=ud(A+L+$,s[1][1])),j=Math.max(j,H),z=Math.max(z,U)}if(a){let H=0,U=0;l&&T>0?H=ud(w+T,a[0][0]):!l&&T<0&&(H=cd(w+F,a[1][0])),c&&I>0?U=ud(A+I,a[0][1]):!c&&I<0&&(U=cd(A+L,a[1][1])),j=Math.max(j,H),z=Math.max(z,U)}if(i){if(u){const H=C5(F/D,S,C)*D;if(j=Math.max(j,H),s){let U=0;!l&&!c||l&&!c&&h?U=ud(A+$+F/D,s[1][1])*D:U=cd(A+$+(l?T:-T)/D,s[0][1])*D,j=Math.max(j,U)}if(a){let U=0;!l&&!c||l&&!c&&h?U=cd(A+F/D,a[1][1])*D:U=ud(A+(l?T:-T)/D,a[0][1])*D,j=Math.max(j,U)}}if(f){const H=C5(L*D,b,v)/D;if(z=Math.max(z,H),s){let U=0;!l&&!c||c&&!l&&h?U=ud(w+L*D+R,s[1][0])/D:U=cd(w+(c?I:-I)*D+R,s[0][0])/D,z=Math.max(z,U)}if(a){let U=0;!l&&!c||c&&!l&&h?U=cd(w+L*D,a[1][0])/D:U=ud(w+(c?I:-I)*D,a[0][0])/D,z=Math.max(z,U)}}}I=I+(I<0?z:-z),T=T+(T<0?j:-j),i&&(h?F>L*D?I=(QG(l,c)?-T:T)/D:T=(QG(l,c)?-I:I)*D:u?(I=T/D,c=l):(T=I*D,l=c));const N=l?w+T:w,W=c?A+I:A;return{width:E+(l?-T:T),height:O+(c?-I:I),x:o[0]*T*(l?-1:1)+N,y:o[1]*I*(c?-1:1)+W}}const Lae={width:0,height:0,x:0,y:0},Git={...Lae,pointerX:0,pointerY:0,aspectRatio:1};function Kit(e){return[[0,0],[e.measured.width,e.measured.height]]}function Yit(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 Xit({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:i}){const o=Rs(e);let s={controlDirection:JG("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:f,resizeDirection:h,onResizeStart:g,onResize:y,onResizeEnd:b,shouldResize:v}){let S={...Lae},C={...Git};s={boundaries:u,resizeDirection:h,keepAspectRatio:f,controlDirection:JG(c)};let w,A=null,E=[],O,D,T,I=!1;const F=Gse().on("start",L=>{const{nodeLookup:R,transform:$,snapGrid:j,snapToGrid:z,nodeOrigin:N,paneDomNode:W}=n();if(w=R.get(t),!w)return;A=W?.getBoundingClientRect()??null;const{xSnapped:H,ySnapped:U}=jy(L.sourceEvent,{transform:$,snapGrid:j,snapToGrid:z,containerBounds:A});S={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},C={...S,pointerX:H,pointerY:U,aspectRatio:S.width/S.height},O=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(O=R.get(w.parentId),D=O&&w.extent==="parent"?Kit(O):void 0),E=[],T=void 0;for(const[K,B]of R)if(B.parentId===t&&(E.push({id:K,position:{...B.position},extent:B.extent}),B.extent==="parent"||B.expandParent)){const q=Yit(B,w,B.origin??N);T?T=[[Math.min(q[0][0],T[0][0]),Math.min(q[0][1],T[0][1])],[Math.max(q[1][0],T[1][0]),Math.max(q[1][1],T[1][1])]]:T=q}g?.(L,{...S})}).on("drag",L=>{const{transform:R,snapGrid:$,snapToGrid:j,nodeOrigin:z}=n(),N=jy(L.sourceEvent,{transform:R,snapGrid:$,snapToGrid:j,containerBounds:A}),W=[];if(!w)return;const{x:H,y:U,width:K,height:B}=S,q={},X=w.origin??z,{width:V,height:Y,x:J,y:ne}=qit(C,s.controlDirection,N,s.boundaries,s.keepAspectRatio,X,D,T),ee=V!==K,se=Y!==B,ue=J!==H&&ee,te=ne!==U&&se;if(!ue&&!te&&!ee&&!se)return;if((ue||te||X[0]===1||X[1]===1)&&(q.x=ue?J:S.x,q.y=te?ne:S.y,S.x=q.x,S.y=q.y,E.length>0)){const de=J-H,be=ne-U;for(const je of E)je.position={x:je.position.x-de+X[0]*(V-K),y:je.position.y-be+X[1]*(Y-B)},W.push(je)}if((ee||se)&&(q.width=ee&&(!s.resizeDirection||s.resizeDirection==="horizontal")?V:S.width,q.height=se&&(!s.resizeDirection||s.resizeDirection==="vertical")?Y:S.height,S.width=q.width,S.height=q.height),O&&w.expandParent){const de=X[0]*(q.width??0);q.x&&q.x<de&&(S.x=de,C.x=C.x-(q.x-de));const be=X[1]*(q.height??0);q.y&&q.y<be&&(S.y=be,C.y=C.y-(q.y-be))}const Z=Wit({width:S.width,prevWidth:K,height:S.height,prevHeight:B,affectsX:s.controlDirection.affectsX,affectsY:s.controlDirection.affectsY}),re={...S,direction:Z};v?.(L,re)!==!1&&(I=!0,y?.(L,re),r(q,W))}).on("end",L=>{I&&(b?.(L,{...S}),i?.({...S}),I=!1)});o.call(F)}function l(){o.on(".drag",null)}return{update:a,destroy:l}}const Zit={},eK=e=>{let t;const n=new Set,r=(u,f)=>{const h=typeof u=="function"?u(t):u;if(!Object.is(h,t)){const g=t;t=f??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(y=>y(t,g))}},i=()=>t,l={setState:r,getState:i,getInitialState:()=>c,subscribe:u=>(n.add(u),()=>n.delete(u)),destroy:()=>{(Zit?"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},Jit=e=>e?eK(e):eK,{useDebugValue:Qit}=qt,{useSyncExternalStoreWithSelector:eot}=RSe,tot=e=>e;function Nae(e,t=tot,n){const r=eot(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return Qit(r),r}const tK=(e,t)=>{const n=Jit(e),r=(i,o=t)=>Nae(n,i,o);return Object.assign(r,n),r},not=(e,t)=>e?tK(e,t):tK;function Wr(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 VC=_.createContext(null),rot=VC.Provider,Fae=yc.error001();function zn(e,t){const n=_.useContext(VC);if(n===null)throw new Error(Fae);return Nae(n,e,t)}function qr(){const e=_.useContext(VC);if(e===null)throw new Error(Fae);return _.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const nK={display:"none"},iot={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},Bae="react-flow__node-desc",zae="react-flow__edge-desc",oot="react-flow__aria-live",sot=e=>e.ariaLiveMessage,aot=e=>e.ariaLabelConfig;function lot({rfId:e}){const t=zn(sot);return m.jsx("div",{id:`${oot}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:iot,children:t})}function cot({rfId:e,disableKeyboardA11y:t}){const n=zn(aot);return m.jsxs(m.Fragment,{children:[m.jsx("div",{id:`${Bae}-${e}`,style:nK,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),m.jsx("div",{id:`${zae}-${e}`,style:nK,children:n["edge.a11yDescription.default"]}),!t&&m.jsx(lot,{rfId:e})]})}const WC=_.forwardRef(({position:e="top-left",children:t,className:n,style:r,...i},o)=>{const s=`${e}`.split("-");return m.jsx("div",{className:Mi(["react-flow__panel",n,...s]),style:r,ref:o,...i,children:t})});WC.displayName="Panel";function uot({proOptions:e,position:t="bottom-right"}){return e?.hideAttribution?null:m.jsx(WC,{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:m.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const dot=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}},E5=e=>e.id;function fot(e,t){return Wr(e.selectedNodes.map(E5),t.selectedNodes.map(E5))&&Wr(e.selectedEdges.map(E5),t.selectedEdges.map(E5))}function hot({onSelectionChange:e}){const t=qr(),{selectedNodes:n,selectedEdges:r}=zn(dot,fot);return _.useEffect(()=>{const i={nodes:n,edges:r};e?.(i),t.getState().onSelectionChangeHandlers.forEach(o=>o(i))},[n,r,e]),null}const pot=e=>!!e.onSelectionChangeHandlers;function mot({onSelectionChange:e}){const t=zn(pot);return e||t?m.jsx(hot,{onSelectionChange:e}):null}const Hae=[0,0],got={x:0,y:0,zoom:1},yot=["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"],rK=[...yot,"rfId"],bot=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}),iK={translateExtent:Q2,nodeOrigin:Hae,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function vot(e){const{setNodes:t,setEdges:n,setMinZoom:r,setMaxZoom:i,setTranslateExtent:o,setNodeExtent:s,reset:a,setDefaultNodesAndEdges:l}=zn(bot,Wr),c=qr();_.useEffect(()=>(l(e.defaultNodes,e.defaultEdges),()=>{u.current=iK,a()}),[]);const u=_.useRef(iK);return _.useEffect(()=>{for(const f of rK){const h=e[f],g=u.current[f];h!==g&&(typeof e[f]>"u"||(f==="nodes"?t(h):f==="edges"?n(h):f==="minZoom"?r(h):f==="maxZoom"?i(h):f==="translateExtent"?o(h):f==="nodeExtent"?s(h):f==="ariaLabelConfig"?c.setState({ariaLabelConfig:lit(h)}):f==="fitView"?c.setState({fitViewQueued:h}):f==="fitViewOptions"?c.setState({fitViewOptions:h}):c.setState({[f]:h})))}u.current=e},rK.map(f=>e[f])),null}function oK(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function xot(e){const[t,n]=_.useState(e==="system"?null:e);return _.useEffect(()=>{if(e!=="system"){n(e);return}const r=oK(),i=()=>n(r?.matches?"dark":"light");return i(),r?.addEventListener("change",i),()=>{r?.removeEventListener("change",i)}},[e]),t!==null?t:oK()?.matches?"dark":"light"}const sK=typeof document<"u"?document:null;function rb(e=null,t={target:sK,actInsideInputWithModifier:!0}){const[n,r]=_.useState(!1),i=_.useRef(!1),o=_.useRef(new Set([])),[s,a]=_.useMemo(()=>{if(e!==null){const c=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.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
|
-
`},Wat={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 qat(e){let{announcements:t=Wat,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=Vat}=e;const{announce:o,announcement:s}=zat(),a=lv("DndLiveRegion"),[l,c]=_.useState(!1);if(_.useEffect(()=>{c(!0)},[]),Hat(_.useMemo(()=>({onDragStart(f){let{active:h}=f;o(t.onDragStart({active:h}))},onDragMove(f){let{active:h,over:g}=f;t.onDragMove&&o(t.onDragMove({active:h,over:g}))},onDragOver(f){let{active:h,over:g}=f;o(t.onDragOver({active:h,over:g}))},onDragEnd(f){let{active:h,over:g}=f;o(t.onDragEnd({active:h,over:g}))},onDragCancel(f){let{active:h,over:g}=f;o(t.onDragCancel({active:h,over:g}))}}),[o,t])),!l)return null;const u=qt.createElement(qt.Fragment,null,qt.createElement(Fat,{id:r,value:i.draggable}),qt.createElement(Bat,{id:a,announcement:s}));return n?Dd.createPortal(u,n):u}var Li;(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"})(Li||(Li={}));function kS(){}function AK(e,t){return _.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Gat(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return _.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const sl=Object.freeze({x:0,y:0});function Cle(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function Ele(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function Kat(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function kK(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 Ale(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function _K(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 Yat=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=_K(t,t.left,t.top),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=Cle(_K(l),i);o.push({id:a,data:{droppableContainer:s,value:c}})}}return o.sort(Ele)},Xat=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=kK(t),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=kK(l),u=i.reduce((h,g,y)=>h+Cle(c[y],g),0),f=Number((u/4).toFixed(4));o.push({id:a,data:{droppableContainer:s,value:f}})}}return o.sort(Ele)};function Zat(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,f=u/(l+c-u);return Number(f.toFixed(4))}return 0}const Jat=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=Zat(a,t);l>0&&i.push({id:s,data:{droppableContainer:o,value:l}})}}return i.sort(Kat)};function Qat(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function kle(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:sl}function elt(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 tlt=elt(1);function nlt(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 rlt(e,t,n){const r=nlt(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,f=o?e.height/o:e.height;return{width:u,height:f,top:c,right:l+u,bottom:c+f,left:l}}const ilt={ignoreTransform:!1};function gg(e,t){t===void 0&&(t=ilt);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:c,transformOrigin:u}=fs(e).getComputedStyle(e);c&&(n=rlt(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 DK(e){return gg(e,{ignoreTransform:!0})}function olt(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function slt(e,t){return t===void 0&&(t=fs(e).getComputedStyle(e)),t.position==="fixed"}function alt(e,t){t===void 0&&(t=fs(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 YC(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(!sv(i)||xle(i)||n.includes(i))return n;const o=fs(e).getComputedStyle(i);return i!==e&&alt(i,o)&&n.push(i),slt(i,o)?n:r(i.parentNode)}return e?r(e):n}function _le(e){const[t]=YC(e,1);return t??null}function QA(e){return!KC||!e?null:pg(e)?e:vI(e)?xI(e)||e===mg(e).scrollingElement?window:sv(e)?e:null:null}function Dle(e){return pg(e)?e.scrollX:e.scrollLeft}function Ole(e){return pg(e)?e.scrollY:e.scrollTop}function tO(e){return{x:Dle(e),y:Ole(e)}}var Xi;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Xi||(Xi={}));function Tle(e){return!KC||!e?!1:e===document.scrollingElement}function Mle(e){const t={x:0,y:0},n=Tle(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 llt={x:.2,y:.2};function clt(e,t,n,r,i){let{top:o,left:s,right:a,bottom:l}=n;r===void 0&&(r=10),i===void 0&&(i=llt);const{isTop:c,isBottom:u,isLeft:f,isRight:h}=Mle(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=Xi.Backward,y.y=r*Math.abs((t.top+b.height-o)/b.height)):!u&&l>=t.bottom-b.height&&(g.y=Xi.Forward,y.y=r*Math.abs((t.bottom-b.height-l)/b.height)),!h&&a>=t.right-b.width?(g.x=Xi.Forward,y.x=r*Math.abs((t.right-b.width-a)/b.width)):!f&&s<=t.left+b.width&&(g.x=Xi.Backward,y.x=r*Math.abs((t.left+b.width-s)/b.width)),{direction:g,speed:y}}function ult(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 Rle(e){return e.reduce((t,n)=>nm(t,tO(n)),sl)}function dlt(e){return e.reduce((t,n)=>t+Dle(n),0)}function flt(e){return e.reduce((t,n)=>t+Ole(n),0)}function hlt(e,t){if(t===void 0&&(t=gg),!e)return;const{top:n,left:r,bottom:i,right:o}=t(e);_le(e)&&(i<=0||o<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const plt=[["x",["left","right"],dlt],["y",["top","bottom"],flt]];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=YC(n),i=Rle(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,s,a]of plt)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 $y{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 mlt(e){const{EventTarget:t}=fs(e);return e instanceof t?e:mg(e)}function ek(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 ta;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(ta||(ta={}));function OK(e){e.preventDefault()}function glt(e){e.stopPropagation()}var Ln;(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"})(Ln||(Ln={}));const Ile={start:[Ln.Space,Ln.Enter],cancel:[Ln.Esc],end:[Ln.Space,Ln.Enter,Ln.Tab]},ylt=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Ln.Right:return{...n,x:n.x+25};case Ln.Left:return{...n,x:n.x-25};case Ln.Down:return{...n,y:n.y+25};case Ln.Up:return{...n,y:n.y-25}}};class EI{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 $y(mg(n)),this.windowListeners=new $y(fs(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(ta.Resize,this.handleCancel),this.windowListeners.add(ta.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(ta.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,r=t.node.current;r&&hlt(r),n(sl)}handleKeyDown(t){if(wI(t)){const{active:n,context:r,options:i}=this.props,{keyboardCodes:o=Ile,coordinateGetter:s=ylt,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}:sl;this.referenceCoordinates||(this.referenceCoordinates=u);const f=s(t,{active:n,context:r.current,currentCoordinates:u});if(f){const h=ob(f,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:A,maxScroll:E,minScroll:O}=Mle(b),D=ult(b),T={x:Math.min(v===Ln.Right?D.right-D.width/2:D.right,Math.max(v===Ln.Right?D.left:D.left+D.width/2,f.x)),y:Math.min(v===Ln.Down?D.bottom-D.height/2:D.bottom,Math.max(v===Ln.Down?D.top:D.top+D.height/2,f.y))},I=v===Ln.Right&&!C||v===Ln.Left&&!w,F=v===Ln.Down&&!A||v===Ln.Up&&!S;if(I&&T.x!==f.x){const L=b.scrollLeft+h.x,R=v===Ln.Right&&L<=E.x||v===Ln.Left&&L>=O.x;if(R&&!h.y){b.scrollTo({left:L,behavior:a});return}R?g.x=b.scrollLeft-L:g.x=v===Ln.Right?b.scrollLeft-E.x:b.scrollLeft-O.x,g.x&&b.scrollBy({left:-g.x,behavior:a});break}else if(F&&T.y!==f.y){const L=b.scrollTop+h.y,R=v===Ln.Down&&L<=E.y||v===Ln.Up&&L>=O.y;if(R&&!h.x){b.scrollTo({top:L,behavior:a});return}R?g.y=b.scrollTop-L:g.y=v===Ln.Down?b.scrollTop-E.y:b.scrollTop-O.y,g.y&&b.scrollBy({top:-g.y,behavior:a});break}}this.handleMove(t,nm(ob(f,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()}}EI.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:r=Ile,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 TK(e){return!!(e&&"distance"in e)}function MK(e){return!!(e&&"delay"in e)}class AI{constructor(t,n,r){var i;r===void 0&&(r=mlt(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=mg(s),this.documentListeners=new $y(this.document),this.listeners=new $y(r),this.windowListeners=new $y(fs(s)),this.initialCoordinates=(i=eO(o))!=null?i:sl,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(ta.Resize,this.handleCancel),this.windowListeners.add(ta.DragStart,OK),this.windowListeners.add(ta.VisibilityChange,this.handleCancel),this.windowListeners.add(ta.ContextMenu,OK),this.documentListeners.add(ta.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(MK(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(TK(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(ta.Click,glt,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(ta.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=eO(t))!=null?n:sl,c=ob(i,l);if(!r&&a){if(TK(a)){if(a.tolerance!=null&&ek(c,a.tolerance))return this.handleCancel();if(ek(c,a.distance))return this.handleStart()}if(MK(a)&&ek(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===Ln.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const blt={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class kI extends AI{constructor(t){const{event:n}=t,r=mg(n.target);super(t,blt,r)}}kI.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 vlt={move:{name:"mousemove"},end:{name:"mouseup"}};var nO;(function(e){e[e.RightClick=2]="RightClick"})(nO||(nO={}));class xlt extends AI{constructor(t){super(t,vlt,mg(t.event.target))}}xlt.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===nO.RightClick?!1:(r?.({event:n}),!0)}}];const tk={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Slt extends AI{constructor(t){super(t,tk)}static setup(){return window.addEventListener(tk.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(tk.move.name,t)};function t(){}}}Slt.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 Ly;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Ly||(Ly={}));var _S;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(_S||(_S={}));function wlt(e){let{acceleration:t,activator:n=Ly.Pointer,canScroll:r,draggingRect:i,enabled:o,interval:s=5,order:a=_S.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:u,delta:f,threshold:h}=e;const g=Elt({delta:f,disabled:!o}),[y,b]=Pat(),v=_.useRef({x:0,y:0}),S=_.useRef({x:0,y:0}),C=_.useMemo(()=>{switch(n){case Ly.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case Ly.DraggableRect:return i}},[n,i,l]),w=_.useRef(null),A=_.useCallback(()=>{const O=w.current;if(!O)return;const D=v.current.x*S.current.x,T=v.current.y*S.current.y;O.scrollBy(D,T)},[]),E=_.useMemo(()=>a===_S.TreeOrder?[...c].reverse():c,[a,c]);_.useEffect(()=>{if(!o||!c.length||!C){b();return}for(const O of E){if(r?.(O)===!1)continue;const D=c.indexOf(O),T=u[D];if(!T)continue;const{direction:I,speed:F}=clt(O,T,C,t,h);for(const L of["x","y"])g[L][I[L]]||(F[L]=0,I[L]=0);if(F.x>0||F.y>0){b(),w.current=O,y(A,s),v.current=F,S.current=I;return}}v.current={x:0,y:0},S.current={x:0,y:0},b()},[t,A,r,b,o,s,JSON.stringify(C),JSON.stringify(g),y,c,E,u,JSON.stringify(h)])}const Clt={x:{[Xi.Backward]:!1,[Xi.Forward]:!1},y:{[Xi.Backward]:!1,[Xi.Forward]:!1}};function Elt(e){let{delta:t,disabled:n}=e;const r=QD(t);return av(i=>{if(n||!r||!i)return Clt;const o={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Xi.Backward]:i.x[Xi.Backward]||o.x===-1,[Xi.Forward]:i.x[Xi.Forward]||o.x===1},y:{[Xi.Backward]:i.y[Xi.Backward]||o.y===-1,[Xi.Forward]:i.y[Xi.Forward]||o.y===1}}},[n,t,r])}function Alt(e,t){const n=t!=null?e.get(t):void 0,r=n?n.node.current:null;return av(i=>{var o;return t==null?null:(o=r??i)!=null?o:null},[r,t])}function klt(e,t){return _.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 ab;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(ab||(ab={}));var rO;(function(e){e.Optimized="optimized"})(rO||(rO={}));const RK=new Map;function _lt(e,t){let{dragging:n,dependencies:r,config:i}=t;const[o,s]=_.useState(null),{frequency:a,measure:l,strategy:c}=i,u=_.useRef(e),f=v(),h=ib(f),g=_.useCallback(function(S){S===void 0&&(S=[]),!h.current&&s(C=>C===null?S:C.concat(S.filter(w=>!C.includes(w))))},[h]),y=_.useRef(null),b=av(S=>{if(f&&!n)return RK;if(!S||S===RK||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 A=w.node.current,E=A?new CI(l(A),A):null;w.rect.current=E,E&&C.set(w.id,E)}return C}return S},[e,o,n,f,l]);return _.useEffect(()=>{u.current=e},[e]),_.useEffect(()=>{f||g()},[n,f]),_.useEffect(()=>{o&&o.length>0&&s(null)},[JSON.stringify(o)]),_.useEffect(()=>{f||typeof a!="number"||y.current!==null||(y.current=setTimeout(()=>{g(),y.current=null},a))},[a,f,g,...r]),{droppableRects:b,measureDroppableContainers:g,measuringScheduled:o!=null};function v(){switch(c){case ab.Always:return!1;case ab.BeforeDragging:return n;default:return!n}}}function Ple(e,t){return av(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function Dlt(e,t){return Ple(e,t)}function Olt(e){let{callback:t,disabled:n}=e;const r=SI(t),i=_.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(r)},[r,n]);return _.useEffect(()=>()=>i?.disconnect(),[i]),i}function XC(e){let{callback:t,disabled:n}=e;const r=SI(t),i=_.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(r)},[n]);return _.useEffect(()=>()=>i?.disconnect(),[i]),i}function Tlt(e){return new CI(gg(e),e)}function IK(e,t,n){t===void 0&&(t=Tlt);const[r,i]=_.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=Olt({callback(l){if(e)for(const c of l){const{type:u,target:f}=c;if(u==="childList"&&f instanceof HTMLElement&&f.contains(e)){o();break}}}}),a=XC({callback:o});return bc(()=>{o(),e?(a?.observe(e),s?.observe(document.body,{childList:!0,subtree:!0})):(a?.disconnect(),s?.disconnect())},[e]),r}function Mlt(e){const t=Ple(e);return kle(e,t)}const PK=[];function Rlt(e){const t=_.useRef(e),n=av(r=>e?r&&r!==PK&&e&&t.current&&e.parentNode===t.current.parentNode?r:YC(e):PK,[e]);return _.useEffect(()=>{t.current=e},[e]),n}function Ilt(e){const[t,n]=_.useState(null),r=_.useRef(e),i=_.useCallback(o=>{const s=QA(o.target);s&&n(a=>a?(a.set(s,tO(s)),new Map(a)):null)},[]);return _.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,tO(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]),_.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,s)=>nm(o,s),sl):Rle(e):sl,[e,t])}function jK(e,t){t===void 0&&(t=[]);const n=_.useRef(null);return _.useEffect(()=>{n.current=null},t),_.useEffect(()=>{const r=e!==sl;r&&!n.current&&(n.current=e),!r&&n.current&&(n.current=null)},[e]),n.current?ob(e,n.current):sl}function Plt(e){_.useEffect(()=>{if(!KC)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 jlt(e,t){return _.useMemo(()=>e.reduce((n,r)=>{let{eventName:i,handler:o}=r;return n[i]=s=>{o(s,t)},n},{}),[e,t])}function jle(e){return _.useMemo(()=>e?olt(e):null,[e])}const $K=[];function $lt(e,t){t===void 0&&(t=gg);const[n]=e,r=jle(n?fs(n):null),[i,o]=_.useState($K);function s(){o(()=>e.length?e.map(l=>Tle(l)?r:new CI(t(l),l)):$K)}const a=XC({callback:s});return bc(()=>{a?.disconnect(),s(),e.forEach(l=>a?.observe(l))},[e]),i}function Llt(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return sv(t)?t:e}function Nlt(e){let{measure:t}=e;const[n,r]=_.useState(null),i=_.useCallback(c=>{for(const{target:u}of c)if(sv(u)){r(f=>{const h=t(u);return f?{...f,width:h.width,height:h.height}:h});break}},[t]),o=XC({callback:i}),s=_.useCallback(c=>{const u=Llt(c);o?.disconnect(),u&&o?.observe(u),r(u?t(u):null)},[t,o]),[a,l]=AS(s);return _.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const Flt=[{sensor:kI,options:{}},{sensor:EI,options:{}}],Blt={current:{}},_4={draggable:{measure:DK},droppable:{measure:DK,strategy:ab.WhileDragging,frequency:rO.Optimized},dragOverlay:{measure:gg}};class Ny 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 zlt={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Ny,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:kS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:_4,measureDroppableContainers:kS,windowRect:null,measuringScheduled:!1},Hlt={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:kS,draggableNodes:new Map,over:null,measureDroppableContainers:kS},ZC=_.createContext(Hlt),$le=_.createContext(zlt);function Ult(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Ny}}}function Vlt(e,t){switch(t.type){case Li.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Li.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 Li.DragEnd:case Li.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Li.RegisterDroppable:{const{element:n}=t,{id:r}=n,i=new Ny(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case Li.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 Ny(e.droppable.containers);return s.set(n,{...o,disabled:i}),{...e,droppable:{...e.droppable,containers:s}}}case Li.UnregisterDroppable:{const{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;const o=new Ny(e.droppable.containers);return o.delete(n),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function Wlt(e){let{disabled:t}=e;const{active:n,activatorEvent:r,draggableNodes:i}=_.useContext(ZC),o=QD(r),s=QD(n?.id);return _.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 f=Lat(u);if(f){f.focus();break}}})}},[r,t,i,s,o]),null}function qlt(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((i,o)=>o({transform:i,...r}),n):n}function Glt(e){return _.useMemo(()=>({draggable:{..._4.draggable,...e?.draggable},droppable:{..._4.droppable,...e?.droppable},dragOverlay:{..._4.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function Klt(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e;const o=_.useRef(!1),{x:s,y:a}=typeof i=="boolean"?{x:i,y:i}:i;bc(()=>{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),f=kle(u,r);if(s||(f.x=0),a||(f.y=0),o.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=_le(c);h&&h.scrollBy({top:f.y,left:f.x})}},[t,s,a,r,n])}const Lle=_.createContext({...sl,scaleX:1,scaleY:1});var xd;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(xd||(xd={}));const Ylt=_.memo(function(t){var n,r,i,o;let{id:s,accessibility:a,autoScroll:l=!0,children:c,sensors:u=Flt,collisionDetection:f=Jat,measuring:h,modifiers:g,...y}=t;const b=_.useReducer(Vlt,void 0,Ult),[v,S]=b,[C,w]=Uat(),[A,E]=_.useState(xd.Uninitialized),O=A===xd.Initialized,{draggable:{active:D,nodes:T,translate:I},droppable:{containers:F}}=v,L=D!=null?T.get(D):null,R=_.useRef({initial:null,translated:null}),$=_.useMemo(()=>{var Dt;return D!=null?{id:D,data:(Dt=L?.data)!=null?Dt:Blt,rect:R}:null},[D,L]),j=_.useRef(null),[z,N]=_.useState(null),[W,H]=_.useState(null),U=ib(y,Object.values(y)),K=lv("DndDescribedBy",s),B=_.useMemo(()=>F.getEnabled(),[F]),q=Glt(h),{droppableRects:X,measureDroppableContainers:V,measuringScheduled:Y}=_lt(B,{dragging:O,dependencies:[I.x,I.y],config:q.droppable}),J=Alt(T,D),ne=_.useMemo(()=>W?eO(W):null,[W]),ee=yr(),se=Dlt(J,q.draggable.measure);Klt({activeNode:D!=null?T.get(D):null,config:ee.layoutShiftCompensation,initialRect:se,measure:q.draggable.measure});const ue=IK(J,q.draggable.measure,se),te=IK(J?J.parentElement:null),Z=_.useRef({activatorEvent:null,active:null,activeNode:J,collisionRect:null,collisions:null,droppableRects:X,draggableNodes:T,draggingNode:null,draggingNodeRect:null,droppableContainers:F,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),re=F.getNodeFor((n=Z.current.over)==null?void 0:n.id),oe=Nlt({measure:q.dragOverlay.measure}),de=(r=oe.nodeRef.current)!=null?r:J,be=O?(i=oe.rect)!=null?i:ue:null,je=!!(oe.nodeRef.current&&oe.rect),De=Mlt(je?null:ue),Ke=jle(de?fs(de):null),xe=Rlt(O?re??J:null),Le=$lt(xe),Te=qlt(g,{transform:{x:I.x-De.x,y:I.y-De.y,scaleX:1,scaleY:1},activatorEvent:W,active:$,activeNodeRect:ue,containerNodeRect:te,draggingNodeRect:be,over:Z.current.over,overlayNodeRect:oe.rect,scrollableAncestors:xe,scrollableAncestorRects:Le,windowRect:Ke}),ht=ne?nm(ne,I):null,mt=Ilt(xe),ze=jK(mt),Ie=jK(mt,[ue]),He=nm(Te,ze),Je=be?tlt(be,Te):null,rt=$&&Je?f({active:$,collisionRect:Je,droppableRects:X,droppableContainers:B,pointerCoordinates:ht}):null,st=Ale(rt,"id"),[Xe,Lt]=_.useState(null),Nt=je?Te:nm(Te,Ie),Ot=Qat(Nt,(o=Xe?.rect)!=null?o:null,ue),Xn=_.useRef(null),rn=_.useCallback((Dt,Pt)=>{let{sensor:Jt,options:jn}=Pt;if(j.current==null)return;const on=T.get(j.current);if(!on)return;const St=Dt.nativeEvent,mn=new Jt({active:j.current,activeNode:on,event:St,options:jn,context:Z,onAbort(br){if(!T.get(br))return;const{onDragAbort:ce}=U.current,pe={id:br};ce?.(pe),C({type:"onDragAbort",event:pe})},onPending(br,ei,ce,pe){if(!T.get(br))return;const{onDragPending:Fe}=U.current,Ue={id:br,constraint:ei,initialCoordinates:ce,offset:pe};Fe?.(Ue),C({type:"onDragPending",event:Ue})},onStart(br){const ei=j.current;if(ei==null)return;const ce=T.get(ei);if(!ce)return;const{onDragStart:pe}=U.current,Se={activatorEvent:St,active:{id:ei,data:ce.data,rect:R}};Dd.unstable_batchedUpdates(()=>{pe?.(Se),E(xd.Initializing),S({type:Li.DragStart,initialCoordinates:br,active:ei}),C({type:"onDragStart",event:Se}),N(Xn.current),H(St)})},onMove(br){S({type:Li.DragMove,coordinates:br})},onEnd:Qr(Li.DragEnd),onCancel:Qr(Li.DragCancel)});Xn.current=mn;function Qr(br){return async function(){const{active:ce,collisions:pe,over:Se,scrollAdjustedTranslate:Fe}=Z.current;let Ue=null;if(ce&&Fe){const{cancelDrop:yt}=U.current;Ue={activatorEvent:St,active:ce,collisions:pe,delta:Fe,over:Se},br===Li.DragEnd&&typeof yt=="function"&&await Promise.resolve(yt(Ue))&&(br=Li.DragCancel)}j.current=null,Dd.unstable_batchedUpdates(()=>{S({type:br}),E(xd.Uninitialized),Lt(null),N(null),H(null),Xn.current=null;const yt=br===Li.DragEnd?"onDragEnd":"onDragCancel";if(Ue){const it=U.current[yt];it?.(Ue),C({type:yt,event:Ue})}})}}},[T]),lt=_.useCallback((Dt,Pt)=>(Jt,jn)=>{const on=Jt.nativeEvent,St=T.get(jn);if(j.current!==null||!St||on.dndKit||on.defaultPrevented)return;const mn={active:St};Dt(Jt,Pt.options,mn)===!0&&(on.dndKit={capturedBy:Pt.sensor},j.current=jn,rn(Jt,Pt))},[T,rn]),Ht=klt(u,lt);Plt(u),bc(()=>{ue&&A===xd.Initializing&&E(xd.Initialized)},[ue,A]),_.useEffect(()=>{const{onDragMove:Dt}=U.current,{active:Pt,activatorEvent:Jt,collisions:jn,over:on}=Z.current;if(!Pt||!Jt)return;const St={active:Pt,activatorEvent:Jt,collisions:jn,delta:{x:He.x,y:He.y},over:on};Dd.unstable_batchedUpdates(()=>{Dt?.(St),C({type:"onDragMove",event:St})})},[He.x,He.y]),_.useEffect(()=>{const{active:Dt,activatorEvent:Pt,collisions:Jt,droppableContainers:jn,scrollAdjustedTranslate:on}=Z.current;if(!Dt||j.current==null||!Pt||!on)return;const{onDragOver:St}=U.current,mn=jn.get(st),Qr=mn&&mn.rect.current?{id:mn.id,rect:mn.rect.current,data:mn.data,disabled:mn.disabled}:null,br={active:Dt,activatorEvent:Pt,collisions:Jt,delta:{x:on.x,y:on.y},over:Qr};Dd.unstable_batchedUpdates(()=>{Lt(Qr),St?.(br),C({type:"onDragOver",event:br})})},[st]),bc(()=>{Z.current={activatorEvent:W,active:$,activeNode:J,collisionRect:Je,collisions:rt,droppableRects:X,draggableNodes:T,draggingNode:de,draggingNodeRect:be,droppableContainers:F,over:Xe,scrollableAncestors:xe,scrollAdjustedTranslate:He},R.current={initial:be,translated:Je}},[$,J,rt,Je,T,de,be,X,F,Xe,xe,He]),wlt({...ee,delta:I,draggingRect:Je,pointerCoordinates:ht,scrollableAncestors:xe,scrollableAncestorRects:Le});const Dn=_.useMemo(()=>({active:$,activeNode:J,activeNodeRect:ue,activatorEvent:W,collisions:rt,containerNodeRect:te,dragOverlay:oe,draggableNodes:T,droppableContainers:F,droppableRects:X,over:Xe,measureDroppableContainers:V,scrollableAncestors:xe,scrollableAncestorRects:Le,measuringConfiguration:q,measuringScheduled:Y,windowRect:Ke}),[$,J,ue,W,rt,te,oe,T,F,X,Xe,V,xe,Le,q,Y,Ke]),Gn=_.useMemo(()=>({activatorEvent:W,activators:Ht,active:$,activeNodeRect:ue,ariaDescribedById:{draggable:K},dispatch:S,draggableNodes:T,over:Xe,measureDroppableContainers:V}),[W,Ht,$,ue,S,K,T,Xe,V]);return qt.createElement(wle.Provider,{value:w},qt.createElement(ZC.Provider,{value:Gn},qt.createElement($le.Provider,{value:Dn},qt.createElement(Lle.Provider,{value:Ot},c)),qt.createElement(Wlt,{disabled:a?.restoreFocus===!1})),qt.createElement(qat,{...a,hiddenTextDescribedById:K}));function yr(){const Dt=z?.autoScrollEnabled===!1,Pt=typeof l=="object"?l.enabled===!1:l===!1,Jt=O&&!Dt&&!Pt;return typeof l=="object"?{...l,enabled:Jt}:{enabled:Jt}}}),Xlt=_.createContext(null),LK="button",Zlt="Draggable";function Jlt(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e;const o=lv(Zlt),{activators:s,activatorEvent:a,active:l,activeNodeRect:c,ariaDescribedById:u,draggableNodes:f,over:h}=_.useContext(ZC),{role:g=LK,roleDescription:y="draggable",tabIndex:b=0}=i??{},v=l?.id===t,S=_.useContext(v?Lle:Xlt),[C,w]=AS(),[A,E]=AS(),O=jlt(s,t),D=ib(n);bc(()=>(f.set(t,{id:t,key:o,node:C,activatorNode:A,data:D}),()=>{const I=f.get(t);I&&I.key===o&&f.delete(t)}),[f,t]);const T=_.useMemo(()=>({role:g,tabIndex:b,"aria-disabled":r,"aria-pressed":v&&g===LK?!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:T,isDragging:v,listeners:r?void 0:O,node:C,over:h,setNodeRef:w,setActivatorNodeRef:E,transform:S}}function Qlt(){return _.useContext($le)}const ect="Droppable",tct={timeout:25};function nct(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e;const o=lv(ect),{active:s,dispatch:a,over:l,measureDroppableContainers:c}=_.useContext(ZC),u=_.useRef({disabled:n}),f=_.useRef(!1),h=_.useRef(null),g=_.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:v}={...tct,...i},S=ib(b??r),C=_.useCallback(()=>{if(!f.current){f.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=XC({callback:C,disabled:y||!s}),A=_.useCallback((T,I)=>{w&&(I&&(w.unobserve(I),f.current=!1),T&&w.observe(T))},[w]),[E,O]=AS(A),D=ib(t);return _.useEffect(()=>{!w||!E.current||(w.disconnect(),f.current=!1,w.observe(E.current))},[E,w]),_.useEffect(()=>(a({type:Li.RegisterDroppable,element:{id:r,key:o,disabled:n,node:E,rect:h,data:D}}),()=>a({type:Li.UnregisterDroppable,key:o,id:r})),[r]),_.useEffect(()=>{n!==u.current.disabled&&(a({type:Li.SetDroppableDisabled,id:r,key:o,disabled:n}),u.current.disabled=n)},[r,o,n,a]),{active:s,rect:h,isOver:l?.id===r,node:E,over:l,setNodeRef:O}}function _I(e,t,n){const r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function rct(e,t){return e.reduce((n,r,i)=>{const o=t.get(r);return o&&(n[i]=o),n},Array(e.length))}function k5(e){return e!==null&&e>=0}function ict(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 oct(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const Nle=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e;const o=_I(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}},_5={scaleX:1,scaleY:1},sct=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,..._5}:null}const l=act(o,i,n);return i>n&&i<=s?{x:0,y:-a.height-l,..._5}:i<n&&i>=s?{x:0,y:a.height+l,..._5}:{x:0,y:0,..._5}};function act(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 Fle="Sortable",Ble=qt.createContext({activeIndex:-1,containerId:Fle,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Nle,disabled:{draggable:!1,droppable:!1}});function lct(e){let{children:t,id:n,items:r,strategy:i=Nle,disabled:o=!1}=e;const{active:s,dragOverlay:a,droppableRects:l,over:c,measureDroppableContainers:u}=Qlt(),f=lv(Fle,n),h=a.rect!==null,g=_.useMemo(()=>r.map(O=>typeof O=="object"&&"id"in O?O.id:O),[r]),y=s!=null,b=s?g.indexOf(s.id):-1,v=c?g.indexOf(c.id):-1,S=_.useRef(g),C=!ict(g,S.current),w=v!==-1&&b===-1||C,A=oct(o);bc(()=>{C&&y&&u(g)},[C,g,y,u]),_.useEffect(()=>{S.current=g},[g]);const E=_.useMemo(()=>({activeIndex:b,containerId:f,disabled:A,disableTransforms:w,items:g,overIndex:v,useDragOverlay:h,sortedRects:rct(g,l),strategy:i}),[b,f,A.draggable,A.droppable,w,g,v,l,h,i]);return qt.createElement(Ble.Provider,{value:E},t)}const cct=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return _I(n,r,i).indexOf(t)},uct=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},dct={duration:200,easing:"ease"},zle="transform",fct=sb.Transition.toString({property:zle,duration:0,easing:"linear"}),hct={roleDescription:"sortable"};function pct(e){let{disabled:t,index:n,node:r,rect:i}=e;const[o,s]=_.useState(null),a=_.useRef(n);return bc(()=>{if(!t&&n!==a.current&&r.current){const l=i.current;if(l){const c=gg(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]),_.useEffect(()=>{o&&s(null)},[o]),o}function mct(e){let{animateLayoutChanges:t=uct,attributes:n,disabled:r,data:i,getNewIndex:o=cct,id:s,strategy:a,resizeObserverConfig:l,transition:c=dct}=e;const{items:u,containerId:f,activeIndex:h,disabled:g,disableTransforms:y,sortedRects:b,overIndex:v,useDragOverlay:S,strategy:C}=_.useContext(Ble),w=gct(r,g),A=u.indexOf(s),E=_.useMemo(()=>({sortable:{containerId:f,index:A,items:u},...i}),[f,i,A,u]),O=_.useMemo(()=>u.slice(u.indexOf(s)),[u,s]),{rect:D,node:T,isOver:I,setNodeRef:F}=nct({id:s,data:E,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:O,...l}}),{active:L,activatorEvent:R,activeNodeRect:$,attributes:j,setNodeRef:z,listeners:N,isDragging:W,over:H,setActivatorNodeRef:U,transform:K}=Jlt({id:s,data:E,attributes:{...hct,...n},disabled:w.draggable}),B=Iat(F,z),q=!!L,X=q&&!y&&k5(h)&&k5(v),V=!S&&W,Y=V&&X?K:null,ne=X?Y??(a??C)({rects:b,activeNodeRect:$,activeIndex:h,overIndex:v,index:A}):null,ee=k5(h)&&k5(v)?o({id:s,items:u,activeIndex:h,overIndex:v}):A,se=L?.id,ue=_.useRef({activeId:se,items:u,newIndex:ee,containerId:f}),te=u!==ue.current.items,Z=t({active:L,containerId:f,isDragging:W,isSorting:q,id:s,index:A,items:u,newIndex:ue.current.newIndex,previousItems:ue.current.items,previousContainerId:ue.current.containerId,transition:c,wasDragging:ue.current.activeId!=null}),re=pct({disabled:!Z,index:A,node:T,rect:D});return _.useEffect(()=>{q&&ue.current.newIndex!==ee&&(ue.current.newIndex=ee),f!==ue.current.containerId&&(ue.current.containerId=f),u!==ue.current.items&&(ue.current.items=u)},[q,ee,f,u]),_.useEffect(()=>{if(se===ue.current.activeId)return;if(se!=null&&ue.current.activeId==null){ue.current.activeId=se;return}const de=setTimeout(()=>{ue.current.activeId=se},50);return()=>clearTimeout(de)},[se]),{active:L,activeIndex:h,attributes:j,data:E,rect:D,index:A,newIndex:ee,items:u,isOver:I,isSorting:q,isDragging:W,listeners:N,node:T,overIndex:v,over:H,setNodeRef:B,setActivatorNodeRef:U,setDroppableNodeRef:F,setDraggableNodeRef:z,transform:re??ne,transition:oe()};function oe(){if(re||te&&ue.current.newIndex===A)return fct;if(!(V&&!wI(R)||!c)&&(q||Z))return sb.Transition.toString({...c,property:zle})}}function gct(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 DS(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 yct=[Ln.Down,Ln.Right,Ln.Up,Ln.Left],bct=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:o,over:s,scrollableAncestors:a}}=t;if(yct.includes(e.code)){if(e.preventDefault(),!n||!r)return;const l=[];o.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const h=i.get(f.id);if(h)switch(e.code){case Ln.Down:r.top<h.top&&l.push(f);break;case Ln.Up:r.top>h.top&&l.push(f);break;case Ln.Left:r.left>h.left&&l.push(f);break;case Ln.Right:r.left<h.left&&l.push(f);break}});const c=Xat({collisionRect:r,droppableRects:i,droppableContainers:l});let u=Ale(c,"id");if(u===s?.id&&c.length>1&&(u=c[1].id),u!=null){const f=o.get(n.id),h=o.get(u),g=h?i.get(h.id):null,y=h?.node.current;if(y&&g&&f&&h){const v=YC(y).some((O,D)=>a[D]!==O),S=Hle(f,h),C=vct(f,h),w=v||!S?{x:0,y:0}:{x:C?r.width-g.width:0,y:C?r.height-g.height:0},A={x:g.left,y:g.top};return w.x&&w.y?A:ob(A,w)}}}};function Hle(e,t){return!DS(e)||!DS(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function vct(e,t){return!DS(e)||!DS(t)||!Hle(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const xct=({bridge:e,index:t})=>{const{attributes:n,listeners:r,setNodeRef:i,transform:o,transition:s,isDragging:a}=mct({id:e.id}),[l,c]=_.useState(!1);_.useEffect(()=>{Tw(e.id).then(c)},[e.id]);const u={transform:sb.Transform.toString(o),transition:s,opacity:a?.5:1};return m.jsx(tr,{ref:i,style:u,variant:"outlined",sx:{cursor:"grab","&:active":{cursor:"grabbing"},bgcolor:a?"action.selected":"background.paper",width:"fit-content"},children:m.jsxs(gr,{sx:{display:"flex",alignItems:"center",gap:1.5,py:1,"&:last-child":{pb:1}},children:[m.jsx(le,{...n,...r,sx:{display:"flex",alignItems:"center",color:"text.secondary"},children:m.jsx(QCe,{})}),m.jsx(Et,{label:t+1,size:"small",color:"primary",sx:{minWidth:32,fontWeight:"bold"}}),l?m.jsx(le,{component:"img",src:i2(e.id),alt:e.name,sx:{width:40,height:40,borderRadius:"50%",objectFit:"cover",boxShadow:2}}):m.jsx(rl,{sx:{bgcolor:MT(e),width:40,height:40,boxShadow:2},children:(()=>{const f=TT(e);return m.jsx(f,{sx:{fontSize:24}})})()}),m.jsxs(le,{sx:{flex:1},children:[m.jsx(ie,{variant:"subtitle1",fontWeight:500,children:e.name}),m.jsxs(ie,{variant:"caption",color:"text.secondary",children:["Port: ",e.port," • Priority: ",e.priority??100]})]})]})})},Sct=()=>{const e=Tu(),{content:t,isLoading:n}=qm(),r=SCe(),[i,o]=_.useState([]),[s,a]=_.useState(!1);_.useEffect(()=>{if(t){const h=[...t].sort((g,y)=>{const b=g.priority??100,v=y.priority??100;return b-v});o(h),a(!1)}},[t]);const l=Gat(AK(kI),AK(EI,{coordinateGetter:bct})),c=_.useCallback(h=>{const{active:g,over:y}=h;y&&g.id!==y.id&&(o(b=>{const v=b.findIndex(C=>C.id===g.id),S=b.findIndex(C=>C.id===y.id);return _I(b,v,S)}),a(!0))},[]),u=_.useCallback(async()=>{const h=i.map((g,y)=>({id:g.id,priority:(y+1)*10}));try{await r(h),e.show({message:"Startup order saved successfully",severity:"success"}),a(!1)}catch(g){e.show({message:g instanceof Error?g.message:"Failed to save startup order",severity:"error"})}},[i,r,e]),f=_.useMemo(()=>i.map(h=>h.id),[i]);return n?m.jsx(ie,{children:"Loading..."}):m.jsxs(zt,{spacing:3,children:[m.jsx(dw,{items:[{name:"Bridges",to:jt.bridges},{name:"Startup Order",to:jt.startup}]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:2,children:[m.jsx(sm,{color:"primary",fontSize:"large"}),m.jsxs(le,{children:[m.jsx(ie,{variant:"h5",fontWeight:600,children:"Startup Order"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Drag and drop bridges to set the startup order. Lower positions start first."})]})]}),s&&m.jsx(kn,{severity:"info",action:m.jsx(kt,{color:"inherit",size:"small",startIcon:m.jsx(o6,{}),onClick:u,children:"Save Changes"}),children:"You have unsaved changes to the startup order."}),m.jsx(Ylt,{sensors:l,collisionDetection:Yat,onDragEnd:c,children:m.jsx(lct,{items:f,strategy:sct,children:m.jsx(zt,{spacing:1,children:i.map((h,g)=>m.jsx(xct,{bridge:h,index:g},h.id))})})}),i.length===0&&m.jsx(ie,{color:"text.secondary",textAlign:"center",py:4,children:"No bridges configured yet."}),s&&i.length>0&&m.jsx(le,{display:"flex",justifyContent:"flex-end",children:m.jsx(kt,{variant:"contained",startIcon:m.jsx(o6,{}),onClick:u,children:"Save Startup Order"})})]})},nk="https://riddix.github.io/home-assistant-matter-hub",jt={dashboard:"/",bridges:"/bridges",bridge:e=>`/bridges/${e}`,createBridge:"/bridges/create",editBridge:e=>`/bridges/${e}/edit`,devices:"/devices",networkMap:"/network-map",health:"/health",labels:"/labels",lockCredentials:"/lock-credentials",settings:"/settings",startup:"/startup",githubRepository:"https://github.com/riddix/home-assistant-matter-hub/",documentation:nk,faq:{multiFabric:`${nk}/connect-multiple-fabrics`,bridgeConfig:`${nk}/bridge-configuration`}},wct=[{path:"",element:m.jsx(_2e,{}),children:[{path:"",element:m.jsx(c9e,{})},{path:jt.bridges,element:m.jsx(s9e,{})},{path:jt.createBridge,element:m.jsx(ZQe,{})},{path:jt.bridge(":bridgeId"),element:m.jsx(ICe,{})},{path:jt.editBridge(":bridgeId"),element:m.jsx(JQe,{})},{path:jt.devices,element:m.jsx(_9e,{})},{path:jt.networkMap,element:m.jsx(Dat,{})},{path:jt.health,element:m.jsx(set,{})},{path:jt.labels,element:m.jsx(det,{})},{path:jt.lockCredentials,element:m.jsx(yet,{})},{path:jt.settings,element:m.jsx(Rat,{})},{path:jt.startup,element:m.jsx(Sct,{})}]}],Cct={items:{isInitialized:!1,isLoading:!1}},Ect=VO(Cct,e=>{e.addCase(Fo.pending,t=>{t.items.isLoading=!0}).addCase(Fo.rejected,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=void 0,t.items.error=n.error}).addCase(Fo.fulfilled,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(BX.fulfilled,(t,n)=>{t.items.content?.push(n.payload)}).addCase(HX.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(UX.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(zX.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(VX,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(WX,(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)}})}),Act={byBridge:{}},kct=VO(Act,e=>{e.addCase(du.pending,(t,n)=>{t.byBridge[n.meta.arg]=rk(t.byBridge[n.meta.arg],n)}).addCase(du.rejected,(t,n)=>{t.byBridge[n.meta.arg]=rk(t.byBridge[n.meta.arg],n)}).addCase(du.fulfilled,(t,n)=>{t.byBridge[n.meta.arg]=rk(t.byBridge[n.meta.arg],n)})}),_ct={isInitialized:!1,isLoading:!1,content:void 0,error:void 0},rk=VO(_ct,e=>{e.addCase(du.pending,t=>{t.isLoading=!0}).addCase(du.rejected,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=void 0,t.error=n.error}).addCase(du.fulfilled,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=n.payload,t.error=void 0})}),Dct=l2e({reducer:{bridges:Ect,devices:kct}}),DI=Wme({createStyledComponent:me("div",{name:"MuiContainer",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`maxWidth${ye(String(n.maxWidth))}`],n.fixed&&t.fixed,n.disableGutters&&t.disableGutters]}}),useThemeProps:e=>ot({props:e,name:"MuiContainer"})});function Oct(e){return et("MuiToolbar",e)}nt("MuiToolbar",["root","gutters","regular","dense"]);const Tct=e=>{const{classes:t,disableGutters:n,variant:r}=e;return tt({root:["root",!n&&"gutters",r]},Oct,t)},Mct=me("div",{name:"MuiToolbar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,!n.disableGutters&&t.gutters,t[n.variant]]}})(Ge(({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}]}))),Ule=_.forwardRef(function(t,n){const r=ot({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=Tct(c);return m.jsx(Mct,{as:o,className:Oe(u.root,i),ref:n,ownerState:c,...l})}),Rct=[{name:"GitHub",url:jt.githubRepository},{name:"Documentation",url:jt.documentation}],Ict=()=>m.jsxs(DI,{sx:{mt:16,mb:4},children:[m.jsx(gi,{sx:{mt:4,mb:4}}),m.jsx(Qe,{container:!0,spacing:2,justifyContent:"center",children:Rct.map((e,t)=>m.jsx(Qe,{size:{xs:12,sm:"auto"},children:m.jsx(kt,{fullWidth:!0,size:"small",variant:"outlined",component:uw,href:e.url,target:"_blank",children:e.name})},t.toString()))})]});function Pct(e){return et("MuiAppBar",e)}nt("MuiAppBar",["root","positionFixed","positionAbsolute","positionSticky","positionStatic","positionRelative","colorDefault","colorPrimary","colorSecondary","colorInherit","colorTransparent","colorError","colorInfo","colorSuccess","colorWarning"]);const jct=e=>{const{color:t,position:n,classes:r}=e,i={root:["root",`color${ye(t)}`,`position${ye(n)}`]};return tt(i,Pct,r)},NK=(e,t)=>e?`${e.replace(")","")}, ${t})`:t,$ct=me(Nr,{name:"MuiAppBar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`position${ye(n.position)}`],t[`color${ye(n.color)}`]]}})(Ge(({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(Fn(["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?NK(e.vars.palette.AppBar.darkBg,"var(--AppBar-background)"):null,color:e.vars?NK(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"})}}]}))),Lct=_.forwardRef(function(t,n){const r=ot({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=jct(c);return m.jsx($ct,{square:!0,component:"header",ownerState:c,elevation:4,className:Oe(u.root,i,a==="fixed"&&"mui-fixed"),ref:n,...l})});function Nct(e,t,n){const r=t.getBoundingClientRect(),i=n&&n.getBoundingClientRect(),o=tl(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 Fct(e){return typeof e=="function"?e():e}function D5(e,t,n){const r=Fct(n),i=Nct(e,t,r);i&&(t.style.webkitTransform=i,t.style.transform=i)}const Bct=_.forwardRef(function(t,n){const r=Oa(),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:f=i,in:h,onEnter:g,onEntered:y,onEntering:b,onExit:v,onExited:S,onExiting:C,style:w,timeout:A=o,TransitionComponent:E=Ta,...O}=t,D=_.useRef(null),T=Tr(mf(l),D,n),I=H=>U=>{H&&(U===void 0?H(D.current):H(D.current,U))},F=I((H,U)=>{D5(u,H,c),NO(H),g&&g(H,U)}),L=I((H,U)=>{const K=Kd({timeout:A,style:w,easing:f},{mode:"enter"});H.style.webkitTransition=r.transitions.create("-webkit-transform",{...K}),H.style.transition=r.transitions.create("transform",{...K}),H.style.webkitTransform="none",H.style.transform="none",b&&b(H,U)}),R=I(y),$=I(C),j=I(H=>{const U=Kd({timeout:A,style:w,easing:f},{mode:"exit"});H.style.webkitTransition=r.transitions.create("-webkit-transform",U),H.style.transition=r.transitions.create("transform",U),D5(u,H,c),v&&v(H)}),z=I(H=>{H.style.webkitTransition="",H.style.transition="",S&&S(H)}),N=H=>{s&&s(D.current,H)},W=_.useCallback(()=>{D.current&&D5(u,D.current,c)},[u,c]);return _.useEffect(()=>{if(h||u==="down"||u==="right")return;const H=PO(()=>{D.current&&D5(u,D.current,c)}),U=tl(D.current);return U.addEventListener("resize",H),()=>{H.clear(),U.removeEventListener("resize",H)}},[u,h,c]),_.useEffect(()=>{h||W()},[h,W]),m.jsx(E,{nodeRef:D,onEnter:F,onEntered:R,onEntering:L,onExit:j,onExited:z,onExiting:$,addEndListener:N,appear:a,in:h,timeout:A,...O,children:(H,{ownerState:U,...K})=>_.cloneElement(l,{ref:T,style:{visibility:H==="exited"&&!h?"hidden":void 0,...w,...l.props.style},...K})})});function zct(e){return et("MuiDrawer",e)}nt("MuiDrawer",["root","docked","paper","anchorLeft","anchorRight","anchorTop","anchorBottom","paperAnchorLeft","paperAnchorRight","paperAnchorTop","paperAnchorBottom","paperAnchorDockedLeft","paperAnchorDockedRight","paperAnchorDockedTop","paperAnchorDockedBottom","modal"]);const Vle=(e,t)=>{const{ownerState:n}=e;return[t.root,(n.variant==="permanent"||n.variant==="persistent")&&t.docked,n.variant==="temporary"&&t.modal]},Hct=e=>{const{classes:t,anchor:n,variant:r}=e,i={root:["root",`anchor${ye(n)}`],docked:[(r==="permanent"||r==="persistent")&&"docked"],modal:["modal"],paper:["paper",`paperAnchor${ye(n)}`,r!=="temporary"&&`paperAnchorDocked${ye(n)}`]};return tt(i,zct,t)},Uct=me(tT,{name:"MuiDrawer",slot:"Root",overridesResolver:Vle})(Ge(({theme:e})=>({zIndex:(e.vars||e).zIndex.drawer}))),Vct=me("div",{shouldForwardProp:ro,name:"MuiDrawer",slot:"Docked",skipVariantsResolver:!1,overridesResolver:Vle})({flex:"0 0 auto"}),Wct=me(Nr,{name:"MuiDrawer",slot:"Paper",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.paper,t[`paperAnchor${ye(n.anchor)}`],n.variant!=="temporary"&&t[`paperAnchorDocked${ye(n.anchor)}`]]}})(Ge(({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}`}}]}))),Wle={left:"right",right:"left",top:"down",bottom:"up"};function qct(e){return["left","right"].includes(e)}function Gct({direction:e},t){return e==="rtl"&&qct(t)?Wle[t]:t}const Kct=_.forwardRef(function(t,n){const r=ot({props:t,name:"MuiDrawer"}),i=Oa(),o=pf(),s={enter:i.transitions.duration.enteringScreen,exit:i.transitions.duration.leavingScreen},{anchor:a="left",BackdropProps:l,children:c,className:u,elevation:f=16,hideBackdrop:h=!1,ModalProps:{BackdropProps:g,...y}={},onClose:b,open:v=!1,PaperProps:S={},SlideProps:C,TransitionComponent:w,transitionDuration:A=s,variant:E="temporary",slots:O={},slotProps:D={},...T}=r,I=_.useRef(!1);_.useEffect(()=>{I.current=!0},[]);const F=Gct({direction:o?"rtl":"ltr"},a),R={...r,anchor:a,elevation:f,open:v,variant:E,...T},$=Hct(R),j={slots:{transition:w,...O},slotProps:{paper:S,transition:C,...D,backdrop:jO(D.backdrop||{...l,...g},{transitionDuration:A})}},[z,N]=ct("root",{ref:n,elementType:Uct,className:Oe($.root,$.modal,u),shouldForwardComponentProp:!0,ownerState:R,externalForwardedProps:{...j,...T,...y},additionalProps:{open:v,onClose:b,hideBackdrop:h,slots:{backdrop:j.slots.backdrop},slotProps:{backdrop:j.slotProps.backdrop}}}),[W,H]=ct("paper",{elementType:Wct,shouldForwardComponentProp:!0,className:Oe($.paper,S.className),ownerState:R,externalForwardedProps:j,additionalProps:{elevation:E==="temporary"?f:0,square:!0,...E==="temporary"&&{role:"dialog","aria-modal":"true"}}}),[U,K]=ct("docked",{elementType:Vct,ref:n,className:Oe($.root,$.docked,u),ownerState:R,externalForwardedProps:j,additionalProps:T}),[B,q]=ct("transition",{elementType:Bct,ownerState:R,externalForwardedProps:j,additionalProps:{in:v,direction:Wle[F],timeout:A,appear:I.current}}),X=m.jsx(W,{...H,children:c});if(E==="permanent")return m.jsx(U,{...K,children:X});const V=m.jsx(B,{...q,children:X});return E==="persistent"?m.jsx(U,{...K,children:V}):m.jsx(z,{...N,children:V})}),Yct=YY({themeId:ua}),ik={error:"#d32f2f",warn:"#ed6c02",info:"#0288d1",debug:"#7b1fa2"},Xct={error:bf,warn:aw,info:QO,debug:Dw},Zct=({open:e,onClose:t})=>{const[n,r]=_.useState([]),[i,o]=_.useState(!0),[s,a]=_.useState("error,warn,info".split(",")),[l,c]=_.useState(""),[u,f]=_.useState(!0),h=_.useCallback(async()=>{try{const S=new URLSearchParams({level:s.join(","),limit:"500",...l&&{search:l}}),C=await fetch(`api/logs?${S}`);if(C.ok){const w=await C.json();r(w.entries)}}catch(S){console.error("Failed to fetch logs:",S)}finally{o(!1)}},[s,l]);_.useEffect(()=>{e&&h()},[e,h]),_.useEffect(()=>{if(!u||!e)return;const S=setInterval(h,5e3);return()=>clearInterval(S)},[u,e,h]);const g=S=>{a(Array.isArray(S.target.value)?S.target.value:[S.target.value])},y=S=>{c(S.target.value)},b=async()=>{try{await fetch("api/logs",{method:"DELETE"}),r([])}catch(S){console.error("Failed to clear logs:",S)}},v=S=>{const C=Xct[S]||QO;return m.jsx(C,{sx:{fontSize:16,color:ik[S]}})};return m.jsxs(vu,{open:e,onClose:t,maxWidth:"lg",fullWidth:!0,children:[m.jsxs(Su,{sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(Dw,{}),"System Logs",m.jsx(le,{sx:{flexGrow:1}}),m.jsx(cn,{title:"Auto Refresh",children:m.jsx(Et,{label:u?"Auto":"Manual",color:u?"success":"default",size:"small",onClick:()=>f(!u),sx:{cursor:"pointer"}})}),m.jsx(_n,{onClick:t,children:m.jsx(qCe,{})})]}),m.jsxs(xu,{children:[m.jsx(zt,{spacing:2,sx:{mb:2},children:m.jsxs(zt,{direction:"row",spacing:2,alignItems:"center",children:[m.jsxs(ha,{size:"small",sx:{minWidth:200},children:[m.jsx(sc,{children:"Log Level"}),m.jsxs(oa,{value:s,label:"Log Level",onChange:g,multiple:!0,renderValue:S=>m.jsx(le,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:(Array.isArray(S)?S:[S]).map(C=>m.jsx(Et,{label:C.toUpperCase(),size:"small",sx:{backgroundColor:ik[C],color:"white"}},C))}),children:[m.jsx(er,{value:"error",children:"Error"}),m.jsx(er,{value:"warn",children:"Warning"}),m.jsx(er,{value:"info",children:"Info"}),m.jsx(er,{value:"debug",children:"Debug"})]})]}),m.jsx(Lr,{size:"small",placeholder:"Search logs...",value:l,onChange:y,sx:{flexGrow:1}}),m.jsx(kt,{variant:"outlined",onClick:h,children:"Refresh"}),m.jsx(kt,{variant:"outlined",color:"error",onClick:b,children:"Clear"})]})}),m.jsx(le,{sx:{height:400,overflow:"auto",backgroundColor:"background.paper",border:1,borderColor:"divider",borderRadius:1,p:1},children:i?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(ie,{children:"Loading logs..."})}):n.length===0?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(ie,{color:"text.secondary",children:"No logs found"})}):m.jsx(zt,{spacing:1,children:n.map((S,C)=>m.jsxs(le,{sx:{p:1,borderRadius:1,backgroundColor:"action.hover",fontFamily:"monospace",fontSize:"0.875rem",wordBreak:"break-all"},children:[m.jsxs(le,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[v(S.level),m.jsx(ie,{variant:"caption",color:"text.secondary",children:new Date(S.timestamp).toLocaleString()}),m.jsx(Et,{label:S.level.toUpperCase(),size:"small",sx:{backgroundColor:ik[S.level],color:"white",fontSize:"0.7rem",height:20}})]}),m.jsx(ie,{sx:{ml:3},children:S.message}),S.context&&m.jsx(ie,{sx:{ml:3,color:"text.secondary",fontSize:"0.8rem"},children:JSON.stringify(S.context,null,2)})]},`${S.timestamp}-${S.level}-${C}`))})})]}),m.jsx(Xd,{children:m.jsx(kt,{onClick:t,children:"Close"})})]})};function FK(){const{isConnected:e}=A2e(),[t,n]=_.useState(null),[r,i]=_.useState(!1);_.useEffect(()=>{const y=async()=>{try{const v=await fetch("api/health");if(v.ok){const S=await v.json();n(S),i(!1)}else i(!0)}catch{i(!0)}};y();const b=setInterval(y,3e4);return()=>clearInterval(b)},[]);const o=y=>{const b=Math.floor(y/3600),v=Math.floor(y%3600/60);return b>0?`${b}h ${v}m`:`${v}m`},s=t?.status==="healthy"&&!r,a=t?.services?.bridges,l=a&&a.total>0&&a.running===a.total,c=a&&a.total===0,u=t?m.jsxs(le,{sx:{p:.5},children:[m.jsxs("div",{children:[m.jsx("strong",{children:"Version:"})," ",t.version??"Unknown"]}),m.jsxs("div",{children:[m.jsx("strong",{children:"Uptime:"})," ",o(t.uptime??0)]}),t.services?.bridges&&m.jsxs("div",{children:[m.jsx("strong",{children:"Bridges:"})," ",t.services.bridges.running??0,"/",t.services.bridges.total??0," running",(t.services.bridges.stopped??0)>0&&` (${t.services.bridges.stopped} stopped)`]}),t.services?.homeAssistant&&m.jsxs("div",{children:[m.jsx("strong",{children:"Home Assistant:"})," ",t.services.homeAssistant.connected?"Connected":"Disconnected"]}),m.jsxs("div",{children:[m.jsx("strong",{children:"WebSocket:"})," ",e?"Connected":"Disconnected"]})]}):"Loading health status...",f=()=>r||!s?m.jsx(bf,{fontSize:"small"}):l?m.jsx(Mu,{fontSize:"small"}):m.jsx(pw,{fontSize:"small"}),h=()=>r||!s?"error":!l||!e?"warning":"success",g=()=>r?"Error":s?e?c?"No Bridges":l?"Online":"Starting":"Offline":"Unhealthy";return m.jsx(cn,{title:u,arrow:!0,children:m.jsx(Et,{icon:f(),label:g(),color:h(),size:"small",variant:"filled",sx:{borderRadius:1,fontWeight:600,"& .MuiChip-icon":{color:"inherit"}}})})}const Jct=e=>_.createElement("svg",{viewBox:"0 0 91 89",xmlSpace:"preserve",xmlns:"http://www.w3.org/2000/svg",...e},_.createElement("g",{style:{display:"inline"}},_.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"}),_.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"}))),Qct="home-assistant-matter-hub",eut={name:Qct};function tut(){const[e,t]=_.useState("2.1.0-alpha.421");return _.useEffect(()=>{fetch("api/health").then(n=>n.ok?n.json():null).then(n=>{n?.version&&t(n.version)}).catch(()=>{})},[]),_.useMemo(()=>({name:eut.name,version:e}),[e])}const nut=e=>{const t=tut();return m.jsxs(le,{component:Du,to:jt.dashboard,sx:{display:"flex",alignItems:"center",justifyContent:e.large?"flex-start":"center",flexGrow:1,textDecoration:"none",color:"inherit"},children:[m.jsx(Jct,{style:{height:"40px"}}),m.jsx(ie,{variant:"inherit",component:"span",sx:{mr:1,ml:1},children:t.name.split("-").map(ye).join("-")}),e.large&&m.jsx(ie,{variant:"caption",component:"span",children:t.version})]})},rut=()=>{const e=Yct("(min-width:600px)"),{mode:t,setMode:n}=ZS(),[r,i]=_.useState(!1),[o,s]=_.useState(!1),a=Jh(),l=()=>{n(t==="dark"?"light":"dark")},c=[{label:"Dashboard",icon:m.jsx(e_,{}),to:jt.dashboard},{label:"Bridges",icon:m.jsx(py,{}),to:jt.bridges},{label:"All Devices",icon:m.jsx(ss,{}),to:jt.devices},{label:"Network Map",icon:m.jsx(r6,{}),to:jt.networkMap},{label:"Startup Order",icon:m.jsx(sm,{}),to:jt.startup},{label:"Lock Credentials",icon:m.jsx(ac,{}),to:jt.lockCredentials},{label:"Filter Reference",icon:m.jsx(i6,{}),to:jt.labels},{label:"Settings",icon:m.jsx(pm,{}),to:jt.settings},{label:t==="dark"?"Light Mode":"Dark Mode",icon:t==="dark"?m.jsx(a8e,{}):m.jsx(YCe,{}),onClick:l},{label:"System Logs",icon:m.jsx(Dw,{}),onClick:()=>i(!0)},{label:"Health Dashboard",icon:m.jsx(X4,{}),to:jt.health}],u=f=>{s(!1),f.onClick?f.onClick():f.to&&a(f.to)};return m.jsxs(le,{children:[m.jsx(Lct,{sx:{height:"72px"},children:m.jsx(Ule,{sx:{paddingLeft:"0 !important",paddingRight:"0 !important"},children:m.jsxs(DI,{sx:{padding:2,height:"100%",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[m.jsx(nut,{large:e}),e?m.jsxs(le,{sx:{display:"flex",alignItems:"center",gap:1},children:[c.map(f=>f.to?m.jsx(cn,{title:f.label,children:m.jsx(_n,{component:Du,to:f.to,sx:{color:"inherit"},children:f.icon})},f.label):m.jsx(cn,{title:f.label,children:m.jsx(_n,{onClick:f.onClick,sx:{color:"inherit"},children:f.icon})},f.label)),m.jsx(FK,{})]}):m.jsxs(le,{sx:{display:"flex",alignItems:"center",gap:.5},children:[m.jsx(FK,{}),m.jsx(_n,{onClick:()=>s(!0),sx:{color:"inherit"},children:m.jsx(l8e,{})})]})]})})}),m.jsx(Kct,{anchor:"right",open:o,onClose:()=>s(!1),children:m.jsx(vc,{sx:{width:250},children:c.map(f=>m.jsxs(obe,{onClick:()=>u(f),children:[m.jsx(Ul,{children:f.icon}),m.jsx(Va,{primary:f.label})]},f.label))})}),m.jsx(Zct,{open:r,onClose:()=>i(!1)})]})},iut=()=>m.jsxs(le,{children:[m.jsx(rut,{}),m.jsx(Ule,{}),m.jsx(DI,{sx:{p:2},children:m.jsx(gY,{})}),m.jsx(Ict,{})]}),out=KS({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 D4=document.getElementsByTagName("base")[0]?.href?.replace(/\/$/,"");D4?.startsWith("http")&&(D4=new URL(D4).pathname);const sut=Hhe([{path:"/",element:m.jsx(iut,{}),children:wct}],{basename:D4});sde.createRoot(document.getElementById("root")).render(m.jsx(_.StrictMode,{children:m.jsx(Cde,{store:Dct,children:m.jsxs(n1e,{theme:out,children:[m.jsx(Zge,{}),m.jsx(uX,{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}}}),m.jsx(k2e,{children:m.jsx(yye,{children:m.jsx(epe,{router:sut})})})]})})}));
|
|
499
|
+
`},Wat={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 qat(e){let{announcements:t=Wat,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=Vat}=e;const{announce:o,announcement:s}=zat(),a=lv("DndLiveRegion"),[l,c]=_.useState(!1);if(_.useEffect(()=>{c(!0)},[]),Hat(_.useMemo(()=>({onDragStart(f){let{active:h}=f;o(t.onDragStart({active:h}))},onDragMove(f){let{active:h,over:g}=f;t.onDragMove&&o(t.onDragMove({active:h,over:g}))},onDragOver(f){let{active:h,over:g}=f;o(t.onDragOver({active:h,over:g}))},onDragEnd(f){let{active:h,over:g}=f;o(t.onDragEnd({active:h,over:g}))},onDragCancel(f){let{active:h,over:g}=f;o(t.onDragCancel({active:h,over:g}))}}),[o,t])),!l)return null;const u=qt.createElement(qt.Fragment,null,qt.createElement(Fat,{id:r,value:i.draggable}),qt.createElement(Bat,{id:a,announcement:s}));return n?Dd.createPortal(u,n):u}var Li;(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"})(Li||(Li={}));function kS(){}function AK(e,t){return _.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Gat(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return _.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const sl=Object.freeze({x:0,y:0});function Cle(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function Ele(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function Kat(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function kK(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 Ale(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function _K(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 Yat=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=_K(t,t.left,t.top),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=Cle(_K(l),i);o.push({id:a,data:{droppableContainer:s,value:c}})}}return o.sort(Ele)},Xat=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const i=kK(t),o=[];for(const s of r){const{id:a}=s,l=n.get(a);if(l){const c=kK(l),u=i.reduce((h,g,y)=>h+Cle(c[y],g),0),f=Number((u/4).toFixed(4));o.push({id:a,data:{droppableContainer:s,value:f}})}}return o.sort(Ele)};function Zat(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,f=u/(l+c-u);return Number(f.toFixed(4))}return 0}const Jat=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=Zat(a,t);l>0&&i.push({id:s,data:{droppableContainer:o,value:l}})}}return i.sort(Kat)};function Qat(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function kle(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:sl}function elt(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 tlt=elt(1);function nlt(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 rlt(e,t,n){const r=nlt(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,f=o?e.height/o:e.height;return{width:u,height:f,top:c,right:l+u,bottom:c+f,left:l}}const ilt={ignoreTransform:!1};function gg(e,t){t===void 0&&(t=ilt);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:c,transformOrigin:u}=fs(e).getComputedStyle(e);c&&(n=rlt(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 DK(e){return gg(e,{ignoreTransform:!0})}function olt(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function slt(e,t){return t===void 0&&(t=fs(e).getComputedStyle(e)),t.position==="fixed"}function alt(e,t){t===void 0&&(t=fs(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 YC(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(!sv(i)||xle(i)||n.includes(i))return n;const o=fs(e).getComputedStyle(i);return i!==e&&alt(i,o)&&n.push(i),slt(i,o)?n:r(i.parentNode)}return e?r(e):n}function _le(e){const[t]=YC(e,1);return t??null}function QA(e){return!KC||!e?null:pg(e)?e:vI(e)?xI(e)||e===mg(e).scrollingElement?window:sv(e)?e:null:null}function Dle(e){return pg(e)?e.scrollX:e.scrollLeft}function Ole(e){return pg(e)?e.scrollY:e.scrollTop}function tO(e){return{x:Dle(e),y:Ole(e)}}var Xi;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Xi||(Xi={}));function Tle(e){return!KC||!e?!1:e===document.scrollingElement}function Mle(e){const t={x:0,y:0},n=Tle(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 llt={x:.2,y:.2};function clt(e,t,n,r,i){let{top:o,left:s,right:a,bottom:l}=n;r===void 0&&(r=10),i===void 0&&(i=llt);const{isTop:c,isBottom:u,isLeft:f,isRight:h}=Mle(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=Xi.Backward,y.y=r*Math.abs((t.top+b.height-o)/b.height)):!u&&l>=t.bottom-b.height&&(g.y=Xi.Forward,y.y=r*Math.abs((t.bottom-b.height-l)/b.height)),!h&&a>=t.right-b.width?(g.x=Xi.Forward,y.x=r*Math.abs((t.right-b.width-a)/b.width)):!f&&s<=t.left+b.width&&(g.x=Xi.Backward,y.x=r*Math.abs((t.left+b.width-s)/b.width)),{direction:g,speed:y}}function ult(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 Rle(e){return e.reduce((t,n)=>nm(t,tO(n)),sl)}function dlt(e){return e.reduce((t,n)=>t+Dle(n),0)}function flt(e){return e.reduce((t,n)=>t+Ole(n),0)}function hlt(e,t){if(t===void 0&&(t=gg),!e)return;const{top:n,left:r,bottom:i,right:o}=t(e);_le(e)&&(i<=0||o<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const plt=[["x",["left","right"],dlt],["y",["top","bottom"],flt]];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=YC(n),i=Rle(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,s,a]of plt)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 $y{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 mlt(e){const{EventTarget:t}=fs(e);return e instanceof t?e:mg(e)}function ek(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 ta;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(ta||(ta={}));function OK(e){e.preventDefault()}function glt(e){e.stopPropagation()}var Ln;(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"})(Ln||(Ln={}));const Ile={start:[Ln.Space,Ln.Enter],cancel:[Ln.Esc],end:[Ln.Space,Ln.Enter,Ln.Tab]},ylt=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Ln.Right:return{...n,x:n.x+25};case Ln.Left:return{...n,x:n.x-25};case Ln.Down:return{...n,y:n.y+25};case Ln.Up:return{...n,y:n.y-25}}};class EI{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 $y(mg(n)),this.windowListeners=new $y(fs(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(ta.Resize,this.handleCancel),this.windowListeners.add(ta.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(ta.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,r=t.node.current;r&&hlt(r),n(sl)}handleKeyDown(t){if(wI(t)){const{active:n,context:r,options:i}=this.props,{keyboardCodes:o=Ile,coordinateGetter:s=ylt,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}:sl;this.referenceCoordinates||(this.referenceCoordinates=u);const f=s(t,{active:n,context:r.current,currentCoordinates:u});if(f){const h=ob(f,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:A,maxScroll:E,minScroll:O}=Mle(b),D=ult(b),T={x:Math.min(v===Ln.Right?D.right-D.width/2:D.right,Math.max(v===Ln.Right?D.left:D.left+D.width/2,f.x)),y:Math.min(v===Ln.Down?D.bottom-D.height/2:D.bottom,Math.max(v===Ln.Down?D.top:D.top+D.height/2,f.y))},I=v===Ln.Right&&!C||v===Ln.Left&&!w,F=v===Ln.Down&&!A||v===Ln.Up&&!S;if(I&&T.x!==f.x){const L=b.scrollLeft+h.x,R=v===Ln.Right&&L<=E.x||v===Ln.Left&&L>=O.x;if(R&&!h.y){b.scrollTo({left:L,behavior:a});return}R?g.x=b.scrollLeft-L:g.x=v===Ln.Right?b.scrollLeft-E.x:b.scrollLeft-O.x,g.x&&b.scrollBy({left:-g.x,behavior:a});break}else if(F&&T.y!==f.y){const L=b.scrollTop+h.y,R=v===Ln.Down&&L<=E.y||v===Ln.Up&&L>=O.y;if(R&&!h.x){b.scrollTo({top:L,behavior:a});return}R?g.y=b.scrollTop-L:g.y=v===Ln.Down?b.scrollTop-E.y:b.scrollTop-O.y,g.y&&b.scrollBy({top:-g.y,behavior:a});break}}this.handleMove(t,nm(ob(f,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()}}EI.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:r=Ile,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 TK(e){return!!(e&&"distance"in e)}function MK(e){return!!(e&&"delay"in e)}class AI{constructor(t,n,r){var i;r===void 0&&(r=mlt(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=mg(s),this.documentListeners=new $y(this.document),this.listeners=new $y(r),this.windowListeners=new $y(fs(s)),this.initialCoordinates=(i=eO(o))!=null?i:sl,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(ta.Resize,this.handleCancel),this.windowListeners.add(ta.DragStart,OK),this.windowListeners.add(ta.VisibilityChange,this.handleCancel),this.windowListeners.add(ta.ContextMenu,OK),this.documentListeners.add(ta.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(MK(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(TK(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(ta.Click,glt,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(ta.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=eO(t))!=null?n:sl,c=ob(i,l);if(!r&&a){if(TK(a)){if(a.tolerance!=null&&ek(c,a.tolerance))return this.handleCancel();if(ek(c,a.distance))return this.handleStart()}if(MK(a)&&ek(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===Ln.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const blt={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class kI extends AI{constructor(t){const{event:n}=t,r=mg(n.target);super(t,blt,r)}}kI.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 vlt={move:{name:"mousemove"},end:{name:"mouseup"}};var nO;(function(e){e[e.RightClick=2]="RightClick"})(nO||(nO={}));class xlt extends AI{constructor(t){super(t,vlt,mg(t.event.target))}}xlt.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===nO.RightClick?!1:(r?.({event:n}),!0)}}];const tk={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Slt extends AI{constructor(t){super(t,tk)}static setup(){return window.addEventListener(tk.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(tk.move.name,t)};function t(){}}}Slt.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 Ly;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Ly||(Ly={}));var _S;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(_S||(_S={}));function wlt(e){let{acceleration:t,activator:n=Ly.Pointer,canScroll:r,draggingRect:i,enabled:o,interval:s=5,order:a=_S.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:u,delta:f,threshold:h}=e;const g=Elt({delta:f,disabled:!o}),[y,b]=Pat(),v=_.useRef({x:0,y:0}),S=_.useRef({x:0,y:0}),C=_.useMemo(()=>{switch(n){case Ly.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case Ly.DraggableRect:return i}},[n,i,l]),w=_.useRef(null),A=_.useCallback(()=>{const O=w.current;if(!O)return;const D=v.current.x*S.current.x,T=v.current.y*S.current.y;O.scrollBy(D,T)},[]),E=_.useMemo(()=>a===_S.TreeOrder?[...c].reverse():c,[a,c]);_.useEffect(()=>{if(!o||!c.length||!C){b();return}for(const O of E){if(r?.(O)===!1)continue;const D=c.indexOf(O),T=u[D];if(!T)continue;const{direction:I,speed:F}=clt(O,T,C,t,h);for(const L of["x","y"])g[L][I[L]]||(F[L]=0,I[L]=0);if(F.x>0||F.y>0){b(),w.current=O,y(A,s),v.current=F,S.current=I;return}}v.current={x:0,y:0},S.current={x:0,y:0},b()},[t,A,r,b,o,s,JSON.stringify(C),JSON.stringify(g),y,c,E,u,JSON.stringify(h)])}const Clt={x:{[Xi.Backward]:!1,[Xi.Forward]:!1},y:{[Xi.Backward]:!1,[Xi.Forward]:!1}};function Elt(e){let{delta:t,disabled:n}=e;const r=QD(t);return av(i=>{if(n||!r||!i)return Clt;const o={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Xi.Backward]:i.x[Xi.Backward]||o.x===-1,[Xi.Forward]:i.x[Xi.Forward]||o.x===1},y:{[Xi.Backward]:i.y[Xi.Backward]||o.y===-1,[Xi.Forward]:i.y[Xi.Forward]||o.y===1}}},[n,t,r])}function Alt(e,t){const n=t!=null?e.get(t):void 0,r=n?n.node.current:null;return av(i=>{var o;return t==null?null:(o=r??i)!=null?o:null},[r,t])}function klt(e,t){return _.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 ab;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(ab||(ab={}));var rO;(function(e){e.Optimized="optimized"})(rO||(rO={}));const RK=new Map;function _lt(e,t){let{dragging:n,dependencies:r,config:i}=t;const[o,s]=_.useState(null),{frequency:a,measure:l,strategy:c}=i,u=_.useRef(e),f=v(),h=ib(f),g=_.useCallback(function(S){S===void 0&&(S=[]),!h.current&&s(C=>C===null?S:C.concat(S.filter(w=>!C.includes(w))))},[h]),y=_.useRef(null),b=av(S=>{if(f&&!n)return RK;if(!S||S===RK||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 A=w.node.current,E=A?new CI(l(A),A):null;w.rect.current=E,E&&C.set(w.id,E)}return C}return S},[e,o,n,f,l]);return _.useEffect(()=>{u.current=e},[e]),_.useEffect(()=>{f||g()},[n,f]),_.useEffect(()=>{o&&o.length>0&&s(null)},[JSON.stringify(o)]),_.useEffect(()=>{f||typeof a!="number"||y.current!==null||(y.current=setTimeout(()=>{g(),y.current=null},a))},[a,f,g,...r]),{droppableRects:b,measureDroppableContainers:g,measuringScheduled:o!=null};function v(){switch(c){case ab.Always:return!1;case ab.BeforeDragging:return n;default:return!n}}}function Ple(e,t){return av(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function Dlt(e,t){return Ple(e,t)}function Olt(e){let{callback:t,disabled:n}=e;const r=SI(t),i=_.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(r)},[r,n]);return _.useEffect(()=>()=>i?.disconnect(),[i]),i}function XC(e){let{callback:t,disabled:n}=e;const r=SI(t),i=_.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(r)},[n]);return _.useEffect(()=>()=>i?.disconnect(),[i]),i}function Tlt(e){return new CI(gg(e),e)}function IK(e,t,n){t===void 0&&(t=Tlt);const[r,i]=_.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=Olt({callback(l){if(e)for(const c of l){const{type:u,target:f}=c;if(u==="childList"&&f instanceof HTMLElement&&f.contains(e)){o();break}}}}),a=XC({callback:o});return bc(()=>{o(),e?(a?.observe(e),s?.observe(document.body,{childList:!0,subtree:!0})):(a?.disconnect(),s?.disconnect())},[e]),r}function Mlt(e){const t=Ple(e);return kle(e,t)}const PK=[];function Rlt(e){const t=_.useRef(e),n=av(r=>e?r&&r!==PK&&e&&t.current&&e.parentNode===t.current.parentNode?r:YC(e):PK,[e]);return _.useEffect(()=>{t.current=e},[e]),n}function Ilt(e){const[t,n]=_.useState(null),r=_.useRef(e),i=_.useCallback(o=>{const s=QA(o.target);s&&n(a=>a?(a.set(s,tO(s)),new Map(a)):null)},[]);return _.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,tO(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]),_.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,s)=>nm(o,s),sl):Rle(e):sl,[e,t])}function jK(e,t){t===void 0&&(t=[]);const n=_.useRef(null);return _.useEffect(()=>{n.current=null},t),_.useEffect(()=>{const r=e!==sl;r&&!n.current&&(n.current=e),!r&&n.current&&(n.current=null)},[e]),n.current?ob(e,n.current):sl}function Plt(e){_.useEffect(()=>{if(!KC)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 jlt(e,t){return _.useMemo(()=>e.reduce((n,r)=>{let{eventName:i,handler:o}=r;return n[i]=s=>{o(s,t)},n},{}),[e,t])}function jle(e){return _.useMemo(()=>e?olt(e):null,[e])}const $K=[];function $lt(e,t){t===void 0&&(t=gg);const[n]=e,r=jle(n?fs(n):null),[i,o]=_.useState($K);function s(){o(()=>e.length?e.map(l=>Tle(l)?r:new CI(t(l),l)):$K)}const a=XC({callback:s});return bc(()=>{a?.disconnect(),s(),e.forEach(l=>a?.observe(l))},[e]),i}function Llt(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return sv(t)?t:e}function Nlt(e){let{measure:t}=e;const[n,r]=_.useState(null),i=_.useCallback(c=>{for(const{target:u}of c)if(sv(u)){r(f=>{const h=t(u);return f?{...f,width:h.width,height:h.height}:h});break}},[t]),o=XC({callback:i}),s=_.useCallback(c=>{const u=Llt(c);o?.disconnect(),u&&o?.observe(u),r(u?t(u):null)},[t,o]),[a,l]=AS(s);return _.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const Flt=[{sensor:kI,options:{}},{sensor:EI,options:{}}],Blt={current:{}},_4={draggable:{measure:DK},droppable:{measure:DK,strategy:ab.WhileDragging,frequency:rO.Optimized},dragOverlay:{measure:gg}};class Ny 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 zlt={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Ny,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:kS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:_4,measureDroppableContainers:kS,windowRect:null,measuringScheduled:!1},Hlt={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:kS,draggableNodes:new Map,over:null,measureDroppableContainers:kS},ZC=_.createContext(Hlt),$le=_.createContext(zlt);function Ult(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Ny}}}function Vlt(e,t){switch(t.type){case Li.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Li.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 Li.DragEnd:case Li.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Li.RegisterDroppable:{const{element:n}=t,{id:r}=n,i=new Ny(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case Li.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 Ny(e.droppable.containers);return s.set(n,{...o,disabled:i}),{...e,droppable:{...e.droppable,containers:s}}}case Li.UnregisterDroppable:{const{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;const o=new Ny(e.droppable.containers);return o.delete(n),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function Wlt(e){let{disabled:t}=e;const{active:n,activatorEvent:r,draggableNodes:i}=_.useContext(ZC),o=QD(r),s=QD(n?.id);return _.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 f=Lat(u);if(f){f.focus();break}}})}},[r,t,i,s,o]),null}function qlt(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((i,o)=>o({transform:i,...r}),n):n}function Glt(e){return _.useMemo(()=>({draggable:{..._4.draggable,...e?.draggable},droppable:{..._4.droppable,...e?.droppable},dragOverlay:{..._4.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function Klt(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e;const o=_.useRef(!1),{x:s,y:a}=typeof i=="boolean"?{x:i,y:i}:i;bc(()=>{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),f=kle(u,r);if(s||(f.x=0),a||(f.y=0),o.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=_le(c);h&&h.scrollBy({top:f.y,left:f.x})}},[t,s,a,r,n])}const Lle=_.createContext({...sl,scaleX:1,scaleY:1});var xd;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(xd||(xd={}));const Ylt=_.memo(function(t){var n,r,i,o;let{id:s,accessibility:a,autoScroll:l=!0,children:c,sensors:u=Flt,collisionDetection:f=Jat,measuring:h,modifiers:g,...y}=t;const b=_.useReducer(Vlt,void 0,Ult),[v,S]=b,[C,w]=Uat(),[A,E]=_.useState(xd.Uninitialized),O=A===xd.Initialized,{draggable:{active:D,nodes:T,translate:I},droppable:{containers:F}}=v,L=D!=null?T.get(D):null,R=_.useRef({initial:null,translated:null}),$=_.useMemo(()=>{var Dt;return D!=null?{id:D,data:(Dt=L?.data)!=null?Dt:Blt,rect:R}:null},[D,L]),j=_.useRef(null),[z,N]=_.useState(null),[W,H]=_.useState(null),U=ib(y,Object.values(y)),K=lv("DndDescribedBy",s),B=_.useMemo(()=>F.getEnabled(),[F]),q=Glt(h),{droppableRects:X,measureDroppableContainers:V,measuringScheduled:Y}=_lt(B,{dragging:O,dependencies:[I.x,I.y],config:q.droppable}),J=Alt(T,D),ne=_.useMemo(()=>W?eO(W):null,[W]),ee=yr(),se=Dlt(J,q.draggable.measure);Klt({activeNode:D!=null?T.get(D):null,config:ee.layoutShiftCompensation,initialRect:se,measure:q.draggable.measure});const ue=IK(J,q.draggable.measure,se),te=IK(J?J.parentElement:null),Z=_.useRef({activatorEvent:null,active:null,activeNode:J,collisionRect:null,collisions:null,droppableRects:X,draggableNodes:T,draggingNode:null,draggingNodeRect:null,droppableContainers:F,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),re=F.getNodeFor((n=Z.current.over)==null?void 0:n.id),oe=Nlt({measure:q.dragOverlay.measure}),de=(r=oe.nodeRef.current)!=null?r:J,be=O?(i=oe.rect)!=null?i:ue:null,je=!!(oe.nodeRef.current&&oe.rect),De=Mlt(je?null:ue),Ke=jle(de?fs(de):null),xe=Rlt(O?re??J:null),Le=$lt(xe),Te=qlt(g,{transform:{x:I.x-De.x,y:I.y-De.y,scaleX:1,scaleY:1},activatorEvent:W,active:$,activeNodeRect:ue,containerNodeRect:te,draggingNodeRect:be,over:Z.current.over,overlayNodeRect:oe.rect,scrollableAncestors:xe,scrollableAncestorRects:Le,windowRect:Ke}),ht=ne?nm(ne,I):null,mt=Ilt(xe),ze=jK(mt),Ie=jK(mt,[ue]),He=nm(Te,ze),Je=be?tlt(be,Te):null,rt=$&&Je?f({active:$,collisionRect:Je,droppableRects:X,droppableContainers:B,pointerCoordinates:ht}):null,st=Ale(rt,"id"),[Xe,Lt]=_.useState(null),Nt=je?Te:nm(Te,Ie),Ot=Qat(Nt,(o=Xe?.rect)!=null?o:null,ue),Xn=_.useRef(null),rn=_.useCallback((Dt,Pt)=>{let{sensor:Jt,options:jn}=Pt;if(j.current==null)return;const on=T.get(j.current);if(!on)return;const St=Dt.nativeEvent,mn=new Jt({active:j.current,activeNode:on,event:St,options:jn,context:Z,onAbort(br){if(!T.get(br))return;const{onDragAbort:ce}=U.current,pe={id:br};ce?.(pe),C({type:"onDragAbort",event:pe})},onPending(br,ei,ce,pe){if(!T.get(br))return;const{onDragPending:Fe}=U.current,Ue={id:br,constraint:ei,initialCoordinates:ce,offset:pe};Fe?.(Ue),C({type:"onDragPending",event:Ue})},onStart(br){const ei=j.current;if(ei==null)return;const ce=T.get(ei);if(!ce)return;const{onDragStart:pe}=U.current,Se={activatorEvent:St,active:{id:ei,data:ce.data,rect:R}};Dd.unstable_batchedUpdates(()=>{pe?.(Se),E(xd.Initializing),S({type:Li.DragStart,initialCoordinates:br,active:ei}),C({type:"onDragStart",event:Se}),N(Xn.current),H(St)})},onMove(br){S({type:Li.DragMove,coordinates:br})},onEnd:Qr(Li.DragEnd),onCancel:Qr(Li.DragCancel)});Xn.current=mn;function Qr(br){return async function(){const{active:ce,collisions:pe,over:Se,scrollAdjustedTranslate:Fe}=Z.current;let Ue=null;if(ce&&Fe){const{cancelDrop:yt}=U.current;Ue={activatorEvent:St,active:ce,collisions:pe,delta:Fe,over:Se},br===Li.DragEnd&&typeof yt=="function"&&await Promise.resolve(yt(Ue))&&(br=Li.DragCancel)}j.current=null,Dd.unstable_batchedUpdates(()=>{S({type:br}),E(xd.Uninitialized),Lt(null),N(null),H(null),Xn.current=null;const yt=br===Li.DragEnd?"onDragEnd":"onDragCancel";if(Ue){const it=U.current[yt];it?.(Ue),C({type:yt,event:Ue})}})}}},[T]),lt=_.useCallback((Dt,Pt)=>(Jt,jn)=>{const on=Jt.nativeEvent,St=T.get(jn);if(j.current!==null||!St||on.dndKit||on.defaultPrevented)return;const mn={active:St};Dt(Jt,Pt.options,mn)===!0&&(on.dndKit={capturedBy:Pt.sensor},j.current=jn,rn(Jt,Pt))},[T,rn]),Ht=klt(u,lt);Plt(u),bc(()=>{ue&&A===xd.Initializing&&E(xd.Initialized)},[ue,A]),_.useEffect(()=>{const{onDragMove:Dt}=U.current,{active:Pt,activatorEvent:Jt,collisions:jn,over:on}=Z.current;if(!Pt||!Jt)return;const St={active:Pt,activatorEvent:Jt,collisions:jn,delta:{x:He.x,y:He.y},over:on};Dd.unstable_batchedUpdates(()=>{Dt?.(St),C({type:"onDragMove",event:St})})},[He.x,He.y]),_.useEffect(()=>{const{active:Dt,activatorEvent:Pt,collisions:Jt,droppableContainers:jn,scrollAdjustedTranslate:on}=Z.current;if(!Dt||j.current==null||!Pt||!on)return;const{onDragOver:St}=U.current,mn=jn.get(st),Qr=mn&&mn.rect.current?{id:mn.id,rect:mn.rect.current,data:mn.data,disabled:mn.disabled}:null,br={active:Dt,activatorEvent:Pt,collisions:Jt,delta:{x:on.x,y:on.y},over:Qr};Dd.unstable_batchedUpdates(()=>{Lt(Qr),St?.(br),C({type:"onDragOver",event:br})})},[st]),bc(()=>{Z.current={activatorEvent:W,active:$,activeNode:J,collisionRect:Je,collisions:rt,droppableRects:X,draggableNodes:T,draggingNode:de,draggingNodeRect:be,droppableContainers:F,over:Xe,scrollableAncestors:xe,scrollAdjustedTranslate:He},R.current={initial:be,translated:Je}},[$,J,rt,Je,T,de,be,X,F,Xe,xe,He]),wlt({...ee,delta:I,draggingRect:Je,pointerCoordinates:ht,scrollableAncestors:xe,scrollableAncestorRects:Le});const Dn=_.useMemo(()=>({active:$,activeNode:J,activeNodeRect:ue,activatorEvent:W,collisions:rt,containerNodeRect:te,dragOverlay:oe,draggableNodes:T,droppableContainers:F,droppableRects:X,over:Xe,measureDroppableContainers:V,scrollableAncestors:xe,scrollableAncestorRects:Le,measuringConfiguration:q,measuringScheduled:Y,windowRect:Ke}),[$,J,ue,W,rt,te,oe,T,F,X,Xe,V,xe,Le,q,Y,Ke]),Gn=_.useMemo(()=>({activatorEvent:W,activators:Ht,active:$,activeNodeRect:ue,ariaDescribedById:{draggable:K},dispatch:S,draggableNodes:T,over:Xe,measureDroppableContainers:V}),[W,Ht,$,ue,S,K,T,Xe,V]);return qt.createElement(wle.Provider,{value:w},qt.createElement(ZC.Provider,{value:Gn},qt.createElement($le.Provider,{value:Dn},qt.createElement(Lle.Provider,{value:Ot},c)),qt.createElement(Wlt,{disabled:a?.restoreFocus===!1})),qt.createElement(qat,{...a,hiddenTextDescribedById:K}));function yr(){const Dt=z?.autoScrollEnabled===!1,Pt=typeof l=="object"?l.enabled===!1:l===!1,Jt=O&&!Dt&&!Pt;return typeof l=="object"?{...l,enabled:Jt}:{enabled:Jt}}}),Xlt=_.createContext(null),LK="button",Zlt="Draggable";function Jlt(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e;const o=lv(Zlt),{activators:s,activatorEvent:a,active:l,activeNodeRect:c,ariaDescribedById:u,draggableNodes:f,over:h}=_.useContext(ZC),{role:g=LK,roleDescription:y="draggable",tabIndex:b=0}=i??{},v=l?.id===t,S=_.useContext(v?Lle:Xlt),[C,w]=AS(),[A,E]=AS(),O=jlt(s,t),D=ib(n);bc(()=>(f.set(t,{id:t,key:o,node:C,activatorNode:A,data:D}),()=>{const I=f.get(t);I&&I.key===o&&f.delete(t)}),[f,t]);const T=_.useMemo(()=>({role:g,tabIndex:b,"aria-disabled":r,"aria-pressed":v&&g===LK?!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:T,isDragging:v,listeners:r?void 0:O,node:C,over:h,setNodeRef:w,setActivatorNodeRef:E,transform:S}}function Qlt(){return _.useContext($le)}const ect="Droppable",tct={timeout:25};function nct(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e;const o=lv(ect),{active:s,dispatch:a,over:l,measureDroppableContainers:c}=_.useContext(ZC),u=_.useRef({disabled:n}),f=_.useRef(!1),h=_.useRef(null),g=_.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:v}={...tct,...i},S=ib(b??r),C=_.useCallback(()=>{if(!f.current){f.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=XC({callback:C,disabled:y||!s}),A=_.useCallback((T,I)=>{w&&(I&&(w.unobserve(I),f.current=!1),T&&w.observe(T))},[w]),[E,O]=AS(A),D=ib(t);return _.useEffect(()=>{!w||!E.current||(w.disconnect(),f.current=!1,w.observe(E.current))},[E,w]),_.useEffect(()=>(a({type:Li.RegisterDroppable,element:{id:r,key:o,disabled:n,node:E,rect:h,data:D}}),()=>a({type:Li.UnregisterDroppable,key:o,id:r})),[r]),_.useEffect(()=>{n!==u.current.disabled&&(a({type:Li.SetDroppableDisabled,id:r,key:o,disabled:n}),u.current.disabled=n)},[r,o,n,a]),{active:s,rect:h,isOver:l?.id===r,node:E,over:l,setNodeRef:O}}function _I(e,t,n){const r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function rct(e,t){return e.reduce((n,r,i)=>{const o=t.get(r);return o&&(n[i]=o),n},Array(e.length))}function k5(e){return e!==null&&e>=0}function ict(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 oct(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const Nle=e=>{let{rects:t,activeIndex:n,overIndex:r,index:i}=e;const o=_I(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}},_5={scaleX:1,scaleY:1},sct=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,..._5}:null}const l=act(o,i,n);return i>n&&i<=s?{x:0,y:-a.height-l,..._5}:i<n&&i>=s?{x:0,y:a.height+l,..._5}:{x:0,y:0,..._5}};function act(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 Fle="Sortable",Ble=qt.createContext({activeIndex:-1,containerId:Fle,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Nle,disabled:{draggable:!1,droppable:!1}});function lct(e){let{children:t,id:n,items:r,strategy:i=Nle,disabled:o=!1}=e;const{active:s,dragOverlay:a,droppableRects:l,over:c,measureDroppableContainers:u}=Qlt(),f=lv(Fle,n),h=a.rect!==null,g=_.useMemo(()=>r.map(O=>typeof O=="object"&&"id"in O?O.id:O),[r]),y=s!=null,b=s?g.indexOf(s.id):-1,v=c?g.indexOf(c.id):-1,S=_.useRef(g),C=!ict(g,S.current),w=v!==-1&&b===-1||C,A=oct(o);bc(()=>{C&&y&&u(g)},[C,g,y,u]),_.useEffect(()=>{S.current=g},[g]);const E=_.useMemo(()=>({activeIndex:b,containerId:f,disabled:A,disableTransforms:w,items:g,overIndex:v,useDragOverlay:h,sortedRects:rct(g,l),strategy:i}),[b,f,A.draggable,A.droppable,w,g,v,l,h,i]);return qt.createElement(Ble.Provider,{value:E},t)}const cct=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return _I(n,r,i).indexOf(t)},uct=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},dct={duration:200,easing:"ease"},zle="transform",fct=sb.Transition.toString({property:zle,duration:0,easing:"linear"}),hct={roleDescription:"sortable"};function pct(e){let{disabled:t,index:n,node:r,rect:i}=e;const[o,s]=_.useState(null),a=_.useRef(n);return bc(()=>{if(!t&&n!==a.current&&r.current){const l=i.current;if(l){const c=gg(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]),_.useEffect(()=>{o&&s(null)},[o]),o}function mct(e){let{animateLayoutChanges:t=uct,attributes:n,disabled:r,data:i,getNewIndex:o=cct,id:s,strategy:a,resizeObserverConfig:l,transition:c=dct}=e;const{items:u,containerId:f,activeIndex:h,disabled:g,disableTransforms:y,sortedRects:b,overIndex:v,useDragOverlay:S,strategy:C}=_.useContext(Ble),w=gct(r,g),A=u.indexOf(s),E=_.useMemo(()=>({sortable:{containerId:f,index:A,items:u},...i}),[f,i,A,u]),O=_.useMemo(()=>u.slice(u.indexOf(s)),[u,s]),{rect:D,node:T,isOver:I,setNodeRef:F}=nct({id:s,data:E,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:O,...l}}),{active:L,activatorEvent:R,activeNodeRect:$,attributes:j,setNodeRef:z,listeners:N,isDragging:W,over:H,setActivatorNodeRef:U,transform:K}=Jlt({id:s,data:E,attributes:{...hct,...n},disabled:w.draggable}),B=Iat(F,z),q=!!L,X=q&&!y&&k5(h)&&k5(v),V=!S&&W,Y=V&&X?K:null,ne=X?Y??(a??C)({rects:b,activeNodeRect:$,activeIndex:h,overIndex:v,index:A}):null,ee=k5(h)&&k5(v)?o({id:s,items:u,activeIndex:h,overIndex:v}):A,se=L?.id,ue=_.useRef({activeId:se,items:u,newIndex:ee,containerId:f}),te=u!==ue.current.items,Z=t({active:L,containerId:f,isDragging:W,isSorting:q,id:s,index:A,items:u,newIndex:ue.current.newIndex,previousItems:ue.current.items,previousContainerId:ue.current.containerId,transition:c,wasDragging:ue.current.activeId!=null}),re=pct({disabled:!Z,index:A,node:T,rect:D});return _.useEffect(()=>{q&&ue.current.newIndex!==ee&&(ue.current.newIndex=ee),f!==ue.current.containerId&&(ue.current.containerId=f),u!==ue.current.items&&(ue.current.items=u)},[q,ee,f,u]),_.useEffect(()=>{if(se===ue.current.activeId)return;if(se!=null&&ue.current.activeId==null){ue.current.activeId=se;return}const de=setTimeout(()=>{ue.current.activeId=se},50);return()=>clearTimeout(de)},[se]),{active:L,activeIndex:h,attributes:j,data:E,rect:D,index:A,newIndex:ee,items:u,isOver:I,isSorting:q,isDragging:W,listeners:N,node:T,overIndex:v,over:H,setNodeRef:B,setActivatorNodeRef:U,setDroppableNodeRef:F,setDraggableNodeRef:z,transform:re??ne,transition:oe()};function oe(){if(re||te&&ue.current.newIndex===A)return fct;if(!(V&&!wI(R)||!c)&&(q||Z))return sb.Transition.toString({...c,property:zle})}}function gct(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 DS(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 yct=[Ln.Down,Ln.Right,Ln.Up,Ln.Left],bct=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:o,over:s,scrollableAncestors:a}}=t;if(yct.includes(e.code)){if(e.preventDefault(),!n||!r)return;const l=[];o.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const h=i.get(f.id);if(h)switch(e.code){case Ln.Down:r.top<h.top&&l.push(f);break;case Ln.Up:r.top>h.top&&l.push(f);break;case Ln.Left:r.left>h.left&&l.push(f);break;case Ln.Right:r.left<h.left&&l.push(f);break}});const c=Xat({collisionRect:r,droppableRects:i,droppableContainers:l});let u=Ale(c,"id");if(u===s?.id&&c.length>1&&(u=c[1].id),u!=null){const f=o.get(n.id),h=o.get(u),g=h?i.get(h.id):null,y=h?.node.current;if(y&&g&&f&&h){const v=YC(y).some((O,D)=>a[D]!==O),S=Hle(f,h),C=vct(f,h),w=v||!S?{x:0,y:0}:{x:C?r.width-g.width:0,y:C?r.height-g.height:0},A={x:g.left,y:g.top};return w.x&&w.y?A:ob(A,w)}}}};function Hle(e,t){return!DS(e)||!DS(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function vct(e,t){return!DS(e)||!DS(t)||!Hle(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}const xct=({bridge:e,index:t})=>{const{attributes:n,listeners:r,setNodeRef:i,transform:o,transition:s,isDragging:a}=mct({id:e.id}),[l,c]=_.useState(!1);_.useEffect(()=>{Tw(e.id).then(c)},[e.id]);const u={transform:sb.Transform.toString(o),transition:s,opacity:a?.5:1};return m.jsx(tr,{ref:i,style:u,variant:"outlined",sx:{cursor:"grab","&:active":{cursor:"grabbing"},bgcolor:a?"action.selected":"background.paper",width:"fit-content"},children:m.jsxs(gr,{sx:{display:"flex",alignItems:"center",gap:1.5,py:1,"&:last-child":{pb:1}},children:[m.jsx(le,{...n,...r,sx:{display:"flex",alignItems:"center",color:"text.secondary"},children:m.jsx(QCe,{})}),m.jsx(Et,{label:t+1,size:"small",color:"primary",sx:{minWidth:32,fontWeight:"bold"}}),l?m.jsx(le,{component:"img",src:i2(e.id),alt:e.name,sx:{width:40,height:40,borderRadius:"50%",objectFit:"cover",boxShadow:2}}):m.jsx(rl,{sx:{bgcolor:MT(e),width:40,height:40,boxShadow:2},children:(()=>{const f=TT(e);return m.jsx(f,{sx:{fontSize:24}})})()}),m.jsxs(le,{sx:{flex:1},children:[m.jsx(ie,{variant:"subtitle1",fontWeight:500,children:e.name}),m.jsxs(ie,{variant:"caption",color:"text.secondary",children:["Port: ",e.port," • Priority: ",e.priority??100]})]})]})})},Sct=()=>{const e=Tu(),{content:t,isLoading:n}=qm(),r=SCe(),[i,o]=_.useState([]),[s,a]=_.useState(!1);_.useEffect(()=>{if(t){const h=[...t].sort((g,y)=>{const b=g.priority??100,v=y.priority??100;return b-v});o(h),a(!1)}},[t]);const l=Gat(AK(kI),AK(EI,{coordinateGetter:bct})),c=_.useCallback(h=>{const{active:g,over:y}=h;y&&g.id!==y.id&&(o(b=>{const v=b.findIndex(C=>C.id===g.id),S=b.findIndex(C=>C.id===y.id);return _I(b,v,S)}),a(!0))},[]),u=_.useCallback(async()=>{const h=i.map((g,y)=>({id:g.id,priority:(y+1)*10}));try{await r(h),e.show({message:"Startup order saved successfully",severity:"success"}),a(!1)}catch(g){e.show({message:g instanceof Error?g.message:"Failed to save startup order",severity:"error"})}},[i,r,e]),f=_.useMemo(()=>i.map(h=>h.id),[i]);return n?m.jsx(ie,{children:"Loading..."}):m.jsxs(zt,{spacing:3,children:[m.jsx(dw,{items:[{name:"Bridges",to:jt.bridges},{name:"Startup Order",to:jt.startup}]}),m.jsxs(le,{display:"flex",alignItems:"center",gap:2,children:[m.jsx(sm,{color:"primary",fontSize:"large"}),m.jsxs(le,{children:[m.jsx(ie,{variant:"h5",fontWeight:600,children:"Startup Order"}),m.jsx(ie,{variant:"body2",color:"text.secondary",children:"Drag and drop bridges to set the startup order. Lower positions start first."})]})]}),s&&m.jsx(kn,{severity:"info",action:m.jsx(kt,{color:"inherit",size:"small",startIcon:m.jsx(o6,{}),onClick:u,children:"Save Changes"}),children:"You have unsaved changes to the startup order."}),m.jsx(Ylt,{sensors:l,collisionDetection:Yat,onDragEnd:c,children:m.jsx(lct,{items:f,strategy:sct,children:m.jsx(zt,{spacing:1,children:i.map((h,g)=>m.jsx(xct,{bridge:h,index:g},h.id))})})}),i.length===0&&m.jsx(ie,{color:"text.secondary",textAlign:"center",py:4,children:"No bridges configured yet."}),s&&i.length>0&&m.jsx(le,{display:"flex",justifyContent:"flex-end",children:m.jsx(kt,{variant:"contained",startIcon:m.jsx(o6,{}),onClick:u,children:"Save Startup Order"})})]})},nk="https://riddix.github.io/home-assistant-matter-hub",jt={dashboard:"/",bridges:"/bridges",bridge:e=>`/bridges/${e}`,createBridge:"/bridges/create",editBridge:e=>`/bridges/${e}/edit`,devices:"/devices",networkMap:"/network-map",health:"/health",labels:"/labels",lockCredentials:"/lock-credentials",settings:"/settings",startup:"/startup",githubRepository:"https://github.com/riddix/home-assistant-matter-hub/",documentation:nk,faq:{multiFabric:`${nk}/connect-multiple-fabrics`,bridgeConfig:`${nk}/bridge-configuration`}},wct=[{path:"",element:m.jsx(_2e,{}),children:[{path:"",element:m.jsx(c9e,{})},{path:jt.bridges,element:m.jsx(s9e,{})},{path:jt.createBridge,element:m.jsx(ZQe,{})},{path:jt.bridge(":bridgeId"),element:m.jsx(ICe,{})},{path:jt.editBridge(":bridgeId"),element:m.jsx(JQe,{})},{path:jt.devices,element:m.jsx(_9e,{})},{path:jt.networkMap,element:m.jsx(Dat,{})},{path:jt.health,element:m.jsx(set,{})},{path:jt.labels,element:m.jsx(det,{})},{path:jt.lockCredentials,element:m.jsx(yet,{})},{path:jt.settings,element:m.jsx(Rat,{})},{path:jt.startup,element:m.jsx(Sct,{})}]}],Cct={items:{isInitialized:!1,isLoading:!1}},Ect=VO(Cct,e=>{e.addCase(Fo.pending,t=>{t.items.isLoading=!0}).addCase(Fo.rejected,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=void 0,t.items.error=n.error}).addCase(Fo.fulfilled,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(BX.fulfilled,(t,n)=>{t.items.content?.push(n.payload)}).addCase(HX.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(UX.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(zX.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(VX,(t,n)=>{t.items.isInitialized=!0,t.items.isLoading=!1,t.items.content=n.payload,t.items.error=void 0}).addCase(WX,(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)}})}),Act={byBridge:{}},kct=VO(Act,e=>{e.addCase(du.pending,(t,n)=>{t.byBridge[n.meta.arg]=rk(t.byBridge[n.meta.arg],n)}).addCase(du.rejected,(t,n)=>{t.byBridge[n.meta.arg]=rk(t.byBridge[n.meta.arg],n)}).addCase(du.fulfilled,(t,n)=>{t.byBridge[n.meta.arg]=rk(t.byBridge[n.meta.arg],n)})}),_ct={isInitialized:!1,isLoading:!1,content:void 0,error:void 0},rk=VO(_ct,e=>{e.addCase(du.pending,t=>{t.isLoading=!0}).addCase(du.rejected,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=void 0,t.error=n.error}).addCase(du.fulfilled,(t,n)=>{t.isInitialized=!0,t.isLoading=!1,t.content=n.payload,t.error=void 0})}),Dct=l2e({reducer:{bridges:Ect,devices:kct}}),DI=Wme({createStyledComponent:me("div",{name:"MuiContainer",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`maxWidth${ye(String(n.maxWidth))}`],n.fixed&&t.fixed,n.disableGutters&&t.disableGutters]}}),useThemeProps:e=>ot({props:e,name:"MuiContainer"})});function Oct(e){return et("MuiToolbar",e)}nt("MuiToolbar",["root","gutters","regular","dense"]);const Tct=e=>{const{classes:t,disableGutters:n,variant:r}=e;return tt({root:["root",!n&&"gutters",r]},Oct,t)},Mct=me("div",{name:"MuiToolbar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,!n.disableGutters&&t.gutters,t[n.variant]]}})(Ge(({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}]}))),Ule=_.forwardRef(function(t,n){const r=ot({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=Tct(c);return m.jsx(Mct,{as:o,className:Oe(u.root,i),ref:n,ownerState:c,...l})}),Rct=[{name:"GitHub",url:jt.githubRepository},{name:"Documentation",url:jt.documentation}],Ict=()=>m.jsxs(DI,{sx:{mt:16,mb:4},children:[m.jsx(gi,{sx:{mt:4,mb:4}}),m.jsx(Qe,{container:!0,spacing:2,justifyContent:"center",children:Rct.map((e,t)=>m.jsx(Qe,{size:{xs:12,sm:"auto"},children:m.jsx(kt,{fullWidth:!0,size:"small",variant:"outlined",component:uw,href:e.url,target:"_blank",children:e.name})},t.toString()))})]});function Pct(e){return et("MuiAppBar",e)}nt("MuiAppBar",["root","positionFixed","positionAbsolute","positionSticky","positionStatic","positionRelative","colorDefault","colorPrimary","colorSecondary","colorInherit","colorTransparent","colorError","colorInfo","colorSuccess","colorWarning"]);const jct=e=>{const{color:t,position:n,classes:r}=e,i={root:["root",`color${ye(t)}`,`position${ye(n)}`]};return tt(i,Pct,r)},NK=(e,t)=>e?`${e.replace(")","")}, ${t})`:t,$ct=me(Nr,{name:"MuiAppBar",slot:"Root",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.root,t[`position${ye(n.position)}`],t[`color${ye(n.color)}`]]}})(Ge(({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(Fn(["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?NK(e.vars.palette.AppBar.darkBg,"var(--AppBar-background)"):null,color:e.vars?NK(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"})}}]}))),Lct=_.forwardRef(function(t,n){const r=ot({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=jct(c);return m.jsx($ct,{square:!0,component:"header",ownerState:c,elevation:4,className:Oe(u.root,i,a==="fixed"&&"mui-fixed"),ref:n,...l})});function Nct(e,t,n){const r=t.getBoundingClientRect(),i=n&&n.getBoundingClientRect(),o=tl(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 Fct(e){return typeof e=="function"?e():e}function D5(e,t,n){const r=Fct(n),i=Nct(e,t,r);i&&(t.style.webkitTransform=i,t.style.transform=i)}const Bct=_.forwardRef(function(t,n){const r=Oa(),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:f=i,in:h,onEnter:g,onEntered:y,onEntering:b,onExit:v,onExited:S,onExiting:C,style:w,timeout:A=o,TransitionComponent:E=Ta,...O}=t,D=_.useRef(null),T=Tr(mf(l),D,n),I=H=>U=>{H&&(U===void 0?H(D.current):H(D.current,U))},F=I((H,U)=>{D5(u,H,c),NO(H),g&&g(H,U)}),L=I((H,U)=>{const K=Kd({timeout:A,style:w,easing:f},{mode:"enter"});H.style.webkitTransition=r.transitions.create("-webkit-transform",{...K}),H.style.transition=r.transitions.create("transform",{...K}),H.style.webkitTransform="none",H.style.transform="none",b&&b(H,U)}),R=I(y),$=I(C),j=I(H=>{const U=Kd({timeout:A,style:w,easing:f},{mode:"exit"});H.style.webkitTransition=r.transitions.create("-webkit-transform",U),H.style.transition=r.transitions.create("transform",U),D5(u,H,c),v&&v(H)}),z=I(H=>{H.style.webkitTransition="",H.style.transition="",S&&S(H)}),N=H=>{s&&s(D.current,H)},W=_.useCallback(()=>{D.current&&D5(u,D.current,c)},[u,c]);return _.useEffect(()=>{if(h||u==="down"||u==="right")return;const H=PO(()=>{D.current&&D5(u,D.current,c)}),U=tl(D.current);return U.addEventListener("resize",H),()=>{H.clear(),U.removeEventListener("resize",H)}},[u,h,c]),_.useEffect(()=>{h||W()},[h,W]),m.jsx(E,{nodeRef:D,onEnter:F,onEntered:R,onEntering:L,onExit:j,onExited:z,onExiting:$,addEndListener:N,appear:a,in:h,timeout:A,...O,children:(H,{ownerState:U,...K})=>_.cloneElement(l,{ref:T,style:{visibility:H==="exited"&&!h?"hidden":void 0,...w,...l.props.style},...K})})});function zct(e){return et("MuiDrawer",e)}nt("MuiDrawer",["root","docked","paper","anchorLeft","anchorRight","anchorTop","anchorBottom","paperAnchorLeft","paperAnchorRight","paperAnchorTop","paperAnchorBottom","paperAnchorDockedLeft","paperAnchorDockedRight","paperAnchorDockedTop","paperAnchorDockedBottom","modal"]);const Vle=(e,t)=>{const{ownerState:n}=e;return[t.root,(n.variant==="permanent"||n.variant==="persistent")&&t.docked,n.variant==="temporary"&&t.modal]},Hct=e=>{const{classes:t,anchor:n,variant:r}=e,i={root:["root",`anchor${ye(n)}`],docked:[(r==="permanent"||r==="persistent")&&"docked"],modal:["modal"],paper:["paper",`paperAnchor${ye(n)}`,r!=="temporary"&&`paperAnchorDocked${ye(n)}`]};return tt(i,zct,t)},Uct=me(tT,{name:"MuiDrawer",slot:"Root",overridesResolver:Vle})(Ge(({theme:e})=>({zIndex:(e.vars||e).zIndex.drawer}))),Vct=me("div",{shouldForwardProp:ro,name:"MuiDrawer",slot:"Docked",skipVariantsResolver:!1,overridesResolver:Vle})({flex:"0 0 auto"}),Wct=me(Nr,{name:"MuiDrawer",slot:"Paper",overridesResolver:(e,t)=>{const{ownerState:n}=e;return[t.paper,t[`paperAnchor${ye(n.anchor)}`],n.variant!=="temporary"&&t[`paperAnchorDocked${ye(n.anchor)}`]]}})(Ge(({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}`}}]}))),Wle={left:"right",right:"left",top:"down",bottom:"up"};function qct(e){return["left","right"].includes(e)}function Gct({direction:e},t){return e==="rtl"&&qct(t)?Wle[t]:t}const Kct=_.forwardRef(function(t,n){const r=ot({props:t,name:"MuiDrawer"}),i=Oa(),o=pf(),s={enter:i.transitions.duration.enteringScreen,exit:i.transitions.duration.leavingScreen},{anchor:a="left",BackdropProps:l,children:c,className:u,elevation:f=16,hideBackdrop:h=!1,ModalProps:{BackdropProps:g,...y}={},onClose:b,open:v=!1,PaperProps:S={},SlideProps:C,TransitionComponent:w,transitionDuration:A=s,variant:E="temporary",slots:O={},slotProps:D={},...T}=r,I=_.useRef(!1);_.useEffect(()=>{I.current=!0},[]);const F=Gct({direction:o?"rtl":"ltr"},a),R={...r,anchor:a,elevation:f,open:v,variant:E,...T},$=Hct(R),j={slots:{transition:w,...O},slotProps:{paper:S,transition:C,...D,backdrop:jO(D.backdrop||{...l,...g},{transitionDuration:A})}},[z,N]=ct("root",{ref:n,elementType:Uct,className:Oe($.root,$.modal,u),shouldForwardComponentProp:!0,ownerState:R,externalForwardedProps:{...j,...T,...y},additionalProps:{open:v,onClose:b,hideBackdrop:h,slots:{backdrop:j.slots.backdrop},slotProps:{backdrop:j.slotProps.backdrop}}}),[W,H]=ct("paper",{elementType:Wct,shouldForwardComponentProp:!0,className:Oe($.paper,S.className),ownerState:R,externalForwardedProps:j,additionalProps:{elevation:E==="temporary"?f:0,square:!0,...E==="temporary"&&{role:"dialog","aria-modal":"true"}}}),[U,K]=ct("docked",{elementType:Vct,ref:n,className:Oe($.root,$.docked,u),ownerState:R,externalForwardedProps:j,additionalProps:T}),[B,q]=ct("transition",{elementType:Bct,ownerState:R,externalForwardedProps:j,additionalProps:{in:v,direction:Wle[F],timeout:A,appear:I.current}}),X=m.jsx(W,{...H,children:c});if(E==="permanent")return m.jsx(U,{...K,children:X});const V=m.jsx(B,{...q,children:X});return E==="persistent"?m.jsx(U,{...K,children:V}):m.jsx(z,{...N,children:V})}),Yct=YY({themeId:ua}),ik={error:"#d32f2f",warn:"#ed6c02",info:"#0288d1",debug:"#7b1fa2"},Xct={error:bf,warn:aw,info:QO,debug:Dw},Zct=({open:e,onClose:t})=>{const[n,r]=_.useState([]),[i,o]=_.useState(!0),[s,a]=_.useState("error,warn,info".split(",")),[l,c]=_.useState(""),[u,f]=_.useState(!0),h=_.useCallback(async()=>{try{const S=new URLSearchParams({level:s.join(","),limit:"500",...l&&{search:l}}),C=await fetch(`api/logs?${S}`);if(C.ok){const w=await C.json();r(w.entries)}}catch(S){console.error("Failed to fetch logs:",S)}finally{o(!1)}},[s,l]);_.useEffect(()=>{e&&h()},[e,h]),_.useEffect(()=>{if(!u||!e)return;const S=setInterval(h,5e3);return()=>clearInterval(S)},[u,e,h]);const g=S=>{a(Array.isArray(S.target.value)?S.target.value:[S.target.value])},y=S=>{c(S.target.value)},b=async()=>{try{await fetch("api/logs",{method:"DELETE"}),r([])}catch(S){console.error("Failed to clear logs:",S)}},v=S=>{const C=Xct[S]||QO;return m.jsx(C,{sx:{fontSize:16,color:ik[S]}})};return m.jsxs(vu,{open:e,onClose:t,maxWidth:"lg",fullWidth:!0,children:[m.jsxs(Su,{sx:{display:"flex",alignItems:"center",gap:1},children:[m.jsx(Dw,{}),"System Logs",m.jsx(le,{sx:{flexGrow:1}}),m.jsx(cn,{title:"Auto Refresh",children:m.jsx(Et,{label:u?"Auto":"Manual",color:u?"success":"default",size:"small",onClick:()=>f(!u),sx:{cursor:"pointer"}})}),m.jsx(_n,{onClick:t,children:m.jsx(qCe,{})})]}),m.jsxs(xu,{children:[m.jsx(zt,{spacing:2,sx:{mb:2},children:m.jsxs(zt,{direction:"row",spacing:2,alignItems:"center",children:[m.jsxs(ha,{size:"small",sx:{minWidth:200},children:[m.jsx(sc,{children:"Log Level"}),m.jsxs(oa,{value:s,label:"Log Level",onChange:g,multiple:!0,renderValue:S=>m.jsx(le,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:(Array.isArray(S)?S:[S]).map(C=>m.jsx(Et,{label:C.toUpperCase(),size:"small",sx:{backgroundColor:ik[C],color:"white"}},C))}),children:[m.jsx(er,{value:"error",children:"Error"}),m.jsx(er,{value:"warn",children:"Warning"}),m.jsx(er,{value:"info",children:"Info"}),m.jsx(er,{value:"debug",children:"Debug"})]})]}),m.jsx(Lr,{size:"small",placeholder:"Search logs...",value:l,onChange:y,sx:{flexGrow:1}}),m.jsx(kt,{variant:"outlined",onClick:h,children:"Refresh"}),m.jsx(kt,{variant:"outlined",color:"error",onClick:b,children:"Clear"})]})}),m.jsx(le,{sx:{height:400,overflow:"auto",backgroundColor:"background.paper",border:1,borderColor:"divider",borderRadius:1,p:1},children:i?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(ie,{children:"Loading logs..."})}):n.length===0?m.jsx(le,{sx:{display:"flex",justifyContent:"center",p:4},children:m.jsx(ie,{color:"text.secondary",children:"No logs found"})}):m.jsx(zt,{spacing:1,children:n.map((S,C)=>m.jsxs(le,{sx:{p:1,borderRadius:1,backgroundColor:"action.hover",fontFamily:"monospace",fontSize:"0.875rem",wordBreak:"break-all"},children:[m.jsxs(le,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[v(S.level),m.jsx(ie,{variant:"caption",color:"text.secondary",children:new Date(S.timestamp).toLocaleString()}),m.jsx(Et,{label:S.level.toUpperCase(),size:"small",sx:{backgroundColor:ik[S.level],color:"white",fontSize:"0.7rem",height:20}})]}),m.jsx(ie,{sx:{ml:3},children:S.message}),S.context&&m.jsx(ie,{sx:{ml:3,color:"text.secondary",fontSize:"0.8rem"},children:JSON.stringify(S.context,null,2)})]},`${S.timestamp}-${S.level}-${C}`))})})]}),m.jsx(Xd,{children:m.jsx(kt,{onClick:t,children:"Close"})})]})};function FK(){const{isConnected:e}=A2e(),[t,n]=_.useState(null),[r,i]=_.useState(!1);_.useEffect(()=>{const y=async()=>{try{const v=await fetch("api/health");if(v.ok){const S=await v.json();n(S),i(!1)}else i(!0)}catch{i(!0)}};y();const b=setInterval(y,3e4);return()=>clearInterval(b)},[]);const o=y=>{const b=Math.floor(y/3600),v=Math.floor(y%3600/60);return b>0?`${b}h ${v}m`:`${v}m`},s=t?.status==="healthy"&&!r,a=t?.services?.bridges,l=a&&a.total>0&&a.running===a.total,c=a&&a.total===0,u=t?m.jsxs(le,{sx:{p:.5},children:[m.jsxs("div",{children:[m.jsx("strong",{children:"Version:"})," ",t.version??"Unknown"]}),m.jsxs("div",{children:[m.jsx("strong",{children:"Uptime:"})," ",o(t.uptime??0)]}),t.services?.bridges&&m.jsxs("div",{children:[m.jsx("strong",{children:"Bridges:"})," ",t.services.bridges.running??0,"/",t.services.bridges.total??0," running",(t.services.bridges.stopped??0)>0&&` (${t.services.bridges.stopped} stopped)`]}),t.services?.homeAssistant&&m.jsxs("div",{children:[m.jsx("strong",{children:"Home Assistant:"})," ",t.services.homeAssistant.connected?"Connected":"Disconnected"]}),m.jsxs("div",{children:[m.jsx("strong",{children:"WebSocket:"})," ",e?"Connected":"Disconnected"]})]}):"Loading health status...",f=()=>r||!s?m.jsx(bf,{fontSize:"small"}):l?m.jsx(Mu,{fontSize:"small"}):m.jsx(pw,{fontSize:"small"}),h=()=>r||!s?"error":!l||!e?"warning":"success",g=()=>r?"Error":s?e?c?"No Bridges":l?"Online":"Starting":"Offline":"Unhealthy";return m.jsx(cn,{title:u,arrow:!0,children:m.jsx(Et,{icon:f(),label:g(),color:h(),size:"small",variant:"filled",sx:{borderRadius:1,fontWeight:600,"& .MuiChip-icon":{color:"inherit"}}})})}const Jct=e=>_.createElement("svg",{viewBox:"0 0 91 89",xmlSpace:"preserve",xmlns:"http://www.w3.org/2000/svg",...e},_.createElement("g",{style:{display:"inline"}},_.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"}),_.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"}))),Qct="home-assistant-matter-hub",eut={name:Qct};function tut(){const[e,t]=_.useState("2.1.0-alpha.422");return _.useEffect(()=>{fetch("api/health").then(n=>n.ok?n.json():null).then(n=>{n?.version&&t(n.version)}).catch(()=>{})},[]),_.useMemo(()=>({name:eut.name,version:e}),[e])}const nut=e=>{const t=tut();return m.jsxs(le,{component:Du,to:jt.dashboard,sx:{display:"flex",alignItems:"center",justifyContent:e.large?"flex-start":"center",flexGrow:1,textDecoration:"none",color:"inherit"},children:[m.jsx(Jct,{style:{height:"40px"}}),m.jsx(ie,{variant:"inherit",component:"span",sx:{mr:1,ml:1},children:t.name.split("-").map(ye).join("-")}),e.large&&m.jsx(ie,{variant:"caption",component:"span",children:t.version})]})},rut=()=>{const e=Yct("(min-width:600px)"),{mode:t,setMode:n}=ZS(),[r,i]=_.useState(!1),[o,s]=_.useState(!1),a=Jh(),l=()=>{n(t==="dark"?"light":"dark")},c=[{label:"Dashboard",icon:m.jsx(e_,{}),to:jt.dashboard},{label:"Bridges",icon:m.jsx(py,{}),to:jt.bridges},{label:"All Devices",icon:m.jsx(ss,{}),to:jt.devices},{label:"Network Map",icon:m.jsx(r6,{}),to:jt.networkMap},{label:"Startup Order",icon:m.jsx(sm,{}),to:jt.startup},{label:"Lock Credentials",icon:m.jsx(ac,{}),to:jt.lockCredentials},{label:"Filter Reference",icon:m.jsx(i6,{}),to:jt.labels},{label:"Settings",icon:m.jsx(pm,{}),to:jt.settings},{label:t==="dark"?"Light Mode":"Dark Mode",icon:t==="dark"?m.jsx(a8e,{}):m.jsx(YCe,{}),onClick:l},{label:"System Logs",icon:m.jsx(Dw,{}),onClick:()=>i(!0)},{label:"Health Dashboard",icon:m.jsx(X4,{}),to:jt.health}],u=f=>{s(!1),f.onClick?f.onClick():f.to&&a(f.to)};return m.jsxs(le,{children:[m.jsx(Lct,{sx:{height:"72px"},children:m.jsx(Ule,{sx:{paddingLeft:"0 !important",paddingRight:"0 !important"},children:m.jsxs(DI,{sx:{padding:2,height:"100%",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[m.jsx(nut,{large:e}),e?m.jsxs(le,{sx:{display:"flex",alignItems:"center",gap:1},children:[c.map(f=>f.to?m.jsx(cn,{title:f.label,children:m.jsx(_n,{component:Du,to:f.to,sx:{color:"inherit"},children:f.icon})},f.label):m.jsx(cn,{title:f.label,children:m.jsx(_n,{onClick:f.onClick,sx:{color:"inherit"},children:f.icon})},f.label)),m.jsx(FK,{})]}):m.jsxs(le,{sx:{display:"flex",alignItems:"center",gap:.5},children:[m.jsx(FK,{}),m.jsx(_n,{onClick:()=>s(!0),sx:{color:"inherit"},children:m.jsx(l8e,{})})]})]})})}),m.jsx(Kct,{anchor:"right",open:o,onClose:()=>s(!1),children:m.jsx(vc,{sx:{width:250},children:c.map(f=>m.jsxs(obe,{onClick:()=>u(f),children:[m.jsx(Ul,{children:f.icon}),m.jsx(Va,{primary:f.label})]},f.label))})}),m.jsx(Zct,{open:r,onClose:()=>i(!1)})]})},iut=()=>m.jsxs(le,{children:[m.jsx(rut,{}),m.jsx(Ule,{}),m.jsx(DI,{sx:{p:2},children:m.jsx(gY,{})}),m.jsx(Ict,{})]}),out=KS({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 D4=document.getElementsByTagName("base")[0]?.href?.replace(/\/$/,"");D4?.startsWith("http")&&(D4=new URL(D4).pathname);const sut=Hhe([{path:"/",element:m.jsx(iut,{}),children:wct}],{basename:D4});sde.createRoot(document.getElementById("root")).render(m.jsx(_.StrictMode,{children:m.jsx(Cde,{store:Dct,children:m.jsxs(n1e,{theme:out,children:[m.jsx(Zge,{}),m.jsx(uX,{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}}}),m.jsx(k2e,{children:m.jsx(yye,{children:m.jsx(epe,{router:sut})})})]})})}));
|