import { __read, __assign } from 'tslib';
import { MediaMatcher, LayoutModule } from '@angular/cdk/layout';
import { Platform, PlatformModule } from '@angular/cdk/platform';
import { ɵɵdirectiveInject, ElementRef, Renderer2, NgZone, ɵɵdefineDirective, ɵɵclassProp, ɵɵNgOnChangesFeature, ɵsetClassMetadata, Directive, Input, ɵɵclassMap, ɵɵstyleProp, Optional, Host, ɵɵdefineNgModule, ɵɵdefineInjector, ɵɵsetNgModuleScope, NgModule } from '@angular/core';
import { gridResponsiveMap, NzDomEventService, isNotNil } from 'ng-zorro-antd/core';
import { ReplaySubject, Subject } from 'rxjs';
import { takeUntil, finalize } from 'rxjs/operators';
import { CommonModule } from '@angular/common';

var NzRowDirective = /** @class */ (function () {
    function NzRowDirective(elementRef, renderer, mediaMatcher, ngZone, platform, nzDomEventService) {
        this.elementRef = elementRef;
        this.renderer = renderer;
        this.mediaMatcher = mediaMatcher;
        this.ngZone = ngZone;
        this.platform = platform;
        this.nzDomEventService = nzDomEventService;
        this.nzAlign = null;
        this.nzJustify = null;
        this.nzGutter = null;
        this.actualGutter$ = new ReplaySubject(1);
        this.destroy$ = new Subject();
    }
    NzRowDirective.prototype.getGutter = function (breakPoint) {
        var results = [0, 0];
        var gutter = this.nzGutter || 0;
        var normalizedGutter = Array.isArray(gutter) ? gutter : [gutter, 0];
        normalizedGutter.forEach(function (g, index) {
            if (typeof g === 'object') {
                results[index] = g[breakPoint] || 0;
            }
            else {
                results[index] = g || 0;
            }
        });
        return results;
    };
    NzRowDirective.prototype.setGutterStyle = function () {
        var _this = this;
        var breakPoint = null;
        Object.keys(gridResponsiveMap).map(function (screen) {
            var bp = screen;
            if (_this.mediaMatcher.matchMedia(gridResponsiveMap[bp]).matches) {
                breakPoint = bp;
            }
        });
        var _a = __read(this.getGutter(breakPoint), 2), horizontalGutter = _a[0], verticalGutter = _a[1];
        this.actualGutter$.next([horizontalGutter, verticalGutter]);
        var renderGutter = function (name, gutter) {
            var nativeElement = _this.elementRef.nativeElement;
            _this.renderer.setStyle(nativeElement, name, "-" + gutter / 2 + "px");
        };
        if (horizontalGutter > 0) {
            renderGutter('margin-left', horizontalGutter);
            renderGutter('margin-right', horizontalGutter);
        }
        if (verticalGutter > 0) {
            renderGutter('margin-top', verticalGutter);
            renderGutter('margin-bottom', verticalGutter);
        }
    };
    NzRowDirective.prototype.ngOnInit = function () {
        this.setGutterStyle();
    };
    NzRowDirective.prototype.ngOnChanges = function (changes) {
        if (changes.nzGutter) {
            this.setGutterStyle();
        }
    };
    NzRowDirective.prototype.ngAfterViewInit = function () {
        var _this = this;
        if (this.platform.isBrowser) {
            this.nzDomEventService
                .registerResizeListener()
                .pipe(takeUntil(this.destroy$), finalize(function () { return _this.nzDomEventService.unregisterResizeListener(); }))
                .subscribe(function () { return _this.setGutterStyle(); });
        }
    };
    NzRowDirective.prototype.ngOnDestroy = function () {
        this.destroy$.next();
        this.destroy$.complete();
    };
    /** @nocollapse */ NzRowDirective.ɵfac = function NzRowDirective_Factory(t) { return new (t || NzRowDirective)(ɵɵdirectiveInject(ElementRef), ɵɵdirectiveInject(Renderer2), ɵɵdirectiveInject(MediaMatcher), ɵɵdirectiveInject(NgZone), ɵɵdirectiveInject(Platform), ɵɵdirectiveInject(NzDomEventService)); };
    /** @nocollapse */ NzRowDirective.ɵdir = ɵɵdefineDirective({ type: NzRowDirective, selectors: [["", "nz-row", ""], ["nz-row"], ["nz-form-item"]], hostVars: 18, hostBindings: function NzRowDirective_HostBindings(rf, ctx) { if (rf & 2) {
            ɵɵclassProp("ant-row", true)("ant-row-top", ctx.nzAlign === "top")("ant-row-middle", ctx.nzAlign === "middle")("ant-row-bottom", ctx.nzAlign === "bottom")("ant-row-start", ctx.nzJustify === "start")("ant-row-end", ctx.nzJustify === "end")("ant-row-center", ctx.nzJustify === "center")("ant-row-space-around", ctx.nzJustify === "space-around")("ant-row-space-between", ctx.nzJustify === "space-between");
        } }, inputs: { nzType: "nzType", nzAlign: "nzAlign", nzJustify: "nzJustify", nzGutter: "nzGutter" }, exportAs: ["nzRow"], features: [ɵɵNgOnChangesFeature] });
    return NzRowDirective;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzRowDirective, [{
        type: Directive,
        args: [{
                selector: '[nz-row],nz-row,nz-form-item',
                exportAs: 'nzRow',
                host: {
                    '[class.ant-row]': "true",
                    '[class.ant-row-top]': "nzAlign === 'top'",
                    '[class.ant-row-middle]': "nzAlign === 'middle'",
                    '[class.ant-row-bottom]': "nzAlign === 'bottom'",
                    '[class.ant-row-start]': "nzJustify === 'start'",
                    '[class.ant-row-end]': "nzJustify === 'end'",
                    '[class.ant-row-center]': "nzJustify === 'center'",
                    '[class.ant-row-space-around]': "nzJustify === 'space-around'",
                    '[class.ant-row-space-between]': "nzJustify === 'space-between'"
                }
            }]
    }], function () { return [{ type: ElementRef }, { type: Renderer2 }, { type: MediaMatcher }, { type: NgZone }, { type: Platform }, { type: NzDomEventService }]; }, { nzType: [{
            type: Input
        }], nzAlign: [{
            type: Input
        }], nzJustify: [{
            type: Input
        }], nzGutter: [{
            type: Input
        }] }); })();

var NzColDirective = /** @class */ (function () {
    function NzColDirective(elementRef, nzRowDirective, renderer) {
        this.elementRef = elementRef;
        this.nzRowDirective = nzRowDirective;
        this.renderer = renderer;
        this.destroy$ = new Subject();
        this.hostClassMap = {};
        this.hostFlexStyle = null;
        this.nzFlex = null;
        this.nzSpan = null;
        this.nzOrder = null;
        this.nzOffset = null;
        this.nzPush = null;
        this.nzPull = null;
        this.nzXs = null;
        this.nzSm = null;
        this.nzMd = null;
        this.nzLg = null;
        this.nzXl = null;
        this.nzXXl = null;
    }
    NzColDirective.prototype.setHostClassMap = function () {
        var _a;
        this.hostClassMap = __assign((_a = {}, _a['ant-col'] = true, _a["ant-col-" + this.nzSpan] = isNotNil(this.nzSpan), _a["ant-col-order-" + this.nzOrder] = isNotNil(this.nzOrder), _a["ant-col-offset-" + this.nzOffset] = isNotNil(this.nzOffset), _a["ant-col-pull-" + this.nzPull] = isNotNil(this.nzPull), _a["ant-col-push-" + this.nzPush] = isNotNil(this.nzPush), _a), this.generateClass());
    };
    NzColDirective.prototype.setHostFlexStyle = function () {
        this.hostFlexStyle = this.parseFlex(this.nzFlex);
    };
    NzColDirective.prototype.parseFlex = function (flex) {
        if (typeof flex === 'number') {
            return flex + " " + flex + " auto";
        }
        else if (typeof flex === 'string') {
            if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
                return "0 0 " + flex;
            }
        }
        return flex;
    };
    NzColDirective.prototype.generateClass = function () {
        var _this = this;
        var listOfSizeInputName = ['nzXs', 'nzSm', 'nzMd', 'nzLg', 'nzXl', 'nzXXl'];
        var listClassMap = {};
        listOfSizeInputName.forEach(function (name) {
            var sizeName = name.replace('nz', '').toLowerCase();
            if (isNotNil(_this[name])) {
                if (typeof _this[name] === 'number' || typeof _this[name] === 'string') {
                    listClassMap["ant-col-" + sizeName + "-" + _this[name]] = true;
                }
                else {
                    var embedded_1 = _this[name];
                    var prefixArray = ['span', 'pull', 'push', 'offset', 'order'];
                    prefixArray.forEach(function (prefix) {
                        var prefixClass = prefix === 'span' ? '-' : "-" + prefix + "-";
                        listClassMap["ant-col-" + sizeName + prefixClass + embedded_1[prefix]] = embedded_1 && isNotNil(embedded_1[prefix]);
                    });
                }
            }
        });
        return listClassMap;
    };
    NzColDirective.prototype.ngOnInit = function () {
        this.setHostClassMap();
        this.setHostFlexStyle();
    };
    NzColDirective.prototype.ngOnChanges = function (changes) {
        this.setHostClassMap();
        var nzFlex = changes.nzFlex;
        if (nzFlex) {
            this.setHostFlexStyle();
        }
    };
    NzColDirective.prototype.ngAfterViewInit = function () {
        var _this = this;
        if (this.nzRowDirective) {
            this.nzRowDirective.actualGutter$.pipe(takeUntil(this.destroy$)).subscribe(function (_a) {
                var _b = __read(_a, 2), horizontalGutter = _b[0], verticalGutter = _b[1];
                var renderGutter = function (name, gutter) {
                    var nativeElement = _this.elementRef.nativeElement;
                    _this.renderer.setStyle(nativeElement, name, gutter / 2 + "px");
                };
                if (horizontalGutter > 0) {
                    renderGutter('padding-left', horizontalGutter);
                    renderGutter('padding-right', horizontalGutter);
                }
                if (verticalGutter > 0) {
                    renderGutter('padding-top', verticalGutter);
                    renderGutter('padding-bottom', verticalGutter);
                }
            });
        }
    };
    NzColDirective.prototype.ngOnDestroy = function () {
        this.destroy$.next();
        this.destroy$.complete();
    };
    /** @nocollapse */ NzColDirective.ɵfac = function NzColDirective_Factory(t) { return new (t || NzColDirective)(ɵɵdirectiveInject(ElementRef), ɵɵdirectiveInject(NzRowDirective, 9), ɵɵdirectiveInject(Renderer2)); };
    /** @nocollapse */ NzColDirective.ɵdir = ɵɵdefineDirective({ type: NzColDirective, selectors: [["", "nz-col", ""], ["nz-col"], ["nz-form-control"], ["nz-form-label"]], hostVars: 4, hostBindings: function NzColDirective_HostBindings(rf, ctx) { if (rf & 2) {
            ɵɵclassMap(ctx.hostClassMap);
            ɵɵstyleProp("flex", ctx.hostFlexStyle);
        } }, inputs: { nzFlex: "nzFlex", nzSpan: "nzSpan", nzOrder: "nzOrder", nzOffset: "nzOffset", nzPush: "nzPush", nzPull: "nzPull", nzXs: "nzXs", nzSm: "nzSm", nzMd: "nzMd", nzLg: "nzLg", nzXl: "nzXl", nzXXl: "nzXXl" }, exportAs: ["nzCol"], features: [ɵɵNgOnChangesFeature] });
    return NzColDirective;
}());
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzColDirective, [{
        type: Directive,
        args: [{
                selector: '[nz-col],nz-col,nz-form-control,nz-form-label',
                exportAs: 'nzCol',
                host: {
                    '[class]': 'hostClassMap',
                    '[style.flex]': 'hostFlexStyle'
                }
            }]
    }], function () { return [{ type: ElementRef }, { type: NzRowDirective, decorators: [{
                type: Optional
            }, {
                type: Host
            }] }, { type: Renderer2 }]; }, { nzFlex: [{
            type: Input
        }], nzSpan: [{
            type: Input
        }], nzOrder: [{
            type: Input
        }], nzOffset: [{
            type: Input
        }], nzPush: [{
            type: Input
        }], nzPull: [{
            type: Input
        }], nzXs: [{
            type: Input
        }], nzSm: [{
            type: Input
        }], nzMd: [{
            type: Input
        }], nzLg: [{
            type: Input
        }], nzXl: [{
            type: Input
        }], nzXXl: [{
            type: Input
        }] }); })();

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
var NzGridModule = /** @class */ (function () {
    function NzGridModule() {
    }
    /** @nocollapse */ NzGridModule.ɵmod = ɵɵdefineNgModule({ type: NzGridModule });
    /** @nocollapse */ NzGridModule.ɵinj = ɵɵdefineInjector({ factory: function NzGridModule_Factory(t) { return new (t || NzGridModule)(); }, imports: [[CommonModule, LayoutModule, PlatformModule]] });
    return NzGridModule;
}());
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵɵsetNgModuleScope(NzGridModule, { declarations: [NzColDirective, NzRowDirective], imports: [CommonModule, LayoutModule, PlatformModule], exports: [NzColDirective, NzRowDirective] }); })();
/*@__PURE__*/ (function () { ɵsetClassMetadata(NzGridModule, [{
        type: NgModule,
        args: [{
                declarations: [NzColDirective, NzRowDirective],
                exports: [NzColDirective, NzRowDirective],
                imports: [CommonModule, LayoutModule, PlatformModule]
            }]
    }], null, null); })();

/**
 * @license
 * Copyright Alibaba.com All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */

/**
 * Generated bundle index. Do not edit.
 */

export { NzColDirective, NzGridModule, NzRowDirective };
//# sourceMappingURL=ng-zorro-antd-grid.js.map
