import './FileTools.scss' ; import { ModalType , EventType , EventKeyType , StoreChannelType } from '@types' ; import { storeChannel } from '@store' ; import { Controller } from '@controllers' ; import { EventUtil } from '@util' ; ( ( ) => { const FileTools = class extends HTMLElement { private saveButton : HTMLElement | null ; constructor ( ) { super ( ) ; this . saveButton = null ; } connectedCallback ( ) { this . render ( ) ; this . initElement ( ) ; this . initEvent ( ) ; this . subscribe ( ) ; } render ( ) { this . innerHTML = `
                <div class="file-tools">
                  <audi-icon-button id="upload" class="delegation" icontype="upload" size="32px" event-key=${ EventKeyType . EDITOR_MENU_OPEN_UPLOAD_BTN_CLICK }></audi-icon-button>
                  <audi-icon-button id="save" class="delegation disabled" icontype="save" size="32px" event-key=${ EventKeyType . EDITOR_MENU_OPEN_DOWNLOAD_BTN_CLICK }></audi-icon-button>
                </div>
            ` ; } initElement ( ) { this . saveButton = this . querySelector ( '#save' ) ; } initEvent ( ) { EventUtil . registerEventToRoot ( { eventTypes : [ EventType . click ] , eventKey : EventKeyType . EDITOR_MENU_OPEN_UPLOAD_BTN_CLICK , listeners : [ this . openUploadModalBtnClickListener ] , bindObj : this } ) ; EventUtil . registerEventToRoot ( { eventTypes : [ EventType . click ] , eventKey : EventKeyType . EDITOR_MENU_OPEN_DOWNLOAD_BTN_CLICK , listeners : [ this . openDownloadModalBtnClickListener ] , bindObj : this } ) ; } openUploadModalBtnClickListener ( ) { Controller . changeModalState ( ModalType . upload , false ) ; } openDownloadModalBtnClickListener ( ) { Controller . changeModalState ( ModalType . download , false ) ; } subscribe ( ) { storeChannel . subscribe ( StoreChannelType . FILE_TOOLS_CHANNEL , this . sectionCountObserverCallback , this ) ; } disconnectedCallback ( ) { this . unsubscribe ( ) ; } unsubscribe ( ) { storeChannel . unsubscribe ( StoreChannelType . FILE_TOOLS_CHANNEL , this . sectionCountObserverCallback , this ) ; } sectionCountObserverCallback ( newTrackList ) { if ( ! this . saveButton ) return ; const possibleSave = newTrackList . find ( track => track . trackSectionList . length > 0 ) ; if ( possibleSave ) { this . saveButton . classList . remove ( 'disabled' ) ; } else { this . saveButton . classList . add ( 'disabled' ) ; } } } ; customElements . define ( 'audi-file-tools' , FileTools ) ; } ) ( ) ; export { } ;