<?php
$page_title = "পেমেন্ট মেথড";
require_once 'includes/auth_check.php';

if (isset($_GET['delete_id'])) {
    $delete_id = (int)$_GET['delete_id'];
    $conn->query("DELETE FROM payment_methods WHERE id = $delete_id");
    header("Location: payment_methods.php"); exit;
}

$methods_result = $conn->query("SELECT * FROM payment_methods ORDER BY id DESC");
include 'includes/header.php';
?>
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>পেমেন্ট মেথড ম্যানেজমেন্ট</h2>
        <a href="add_edit_method.php" class="btn btn-primary"><i class="fas fa-plus"></i> নতুন মেথড যোগ করুন</a>
    </div>
    <div class="card"><div class="card-body"><div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead class="table-light"><tr><th>ID</th><th>লোগো</th><th>নাম</th><th>নম্বর</th><th>ধরন</th><th>স্ট্যাটাস</th><th>একশন</th></tr></thead>
            <tbody>
                <?php while($row = $methods_result->fetch_assoc()): ?>
                <tr>
                    <td><?php echo $row['id']; ?></td>
                    <td><img src="<?php echo htmlspecialchars($row['logo_url']); ?>" alt="" width="40"></td>
                    <td><?php echo htmlspecialchars($row['method_name']); ?></td>
                    <td><?php echo htmlspecialchars($row['account_number']); ?></td>
                    <td><?php echo htmlspecialchars($row['account_type']); ?></td>
                    <td><span class="badge bg-<?php echo $row['status'] == 'Active' ? 'success' : 'danger'; ?>"><?php echo $row['status']; ?></span></td>
                    <td>
                        <a href="add_edit_method.php?id=<?php echo $row['id']; ?>" class="btn btn-sm btn-info"><i class="fas fa-edit"></i></a>
                        <a href="?delete_id=<?php echo $row['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('আপনি কি নিশ্চিত?')"><i class="fas fa-trash"></i></a>
                    </td>
                </tr>
                <?php endwhile; ?>
            </tbody>
        </table>
    </div></div></div>
</div>
<?php include 'includes/footer.php'; $conn->close(); ?>