export class SyncPanel {
  constructor(handlers) {
    this.handlers = handlers;
  }

  async handleAction(action, event, actionEl) {
    switch (action) {
      case "open-settings":
        event.preventDefault();
        await this.handlers.openSettings(event);
        return true;
      case "close-settings":
        this.handlers.closeSettings();
        return true;
      case "toggle-credentials-form":
        this.handlers.toggleCredentialsForm();
        return true;
      case "toggle-sync-form":
        this.handlers.toggleSyncForm();
        return true;
      case "change-credentials":
        await this.handlers.changeCredentials();
        return true;
      case "sync-edit-client":
        event.stopPropagation();
        this.handlers.editSyncClientSettings(actionEl);
        return true;
      case "sync-delete-client":
        event.stopPropagation();
        this.handlers.deleteSyncClientSettings(actionEl);
        return true;
      case "sync-save-client":
        this.handlers.saveSyncClientDisplayName(actionEl.dataset.nodeId || "");
        return true;
      case "sync-cancel-edit":
        await this.handlers.loadSyncClientsSettings();
        return true;
      default:
        return false;
    }
  }
}
