<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Guild Data Extractor</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f4f7f6;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .container {
            background: white;
            padding: 25px;
            border-radius: 10px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            width: 90%;
            max-width: 800px;
        }
        h2 {
            color: #333;
            text-align: center;
        }
        textarea {
            width: 100%;
            height: 200px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            resize: vertical;
            font-family: monospace;
            box-sizing: border-box;
        }
        button {
            background-color: #28a745;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            width: 100%;
            margin-top: 10px;
            font-size: 16px;
            font-weight: bold;
        }
        button:hover {
            background-color: #218838;
        }
        .result-container {
            margin-top: 30px;
            width: 100%;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
            background: white;
        }
        th, td {
            text-align: left;
            padding: 12px;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #007bff;
            color: white;
        }
        tr:hover {
            background-color: #f1f1f1;
        }
        .badge-point {
            background: #e74c3c;
            color: white;
            padding: 4px 8px;
            border-radius: 4px;
            font-weight: bold;
        }
        .badge-active {
            background: #f39c12;
            color: white;
            padding: 4px 8px;
            border-radius: 4px;
            font-weight: bold;
        }
    </style>
</head>
<body>

<div class="container">
    <h2>Guild Member Points Scraper</h2>
    <form method="POST">
        <textarea name="json_input" placeholder="এখানে আপনার কোডগুলো পেস্ট করুন... (যেমন: { 'account_id': ... }, { ... })"></textarea>
        <button type="submit" name="process">ডাটা প্রসেস করুন</button>
    </form>

    <?php
    if (isset($_POST['process'])) {
        $raw_input = $_POST['json_input'];

        // ইনপুটটি যদি সরাসরি JSON অ্যারে না হয়, তবে এটিকে অ্যারে ফরম্যাটে আনার চেষ্টা করা
        $trimmed_input = trim($raw_input);
        
        // যদি ইনপুটটি [ ] দিয়ে শুরু না হয়, তবে এটি একটি ভ্যালিড JSON অ্যারে করতে [ ] যোগ করা হচ্ছে
        if (!empty($trimmed_input)) {
            if ($trimmed_input[0] !== '[') {
                $trimmed_input = '[' . rtrim($trimmed_input, ',') . ']';
            }

            $data = json_decode($trimmed_input, true);

            if ($data) {
                echo '<div class="result-container">';
                echo '<h3>ফলাফল:</h3>';
                echo '<table>';
                echo '<thead>
                        <tr>
                            <th>Nickname</th>
                            <th>Total Activeness</th>
                            <th>Guild War Points</th>
                        </tr>
                      </thead>';
                echo '<tbody>';

                foreach ($data as $player) {
                    $nickname = isset($player['nickname']) ? htmlspecialchars($player['nickname']) : 'N/A';
                    $activeness = isset($player['total_activeness']) ? $player['total_activeness'] : 0;
                    $points = isset($player['guild_war_total_point']) ? $player['guild_war_total_point'] : 0;

                    echo "<tr>
                            <td><strong>{$nickname}</strong></td>
                            <td><span class='badge-active'>{$activeness}</span></td>
                            <td><span class='badge-point'>{$points}</span></td>
                          </tr>";
                }

                echo '</tbody></table>';
                echo '</div>';
            } else {
                echo '<p style="color:red; margin-top:10px;">ভুল ফরম্যাট! দয়া করে সঠিক কোড পেস্ট করুন।</p>';
            }
        }
    }
    ?>
</div>

</body>
</html>