import * as i0 from '@angular/core';
import { forwardRef, Component, ChangeDetectionStrategy, Input, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import * as i1 from '@angular/forms';
import { FormControl, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import * as i2 from '@ironsource/fusion-ui/components/daterange/v3';
import { DaterangeModule } from '@ironsource/fusion-ui/components/daterange/v3';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

const DEFAULT_OPTIONS = {
    calendarAmount: 1,
    presets: []
};
class DatepickerComponent {
    constructor() {
        this.onDestroy$ = new Subject();
        this.daterangeOptions = { ...DEFAULT_OPTIONS };
        this.daterangeFormControl = new FormControl();
        this.propagateChange = (_) => { };
        this.propagateTouched = () => { };
    }
    set options(value) {
        this.daterangeOptions = { ...DEFAULT_OPTIONS, ...value };
    }
    set minDate(value) {
        this.daterangeMinDate = value;
    }
    set maxDate(value) {
        this.daterangeMaxDate = value;
    }
    ngOnInit() {
        this.daterangeFormControl.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(value => {
            this.propagateChange(value);
        });
    }
    ngOnDestroy() {
        this.onDestroy$.next();
        this.onDestroy$.complete();
    }
    writeValue(value) {
        this.daterangeFormControl.setValue(value, { emitEvent: false });
    }
    registerOnChange(fn) {
        this.propagateChange = fn;
    }
    registerOnTouched(fn) {
        this.propagateTouched = fn;
    }
    static { this.ɵfac = function DatepickerComponent_Factory(t) { return new (t || DatepickerComponent)(); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: DatepickerComponent, selectors: [["fusion-datepicker"]], inputs: { options: "options", minDate: "minDate", maxDate: "maxDate" }, features: [i0.ɵɵProvidersFeature([
                {
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: forwardRef(() => DatepickerComponent),
                    multi: true
                }
            ])], decls: 1, vars: 4, consts: [[3, "minDate", "maxDate", "options", "formControl"]], template: function DatepickerComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelement(0, "fusion-daterange", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("minDate", ctx.daterangeMinDate)("maxDate", ctx.daterangeMaxDate)("options", ctx.daterangeOptions)("formControl", ctx.daterangeFormControl);
        } }, dependencies: [i1.NgControlStatus, i1.FormControlDirective, i2.DaterangeComponent], styles: ["[_nghost-%COMP%]{margin:0;padding:0}fusion-daterange[_ngcontent-%COMP%]{width:256px}"], changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DatepickerComponent, [{
        type: Component,
        args: [{ selector: 'fusion-datepicker', template: `<fusion-daterange
        [minDate]="daterangeMinDate"
        [maxDate]="daterangeMaxDate"
        [options]="daterangeOptions"
        [formControl]="daterangeFormControl"
    ></fusion-daterange>`, changeDetection: ChangeDetectionStrategy.OnPush, providers: [
                    {
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: forwardRef(() => DatepickerComponent),
                        multi: true
                    }
                ], styles: [":host{margin:0;padding:0}fusion-daterange{width:256px}\n"] }]
    }], null, { options: [{
            type: Input
        }], minDate: [{
            type: Input
        }], maxDate: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(DatepickerComponent, { className: "DatepickerComponent", filePath: "v3/datepicker.component.ts", lineNumber: 31 }); })();

class DatepickerModule {
    static { this.ɵfac = function DatepickerModule_Factory(t) { return new (t || DatepickerModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: DatepickerModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule, ReactiveFormsModule, DaterangeModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(DatepickerModule, [{
        type: NgModule,
        args: [{
                declarations: [DatepickerComponent],
                imports: [CommonModule, ReactiveFormsModule, DaterangeModule],
                exports: [DatepickerComponent]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(DatepickerModule, { declarations: [DatepickerComponent], imports: [CommonModule, ReactiveFormsModule, DaterangeModule], exports: [DatepickerComponent] }); })();

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

export { DatepickerComponent, DatepickerModule };
//# sourceMappingURL=ironsource-fusion-ui-components-datepicker.mjs.map
