// Firmware View Component
class FirmwareViewComponent extends Component {
    constructor(container, viewModel, eventBus) {
        super(container, viewModel, eventBus);
        
        logger.debug('FirmwareViewComponent: Constructor called');
        logger.debug('FirmwareViewComponent: Container:', container);
        
        const firmwareContainer = this.findElement('#firmware-container');
        logger.debug('FirmwareViewComponent: Firmware container found:', !!firmwareContainer);
        
        this.firmwareComponent = new FirmwareComponent(
            firmwareContainer,
            viewModel,
            eventBus
        );
        
        logger.debug('FirmwareViewComponent: FirmwareComponent created');
    }

    mount() {
        super.mount();
        
        logger.debug('FirmwareViewComponent: Mounting...');
        
        // Mount sub-component
        this.firmwareComponent.mount();
        
        // Update available nodes
        this.updateAvailableNodes();
        
        logger.debug('FirmwareViewComponent: Mounted successfully');
    }

    unmount() {
        // Unmount sub-component
        if (this.firmwareComponent) {
            this.firmwareComponent.unmount();
        }
        
        super.unmount();
    }

    // Override pause method to handle sub-components
    onPause() {
        logger.debug('FirmwareViewComponent: Pausing...');
        
        // Pause sub-component
        if (this.firmwareComponent && this.firmwareComponent.isMounted) {
            this.firmwareComponent.pause();
        }
    }

    // Override resume method to handle sub-components
    onResume() {
        logger.debug('FirmwareViewComponent: Resuming...');
        
        // Resume sub-component
        if (this.firmwareComponent && this.firmwareComponent.isMounted) {
            this.firmwareComponent.resume();
        }
    }

    // Override to determine if re-render is needed on resume
    shouldRenderOnResume() {
        // Don't re-render on resume - maintain current state
        return false;
    }

    async updateAvailableNodes() {
        try {
            logger.debug('FirmwareViewComponent: updateAvailableNodes called');
            const response = await window.apiClient.getClusterMembers();
            const nodes = response.members || [];
            logger.debug('FirmwareViewComponent: Got nodes:', nodes);
            this.viewModel.updateAvailableNodes(nodes);
            logger.debug('FirmwareViewComponent: Available nodes updated in view model');
        } catch (error) {
            logger.error('Failed to update available nodes:', error);
        }
    }
} 