import type { ReactElement } from 'react' ; import type { ITab } from '@cloudbeaver/core-ui' ; import { Entity , inject , injectable } from '@cloudbeaver/core-di' ; import { ITabContainerEntity , TabContainerToken } from './TabContainerToken' ; import { TabContext } from './TabContext' ; import { TabToken } from './TabToken' ; @ injectable ( ) export class TabViewModel implements ITab { tabId : string ; panel : ( ) => ReactElement | null ; get title ( ) : string { return this . tabModel . title ; } get icon ( ) : string | undefined { return this . tabModel . icon ; } onClose ? : ( ) => void ; onActivate = ( ) => { this . tabContainer . activateTab ( this . tabId ) ; } ; constructor ( @ inject ( TabToken ) private readonly tabModel , private readonly entity , @ inject ( TabContainerToken ) private readonly tabContainer ) { this . tabId = this . entity . id ; this . onClose = this . tabModel . onClose ? ( ) => { this . _onClose ( ) ; } : undefined ; this . panel = ( ) => TabContext ( tabContainer . getTabServiceInjector ( this . tabId ) , this . tabModel . panel ) ; } private _onClose ( ) { this . tabContainer . closeTab ( this . tabId ) ; } }