import { Observable , Subject , defer , delay , finalize , map , merge , of , switchMap , tap } from "rxjs" ; import { getElement } from "~/browser" ; import { Component } from "../_" ; /**
 * Dialog
 */ export interface Dialog { message : string ; active : boolean ; } /**
 * Watch options
 */ interface WatchOptions { alert$ : Subject < string > ; } /**
 * Mount options
 */ interface MountOptions { alert$ : Subject < string > ; } param _el param options returns export function watchDialog ( _el , { alert$ } ) { return alert$ . pipe ( switchMap ( message => merge ( of ( true ) , of ( false ) . pipe ( delay ( 2000 ) ) ) . pipe ( map ( active => ( { message , active } ) ) ) ) ) ; } param el param options returns export function mountDialog ( el , options ) { const inner = getElement ( ".md-typeset" , el ) ; return defer ( ( ) => { const push$ = new Subject < Dialog > ( ) ; push$ . subscribe ( ( { message , active } ) => { inner . textContent = message ; if ( active ) el . setAttribute ( "data-md-state" , "open" ) ; else el . removeAttribute ( "data-md-state" ) ; } ) ; return watchDialog ( el , options ) . pipe ( tap ( state => push$ . next ( state ) ) , finalize ( ( ) => push$ . complete ( ) ) , map ( state => ( { ref : el , ... state } ) ) ) ; } ) ; }