import { Observable , map } from "rxjs" ; import { getElement , requestJSON } from "~/browser" ; import { renderPrivateSponsor , renderPublicSponsor } from "_/templates" ; import { Component , getComponentElement } from "../_" ; /**
 * Sponsor type
 */ export type SponsorType = "user" | "organization" ; /**
 * Sponsor visibility
 */ export type SponsorVisibility = "public" | "private" ; /**
 * Sponsor user
 */ export interface SponsorUser { type : SponsorType ; name : string ; image : string ; url : string ; } /**
 * Public sponsor
 */ export interface PublicSponsor { type : "public" ; user : SponsorUser ; } /**
 * Private sponsor
 */ export interface PrivateSponsor { type : "private" ; } /**
 * Sponsor
 */ export type Sponsor = PublicSponsor | PrivateSponsor ; /**
 * Sponsorship
 */ export interface Sponsorship { sponsors : Sponsor [ ] ; total : number ; } param el returns export function mountSponsorship ( el ) { const sponsorship$ = requestJSON < Sponsorship > ( "https://3if8u9o552.execute-api.us-east-1.amazonaws.com/_/" ) ; const count = getComponentElement ( "sponsorship-count" ) ; const total = getComponentElement ( "sponsorship-total" ) ; sponsorship$ . subscribe ( sponsorship => { el . removeAttribute ( "hidden" ) ; const list = getElement ( ":scope > :first-child" , el ) ; for ( const sponsor of sponsorship . sponsors ) if ( sponsor . type === "public" ) list . appendChild ( renderPublicSponsor ( sponsor . user ) ) ; list . appendChild ( renderPrivateSponsor ( sponsorship . sponsors . filter ( ( { type } ) => ( type === "private" ) ) . length ) ) ; count . innerText = `${ sponsorship . sponsors . length }` ; total . innerText = `$ ${ sponsorship . total . toString ( ) . replace ( /\B(?=(\d{3})+(?!\d))/g , "," ) } a month` ; } ) ; return sponsorship$ . pipe ( map ( state => ( { ref : el , ... state } ) ) ) ; }