import * as i0 from '@angular/core';
import { Component, Input, NgModule } from '@angular/core';
import * as i1$1 from '@aztrix/sdk';
import { map, ReplaySubject, combineLatest, switchMap } from 'rxjs';
import * as i1 from '@aztrix/helpers';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@aztrix/icons';
import { IconsModule } from '@aztrix/icons';

class AppleWalletButtonComponent {
    constructor(_translateService, _platformService) {
        this._translateService = _translateService;
        this._platformService = _platformService;
        this.icon$ = this._translateService.lang$.pipe(map((lang) => `brands:apple-wallet-${lang}`));
    }
    addToAppleWallet() {
        const blob = new Blob([this.walletResult], { type: 'application/vnd.apple.pkpass' });
        const downloadURL = window.URL.createObjectURL(blob);
        const anchor = document.createElement('a');
        anchor.download = `aztrix-${this.fileName}.pkpass`;
        anchor.href = downloadURL;
        anchor.click();
    }
    get isApple() {
        return this._platformService.isApple();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AppleWalletButtonComponent, deps: [{ token: i1.TranslateService }, { token: i1.PlatformService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: AppleWalletButtonComponent, selector: "ax-apple-wallet-button", inputs: { walletResult: "walletResult", fileName: "fileName" }, ngImport: i0, template: "<ax-icon\n  *ngIf=\"isApple\"\n  class=\"button\"\n  [name]=\"(icon$ | async) || undefined\"\n  (click)=\"addToAppleWallet()\"\n></ax-icon>\n", styles: [":host{display:block}.button{color:initial;display:block;width:180px;margin:0 auto}.button:hover{cursor:pointer}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AppleWalletButtonComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-apple-wallet-button', template: "<ax-icon\n  *ngIf=\"isApple\"\n  class=\"button\"\n  [name]=\"(icon$ | async) || undefined\"\n  (click)=\"addToAppleWallet()\"\n></ax-icon>\n", styles: [":host{display:block}.button{color:initial;display:block;width:180px;margin:0 auto}.button:hover{cursor:pointer}\n"] }]
        }], ctorParameters: () => [{ type: i1.TranslateService }, { type: i1.PlatformService }], propDecorators: { walletResult: [{
                type: Input
            }], fileName: [{
                type: Input
            }] } });

class AlistAppleWalletButtonComponent {
    constructor(_alistService) {
        this._alistService = _alistService;
        this._alistId$ = new ReplaySubject(1);
        this._alistLanguageId$ = new ReplaySubject(1);
        this.alistWallet$ = combineLatest([this._alistId$, this._alistLanguageId$]).pipe(switchMap(([alistId, alistLanguageId]) => this._alistService.getPassbookCardForAlist(alistId, alistLanguageId)));
    }
    ngOnChanges(changes) {
        if (changes.alistName && this.alistId) {
            this._alistId$.next(this.alistId);
        }
        if (changes.alistLanguageId && this.alistLanguageId) {
            this._alistLanguageId$.next(this.alistLanguageId);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AlistAppleWalletButtonComponent, deps: [{ token: i1$1.AlistsService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: AlistAppleWalletButtonComponent, selector: "ax-alist-apple-wallet-button", inputs: { alistId: "alistId", alistLanguageId: "alistLanguageId", alistName: "alistName" }, usesOnChanges: true, ngImport: i0, template: "<ax-apple-wallet-button\n  [walletResult]=\"alistWallet$ | async\"\n  [fileName]=\"alistName ? alistName : alistId\"\n></ax-apple-wallet-button>\n", styles: [":host{display:block}\n"], dependencies: [{ kind: "component", type: AppleWalletButtonComponent, selector: "ax-apple-wallet-button", inputs: ["walletResult", "fileName"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AlistAppleWalletButtonComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-alist-apple-wallet-button', template: "<ax-apple-wallet-button\n  [walletResult]=\"alistWallet$ | async\"\n  [fileName]=\"alistName ? alistName : alistId\"\n></ax-apple-wallet-button>\n", styles: [":host{display:block}\n"] }]
        }], ctorParameters: () => [{ type: i1$1.AlistsService }], propDecorators: { alistId: [{
                type: Input
            }], alistLanguageId: [{
                type: Input
            }], alistName: [{
                type: Input
            }] } });

class ProfileAppleWalletButtonComponent {
    constructor(_profilesService) {
        this._profilesService = _profilesService;
        this._profileId$ = new ReplaySubject(1);
        this.profileWallet$ = this._profileId$.pipe(switchMap((profileId) => this._profilesService.getPassbookCardForProfile(profileId)));
    }
    ngOnChanges(changes) {
        if (changes.profileId && this.profileId) {
            this._profileId$.next(this.profileId);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ProfileAppleWalletButtonComponent, deps: [{ token: i1$1.ProfilesService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: ProfileAppleWalletButtonComponent, selector: "ax-profile-apple-wallet-button", inputs: { profileId: "profileId" }, usesOnChanges: true, ngImport: i0, template: "<ax-apple-wallet-button\n  [walletResult]=\"profileWallet$ | async\"\n  [fileName]=\"profileId\"\n></ax-apple-wallet-button>\n", styles: [":host{display:block}\n"], dependencies: [{ kind: "component", type: AppleWalletButtonComponent, selector: "ax-apple-wallet-button", inputs: ["walletResult", "fileName"] }, { kind: "pipe", type: i2.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ProfileAppleWalletButtonComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-profile-apple-wallet-button', template: "<ax-apple-wallet-button\n  [walletResult]=\"profileWallet$ | async\"\n  [fileName]=\"profileId\"\n></ax-apple-wallet-button>\n", styles: [":host{display:block}\n"] }]
        }], ctorParameters: () => [{ type: i1$1.ProfilesService }], propDecorators: { profileId: [{
                type: Input
            }] } });

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

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

export { AlistAppleWalletButtonComponent, AppleWalletButtonComponent, AppleWalletButtonModule, ProfileAppleWalletButtonComponent };
//# sourceMappingURL=aztrix-components-apple-wallet-button.mjs.map
