/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2026, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////

import gettext from 'sources/gettext';
import ImportExportServers from './ImportExportServers';
import { BROWSER_PANELS } from '../../../../browser/static/js/constants';
import pgAdmin from 'sources/pgadmin';
import { isDefaultWorkspace } from '../../../../static/js/utils';

export default class ImportExportServersModule {
  static instance;

  static getInstance(...args) {
    if(!ImportExportServersModule.instance) {
      ImportExportServersModule.instance = new ImportExportServersModule(...args);
    }
    return ImportExportServersModule.instance;
  }

  init() {
    if (this.initialized)
      return;
    this.initialized = true;

    // Define the nodes on which the menus to be appear
    let menus = [{
      name: 'import_export_servers',
      module: this,
      applies: ['tools'],
      callback: 'showImportExportServers',
      enable: isDefaultWorkspace,
      priority: 3,
      label: gettext('Import/Export Servers...'),
      permission: 'tools_import_export_servers',
    }];

    pgAdmin.Browser.add_menus(menus);
  }

  // This is a callback function to show import/export servers when user click on menu item.
  showImportExportServers() {
    const panelTitle = gettext('Import/Export Servers');
    const panelId = BROWSER_PANELS.IMPORT_EXPORT_SERVERS;
    pgAdmin.Browser.docker.default_workspace.openDialog({
      id: panelId,
      title: panelTitle,
      manualClose: false,
      content: (
        <ImportExportServers onClose={()=>{pgAdmin.Browser.docker.default_workspace.close(panelId);}}/>
      )
    }, pgAdmin.Browser.stdW.lg, pgAdmin.Browser.stdH.lg);
  }
}
