// (C) 2019-2026 GoodData Corporation
import { isEqual } from "lodash-es";
import { areSectionLayoutPathsEqual, asLayoutItemPath, updateSectionIndex, } from "../../../layout/coordinates.js";
import { DashboardLayoutItemFacade } from "./item.js";
import { DashboardLayoutItemsFacade } from "./items.js";
/**
 * @alpha
 */
export class DashboardLayoutSectionFacade {
    layoutFacade;
    section;
    sectionIndex;
    constructor(layoutFacade, section, sectionIndex) {
        this.layoutFacade = layoutFacade;
        this.section = section;
        this.sectionIndex = sectionIndex;
    }
    static for(layoutFacade, section, index) {
        return new DashboardLayoutSectionFacade(layoutFacade, section, index);
    }
    raw() {
        return this.section;
    }
    header() {
        return this.section.header;
    }
    title() {
        return this.header()?.title;
    }
    description() {
        return this.header()?.description;
    }
    index() {
        return this.sectionIndex;
    }
    isFirst() {
        return this.indexIs(updateSectionIndex(this.sectionIndex, 0));
    }
    isLast() {
        return this.indexIs(updateSectionIndex(this.sectionIndex, this.layoutFacade.sections().count() - 1));
    }
    testRaw(pred) {
        return pred(this.raw());
    }
    test(pred) {
        return pred(this);
    }
    indexIs(index) {
        return areSectionLayoutPathsEqual(this.index(), index);
    }
    headerEquals(header) {
        return isEqual(this.header(), header);
    }
    hasHeader() {
        const header = this.header();
        return !(header === null || header === undefined);
    }
    hasTitle() {
        const title = this.title();
        return !(title === null || title === undefined);
    }
    hasDescription() {
        const description = this.description();
        return !(description === null || description === undefined);
    }
    titleEquals(title) {
        return isEqual(this.title(), title);
    }
    descriptionEquals(description) {
        return isEqual(this.description(), description);
    }
    isEmpty() {
        return this.items().count() === 0;
    }
    items() {
        return DashboardLayoutItemsFacade.for(this, this.section.items);
    }
    item(index) {
        const column = this.section.items[index];
        if (!column) {
            return undefined;
        }
        const layoutPath = asLayoutItemPath(this.sectionIndex, index);
        return DashboardLayoutItemFacade.for(this, column, layoutPath);
    }
    layout() {
        return this.layoutFacade;
    }
}
//# sourceMappingURL=section.js.map