import { BaseView } from "../../BaseView.js";
export class GridLabelResizer extends BaseView {
    constructor(options) {
        super(options);
        this.m_parent = options.parent;
        this.state.unset("parent");
    }
    get parent() {
        return this.m_parent;
    }
    get source() {
        return super.source;
    }
    template() {
        return `<div class="-fb-grid-resizer -fb-grid-resizer-content"></div>`;
    }
    onActivate(e) {
        super.onActivate(e);
        this.node.draggable({
            axis: "x",
            containment: "parent",
            drag: (e) => {
                $(e.target).css({
                    opacity: ".3"
                });
            },
            stop: (e, ui) => {
                let parentWidth = this.parent.node.width();
                let parentOffsetLeft = this.parent.node.offset().left;
                let width = ui.offset.left - parentOffsetLeft;
                if (width < 100) {
                    width = 100;
                }
                if (width > (parentWidth - 100)) {
                    width = (parentWidth) - 100;
                }
                $(e.target).css({
                    left: `${width}px`,
                    opacity: 0
                });
                this.source.locals.events.labelResizePublish({
                    width: width - 20
                });
            }
        });
    }
    onDestroy(e) {
        super.onDestroy(e);
        if (this.node.data("ui-draggable")) {
            this.node.draggable("destroy");
        }
    }
}
