import * as i0 from '@angular/core';
import { Input, Component, NgModule } from '@angular/core';
import * as i6 from '@aztrix/helpers';
import { OpeningHoursParser, matchingOpeningHours, HelperPipesModule } from '@aztrix/helpers';
import { BehaviorSubject, map, shareReplay } from 'rxjs';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@aztrix/components/button';
import { ButtonModule } from '@aztrix/components/button';
import * as i3 from '@aztrix/icons';
import { IconsModule } from '@aztrix/icons';
import * as i4 from '@aztrix/components/property-view';
import { PropertyViewModule } from '@aztrix/components/property-view';
import * as i5 from '@aztrix/translate';
import { TranslatePipe } from '@aztrix/translate';

class OpeningHoursStatusComponent {
    constructor() {
        this.collapsed = true;
        this.property$ = new BehaviorSubject({});
        this.match$ = this.property$.pipe(map((property) => OpeningHoursParser.parse(property?.value)), map((parsed) => matchingOpeningHours(new Date(), parsed)), shareReplay(1));
        this.range$ = this.match$.pipe(map((r) => r?.range), shareReplay(1));
        this.from$ = this.range$.pipe(map((r) => r?.from), shareReplay(1));
        this.to$ = this.range$.pipe(map((r) => r?.to), shareReplay(1));
        this.open$ = this.match$.pipe(map((r) => !!r?.open), shareReplay(1));
    }
    ngOnChanges(changes) {
        if (changes.property) {
            this.property$.next(this.property);
            this.collapsed = true;
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: OpeningHoursStatusComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: OpeningHoursStatusComponent, selector: "ax-opening-hours-status", inputs: { property: "property" }, usesOnChanges: true, ngImport: i0, template: "<div class=\"status\">\n  <span>{{ ((open$ | async) ? 'label.open' : 'label.closed') | translate }}</span>\n\n  <ng-template #content>\n    <button class=\"button\" axButton color=\"primary\" (click)=\"collapsed = !collapsed\">\n      <ax-icon class=\"icon\" [name]=\"collapsed ? 'chevron-down' : 'chevron-up'\"></ax-icon>\n    </button>\n  </ng-template>\n\n  <ng-container *ngIf=\"(from$ | async) && (to$ | async); else content\">\n    <span> - </span>\n    <button class=\"button\" axButton color=\"primary\" (click)=\"collapsed = !collapsed\">\n      <span class=\"from\">{{ from$ | async | formatTime }}</span>\n      <span> - </span>\n      <span class=\"to\">{{ to$ | async | formatTime }}</span>\n      <ax-icon class=\"icon\" [name]=\"collapsed ? 'chevron-down' : 'chevron-up'\"></ax-icon>\n    </button>\n  </ng-container>\n</div>\n\n<ng-container *ngIf=\"!collapsed\">\n  <span class=\"spacer\"></span>\n  <ax-property-value-view [property]=\"property\"></ax-property-value-view>\n</ng-container>\n", styles: [".status{display:flex;align-items:center;gap:.5ch}.button{padding:0;min-width:0}.spacer{display:block;width:16px;border-top:1px solid var(--font-color)}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.ButtonDirective, selector: "[axButton]", inputs: ["color", "labelHideMobile", "smallButton", "bigButton", "fullWidth", "filled", "outline", "icon-button", "hoverLabel", "hover", "lowercase", "disabled"] }, { kind: "component", type: i3.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "component", type: i4.PropertyValueViewComponent, selector: "ax-property-value-view", inputs: ["property", "showVerificationLabel", "clickable", "isIndividual", "params"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "pipe", type: i5.TranslatePipe, name: "translate" }, { kind: "pipe", type: i6.FormatTimePipe, name: "formatTime" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: OpeningHoursStatusComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-opening-hours-status', template: "<div class=\"status\">\n  <span>{{ ((open$ | async) ? 'label.open' : 'label.closed') | translate }}</span>\n\n  <ng-template #content>\n    <button class=\"button\" axButton color=\"primary\" (click)=\"collapsed = !collapsed\">\n      <ax-icon class=\"icon\" [name]=\"collapsed ? 'chevron-down' : 'chevron-up'\"></ax-icon>\n    </button>\n  </ng-template>\n\n  <ng-container *ngIf=\"(from$ | async) && (to$ | async); else content\">\n    <span> - </span>\n    <button class=\"button\" axButton color=\"primary\" (click)=\"collapsed = !collapsed\">\n      <span class=\"from\">{{ from$ | async | formatTime }}</span>\n      <span> - </span>\n      <span class=\"to\">{{ to$ | async | formatTime }}</span>\n      <ax-icon class=\"icon\" [name]=\"collapsed ? 'chevron-down' : 'chevron-up'\"></ax-icon>\n    </button>\n  </ng-container>\n</div>\n\n<ng-container *ngIf=\"!collapsed\">\n  <span class=\"spacer\"></span>\n  <ax-property-value-view [property]=\"property\"></ax-property-value-view>\n</ng-container>\n", styles: [".status{display:flex;align-items:center;gap:.5ch}.button{padding:0;min-width:0}.spacer{display:block;width:16px;border-top:1px solid var(--font-color)}\n"] }]
        }], propDecorators: { property: [{
                type: Input
            }] } });

class OpeningHoursStatusModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: OpeningHoursStatusModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: OpeningHoursStatusModule, declarations: [OpeningHoursStatusComponent], imports: [CommonModule,
            TranslatePipe,
            HelperPipesModule,
            ButtonModule,
            IconsModule,
            PropertyViewModule], exports: [OpeningHoursStatusComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: OpeningHoursStatusModule, imports: [CommonModule,
            HelperPipesModule,
            ButtonModule,
            IconsModule,
            PropertyViewModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: OpeningHoursStatusModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [OpeningHoursStatusComponent],
                    imports: [
                        CommonModule,
                        TranslatePipe,
                        HelperPipesModule,
                        ButtonModule,
                        IconsModule,
                        PropertyViewModule,
                    ],
                    exports: [OpeningHoursStatusComponent],
                }]
        }] });

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

export { OpeningHoursStatusComponent, OpeningHoursStatusModule };
//# sourceMappingURL=aztrix-components-opening-hours-status.mjs.map
