<!DOCTYPE html>
<html>
<head>
    <title>Simple Save Test</title>
    <style>
        body { font-family: Arial; padding: 20px; background: #f5f5f5; }
        .container { background: white; padding: 30px; border-radius: 8px; max-width: 800px; margin: 0 auto; }
        table { width: 100%; border-collapse: collapse; margin: 20px 0; }
        th, td { padding: 10px; border: 1px solid #ddd; text-align: left; }
        th { background: #4CAF50; color: white; }
        input { padding: 8px; width: 100%; box-sizing: border-box; }
        .btn { padding: 12px 24px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; }
        .btn:hover { background: #45a049; }
        .success { background: #d4edda; color: #155724; padding: 15px; border-radius: 4px; margin: 10px 0; }
        .error { background: #f8d7da; color: #721c24; padding: 15px; border-radius: 4px; margin: 10px 0; }
    </style>
</head>
<body>
    <div class="container">
        <h1>🧪 Simple Salary Register Test</h1>
        
        <?php
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            echo "<div class='success'><h3>✅ Form Submitted Successfully!</h3>";
            
            echo "<h4>Received Data:</h4>";
            echo "<pre style='background:#f9f9f9;padding:10px;border-radius:4px;'>";
            print_r($_POST);
            echo "</pre>";
            
            if (isset($_POST['employees'])) {
                $count = 0;
                $withNames = 0;
                
                foreach ($_POST['employees'] as $empData) {
                    $count++;
                    if (!empty(trim($empData['employee_name'] ?? ''))) {
                        $withNames++;
                    }
                }
                
                echo "<h4>Analysis:</h4>";
                echo "<ul>";
                echo "<li>Total rows: <strong>{$count}</strong></li>";
                echo "<li>Rows with names: <strong style='color:green;'>{$withNames}</strong></li>";
                echo "<li>Empty rows: <strong>{$count - $withNames}</strong></li>";
                echo "</ul>";
                
                if ($withNames > 0) {
                    echo "<p style='color:green;font-weight:bold;'>✅ This would SAVE successfully! ({$withNames} employees)</p>";
                } else {
                    echo "<p style='color:red;font-weight:bold;'>❌ This would FAIL - no employee names!</p>";
                }
            } else {
                echo "<div class='error'>❌ No 'employees' array found in POST data!</div>";
            }
            
            echo "</div>";
        }
        ?>
        
        <p>This is a simplified test to verify the form structure works correctly.</p>
        
        <form method="POST" action="test_save_simple.php">
            
            <h3>📋 Employee Data</h3>
            <table>
                <thead>
                    <tr>
                        <th>Sl</th>
                        <th>Employee Name *</th>
                        <th>Designation</th>
                        <th>Basic Salary</th>
                    </tr>
                </thead>
                <tbody>
                    <?php for ($i = 0; $i < 3; $i++): ?>
                    <tr>
                        <td><?php echo $i + 1; ?></td>
                        <td>
                            <input type="text" 
                                   name="employees[<?php echo $i; ?>][employee_name]" 
                                   placeholder="Enter employee name"
                                   <?php echo $i === 0 ? 'required' : ''; ?>>
                        </td>
                        <td>
                            <input type="text" 
                                   name="employees[<?php echo $i; ?>][designation]" 
                                   placeholder="Position">
                        </td>
                        <td>
                            <input type="number" 
                                   name="employees[<?php echo $i; ?>][basic_employer]" 
                                   placeholder="15000"
                                   step="0.01">
                        </td>
                    </tr>
                    <?php endfor; ?>
                </tbody>
            </table>
            
            <div style="background:#e3f2fd;padding:15px;border-radius:4px;margin:15px 0;">
                <strong>💡 Instructions:</strong>
                <ul style="margin:10px 0;">
                    <li>Fill at least Row 1's Employee Name (required)</li>
                    <li>Other rows can be left empty</li>
                    <li>Click Submit to test</li>
                </ul>
            </div>
            
            <button type="submit" name="test_save" class="btn">✅ Submit Test Form</button>
            
        </form>
        
        <div style="margin-top:30px;padding:15px;background:#f9f9f9;border-radius:4px;">
            <h3>🔗 Quick Links</h3>
            <a href="modules/payroll/salary_register.php" style="display:inline-block;padding:10px 20px;background:#4CAF50;color:white;text-decoration:none;border-radius:4px;margin:5px;">📊 Salary Register</a>
            <a href="check_form_data.php" style="display:inline-block;padding:10px 20px;background:#2196F3;color:white;text-decoration:none;border-radius:4px;margin:5px;">🔍 Check Form Data</a>
            <a href="test_salary_register.php" style="display:inline-block;padding:10px 20px;background:#FF9800;color:white;text-decoration:none;border-radius:4px;margin:5px;">🔧 Database Test</a>
        </div>
    </div>
</body>
</html>
