import { ChangeDetectionStrategy , Component , EventEmitter , OnInit , Output , } from '@angular/core' ; import { ComposerService } from '../../../../../services/composer.service' ; import { SupportTier , SupportTiersService , } from '../../../../../../wire/v2/support-tiers.service' ; import { Session } from '../../../../../../../services/session' ; import { FeaturesService } from '../../../../../../../services/features.service' ; import { ConfigsService } from '../../../../../../../common/services/configs.service' ; import { ComposerMonetizeV2Service } from './monetize.service' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; export type MonetizationTabType = 'plus' | 'membership' | 'custom' ; @ Component ( { selector : 'm-composer__monetizeV2' , templateUrl : 'monetize.component.html' , providers : [ SupportTiersService , ComposerMonetizeV2Service ] , } ) export class ComposerMonetizeV2Component implements OnInit { type : MonetizationTabType = 'membership' ; hasSupportTiers$ : Observable < boolean > = this . monetizeService . supportTiers$ . pipe ( map ( supportTiers => { return supportTiers . length > 0 ; } ) ) ; isEditingPlus : boolean = false ; isGroupPost : boolean = false ; plusTierUrn : string = '' ; /**
     * Signal event emitter to parent's popup service
     */ @ Output ( ) dismissIntent : EventEmitter < any > = new EventEmitter < any > ( ) ; param service param supportTiers param session param features constructor ( public service , public features , protected session , configs , protected monetizeService ) { this . plusTierUrn = configs . get ( 'plus' ) . support_tier_urn ; if ( this . features . has ( 'plus-2020' ) ) { this . type = 'plus' ; } } /**
     * Component initialization. Set initial state.
     */ ngOnInit ( ) { this . monetizeService . loadSupportTiers ( this . session . getLoggedInUser ( ) . guid ) ; const monetization = this . service . monetization$ . getValue ( ) ; const pendingMonetization = this . service . pendingMonetization$ . getValue ( ) ; /**
         * Go to the tab of most recent monetization
         */ if ( monetization && monetization . support_tier ) { this . setType ( monetization . support_tier ) ; } if ( pendingMonetization ) { this . type = pendingMonetization . type || 'plus' ; return ; } this . service . isGroupPost$ . subscribe ( is => { this . isGroupPost = is ; this . type = is ? 'membership' : 'plus' ; } ) ; } setType ( tier ) { if ( ! tier . public ) { this . type = 'custom' ; } else if ( tier . urn === this . plusTierUrn ) { this . type = 'plus' ; const savedState = this . service . entity ; if ( savedState && savedState . wire_threshold && savedState . wire_threshold . support_tier ) { if ( savedState . wire_threshold . support_tier . urn === this . plusTierUrn ) { this . isEditingPlus = true ; } } } else { this . type = 'membership' ; } } }