/**
 * Admin Cuts Management Module
 * Main initialization file that imports and orchestrates all cut management modules
 */

// Global admin cuts manager instance
let adminCutsManager = null;

// Initialize the admin cuts system when DOM is ready
document.addEventListener('DOMContentLoaded', async function() {
    console.log('DOM loaded, initializing admin cuts system...');
    
    try {
        // Wait for all module classes to be loaded
        if (typeof AdminCutsManager === 'undefined') {
            console.error('AdminCutsManager class not loaded');
            return;
        }
        
        if (typeof CutDrawing === 'undefined') {
            console.error('CutDrawing class not loaded');
            return;
        }
        
        if (typeof CutLocationManager === 'undefined') {
            console.error('CutLocationManager class not loaded');
            return;
        }
        
        if (typeof CutPrintUtils === 'undefined') {
            console.error('CutPrintUtils class not loaded');
            return;
        }
        
        // Create manager instance
        adminCutsManager = new AdminCutsManager();
        
        // Initialize the system
        await adminCutsManager.initialize();
        
        console.log('Admin cuts system initialized successfully');
        
        // Make manager globally accessible for debugging
        window.adminCutsManager = adminCutsManager;
        
    } catch (error) {
        console.error('Failed to initialize admin cuts system:', error);
        
        // Show error notification if available
        if (typeof showNotification === 'function') {
            showNotification('Failed to initialize cuts management system', 'error');
        }
    }
});

// Global functions for backward compatibility
function startDrawing() {
    if (adminCutsManager && adminCutsManager.cutDrawing) {
        adminCutsManager.handleStartDrawing();
    }
}

function finishDrawing() {
    if (adminCutsManager && adminCutsManager.cutDrawing) {
        adminCutsManager.cutDrawing.finishDrawing();
    }
}

function cancelDrawing() {
    if (adminCutsManager && adminCutsManager.cutDrawing) {
        adminCutsManager.cutDrawing.cancelDrawing();
    }
}

function resetForm() {
    if (adminCutsManager) {
        adminCutsManager.resetForm();
    }
}

function exportCuts() {
    if (adminCutsManager) {
        adminCutsManager.exportCuts();
    }
}

function refreshCuts() {
    if (adminCutsManager) {
        adminCutsManager.loadCuts();
    }
}

// Debug functions
function debugFormState() {
    if (adminCutsManager) {
        adminCutsManager.debugFormState();
    }
}

function debugOpacityState() {
    if (adminCutsManager) {
        adminCutsManager.debugOpacityState();
    }
}

function forceUpdateDrawingStyle() {
    if (adminCutsManager) {
        adminCutsManager.forceUpdateDrawingStyle();
    }
}
