import * as TSU from "@panyam/tsutils";
import { Embelishment } from "../shapes";
export class LeafAtomViewEmbelishment extends Embelishment {
    constructor(atomView) {
        super();
        this.atomView = atomView;
    }
}
export class OctaveIndicator extends LeafAtomViewEmbelishment {
    constructor(noteView, note) {
        super(noteView);
        this.noteView = noteView;
        this.note = note;
        this.dotRadius = 1;
        this.dotSpacing = 2.5;
        const rootElem = this.noteView.embRoot();
        const numDots = Math.abs(note.octave);
        this.dotsElem = TSU.DOM.createSVGNode("g", {
            doc: document,
            parent: rootElem,
            attrs: {
                width: this.dotRadius * 2 * numDots + (numDots - 1) * this.dotSpacing,
                height: this.dotRadius * 2,
                source: "atom" + this.noteView.leafAtom.uuid,
            },
        });
        let cx = 0;
        for (let i = 0; i < numDots; i++) {
            TSU.DOM.createSVGNode("circle", {
                doc: document,
                parent: this.dotsElem,
                attrs: {
                    cx: cx,
                    cy: 0,
                    r: this.dotRadius,
                    class: "notation-octave-dot",
                },
            });
            cx += this.dotRadius + this.dotRadius + this.dotSpacing;
        }
    }
    refreshBBox() {
        return TSU.DOM.svgBBox(this.dotsElem);
    }
    refreshMinSize() {
        const numDots = Math.abs(this.note.octave);
        return {
            width: this.dotRadius * 2 * numDots + (numDots - 1) * this.dotSpacing,
            height: this.dotRadius * 2,
        };
    }
    updateBounds(x, y, _w, _h) {
        if (x == null)
            x = this.x;
        if (y == null)
            y = this.y;
        return [x, y, null, null];
    }
    refreshLayout() {
        this.dotsElem.setAttribute("transform", "translate(" + this.x + "," + this.y + ")");
    }
}
export class LabelEmbelishment extends LeafAtomViewEmbelishment {
    constructor(label, atomView) {
        super(atomView);
        this.label = label;
        this.atomView = atomView;
        const rootElem = this.atomView.embRoot();
        this.labelElem = TSU.DOM.createSVGNode("text", {
            doc: document,
            parent: rootElem,
            text: label,
            attrs: {
                source: "atom" + this.atomView.leafAtom.uuid,
                class: "notation-embelishment-label",
                "dominant-baseline": "hanging",
            },
        });
    }
    refreshBBox() {
        return TSU.DOM.svgBBox(this.labelElem);
    }
    refreshMinSize() {
        return TSU.DOM.svgBBox(this.labelElem);
    }
    updateBounds(x, y, w, h) {
        return [x, y, w, h];
    }
    refreshLayout() {
        this.labelElem.setAttribute("x", "" + this.x);
        this.labelElem.setAttribute("y", "" + this.y);
    }
}
export class BeatStartLines extends Embelishment {
    constructor(source, rootElement) {
        super();
        this.source = source;
        this.rootElement = rootElement;
        this.barSpacing = 10;
        this.line = TSU.DOM.createSVGNode("line", {
            doc: document,
            parent: this.rootElement,
            attrs: {
                class: "bar-start-line",
            },
        });
    }
    refreshBBox() {
        return new TSU.Geom.Rect(0, 0, 0, 0);
    }
    refreshMinSize() {
        return new TSU.Geom.Rect(0, 0, 0, 0);
    }
    refreshLayout() {
        const line = this.line;
        const x = this.source.x - this.barSpacing;
        line.setAttribute("x1", "" + x);
        line.setAttribute("x2", "" + x);
        const y = this.source.y + this.source.bbox.y;
        const h = this.source.bbox.height;
        line.setAttribute("y1", "" + y);
        line.setAttribute("y2", "" + (y + h));
    }
    updateBounds(x, y, w, h) {
        return [x, y, null, h];
    }
}
export class BeatEndLines extends Embelishment {
    constructor(source, rootElement, nLines = 1) {
        super();
        this.source = source;
        this.rootElement = rootElement;
        this.lineSpacing = 2;
        this.barSpacing = 0;
        this.lines = [];
        for (let i = 0; i < nLines; i++) {
            this.lines.push(TSU.DOM.createSVGNode("line", {
                doc: document,
                parent: this.rootElement,
                attrs: {
                    class: "bar-end-line",
                },
            }));
        }
    }
    refreshBBox() {
        return new TSU.Geom.Rect(0, 0, 0, 0);
    }
    refreshMinSize() {
        return new TSU.Geom.Rect(0, 0, 0, 0);
    }
    updatePosition(x, y) {
        return [x, y];
    }
    refreshLayout() {
        const x = this.source.x + this.source.width + this.barSpacing;
        const y = this.source.y + this.source.bbox.y;
        const h = this.source.bbox.height;
        let currX = x;
        for (const line of this.lines) {
            const lx = "" + currX;
            line.setAttribute("x1", lx);
            line.setAttribute("x2", lx);
            currX += 4;
        }
        for (const line of this.lines) {
            line.setAttribute("y1", "" + y);
            line.setAttribute("y2", "" + (y + h));
        }
    }
    updateBounds(_x, _y, _w, _h) {
        return [null, null, null, null];
    }
}
export class Kampitham extends LabelEmbelishment {
    constructor(atomView) {
        super("~", atomView);
        this.atomView = atomView;
    }
}
export class Nokku extends LabelEmbelishment {
    constructor(atomView) {
        super("w", atomView);
        this.atomView = atomView;
    }
}
export class Prathyagatham extends LabelEmbelishment {
    constructor(atomView) {
        super("∵", atomView);
        this.atomView = atomView;
    }
}
export class Spuritham extends LabelEmbelishment {
    constructor(atomView) {
        super("∴", atomView);
        this.atomView = atomView;
    }
}
export class Raavi extends LabelEmbelishment {
    constructor(atomView) {
        super("^", atomView);
        this.atomView = atomView;
    }
}
export class Kandippu extends LabelEmbelishment {
    constructor(atomView) {
        super("✓", atomView);
        this.atomView = atomView;
    }
}
export class Vaali extends LabelEmbelishment {
    constructor(atomView) {
        super("⌒", atomView);
        this.atomView = atomView;
    }
}
export class Odukkal extends LabelEmbelishment {
    constructor(atomView) {
        super("x", atomView);
        this.atomView = atomView;
    }
}
export class Orikkai extends LabelEmbelishment {
    constructor(atomView) {
        super("γ", atomView);
        this.atomView = atomView;
    }
}
export class Jaaru extends LeafAtomViewEmbelishment {
    constructor(jaaru, atomView) {
        super(atomView);
        this.jaaru = jaaru;
        this.atomView = atomView;
        const rootElem = this.atomView.embRoot();
        this.pathElem = TSU.DOM.createSVGNode("path", {
            doc: document,
            parent: rootElem,
            attrs: {
                source: "atom" + this.atomView.leafAtom.uuid,
                class: "notation-jaaru-path",
                d: this.pathAttribute(),
            },
        });
    }
    pathAttribute(x = 0) {
        const avbbox = this.atomView.glyph.minSize;
        let y2 = 0;
        const h2 = avbbox.height / 2;
        const x2 = x + h2;
        let y = this.atomView.y;
        if (this.jaaru.ascending) {
            y += avbbox.height;
            y2 = y - h2;
        }
        else {
            y -= h2;
            y2 = y + h2;
        }
        return [`M ${x} ${y}`, `Q ${x2} ${y} ${x2} ${y2}`].join(" ");
    }
    refreshMinSize() {
        return TSU.DOM.svgBBox(this.pathElem);
    }
    refreshBBox() {
        return TSU.DOM.svgBBox(this.pathElem);
    }
    updateBounds(x, _y, _w, _h) {
        return [x, null, null, null];
    }
    refreshLayout() {
        this.pathElem.setAttribute("d", this.pathAttribute(this.x));
    }
}
//# sourceMappingURL=embelishments.js.map