import { html, nothing } from "lit"
import PinElement from "../element/PinElement"
import ISelectableDraggableTemplate from "./ISelectableDraggableTemplate"
/** @typedef {import("../element/NodeElement").default} NodeElement */
export default class NodeTemplate extends ISelectableDraggableTemplate {
toggleAdvancedDisplayHandler
render() {
return html`
${this.element.nodeDisplayName}
${this.element.enabledState?.toString() == "DevelopmentOnly" ? html`
Development Only
` : nothing}
${this.element.advancedPinDisplay ? html`
` : nothing}
`
}
/** @param {Map} changedProperties */
async firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
const inputContainer = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-inputs"))
const outputContainer = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-outputs"))
Promise.all(this.element.getPinElements().map(n => n.updateComplete)).then(() => this.element.dispatchReflowEvent())
this.element.getPinElements().forEach(p => {
if (p.isInput()) {
inputContainer.appendChild(p)
} else if (p.isOutput()) {
outputContainer.appendChild(p)
}
})
this.toggleAdvancedDisplayHandler = _ => {
this.element.toggleShowAdvancedPinDisplay()
this.element.addNextUpdatedCallbacks(() => this.element.dispatchReflowEvent(), true)
}
this.element.nodeNameElement = /** @type {HTMLElement} */(this.element.querySelector(".ueb-node-name-text"))
}
/**
* @param {NodeElement} node
* @returns {NodeListOf}
*/
getPinElements(node) {
return node.querySelectorAll("ueb-pin")
}
}