<?php include "header.php"; ?>
<?php
include_once __DIR__ . '/../includes/white_label_lib.php';

// If the session/user lookup in header.php didn't produce a valid
// $userdata (e.g. an expired session), stop here instead of letting the
// rest of this page run with $userdata undefined. header.php has already
// sent output at this point, so a header() redirect wouldn't work - show
// an inline message with a manual link instead.
if (!isset($userdata) || !is_array($userdata)) {
    echo '<div style="padding:40px;text-align:center;color:#fff;font-family:sans-serif;">
        Your session could not be loaded. <a href="/index" style="color:#a99bff;">Please log in again</a>.
    </div>';
    exit;
}

// ---- Create Payment Link handler ----
// Previously this whole section (and the page below it) was gated to
// role == 'User' only. Admin now gets the same create-link UI too.
if (isset($_POST['create'])) {

    $name   = trim($_POST['name'] ?? '');
    $mobile = trim($_POST['mobile'] ?? '');
    $remark = trim($_POST['remark'] ?? '');
    $amount = trim($_POST['amount'] ?? '');

    // The "Quick Link" tab only asks for an amount — everything else falls
    // back to a sensible default so the same /api/create-order call works
    // either way without needing a second backend path.
    if ($name === '')   { $name = 'Customer'; }
    if ($mobile === '') { $mobile = '0000000000'; }
    if ($remark === '') { $remark = 'Your Payment Link is Created'; }

    $orderid = mt_rand(10000000000, 9999999999999);

    // Plain curl to THIS SAME domain's own /api/create-order - same as the
    // original script. origin_domain tells create_order.php which domain
    // the *returned* link should use (falls back to white-label domain,
    // then to whatever domain this call itself lands on).
    $data = array(
        'customer_mobile' => $mobile,
        'user_token' => $userdata["user_token"],
        'amount' => $amount,
        'order_id' => $orderid,
        'redirect_url' => 'https://' . current_host() . '/success',
        'remark1' => $remark,
        'origin_domain' => current_host(),
    );

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://' . current_host() . '/api/create-order',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => http_build_query($data),
    ));

    $response = curl_exec($curl);
    $curlErr = curl_error($curl);
    curl_close($curl);

    $jsondatares = json_decode($response, true);

    $paymentlink = '';
    if (is_array($jsondatares) && ($jsondatares["status"] ?? false) == true) {
        $paymentlink = $jsondatares["result"]["payment_url"];
    } else {
        $errText = $jsondatares["message"] ?? ($curlErr ?: 'Server did not return a valid response. Raw: ' . substr(strip_tags((string)$response), 0, 200));
        echo '<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18"></script><script>
    Swal.fire({
        title: "Oops! Failed to create payment link",
        text: "'.addslashes($errText).'",
        confirmButtonText: "Ok",
        icon: "error",
        background: "#14141f",
        color: "#fff"
    }).then((result) => {
        if (result.isConfirmed) {
            window.location.href = "payment_link";
        }
    });
</script>';
        exit;
    }
}

$canCreateLinks = in_array($userdata["role"], ['User', 'Admin'], true);
?>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">

<style>
    :root{
        --p:#6c63ff; --p2:#e040fb;
        --g: linear-gradient(135deg,#6c63ff,#e040fb);
        --success:#43e97b; --danger:#ff6584; --warning:#f5b93b; --info:#3ea6ff;
    }
    *{box-sizing:border-box}
    html, body, .content-wrapper{ background:#0a0a12 !important; }
    body{ font-family:'Inter',sans-serif; color:#fff; }
    .content-wrapper{min-height:100vh}

    .pl-wrap{padding:20px;max-width:1300px;margin:0 auto;animation:pageIn .4s ease both}
    @keyframes pageIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}

    .pl-head{margin-bottom:22px}
    .pl-head h1{font-size:1.55rem;font-weight:800;margin:0;color:#fff;display:flex;align-items:center;gap:10px}
    .pl-head h1 .icn{
        width:38px;height:38px;border-radius:12px;background:var(--g);display:inline-flex;
        align-items:center;justify-content:center;font-size:16px;box-shadow:0 6px 18px rgba(108,99,255,.35);
    }
    .pl-head p{font-size:.85rem;color:rgba(255,255,255,.45);margin:4px 0 0 48px}

    .glass-card{
        background:rgba(255,255,255,.04);backdrop-filter:blur(20px);
        border:1px solid rgba(255,255,255,.08);border-radius:20px;overflow:hidden;margin-bottom:20px;
    }
    .card-header{
        padding:18px 22px;border-bottom:1px solid rgba(255,255,255,.07);
        display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px;
    }
    .card-header h3{font-size:1.05rem;font-weight:700;margin:0;color:#fff;display:flex;align-items:center;gap:8px}
    .card-header h3 i{color:var(--p)}
    .card-body{padding:22px}

    .link-tabs{display:flex;gap:6px;background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);padding:4px;border-radius:12px;margin-bottom:20px;max-width:340px}
    .link-tab{
        flex:1;text-align:center;padding:9px 10px;border-radius:9px;font-size:.82rem;font-weight:700;color:rgba(255,255,255,.5);
        cursor:pointer;transition:.2s;display:flex;align-items:center;justify-content:center;gap:6px;
    }
    .link-tab:hover{color:#fff}
    .link-tab.active{background:var(--g);color:#fff;box-shadow:0 4px 14px rgba(108,99,255,.35)}
    .tab-panel{display:none}
    .tab-panel.active{display:block;animation:fadeUp .3s ease both}
    @keyframes fadeUp{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}

    .form-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
    @media(max-width:640px){.form-grid{grid-template-columns:1fr}}
    .form-label{display:block;font-size:.78rem;font-weight:600;color:rgba(255,255,255,.5);margin-bottom:7px;text-transform:uppercase;letter-spacing:.3px}
    .form-control{
        width:100%;background:rgba(255,255,255,.05);border:1.5px solid rgba(255,255,255,.1);border-radius:10px;
        padding:11px 13px;color:#fff;font-size:.88rem;outline:none;transition:.2s;font-family:'Inter',sans-serif;
    }
    .form-control:focus{border-color:var(--p);background:rgba(108,99,255,.08);box-shadow:0 0 0 3px rgba(108,99,255,.15)}
    .form-control::placeholder{color:rgba(255,255,255,.3)}

    .quick-amount-row{display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap}
    .quick-amount-row .amt-field{flex:1;min-width:200px}
    .quick-amount-row .amt-field input{
        font-size:1.3rem;font-weight:800;padding:14px 16px 14px 34px;
    }
    .amt-wrap{position:relative}
    .amt-wrap i{position:absolute;left:14px;top:50%;transform:translateY(-50%);color:rgba(255,255,255,.4);font-size:1.1rem;font-weight:800;font-style:normal}

    .btn-primary-cta{
        background:var(--g);border:none;color:#fff;padding:11px 24px;border-radius:10px;
        font-size:.88rem;font-weight:700;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:8px;
        transition:.2s;box-shadow:0 6px 18px rgba(108,99,255,.3);white-space:nowrap;
    }
    .btn-primary-cta:hover{transform:translateY(-1px);box-shadow:0 10px 24px rgba(108,99,255,.45);color:#fff}
    .btn-primary-cta:active{transform:translateY(0)}

    .form-actions{margin-top:18px}

    .pill{display:inline-flex;align-items:center;gap:5px;padding:5px 11px;border-radius:20px;font-size:.72rem;font-weight:700}
    .pill-success{background:rgba(67,233,123,.13);color:var(--success)}
    .pill-danger{background:rgba(255,101,132,.13);color:var(--danger)}
    .pill-warning{background:rgba(245,185,59,.15);color:var(--warning)}
    .mono{font-family:'JetBrains Mono',monospace;font-size:.8rem;color:rgba(255,255,255,.65)}

    table.table{width:100%;color:#fff;border-collapse:separate;border-spacing:0}
    table.table thead th{
        color:rgba(255,255,255,.45);font-size:.72rem;text-transform:uppercase;letter-spacing:.5px;
        border-bottom:1px solid rgba(255,255,255,.08);padding:12px 14px;font-weight:700;white-space:nowrap;text-align:left;
    }
    table.table tbody td{
        border-bottom:1px solid rgba(255,255,255,.05);padding:12px 14px;
        font-size:.85rem;color:rgba(255,255,255,.85);vertical-align:middle;
    }
    table.table tbody tr{transition:.15s;animation:rowIn .35s ease both}
    @keyframes rowIn{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}
    table.table tbody tr:hover{background:rgba(108,99,255,.06)}

    .empty-state{text-align:center;padding:50px 20px;color:rgba(255,255,255,.35)}
    .empty-state i{font-size:2.2rem;margin-bottom:12px;display:block;color:rgba(255,255,255,.15)}
    .empty-state h4{color:rgba(255,255,255,.55);font-size:.95rem;margin-bottom:4px}

    .mobile-cards{display:none}
    @media(max-width:900px){
        .card-body{padding:14px}
        .table-responsive{display:none}
        .mobile-cards{display:block}
        .mc-card{
            background:rgba(255,255,255,.03);border:1px solid rgba(255,255,255,.07);border-radius:14px;
            padding:14px;margin-bottom:10px;animation:rowIn .3s ease both;
        }
        .mc-top{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
        .mc-row{display:flex;justify-content:space-between;font-size:.78rem;padding:5px 0;color:rgba(255,255,255,.55)}
        .mc-row span:last-child{color:#fff;font-weight:600;text-align:right}
    }

    .link-modal-overlay{
        position:fixed;inset:0;background:rgba(0,0,0,.7);backdrop-filter:blur(4px);
        display:flex;align-items:center;justify-content:center;z-index:99999;padding:20px;
    }
    .link-modal{
        background:#14141f;border:1px solid rgba(255,255,255,.1);border-radius:20px;
        max-width:420px;width:100%;padding:28px 24px;text-align:center;box-shadow:0 25px 60px rgba(0,0,0,.55);
        animation:fadeUp .3s ease both;
    }
    .link-modal .ok-icon{
        width:56px;height:56px;border-radius:50%;background:rgba(67,233,123,.15);color:var(--success);
        display:flex;align-items:center;justify-content:center;font-size:1.6rem;margin:0 auto 14px;
    }
    .link-modal h4{font-size:1.1rem;font-weight:800;color:#fff;margin:0 0 6px}
    .link-modal .sub{font-size:.8rem;color:rgba(255,255,255,.4);margin-bottom:18px}
    .copy-row{position:relative;margin-bottom:8px}
    .copy-row input{
        width:100%;background:rgba(255,255,255,.05);border:1.5px solid rgba(255,255,255,.12);border-radius:10px;
        padding:12px 46px 12px 14px;color:#fff;font-size:.82rem;font-family:'JetBrains Mono',monospace;
        outline:none;box-sizing:border-box;
    }
    .copy-row button{
        position:absolute;right:6px;top:50%;transform:translateY(-50%);background:var(--g);border:none;
        color:#fff;width:34px;height:34px;border-radius:8px;cursor:pointer;display:flex;align-items:center;justify-content:center;
    }
    .link-modal .expiry-note{font-size:.75rem;color:rgba(255,255,255,.35);margin:10px 0 18px}
    .modal-actions{display:flex;gap:10px}
    .link-modal .open-link-btn{
        flex:1;background:var(--g);border:none;color:#fff;text-decoration:none;
        padding:11px;border-radius:10px;font-weight:700;font-size:.85rem;cursor:pointer;
        display:inline-flex;align-items:center;justify-content:center;gap:7px;
        box-shadow:0 6px 18px rgba(108,99,255,.3);transition:.2s;
    }
    .link-modal .open-link-btn:hover{transform:translateY(-1px);box-shadow:0 10px 24px rgba(108,99,255,.45);color:#fff}
    .link-modal .close-modal-btn{
        flex:1;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.12);color:#fff;
        padding:11px;border-radius:10px;font-weight:700;font-size:.85rem;cursor:pointer;
    }
</style>

<div class="pl-wrap">
    <div class="pl-head">
        <h1><span class="icn"><i class="fas fa-link"></i></span>Payment Links</h1>
        <p>Generate a shareable UPI payment link for any amount</p>
    </div>

    <?php if ($canCreateLinks): ?>
    <div class="glass-card">
        <div class="card-header"><h3><i class="fas fa-circle-plus"></i> Create Payment Link</h3></div>
        <div class="card-body">

            <div class="link-tabs">
                <div class="link-tab active" data-tab="quick"><i class="fas fa-bolt"></i> Quick Link</div>
                <div class="link-tab" data-tab="detailed"><i class="fas fa-list-check"></i> Detailed Link</div>
            </div>

            <div class="tab-panel active" id="tab-quick">
                <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
                    <input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($_SESSION['csrf_token']); ?>">
                    <div class="quick-amount-row">
                        <div class="amt-field">
                            <label class="form-label">Amount (INR)</label>
                            <div class="amt-wrap">
                                <i>₹</i>
                                <input type="number" name="amount" step="0.01" min="1" placeholder="0.00" class="form-control" required>
                            </div>
                        </div>
                        <button type="submit" name="create" class="btn-primary-cta"><i class="fas fa-bolt"></i> Generate Link</button>
                    </div>
                    <p style="font-size:.78rem;color:rgba(255,255,255,.35);margin:12px 0 0">Just enter an amount — a payment link is generated instantly with no other details needed.</p>
                </form>
            </div>

            <div class="tab-panel" id="tab-detailed">
                <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
                    <input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars($_SESSION['csrf_token']); ?>">
                    <div class="form-grid">
                        <div>
                            <label class="form-label">Customer Name</label>
                            <input type="text" name="name" placeholder="Your Name" class="form-control" required>
                        </div>
                        <div>
                            <label class="form-label">Mobile Number</label>
                            <input type="number" name="mobile" placeholder="Your Mobile" class="form-control" required>
                        </div>
                        <div>
                            <label class="form-label">Amount (INR)</label>
                            <input type="number" name="amount" step="0.01" min="1" placeholder="₹0.00" class="form-control" required>
                        </div>
                        <div>
                            <label class="form-label">Remark</label>
                            <input type="text" name="remark" placeholder="Eg. Gift, Deposit etc." class="form-control">
                        </div>
                    </div>
                    <div class="form-actions">
                        <button type="submit" name="create" class="btn-primary-cta"><i class="fas fa-paper-plane"></i> Submit</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="glass-card">
        <div class="card-header"><h3><i class="fas fa-list"></i> List of Payment Links</h3></div>
        <div class="card-body">
            <?php
            $ownRows = [];
            $ownQuery = "SELECT * FROM `orders` WHERE user_id='{$userdata["id"]}' ORDER BY `id` DESC LIMIT 25";
            $ownQueryRun = mysqli_query($conn, $ownQuery);
            if ($ownQueryRun) {
                while ($row = mysqli_fetch_assoc($ownQueryRun)) { $ownRows[] = $row; }
            }
            if (count($ownRows) === 0):
            ?>
                <div class="empty-state">
                    <i class="fas fa-link-slash"></i>
                    <h4>No payment links yet</h4>
                    <p>Links you create above will show up here.</p>
                </div>
            <?php else: ?>
            <div class="table-responsive">
                <table class="table" width="100%">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Customer Mobile</th>
                            <th>Amount</th>
                            <th>Order ID</th>
                            <th>Status</th>
                            <th>Remarks</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($ownRows as $row):
                            if ($row['status'] == 'SUCCESS') { $pillClass = 'pill-success'; $icon = 'fa-check'; $sts = 'Success'; }
                            elseif ($row['status'] == 'FAILURE') { $pillClass = 'pill-danger'; $icon = 'fa-xmark'; $sts = 'Failed'; }
                            else { $pillClass = 'pill-warning'; $icon = 'fa-hourglass-half'; $sts = 'Pending'; }
                        ?>
                        <tr>
                            <td class="mono">#<?php echo htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'); ?></td>
                            <td class="mono"><?php echo htmlspecialchars($row['customer_mobile'], ENT_QUOTES, 'UTF-8'); ?></td>
                            <td style="font-weight:700">₹<?php echo htmlspecialchars(number_format((float)$row['amount'], 2), ENT_QUOTES, 'UTF-8'); ?></td>
                            <td class="mono"><?php echo htmlspecialchars($row['order_id'], ENT_QUOTES, 'UTF-8'); ?></td>
                            <td><span class="pill <?php echo $pillClass; ?>"><i class="fas <?php echo $icon; ?>"></i> <?php echo $sts; ?></span></td>
                            <td><?php echo htmlspecialchars($row['remark1'], ENT_QUOTES, 'UTF-8'); ?></td>
                            <td><?php echo htmlspecialchars($row['create_date'], ENT_QUOTES, 'UTF-8'); ?></td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>

            <div class="mobile-cards">
                <?php foreach ($ownRows as $row):
                    if ($row['status'] == 'SUCCESS') { $pillClass = 'pill-success'; $icon = 'fa-check'; $sts = 'Success'; }
                    elseif ($row['status'] == 'FAILURE') { $pillClass = 'pill-danger'; $icon = 'fa-xmark'; $sts = 'Failed'; }
                    else { $pillClass = 'pill-warning'; $icon = 'fa-hourglass-half'; $sts = 'Pending'; }
                ?>
                <div class="mc-card">
                    <div class="mc-top">
                        <span class="mono"><?php echo htmlspecialchars($row['customer_mobile'], ENT_QUOTES, 'UTF-8'); ?></span>
                        <span class="pill <?php echo $pillClass; ?>"><i class="fas <?php echo $icon; ?>"></i> <?php echo $sts; ?></span>
                    </div>
                    <div class="mc-row"><span>Amount</span><span>₹<?php echo number_format((float)$row['amount'], 2); ?></span></div>
                    <div class="mc-row"><span>Order ID</span><span><?php echo htmlspecialchars($row['order_id'], ENT_QUOTES, 'UTF-8'); ?></span></div>
                    <div class="mc-row"><span>Remark</span><span><?php echo htmlspecialchars($row['remark1'], ENT_QUOTES, 'UTF-8'); ?></span></div>
                    <div class="mc-row"><span>Date</span><span><?php echo htmlspecialchars($row['create_date'], ENT_QUOTES, 'UTF-8'); ?></span></div>
                </div>
                <?php endforeach; ?>
            </div>
            <?php endif; ?>
        </div>
    </div>
    <?php endif; ?>

    <?php if ($userdata["role"] != 'User'):
        // Existing withdrawal/settlement list, previously the only thing
        // non-User roles saw on this page. Kept as-is, just restyled and
        // moved below the new payment-link section instead of replacing it.
        $getst = isset($_GET["getfundst"]) ? $_GET["getfundst"] : '';
        $settleRows = [];
        $settleQuery = "SELECT * FROM `settlement` WHERE status='" . mysqli_real_escape_string($conn, $getst) . "'";
        $settleQueryRun = mysqli_query($conn, $settleQuery);
        if ($settleQueryRun) {
            while ($row = mysqli_fetch_assoc($settleQueryRun)) { $settleRows[] = $row; }
        }
    ?>
    <div class="glass-card">
        <div class="card-header"><h3><i class="fas fa-money-bill-transfer"></i> Settlement Requests</h3></div>
        <div class="card-body">
            <?php if (count($settleRows) === 0): ?>
                <div class="empty-state">
                    <i class="fas fa-inbox"></i>
                    <h4>No settlement records for this filter</h4>
                </div>
            <?php else: ?>
            <div class="table-responsive">
                <table class="table" width="100%">
                    <thead>
                        <tr>
                            <th>#</th><th>User</th><th>Amount</th><th>UTR Number</th><th>Status</th><th>Remarks</th><th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($settleRows as $row):
                            $fetchuser = $conn->query("SELECT * FROM `users` WHERE id = '" . (int)$row["userid"] . "'")->fetch_assoc();
                            if ($row['status'] == 1) { $pillClass = 'pill-success'; $icon = 'fa-check'; $sts = 'Success'; }
                            elseif ($row['status'] == 0) { $pillClass = 'pill-danger'; $icon = 'fa-xmark'; $sts = 'Rejected'; }
                            else { $pillClass = 'pill-warning'; $icon = 'fa-hourglass-half'; $sts = 'Pending'; }
                        ?>
                        <tr>
                            <td class="mono">#<?php echo htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'); ?></td>
                            <td><?php echo htmlspecialchars($fetchuser['name'] ?? '', ENT_QUOTES, 'UTF-8'); ?> <span class="mono">(<?php echo htmlspecialchars($fetchuser['mobile'] ?? '', ENT_QUOTES, 'UTF-8'); ?>)</span></td>
                            <td style="font-weight:700">₹<?php echo htmlspecialchars(number_format((float)$row['amount'], 2), ENT_QUOTES, 'UTF-8'); ?></td>
                            <td class="mono"><?php echo htmlspecialchars($row['utr_no'], ENT_QUOTES, 'UTF-8'); ?></td>
                            <td><span class="pill <?php echo $pillClass; ?>"><i class="fas <?php echo $icon; ?>"></i> <?php echo $sts; ?></span></td>
                            <td><?php echo htmlspecialchars($row['remark'], ENT_QUOTES, 'UTF-8'); ?></td>
                            <td><?php echo htmlspecialchars($row['date'], ENT_QUOTES, 'UTF-8'); ?></td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
            <?php endif; ?>
        </div>
    </div>
    <?php endif; ?>
</div>

<?php if (!empty($paymentlink)): ?>
<div class="link-modal-overlay" id="linkModalOverlay">
    <div class="link-modal">
        <div class="ok-icon"><i class="fas fa-check"></i></div>
        <h4>Payment Link Created!</h4>
        <div class="sub">Share this link with your customer to collect payment</div>
        <div class="copy-row">
            <input type="text" value="<?php echo htmlspecialchars($paymentlink); ?>" id="copyClipboard" readonly onclick="this.select()">
            <button onclick="copyLink()"><i class="fas fa-copy"></i></button>
        </div>
        <div class="expiry-note"><i class="fas fa-clock"></i> This link is valid for only 10 minutes</div>
        <div class="modal-actions">
            <a class="open-link-btn" href="<?php echo htmlspecialchars($paymentlink); ?>" target="_blank" rel="noopener"><i class="fas fa-arrow-up-right-from-square"></i> Open</a>
            <button class="close-modal-btn" onclick="document.getElementById('linkModalOverlay').remove()">Close</button>
        </div>
    </div>
</div>
<?php endif; ?>

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.18"></script>
<script src="./assets/vendors/jquery/dist/jquery.min.js"></script>
<script src="./assets/vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="assets/js/app.min.js" type="text/javascript"></script>
<script src="./assets/js/scripts/dashboard_1_demo.js" type="text/javascript"></script>
<script>
    document.querySelectorAll('.link-tab').forEach(function(tab){
        tab.addEventListener('click', function(){
            document.querySelectorAll('.link-tab').forEach(t => t.classList.remove('active'));
            document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
            this.classList.add('active');
            document.getElementById('tab-' + this.dataset.tab).classList.add('active');
        });
    });

    function copyLink() {
        var input = document.getElementById('copyClipboard');
        input.select();
        input.setSelectionRange(0, 99999);
        navigator.clipboard.writeText(input.value);
        var btn = event.currentTarget;
        var original = btn.innerHTML;
        btn.innerHTML = '<i class="fas fa-check"></i>';
        setTimeout(function(){ btn.innerHTML = original; }, 1200);
    }
</script>
</body>
</html>
