/**
 *
 * @ai-apps/angular v2.147.1-next.0 | custom-date-time.component.js
 *
 * Copyright 2014, 2022 IBM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import { Component, EventEmitter, HostBinding, Input, Output, } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "carbon-components-angular";
import * as i3 from "@angular/forms";
import * as i4 from "./date-time-relative.component";
import * as i5 from "./date-time-absolute.component";
function CustomDateTimeComponent_div_0_Template(rf, ctx) { if (rf & 1) {
    const _r4 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵelementStart(1, "fieldset", 4);
    i0.ɵɵelementStart(2, "legend", 5);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "ibm-radio-group", 6);
    i0.ɵɵlistener("ngModelChange", function CustomDateTimeComponent_div_0_Template_ibm_radio_group_ngModelChange_4_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r3 = i0.ɵɵnextContext(); return ctx_r3.mode = $event; });
    i0.ɵɵelementStart(5, "ibm-radio", 7);
    i0.ɵɵtext(6);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "ibm-radio", 8);
    i0.ɵɵtext(8);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(ctx_r0.batchText.CUSTOM_RANGE);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngModel", ctx_r0.mode);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r0.batchText.RELATIVE);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r0.batchText.ABSOLUTE);
} }
function CustomDateTimeComponent_ai_date_time_relative_1_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "ai-date-time-relative", 9);
    i0.ɵɵlistener("valueChange", function CustomDateTimeComponent_ai_date_time_relative_1_Template_ai_date_time_relative_valueChange_0_listener($event) { i0.ɵɵrestoreView(_r6); const ctx_r5 = i0.ɵɵnextContext(); return ctx_r5.relativeChange($event); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵproperty("value", ctx_r1.value)("batchText", ctx_r1.batchText)("relativeToOptions", ctx_r1.relativeToOptions);
} }
function CustomDateTimeComponent_ai_date_time_absolute_2_Template(rf, ctx) { if (rf & 1) {
    const _r8 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "ai-date-time-absolute", 10);
    i0.ɵɵlistener("valueChange", function CustomDateTimeComponent_ai_date_time_absolute_2_Template_ai_date_time_absolute_valueChange_0_listener($event) { i0.ɵɵrestoreView(_r8); const ctx_r7 = i0.ɵɵnextContext(); return ctx_r7.absoluteChange($event); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵproperty("value", ctx_r2.value)("batchText", ctx_r2.batchText)("dateFormat", ctx_r2.dateFormat)("placeholder", ctx_r2.placeholder)("flatpickrOptions", ctx_r2.flatpickrOptions);
} }
export class CustomDateTimeComponent {
    constructor() {
        this.mode = 'relative';
        this.value = [];
        this.range = null;
        this.hasRelative = true;
        this.hasAbsolute = true;
        /**
         * Format of date
         *
         * For reference: https://flatpickr.js.org/formatting/
         */
        this.dateFormat = 'Y-m-d';
        this.placeholder = 'yyyy-mm-dd';
        this.rangeChange = new EventEmitter();
        this.wrapperClass = true;
    }
    ngOnChanges(changes) {
        var _a, _b, _c;
        if ((_a = changes === null || changes === void 0 ? void 0 : changes.range) === null || _a === void 0 ? void 0 : _a.currentValue) {
            const [type, start, end, relativeConfig] = changes.range.currentValue;
            if (type === 'RELATIVE') {
                this.mode = 'relative';
                this.value = [start, end, relativeConfig];
            }
            if (type === 'ABSOLUTE') {
                this.mode = 'absolute';
                this.value = [start, end];
            }
        }
        if (((_b = changes === null || changes === void 0 ? void 0 : changes.hasRelative) === null || _b === void 0 ? void 0 : _b.currentValue) === false) {
            this.mode = 'absolute';
        }
        if (((_c = changes === null || changes === void 0 ? void 0 : changes.hasAbsolute) === null || _c === void 0 ? void 0 : _c.currentValue) === false) {
            this.mode = 'relative';
        }
    }
    relativeChange(change) {
        this.rangeChange.emit(['RELATIVE', ...change]);
    }
    absoluteChange(change) {
        this.rangeChange.emit(['ABSOLUTE', ...change]);
    }
}
CustomDateTimeComponent.ɵfac = function CustomDateTimeComponent_Factory(t) { return new (t || CustomDateTimeComponent)(); };
CustomDateTimeComponent.ɵcmp = i0.ɵɵdefineComponent({ type: CustomDateTimeComponent, selectors: [["ai-custom-date-time"]], hostVars: 2, hostBindings: function CustomDateTimeComponent_HostBindings(rf, ctx) { if (rf & 2) {
        i0.ɵɵclassProp("iot--date-time-picker__custom-wrapper", ctx.wrapperClass);
    } }, inputs: { range: "range", hasRelative: "hasRelative", hasAbsolute: "hasAbsolute", batchText: "batchText", dateFormat: "dateFormat", placeholder: "placeholder", relativeToOptions: "relativeToOptions", flatpickrOptions: "flatpickrOptions" }, outputs: { rangeChange: "rangeChange" }, features: [i0.ɵɵNgOnChangesFeature], decls: 3, vars: 3, consts: [["class", "bx--form-item", 4, "ngIf"], [3, "value", "batchText", "relativeToOptions", "valueChange", 4, "ngIf"], [3, "value", "batchText", "dateFormat", "placeholder", "flatpickrOptions", "valueChange", 4, "ngIf"], [1, "bx--form-item"], [1, "bx--fieldset"], [1, "bx--label"], [3, "ngModel", "ngModelChange"], ["value", "relative"], ["value", "absolute"], [3, "value", "batchText", "relativeToOptions", "valueChange"], [3, "value", "batchText", "dateFormat", "placeholder", "flatpickrOptions", "valueChange"]], template: function CustomDateTimeComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵtemplate(0, CustomDateTimeComponent_div_0_Template, 9, 4, "div", 0);
        i0.ɵɵtemplate(1, CustomDateTimeComponent_ai_date_time_relative_1_Template, 1, 3, "ai-date-time-relative", 1);
        i0.ɵɵtemplate(2, CustomDateTimeComponent_ai_date_time_absolute_2_Template, 1, 5, "ai-date-time-absolute", 2);
    } if (rf & 2) {
        i0.ɵɵproperty("ngIf", ctx.hasRelative && ctx.hasAbsolute);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.mode === "relative" && ctx.hasRelative);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.mode === "absolute" && ctx.hasAbsolute);
    } }, directives: [i1.NgIf, i2.RadioGroup, i3.NgControlStatus, i3.NgModel, i2.Radio, i4.DateTimeRelativeComponent, i5.DateTimeAbsoluteComponent], styles: ["[_nghost-%COMP%] {\n        display: block;\n      }"] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CustomDateTimeComponent, [{
        type: Component,
        args: [{
                selector: 'ai-custom-date-time',
                template: `
    <div class="bx--form-item" *ngIf="hasRelative && hasAbsolute">
      <fieldset class="bx--fieldset">
        <legend class="bx--label">{{ batchText.CUSTOM_RANGE }}</legend>
        <ibm-radio-group [(ngModel)]="mode">
          <ibm-radio value="relative">{{ batchText.RELATIVE }}</ibm-radio>
          <ibm-radio value="absolute">{{ batchText.ABSOLUTE }}</ibm-radio>
        </ibm-radio-group>
      </fieldset>
    </div>
    <!-- relative picker -->
    <ai-date-time-relative
      *ngIf="mode === 'relative' && hasRelative"
      (valueChange)="relativeChange($event)"
      [value]="value"
      [batchText]="batchText"
      [relativeToOptions]="relativeToOptions"
    >
    </ai-date-time-relative>
    <ai-date-time-absolute
      *ngIf="mode === 'absolute' && hasAbsolute"
      (valueChange)="absoluteChange($event)"
      [value]="value"
      [batchText]="batchText"
      [dateFormat]="dateFormat"
      [placeholder]="placeholder"
      [flatpickrOptions]="flatpickrOptions"
    >
    </ai-date-time-absolute>
  `,
                styles: [
                    `
      :host {
        display: block;
      }
    `,
                ],
            }]
    }], null, { range: [{
            type: Input
        }], hasRelative: [{
            type: Input
        }], hasAbsolute: [{
            type: Input
        }], batchText: [{
            type: Input
        }], dateFormat: [{
            type: Input
        }], placeholder: [{
            type: Input
        }], relativeToOptions: [{
            type: Input
        }], flatpickrOptions: [{
            type: Input
        }], rangeChange: [{
            type: Output
        }], wrapperClass: [{
            type: HostBinding,
            args: ['class.iot--date-time-picker__custom-wrapper']
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 