import { ChangeDetectionStrategy , Component , EventEmitter , OnInit , Output , } from '@angular/core' ; import { ComposerService , MonetizationSubjectValue , } from '../../../services/composer.service' ; import { UniqueId } from '../../../../../helpers/unique-id.helper' ; import { SupportTier , SupportTiersService , } from '../../../../wire/v2/support-tiers.service' ; import { Session } from '../../../../../services/session' ; import { FeaturesService } from '../../../../../services/features.service' ; interface MonetizationState { enabled : boolean ; type : 'tokens' | 'money' ; amount : number ; supportTier ? : SupportTier ; } @ Component ( { selector : 'm-composer__monetize' , changeDetection : ChangeDetectionStrategy . OnPush , templateUrl : 'monetize.component.html' , providers : [ SupportTiersService ] , } ) export class MonetizeComponent implements OnInit { @ Output ( ) dismissIntent : EventEmitter < any > = new EventEmitter < any > ( ) ; /**
     * ID for input/label relationships
     */ readonly inputId : string = UniqueId . generate ( 'm-composer__tags' ) ; /**
     * Monetization popup state object
     */ state : MonetizationState = { enabled : false , type : 'tokens' , amount : 0 , supportTier : null , } ; param service param supportTiers param session param features constructor ( public service , public supportTiers , public features , protected session ) { this . supportTiers . setEntityGuid ( this . session . getLoggedInUser ( ) . guid ) ; } /**
     * Component initialization. Set initial state.
     */ ngOnInit ( ) { const monetization = this . service . monetization$ . getValue ( ) ; this . state = { enabled : Boolean ( monetization ) , type : ( monetization && monetization . type ) || 'tokens' , amount : ( monetization && monetization . min ) || 0 , } ; } param supportTier selectSupportTier ( supportTier ) { this . state . supportTier = supportTier ; if ( supportTier ) { this . state . type = supportTier . has_usd ? 'money' : supportTier . has_tokens ? 'tokens' : null ; this . state . amount = supportTier [ supportTier . has_usd ? 'usd' : supportTier . has_tokens ? 'tokens' : null ] ; } } param a param b byUrn ( a , b ) { return ( ! a && ! b ) || ( a && b && a . urn === b . urn ) ; } /**
     * Emit to subject
     */ save ( ) { let payload = null ; if ( this . state . enabled ) { payload = { type : this . state . type , min : this . state . amount , } ; if ( this . features . has ( 'channels-shop' ) ) { payload . support_tier = this . state . supportTier || null ; } } this . service . monetization$ . next ( payload ) ; this . dismissIntent . emit ( ) ; } }