import { Group } from "../graphic/group";

import { CheckBox } from "./../../vrender";

export class CheckboxContent extends Group {
    constructor(params) {
        super(params), this._autoWidth = !1, this._autoHeight = !1, this._leftGroup = new Group({
            pickable: !1,
            fill: !1,
            stroke: !1
        }), this._leftGroup.role = "content-left", this._rightGroup = new Group({
            pickable: !1,
            fill: !1,
            stroke: !1
        }), this._rightGroup.role = "content-right", this._checkboxGroup = new Group({
            pickable: !1,
            fill: !1,
            stroke: !1
        }), this._checkboxGroup.role = "content-center", this.appendChild(this._leftGroup), 
        this.appendChild(this._rightGroup), this.appendChild(this._checkboxGroup);
    }
    addLeftOccupyingIcon(icon) {
        var _a, _b, _c;
        icon.setAttribute("x", this._leftGroup.width + (null !== (_a = icon.attribute.marginLeft) && void 0 !== _a ? _a : 0)), 
        this._leftGroup.appendChild(icon), this._leftGroup.setDeltaWidth((null !== (_b = icon.attribute.marginLeft) && void 0 !== _b ? _b : 0) + (null !== (_c = icon.attribute.marginRight) && void 0 !== _c ? _c : 0) + icon.attribute.width);
    }
    addRightOccupyingIcon(icon) {
        var _a, _b, _c;
        icon.setAttribute("x", this._rightGroup.width + (null !== (_a = icon.attribute.marginLeft) && void 0 !== _a ? _a : 0)), 
        this._rightGroup.appendChild(icon), this._rightGroup.setDeltaWidth((null !== (_b = icon.attribute.marginLeft) && void 0 !== _b ? _b : 0) + (null !== (_c = icon.attribute.marginRight) && void 0 !== _c ? _c : 0) + icon.attribute.width);
    }
    addCheckbox(checkbox) {
        this._checkboxGroup.appendChild(checkbox);
    }
    setCheckboxContentOption(option) {
        this._autoWidth = option.autoWidth, this._autoHeight = option.autoHeight, this._cellWidth = option.cellWidth, 
        this._originCellWidth = option.cellWidth, this._cellHeight = option.cellHeight, 
        this._align = option.align, this._baseline = option.baseline;
    }
    layout() {
        let leftOccupyingWidth = this._leftGroup.width;
        leftOccupyingWidth === 1 / 0 && (leftOccupyingWidth = 0);
        let rightOccupyingWidth = this._rightGroup.width;
        if (rightOccupyingWidth === -1 / 0 && (rightOccupyingWidth = 0), this._autoWidth) {
            const checkboxWidth = this._checkboxGroup.width;
            this._cellWidth = leftOccupyingWidth + rightOccupyingWidth + checkboxWidth, this.setAttribute("width", this._cellWidth);
        } else {
            const contentWidth = this._cellWidth - leftOccupyingWidth - rightOccupyingWidth;
            this.updateCenterLayout(contentWidth);
            const centerWidth = this._checkboxGroup.width;
            this._cellWidth = leftOccupyingWidth + rightOccupyingWidth + centerWidth, this.setAttribute("width", this._cellWidth);
        }
        this.updateHorizontalPos();
        const leftOccupyingHeight = this._leftGroup.height, rightOccupyingHeight = this._rightGroup.height, centerHeight = this._checkboxGroup.height;
        this._cellHeight = Math.max(leftOccupyingHeight, rightOccupyingHeight, centerHeight), 
        this.setAttribute("height", this._cellHeight), this.updateVerticalPos();
    }
    updateCenterLayout(contentWidth) {
        let checkboxWidth = contentWidth;
        this._checkboxGroup.forEachChildren((child => {
            child instanceof CheckBox && (checkboxWidth -= child.AABBBounds.width());
        }));
        const checkbox = this._checkboxGroup.getChildByName("checkbox-content");
        checkbox instanceof CheckBox && checkbox.setAttribute("width", checkboxWidth);
        let x = 0;
        this._checkboxGroup.forEachChildren((child => {
            child.setAttribute("x", x), x += child.AABBBounds.width();
        }));
    }
    updateHorizontalPos() {
        this._leftGroup.setAttribute("x", 0), this._rightGroup.setAttribute("x", this._cellWidth - this._rightGroup.width), 
        this._checkboxGroup.setAttribute("x", 4), "left" === this._align || "start" === this._align ? this.setAttribute("dx", 0) : "center" === this._align ? this.setAttribute("dx", -this.attribute.width / 2) : "right" !== this._align && "end" !== this._align || this.setAttribute("dx", -this.attribute.width);
    }
    updateVerticalPos() {
        "top" === this._baseline ? (this._leftGroup.setAttribute("y", 0), this._rightGroup.setAttribute("y", 0), 
        this._checkboxGroup.setAttribute("y", 0)) : "middle" === this._baseline ? (this._leftGroup.forEachChildren((icon => {
            icon.setAttribute("y", (this._leftGroup.height - icon.AABBBounds.height()) / 2);
        })), this._rightGroup.forEachChildren((icon => {
            icon.setAttribute("y", (this._rightGroup.height - icon.AABBBounds.height()) / 2);
        })), this._leftGroup.setAttribute("y", this._cellHeight / 2 - this._leftGroup.height / 2), 
        this._rightGroup.setAttribute("y", this._cellHeight / 2 - this._rightGroup.height / 2), 
        this._checkboxGroup.setAttribute("y", this._cellHeight / 2 - this._checkboxGroup.height / 2)) : "bottom" === this._baseline && (this._leftGroup.forEachChildren((icon => {
            icon.setAttribute("y", this._leftGroup.height - icon.AABBBounds.height());
        })), this._rightGroup.forEachChildren((icon => {
            icon.setAttribute("y", this._rightGroup.height - icon.AABBBounds.height());
        })), this._leftGroup.setAttribute("y", this._cellHeight - this._leftGroup.height), 
        this._rightGroup.setAttribute("y", this._cellHeight - this._rightGroup.height), 
        this._checkboxGroup.setAttribute("y", this._cellHeight - this._checkboxGroup.height));
    }
}
//# sourceMappingURL=checkbox-content.js.map
