/**
 * SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
 * Copyright (C) 2021 SalesAgility Ltd.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Supercharged by SuiteCRM".
 */
import { Component, Input } from '@angular/core';
import { BreakpointObserver } from '@angular/cdk/layout';
import { BaseFieldGridComponent } from './base-field-grid.component';
import * as i0 from "@angular/core";
import * as i1 from "@angular/cdk/layout";
import * as i2 from "@angular/common";
import * as i3 from "../../fields/field.component";
import * as i4 from "../label/label.component";
function FieldGridComponent_div_1_div_1_div_2_label_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "label", 1);
    i0.ɵɵtext(1);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const col_r3 = i0.ɵɵnextContext(2).$implicit;
    const ctx_r8 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("ngClass", ctx_r8.labelClass);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(col_r3.field.label);
} }
function FieldGridComponent_div_1_div_1_div_2_scrm_label_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "scrm-label", 8);
} if (rf & 2) {
    const col_r3 = i0.ɵɵnextContext(2).$implicit;
    const ctx_r9 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("labelKey", col_r3.field.labelKey)("ngClass", ctx_r9.labelClass);
} }
function FieldGridComponent_div_1_div_1_div_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵtemplate(1, FieldGridComponent_div_1_div_1_div_2_label_1_Template, 2, 2, "label", 6);
    i0.ɵɵtemplate(2, FieldGridComponent_div_1_div_1_div_2_scrm_label_2_Template, 1, 2, "scrm-label", 7);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const col_r3 = i0.ɵɵnextContext().$implicit;
    const ctx_r4 = i0.ɵɵnextContext(2);
    i0.ɵɵclassProp("pr-3", ctx_r4.labelDisplay === "inline");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", col_r3.field.label);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !col_r3.field.label && col_r3.field.labelKey);
} }
function FieldGridComponent_div_1_div_1_div_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelement(1, "scrm-field", 9);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const col_r3 = i0.ɵɵnextContext().$implicit;
    const ctx_r5 = i0.ɵɵnextContext(2);
    i0.ɵɵclassProp("flex-grow-1", ctx_r5.labelDisplay === "inline");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("field", col_r3.field)("klass", ctx_r5.inputClass)("mode", ctx_r5.fieldMode)("record", ctx_r5.record)("type", col_r3.field.type);
} }
function FieldGridComponent_div_1_div_1_ng_container_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵprojection(1);
    i0.ɵɵelementContainerEnd();
} }
function FieldGridComponent_div_1_div_1_ng_container_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵprojection(1, 1);
    i0.ɵɵelementContainerEnd();
} }
function FieldGridComponent_div_1_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 1)(1, "div", 2);
    i0.ɵɵtemplate(2, FieldGridComponent_div_1_div_1_div_2_Template, 3, 4, "div", 3);
    i0.ɵɵtemplate(3, FieldGridComponent_div_1_div_1_div_3_Template, 2, 7, "div", 4);
    i0.ɵɵtemplate(4, FieldGridComponent_div_1_div_1_ng_container_4_Template, 2, 0, "ng-container", 5);
    i0.ɵɵtemplate(5, FieldGridComponent_div_1_div_1_ng_container_5_Template, 2, 0, "ng-container", 5);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const col_r3 = ctx.$implicit;
    const ctx_r2 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("ngClass", ctx_r2.colClass);
    i0.ɵɵadvance(1);
    i0.ɵɵclassProp("align-items-center", ctx_r2.labelDisplay === "inline" && !ctx_r2.colAlignItems)("flex-column", ctx_r2.labelDisplay === "top")("flex-row", ctx_r2.labelDisplay === "inline")("justify-content-end", !col_r3.field);
    i0.ɵɵproperty("ngClass", ctx_r2.colAlignItems ? ctx_r2.colAlignItems : "");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", col_r3.field && col_r3.field.display !== "none");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", col_r3.field && col_r3.field.display !== "none");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", col_r3.actionSlot);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", col_r3.specialSlot);
} }
function FieldGridComponent_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 1);
    i0.ɵɵtemplate(1, FieldGridComponent_div_1_div_1_Template, 6, 14, "div", 0);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const row_r1 = ctx.$implicit;
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngClass", ctx_r0.rowClass);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngForOf", row_r1.cols);
} }
const _c0 = [[["", "field-grid-actions", ""]], [["", "field-grid-actions", ""]]];
const _c1 = ["[field-grid-actions]", "[field-grid-actions]"];
class FieldGridComponent extends BaseFieldGridComponent {
    constructor(breakpointObserver) {
        super(breakpointObserver);
        this.breakpointObserver = breakpointObserver;
        this.fieldMode = 'detail';
    }
    ngOnChanges() {
        this.buildGrid();
    }
    buildGrid() {
        const grid = [];
        if (!this.fields || this.fields.length === 0) {
            this.fieldGrid = [];
            return;
        }
        let col = 0;
        let row = {
            cols: []
        };
        grid.push(row);
        this.fields.forEach(field => {
            if (col >= this.colNumber) {
                col = 0;
                row = {
                    cols: []
                };
                grid.push(row);
            }
            row.cols.push({
                field
            });
            col++;
        });
        const lastRow = grid[grid.length - 1];
        if (col < this.colNumber) {
            this.fillRow(lastRow);
        }
        this.addSpecialSlots(grid);
        this.fieldGrid = grid;
    }
    static { this.ɵfac = function FieldGridComponent_Factory(t) { return new (t || FieldGridComponent)(i0.ɵɵdirectiveInject(i1.BreakpointObserver)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: FieldGridComponent, selectors: [["scrm-field-grid"]], inputs: { fields: "fields", record: "record", fieldMode: "fieldMode" }, features: [i0.ɵɵInheritDefinitionFeature, i0.ɵɵNgOnChangesFeature], ngContentSelectors: _c1, decls: 2, vars: 1, consts: [[3, "ngClass", 4, "ngFor", "ngForOf"], [3, "ngClass"], [1, "d-flex", 3, "ngClass"], [3, "pr-3", 4, "ngIf"], [3, "flex-grow-1", 4, "ngIf"], [4, "ngIf"], [3, "ngClass", 4, "ngIf"], [3, "labelKey", "ngClass", 4, "ngIf"], [3, "labelKey", "ngClass"], [3, "field", "klass", "mode", "record", "type"]], template: function FieldGridComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵprojectionDef(_c0);
            i0.ɵɵelementStart(0, "form");
            i0.ɵɵtemplate(1, FieldGridComponent_div_1_Template, 2, 2, "div", 0);
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngForOf", ctx.fieldGrid);
        } }, dependencies: [i2.NgClass, i2.NgForOf, i2.NgIf, i3.FieldComponent, i4.LabelComponent], encapsulation: 2 }); }
}
export { FieldGridComponent };
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FieldGridComponent, [{
        type: Component,
        args: [{ selector: 'scrm-field-grid', template: "<! --\n/**\n* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.\n* Copyright (C) 2021 SalesAgility Ltd.\n*\n* This program is free software; you can redistribute it and/or modify it under\n* the terms of the GNU Affero General Public License version 3 as published by the\n* Free Software Foundation with the addition of the following permission added\n* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK\n* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE\n* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.\n*\n* This program is distributed in the hope that it will be useful, but WITHOUT\n* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n* details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program.  If not, see http://www.gnu.org/licenses.\n*\n* In accordance with Section 7(b) of the GNU Affero General Public License\n* version 3, these Appropriate Legal Notices must retain the display of the\n* \"Supercharged by SuiteCRM\" logo. If the display of the logos is not reasonably\n* feasible for technical reasons, the Appropriate Legal Notices must display\n* the words \"Supercharged by SuiteCRM\".\n*/\n-->\n<form>\n    <div [ngClass]=\"rowClass\" *ngFor=\"let row of fieldGrid\">\n\n        <div [ngClass]=\"colClass\" *ngFor=\"let col of row.cols\">\n            <div [class.align-items-center]=\"labelDisplay === 'inline' && !colAlignItems\"\n                     [class.flex-column]=\"labelDisplay === 'top'\"\n                     [class.flex-row]=\"labelDisplay === 'inline'\"\n                     [class.justify-content-end]=\"!col.field\"\n                     [ngClass]=\"colAlignItems ? colAlignItems : ''\"\n                     class=\"d-flex\"\n                >\n                    <div *ngIf=\"col.field && col.field.display !== 'none'\"\n                         [class.pr-3]=\"labelDisplay === 'inline'\" >\n                        <label *ngIf=\"col.field.label\" [ngClass]=\"labelClass\">{{col.field.label}}</label>\n                        <scrm-label *ngIf=\"!col.field.label && col.field.labelKey\"\n                                    [labelKey]=\"col.field.labelKey\"\n                                    [ngClass]=\"labelClass\"></scrm-label>\n                    </div>\n                    <div *ngIf=\"col.field && col.field.display !== 'none'\"\n                         [class.flex-grow-1]=\"labelDisplay === 'inline'\">\n                        <scrm-field [field]=\"col.field\"\n                                    [klass]=\"inputClass\"\n                                    [mode]=\"fieldMode\"\n                                    [record]=\"record\"\n                                    [type]=\"col.field.type\">\n                        </scrm-field>\n                    </div>\n                    <ng-container *ngIf=\"col.actionSlot\">\n                        <ng-content select=\"[field-grid-actions]\"></ng-content>\n                    </ng-container>\n                    <ng-container *ngIf=\"col.specialSlot\">\n                        <ng-content select=\"[field-grid-actions]\"></ng-content>\n                    </ng-container>\n                </div>\n        </div>\n    </div>\n</form>\n" }]
    }], function () { return [{ type: i1.BreakpointObserver }]; }, { fields: [{
            type: Input
        }], record: [{
            type: Input
        }], fieldMode: [{
            type: Input
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 