import { BaseCellAnchorXform } from "./base-cell-anchor-xform.js";
import { StaticXform } from "../static-xform.js";
import { CellPositionXform } from "./cell-position-xform.js";
import { PicXform } from "./pic-xform.js";
import { SpXform } from "./sp-xform.js";
class TwoCellAnchorXform extends BaseCellAnchorXform {
    constructor() {
        super();
        this.map = {
            "xdr:from": new CellPositionXform({ tag: "xdr:from" }),
            "xdr:to": new CellPositionXform({ tag: "xdr:to" }),
            "xdr:pic": new PicXform(),
            "xdr:sp": new SpXform(),
            "xdr:clientData": new StaticXform({ tag: "xdr:clientData" })
        };
    }
    get tag() {
        return "xdr:twoCellAnchor";
    }
    prepare(model, options) {
        if (model.picture) {
            this.map["xdr:pic"].prepare(model.picture, options);
        }
    }
    render(xmlStream, model) {
        const wrapAlternateContent = !!model.alternateContent;
        if (wrapAlternateContent) {
            xmlStream.openNode("mc:AlternateContent", {
                "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006"
            });
            xmlStream.openNode("mc:Choice", {
                Requires: model.alternateContent?.requires,
                ...(model.alternateContent?.requires === "a14"
                    ? {
                        "xmlns:a14": "http://schemas.microsoft.com/office/drawing/2010/main"
                    }
                    : {})
            });
        }
        xmlStream.openNode(this.tag, { editAs: model.range.editAs || "oneCell" });
        this.map["xdr:from"].render(xmlStream, model.range.tl);
        this.map["xdr:to"].render(xmlStream, model.range.br);
        if (model.picture) {
            this.map["xdr:pic"].render(xmlStream, model.picture);
        }
        else if (model.shape) {
            this.map["xdr:sp"].render(xmlStream, model.shape);
        }
        this.map["xdr:clientData"].render(xmlStream, {});
        xmlStream.closeNode();
        if (wrapAlternateContent) {
            xmlStream.closeNode(); // mc:Choice
            xmlStream.leafNode("mc:Fallback");
            xmlStream.closeNode(); // mc:AlternateContent
        }
    }
    parseClose(name) {
        if (this.parser) {
            if (!this.parser.parseClose(name)) {
                this.parser = undefined;
            }
            return true;
        }
        switch (name) {
            case this.tag:
                this.model.range.tl = this.map["xdr:from"].model;
                this.model.range.br = this.map["xdr:to"].model;
                this.model.picture = this.map["xdr:pic"].model;
                return false;
            default:
                // could be some unrecognised tags
                return true;
        }
    }
    reconcile(model, options) {
        model.medium = this.reconcilePicture(model.picture, options);
    }
}
export { TwoCellAnchorXform };
