import { EventEmitter, Component, Output, Input, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormControl, Validators, FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgZorroAntdModule } from 'ng-zorro-antd';
import { BcacButtonModule } from 'bcac-lib/base-component/currency/bcac-button';
import { differenceInCalendarDays } from 'date-fns';

/**
 * @fileoverview added by tsickle
 * Generated from: common-form/common-form.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
class CommonFormComponent {
    /**
     * @param {?} fb
     */
    constructor(fb) {
        this.fb = fb;
        this.bcacFormEmit = new EventEmitter();
        this.validateForm = this.fb.group({});
        this.formSize = "small";
        this.fieldList = [];
    }
    /**
     * @return {?}
     */
    ngOnInit() {
    }
    /**
     * @param {?} value
     * @return {?}
     */
    set bcacSize(value) {
        this.formSize = value;
    }
    /**
     * @param {?} fields
     * @return {?}
     */
    set bcacFields(fields) {
        this.fieldList = fields;
        this.fieldList.forEach((/**
         * @param {?} element
         * @return {?}
         */
        element => {
            /** @type {?} */
            let formControl = new FormControl();
            if (element.required) {
                formControl.setValidators(Validators.required);
            }
            this.validateForm.addControl(element.value, formControl);
        }));
    }
    /**
     * @return {?}
     */
    submit() {
        console.log("submit");
        this.fieldList.forEach((/**
         * @param {?} element
         * @return {?}
         */
        element => {
            if (element.type === "tree") {
                this.validateForm.get(element.value).setValue(element.nodes);
            }
        }));
        this.bcacFormEmit.emit(this.validateForm);
    }
    /**
     * @return {?}
     */
    resetForm() {
        this.validateForm.reset();
    }
}
CommonFormComponent.decorators = [
    { type: Component, args: [{
                selector: 'bcac-common-form',
                template: "<!-- <div>\r\n    <form nz-form [formGroup]=\"validateForm\">\r\n        <div nz-row [nzGutter]=\"0\">\r\n            <div nz-col [nzSpan]=\"colSpan\" *ngFor=\"let field of fieldList\">\r\n                <nz-form-item nzFlex>\r\n                    <nz-form-label>{{field.label}}</nz-form-label>\r\n                    <nz-form-control>\r\n                        <input\r\n                            nz-input\r\n                            [placeholder]=\"field.label\"\r\n                            [formControlName]=\"field.value\"/>\r\n                    </nz-form-control>\r\n                </nz-form-item>\r\n            </div>\r\n        </div>\r\n    </form>\r\n    <div class=\"button-area\">\r\n        <bcac-button bcacContent=\"\u53D6\u6D88\" bcacType=\"default\" bcacSize=\"small\" (click)=\"modalClose()\"></bcac-button>\r\n        <bcac-button bcacContent=\"\u786E\u5B9A\" bcacType=\"primary\" bcacSize=\"small\" (click)=\"print()\"></bcac-button>\r\n    </div>\r\n</div> -->\r\n<form nz-form [formGroup]=\"validateForm\">\r\n    <nz-form-item *ngFor=\"let field of fieldList\">\r\n        <nz-form-label [nzSpan]=\"field.labelSpan\" [nzRequired]=\"field.required\">{{field.label}}</nz-form-label>\r\n        <!-- [nzSm]=\"8\" [nzXs]=\"24\" required -->\r\n        <!-- [nzSm]=\"16\" [nzXs]=\"24\" -->\r\n        <nz-form-control [nzSpan]=\"field.valueSpan\">\r\n            <ng-container *ngIf=\"field.type === 'text'\">\r\n                <input nz-input [nzSize]=\"formSize\" [placeholder]=\"field.placeholder? field.placeholder: ''\" [formControlName]=\"field.value\" />\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'date'\">\r\n                <nz-date-picker [nzSize]=\"formSize\" [formControlName]=\"field.value\" [nzPlaceHolder]=\"field.placeholder? field.placeholder: '\u8BF7\u9009\u62E9\u65E5\u671F'\"></nz-date-picker>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'date-time'\">\r\n                <nz-date-picker nzShowTime [nzSize]=\"formSize\" [formControlName]=\"field.value\" [nzPlaceHolder]=\"field.placeholder? field.placeholder: '\u8BF7\u9009\u62E9\u65F6\u95F4'\"></nz-date-picker>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'month'\">\r\n                <nz-month-picker  [nzSize]=\"formSize\" [formControlName]=\"field.value\" [nzPlaceHolder]=\"field.placeholder? field.placeholder: '\u8BF7\u9009\u62E9\u6708\u4EFD'\"></nz-month-picker>\r\n            </ng-container>\r\n            <!-- <ng-container *ngIf=\"field.type === 'month'\">\r\n                <nz-month-picker [formControlName]=\"field.value\"></nz-month-picker>\r\n            </ng-container> -->\r\n            <ng-container *ngIf=\"field.type === 'time'\">\r\n                <nz-time-picker [nzSize]=\"formSize\" [formControlName]=\"field.value\" [nzPlaceHolder]=\"field.placeholder? field.placeholder: '\u8BF7\u9009\u62E9\u65F6\u95F4'\"></nz-time-picker>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'year'\">\r\n                <nz-year-picker [nzSize]=\"formSize\" [formControlName]=\"field.value\" [nzPlaceHolder]=\"field.placeholder? field.placeholder: '\u8BF7\u9009\u62E9\u5E74\u4EFD'\"></nz-year-picker>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'week'\">\r\n                <nz-week-picker [nzSize]=\"formSize\" [formControlName]=\"field.value\" [nzPlaceHolder]=\"field.placeholder? field.placeholder: '\u8BF7\u9009\u62E9\u5468'\"></nz-week-picker>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'time-range'\">\r\n                <nz-range-picker [nzFormat]=\"field.format\" [nzSize]=\"formSize\" [formControlName]=\"field.value\" [nzPlaceHolder]=\"field.placeholder? field.placeholder: ['\u5F00\u59CB', '\u7ED3\u675F']\"></nz-range-picker>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'textarea'\">\r\n                <textarea [nzSize]=\"formSize\" [formControlName]=\"field.value\" nz-input [rows]=\"field.textAreaRows\" [placeholder]=\"field.placeholder? field.placeholder: '\u8BF7\u8F93\u5165'\"></textarea>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'select'\">\r\n                <nz-select nzPlaceHolder=\"\u5168\u90E8\" [nzAllowClear]=\"true\" [nzSize]=\"formSize\" [formControlName]=\"field.value\">\r\n                    <nz-option *ngFor=\"let option of field.selectOptions\" [nzLabel]=\"option.label\" [nzValue]=\"option.value\">\r\n                    </nz-option>\r\n                </nz-select>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'radio'\">\r\n                <nz-radio-group [nzSize]=\"formSize\" [formControlName]=\"field.value\" [(ngModel)]=\"field.default\">\r\n                    <label nz-radio *ngFor=\"let option of field.selectOptions\" [nzValue]=\"option.value\">{{option.label}}</label>\r\n                </nz-radio-group>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'switch'\">\r\n                <nz-switch [nzSize]=\"formSize\" nzCheckedChildren=\"\u5F00\" nzUnCheckedChildren=\"\u5173\" [formControlName]=\"field.value\" [(ngModel)]=\"field.default\"></nz-switch>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'slider'\">\r\n                <nz-slider [nzMin]=\"field.nzMin? field.nzMin: 1\" [nzMax]=\"field.nzMax? field.nzMax: 100\" \r\n                [formControlName]=\"field.value\"\r\n                [nzTooltipVisible]=\"field.sliderTooltipVisible? field.sliderTooltipVisible: 'default'\"></nz-slider>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"field.type === 'tree'\">\r\n                <nz-tree\r\n                [nzData]=\"field.nodes\"\r\n                nzCheckable\r\n                nzMultiple\r\n                ></nz-tree>\r\n            </ng-container>\r\n        </nz-form-control>\r\n    </nz-form-item>\r\n    <nz-form-item *ngIf=\"fieldList.length > 0\">\r\n        <nz-form-control [nzOffset]=\"fieldList[0].labelSpan\" [nzSpan]=\"fieldList[0].valueSpan\">\r\n            <bcac-button class=\"left-button\" bcacContent=\"\u63D0\u4EA4\" bcacType=\"primary\" [bcacSize]=\"formSize\" (click)=\"submit()\" \r\n            [disabled]=\"!validateForm.valid\" ></bcac-button>\r\n            <bcac-button bcacContent=\"\u91CD\u7F6E\" bcacType=\"default\" [bcacSize]=\"formSize\" (click)=\"resetForm()\"></bcac-button>\r\n        </nz-form-control>\r\n      </nz-form-item>\r\n</form>\r\n<!-- <div class=\"button-area\">\r\n    <bcac-button bcacContent=\"\u53D6\u6D88\" bcacType=\"default\" bcacSize=\"default\" (click)=\"modalClose()\"></bcac-button>\r\n    <bcac-button bcacContent=\"\u786E\u5B9A\" bcacType=\"primary\" bcacSize=\"default\" (click)=\"print()\"></bcac-button>\r\n</div> -->\r\n",
                host: {
                    '[class.bcac-form-sm]': `formSize === 'small'`,
                },
                styles: [".left-button{margin-right:.8rem}:host ::ng-deep .ant-form-item{margin-bottom:1rem}:host.bcac-form-sm .ant-form-item{margin-bottom:0}"]
            }] }
];
/** @nocollapse */
CommonFormComponent.ctorParameters = () => [
    { type: FormBuilder }
];
CommonFormComponent.propDecorators = {
    bcacFormEmit: [{ type: Output }],
    bcacSize: [{ type: Input }],
    bcacFields: [{ type: Input }]
};
if (false) {
    /** @type {?} */
    CommonFormComponent.prototype.bcacFormEmit;
    /** @type {?} */
    CommonFormComponent.prototype.validateForm;
    /** @type {?} */
    CommonFormComponent.prototype.formSize;
    /** @type {?} */
    CommonFormComponent.prototype.fieldList;
    /**
     * @type {?}
     * @private
     */
    CommonFormComponent.prototype.fb;
}

/**
 * @fileoverview added by tsickle
 * Generated from: edit-form/edit-form.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
class EditFormComponent {
    /**
     * @param {?} fb
     */
    constructor(fb) {
        this.fb = fb;
        this.formGroup = this.fb.group({});
        this.bcacResetForm = new EventEmitter();
        //禁用今日之后的时间
        this.disabledDateFn1 = (/**
         * @param {?} current
         * @return {?}
         */
        (current) => {
            return differenceInCalendarDays(current, new Date()) > 0;
        });
        // 禁用今日之前的时间
        this.disabledDateFn2 = (/**
         * @param {?} current
         * @return {?}
         */
        (current) => {
            return differenceInCalendarDays(current, new Date()) < 0;
        });
        // timeDefaultValue = setDate()
        this.disabledDateTime = (/**
         * @return {?}
         */
        () => {
            return {
                nzDisabledHours: (/**
                 * @return {?}
                 */
                () => this.range(0, 24)),
                nzDisabledMinutes: (/**
                 * @return {?}
                 */
                () => this.range(30, 60)),
                nzDisabledSeconds: (/**
                 * @return {?}
                 */
                () => [55, 56])
            };
        });
    }
    /**
     * @param {?} formItem
     * @return {?}
     */
    set bcacFormItems(formItem) {
        this.formItems = formItem;
        /** @type {?} */
        let obj = {};
        formItem.forEach((/**
         * @param {?} element
         * @return {?}
         */
        element => {
            /** @type {?} */
            let formControl = new FormControl();
            if (element.required)
                formControl.setValidators(Validators.required);
            this.formGroup.addControl(element.fieldName, formControl);
            obj[element.fieldName] = element.value;
            if (element.disabledType) {
                switch (element.disabledType) {
                    case 1:
                        element['disabledDateFn'] = this.disabledDateFn1;
                        break;
                    case 2:
                        element['disabledDateFn'] = this.disabledDateFn2;
                        break;
                    default:
                        break;
                }
            }
        }));
        this.formGroup.setValue(obj);
    }
    /**
     * @return {?}
     */
    ngOnInit() {
    }
    /**
     * @param {?} start
     * @param {?} end
     * @return {?}
     */
    range(start, end) {
        /** @type {?} */
        const result = [];
        for (let i = start; i < end; i++) {
            result.push(i);
        }
        return result;
    }
    /**
     * @param {?} e
     * @return {?}
     */
    resetForm(e) {
        e.preventDefault();
        this.formGroup.reset();
        for (const key in this.formGroup.controls) {
            if (Object.prototype.hasOwnProperty.call(this.formGroup.controls, key)) {
                /** @type {?} */
                const element = this.formGroup.controls[key];
                element.markAsPristine();
                element.updateValueAndValidity();
            }
        }
        this.bcacResetForm.emit(true);
    }
}
EditFormComponent.decorators = [
    { type: Component, args: [{
                selector: 'bcac-edit-form',
                template: "<form nz-form [formGroup]=\"formGroup\">\r\n    <nz-form-item *ngFor=\"let item of formItems\">\r\n        <nz-form-label nzSpan={{item.labelSpan}} [nzRequired]=\"item.required\">{{item.text}}</nz-form-label>\r\n        <nz-form-control nzSpan={{item.controlSpan}}>\r\n            <nz-date-picker *ngIf=\"item.type === 'date-time'\" nzSize=\"small\" nzShowTime={{item.showTime}} [nzDisabledDate]=\"item.disabledDateFn\" [nzDisabledTime]=\"disabledDateTime\"\r\n                formControlName={{item.fieldName}}>\r\n            </nz-date-picker>\r\n            <nz-month-picker *ngIf=\"item.type === 'date-month'\" nzSize=\"small\" formControlName=\"{{item.fieldName}}\">\r\n            </nz-month-picker>\r\n            <nz-time-picker *ngIf=\"item.type === 'time'\" formControlName=\"{{item.fieldName}}\"></nz-time-picker>\r\n            <nz-year-picker *ngIf=\"item.type === 'date-year'\" nzSize=\"small\" formControlName=\"{{item.fieldName}}\">\r\n            </nz-year-picker>\r\n            <nz-select *ngIf=\"item.type === 'select'\" nzSize='small' formControlName=\"{{item.fieldName}}\">\r\n                <nz-option *ngFor=\"let opt of item.list\" [nzLabel]=\"opt.label\" [nzValue]=\"opt.value\"\r\n                    [nzDisabled]=\"opt.disabled\">\r\n                </nz-option>\r\n            </nz-select>\r\n            <nz-range-picker *ngIf=\"item.type === 'date-range'\" [nzSize]=\"'small'\" formControlName=\"{{item.fieldName}}\"\r\n                [nzShowTime]=\"true\"></nz-range-picker>\r\n            <input *ngIf=\"item.type === 'text'\" nzSize=\"small\" nz-input formControlName=\"{{item.fieldName}}\">\r\n        </nz-form-control>\r\n    </nz-form-item>\r\n    <nz-form-item>\r\n        <nz-form-control nzSpan=\"6\" nzOffset=\"7\" class=\"form-btn\">\r\n            <button nz-button nzSize=\"small\" nzType=\"primary\" [disabled]=\"!formGroup.valid\">\u63D0\u4EA4</button>\r\n            <button nz-button nzSize=\"small\" nzType=\"text\" (click)=\"resetForm($event)\">\u91CD\u7F6E</button>\r\n        </nz-form-control>\r\n    </nz-form-item>\r\n</form>",
                styles: [".form-btn{display:flex;justify-content:center}.form-btn button:not(:first-child){margin-left:5rem}"]
            }] }
];
/** @nocollapse */
EditFormComponent.ctorParameters = () => [
    { type: FormBuilder }
];
EditFormComponent.propDecorators = {
    bcacFormItems: [{ type: Input }],
    bcacSubmitForm: [{ type: Output }],
    bcacResetForm: [{ type: Output }]
};
if (false) {
    /** @type {?} */
    EditFormComponent.prototype.formGroup;
    /** @type {?} */
    EditFormComponent.prototype.formItems;
    /** @type {?} */
    EditFormComponent.prototype.bcacSubmitForm;
    /** @type {?} */
    EditFormComponent.prototype.bcacResetForm;
    /** @type {?} */
    EditFormComponent.prototype.disabledDateFn1;
    /** @type {?} */
    EditFormComponent.prototype.disabledDateFn2;
    /** @type {?} */
    EditFormComponent.prototype.disabledDateTime;
    /**
     * @type {?}
     * @private
     */
    EditFormComponent.prototype.fb;
}

/**
 * @fileoverview added by tsickle
 * Generated from: bcac-form.module.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
class BcacFormModule {
}
BcacFormModule.decorators = [
    { type: NgModule, args: [{
                declarations: [CommonFormComponent, EditFormComponent],
                imports: [
                    CommonModule,
                    FormsModule,
                    ReactiveFormsModule,
                    NgZorroAntdModule,
                    BcacButtonModule
                ], exports: [
                    CommonFormComponent,
                    EditFormComponent
                ]
            },] }
];

/**
 * @fileoverview added by tsickle
 * Generated from: public-api.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * Generated from: index.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

/**
 * @fileoverview added by tsickle
 * Generated from: bcac-lib-base-component-currency-bcac-form.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */

export { BcacFormModule, CommonFormComponent as ɵa, EditFormComponent as ɵb };
//# sourceMappingURL=bcac-lib-base-component-currency-bcac-form.js.map
