/* ===================== AUTOGENERATED SOURCE IMPORT ===================== */

import GlobalStyle from "/emcJS/util/html/template/CSSTemplate.js";

const STYLE = new GlobalStyle(`
    :host {
        --logic-color-back: repeating-linear-gradient(145deg, #ffffe0, #ffffe0 20px, #ffdfe4 20px, #ffdfe4 40px);
        --logic-color-border: #ffa500;
    }
`);

/* ======================================================================= */

import AbstractElement from "../abstract/AbstractElement.js";
import AbstractInfChildrenElement from "../abstract/AbstractInfChildrenElement.js";

const TPL_CAPTION = "NAND";
const REFERENCE = "nand";

export default class OperatorNand extends AbstractInfChildrenElement {

    constructor() {
        super(REFERENCE, TPL_CAPTION);
        STYLE.apply(this.shadowRoot);
    }

    calculate(state = {}) {
        const ch = this.childList.map((ndoe) => ndoe.calculate(state));
        for (const val of ch) {
            if (!val) {
                this.shadowRoot.getElementById("header").setAttribute("value", "1");
                return 1;
            }
        }
        this.shadowRoot.getElementById("header").setAttribute("value", "0");
        return 0;
    }

}

AbstractElement.registerReference(REFERENCE, OperatorNand);
customElements.define(`emc-logic-${REFERENCE}`, OperatorNand);
