import { ChangeDetectionStrategy , Component } from '@angular/core' ; import { BehaviorSubject , combineLatest } from 'rxjs' ; import { map , take } from 'rxjs/operators' ; import { AbstractSubscriberComponent } from '../../../../../common/components/abstract-subscriber/abstract-subscriber.component' ; import { ConfirmationAction , SubscriptionTimespan , } from './admin-confirmation.type' ; /**
 * Admin confirmation modal.
 */ @ Component ( { selector : 'm-channel__adminConfirmation' , changeDetection : ChangeDetectionStrategy . OnPush , templateUrl : 'admin-confirmation.component.html' , styleUrls : [ 'admin-confirmation.component.ng.scss' ] , } ) export class ChannelAdminConfirmationComponent extends AbstractSubscriberComponent { public readonly period$ = new BehaviorSubject < SubscriptionTimespan > ( 'month' ) ; public action$ : BehaviorSubject < ConfirmationAction > = new BehaviorSubject < ConfirmationAction > ( null ) ; /**
     * Completion intent.
     */ onComplete : ( tier : SubscriptionTimespan ) => any = ( ) => { } ; /**
     * Dismiss intent.
     */ onDismissIntent : ( ) => void = ( ) => { } ; constructor ( ) { super ( ) ; } /**
     * Opts to pass into component.
     */ set opts ( { action , onComplete , onDismissIntent } ) { this . action$ . next ( action ?? '' ) ; this . onComplete = onComplete || ( ( ) => { } ) ; this . onDismissIntent = onDismissIntent || ( ( ) => { } ) ; } param { SubscriptionTimespan } returns { void } public onSelectChange ( value ) { this . period$ . next ( value ) ; } returns { void } public confirmClick ( ) { this . subscriptions . push ( combineLatest ( [ this . action$ , this . period$ ] ) . pipe ( take ( 1 ) , map ( ( [ action , period ] ) => { this . onComplete ( action === 'make' ? period : '' ) ; } ) ) . subscribe ( ) ) ; } }