import { colCache } from "./utils/col-cache.js";
import { Anchor } from "./anchor.js";
class Image {
    constructor(worksheet, model) {
        this.worksheet = worksheet;
        if (model) {
            this.model = model;
        }
    }
    get model() {
        switch (this.type) {
            case "background":
                return {
                    type: this.type,
                    imageId: this.imageId
                };
            case "image":
                return {
                    type: this.type,
                    imageId: this.imageId,
                    hyperlinks: this.range.hyperlinks,
                    range: {
                        tl: this.range.tl.model,
                        br: this.range.br && this.range.br.model,
                        ext: this.range.ext,
                        editAs: this.range.editAs
                    }
                };
            default:
                throw new Error("Invalid Image Type");
        }
    }
    set model({ type, imageId, range, hyperlinks }) {
        this.type = type;
        this.imageId = imageId;
        if (type === "image") {
            if (typeof range === "string") {
                const decoded = colCache.decode(range);
                if ("top" in decoded) {
                    // It's a Location (range like "A1:C3")
                    this.range = {
                        tl: new Anchor(this.worksheet, { col: decoded.left, row: decoded.top }, -1),
                        br: new Anchor(this.worksheet, { col: decoded.right, row: decoded.bottom }, 0),
                        editAs: "oneCell"
                    };
                }
            }
            else if (range) {
                this.range = {
                    tl: new Anchor(this.worksheet, range.tl, 0),
                    br: range.br ? new Anchor(this.worksheet, range.br, 0) : undefined,
                    ext: range.ext,
                    editAs: range.editAs,
                    hyperlinks: hyperlinks || ("hyperlinks" in range ? range.hyperlinks : undefined)
                };
            }
        }
    }
}
export { Image };
