<?php
session_start();
include('con.php');

if (!isset($_SESSION['phone'])) {
    header("Location: login.php");
    exit;
}

$mobile = mysqli_real_escape_string($ahk_conn, $_SESSION['phone']);

$customerName = "User";
$balance = "0.00";
$customertype = "";

/* ================= USER DATA ================= */

$getUser = mysqli_query(
    $ahk_conn,
    "SELECT name,balance,type FROM users WHERE phone='$mobile'"
);

if(mysqli_num_rows($getUser)>0){

    $user = mysqli_fetch_assoc($getUser);

    $customerName = $user['name'];

    $balance = number_format($user['balance'],2);

    $customertype = $user['type'];
}

/* ================= SERVICE STATUS FUNCTION ================= */

function serviceStatus($conn, $service_name){

    $service_name = mysqli_real_escape_string($conn, $service_name);

    $query = mysqli_query(
        $conn,
        "SELECT status FROM price WHERE service='$service_name' LIMIT 1"
    );

    if(mysqli_num_rows($query)>0){

        $data = mysqli_fetch_assoc($query);

        return ($data['status'] == 1);
    }

    return false;
}
?>

<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">

<title>Dashboard</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

<style>

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
}

body{
    background:#f3f6fb;
    font-family:'Segoe UI',sans-serif;
}

/* ================= TOPBAR ================= */

.topbar{
    background:linear-gradient(135deg,#4f46e5,#7c3aed);
    padding:22px;
    border-radius:0 0 28px 28px;
    box-shadow:0 10px 30px rgba(79,70,229,0.25);
    margin-bottom:25px;
}

.logo{
    color:#fff;
    font-size:28px;
    font-weight:800;
}

.sub-text{
    color:rgba(255,255,255,0.85);
    font-size:14px;
    margin-top:4px;
}

.balance-box{
    background:rgba(255,255,255,0.15);
    padding:12px 20px;
    border-radius:18px;
    color:#fff;
    min-width:180px;
    backdrop-filter:blur(10px);
}

.balance-box h6{
    font-size:12px;
    margin-bottom:5px;
    opacity:0.8;
}

.balance-box h3{
    margin:0;
    font-size:24px;
    font-weight:700;
}

.logout-btn{
    background:#fff;
    color:#4f46e5;
    border:none;
    border-radius:14px;
    padding:10px 18px;
    font-weight:700;
    text-decoration:none;
    transition:0.3s;
}

.logout-btn:hover{
    transform:translateY(-2px);
    color:#4f46e5;
}

/* ================= DISTRIBUTOR MENU ================= */

.distributor-bar{
    margin-top:18px;
    display:flex;
    gap:15px;
    flex-wrap:wrap;
}

.dist-btn{
    background:rgba(255,255,255,0.18);
    border:1px solid rgba(255,255,255,0.25);
    color:#fff;
    padding:12px 22px;
    border-radius:16px;
    text-decoration:none;
    font-weight:700;
    transition:0.3s;
    backdrop-filter:blur(10px);
    display:flex;
    align-items:center;
    gap:10px;
}

.dist-btn:hover{
    background:#fff;
    color:#4f46e5;
    transform:translateY(-3px);
}

/* ================= DASHBOARD ================= */

.dashboard{
    padding:0 20px 40px;
}

.service-grid{
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
    gap:18px;
}

/* ================= SERVICE CARD ================= */

.service-card{
    background:#fff;
    border-radius:22px;
    padding:22px 15px;
    text-align:center;
    position:relative;
    overflow:hidden;
    border:1px solid #edf2f7;
    transition:0.35s;
    box-shadow:0 8px 20px rgba(0,0,0,0.05);
}

.service-card:hover{
    transform:translateY(-7px);
    box-shadow:0 20px 45px rgba(79,70,229,0.15);
}

.service-card::before{
    content:'';
    position:absolute;
    width:120px;
    height:120px;
    background:linear-gradient(135deg,#4f46e5,#7c3aed);
    border-radius:50%;
    top:-70px;
    right:-70px;
    opacity:0.07;
}

/* ================= ICON ================= */

.icon-box{
    width:76px;
    height:76px;
    border-radius:22px;
    background:linear-gradient(135deg,#eef2ff,#f8fafc);
    border:1px solid #e5e7eb;
    display:flex;
    align-items:center;
    justify-content:center;
    margin:auto;
    margin-bottom:15px;
    transition:0.3s;
}

.icon-box img{
    width:45px;
    height:45px;
    object-fit:contain;
    transition:0.3s;
}

.service-card:hover .icon-box{
    background:linear-gradient(135deg,#4f46e5,#7c3aed);
}

.service-card:hover .icon-box img{
    filter:brightness(0) invert(1);
    transform:scale(1.1);
}

/* ================= TEXT ================= */

.service-title{
    font-size:15px;
    font-weight:700;
    color:#111827;
    line-height:1.4;
    min-height:42px;
}

.service-sub{
    font-size:12px;
    color:#6b7280;
    margin-top:6px;
}

/* ================= BADGE ================= */

.live-badge{
    position:absolute;
    top:12px;
    right:12px;
    background:linear-gradient(135deg,#10b981,#059669);
    color:#fff;
    font-size:10px;
    font-weight:700;
    padding:5px 10px;
    border-radius:30px;
    box-shadow:0 4px 10px rgba(16,185,129,0.25);
}

/* ================= LINKS ================= */

.service-link{
    text-decoration:none;
}

/* ================= MOBILE ================= */

@media(max-width:768px){

    .dashboard{
        padding:0 12px 30px;
    }

    .service-grid{
        grid-template-columns:repeat(2,1fr);
        gap:14px;
    }

    .service-card{
        padding:16px 10px;
        border-radius:18px;
    }

    .icon-box{
        width:62px;
        height:62px;
        border-radius:18px;
    }

    .icon-box img{
        width:36px;
        height:36px;
    }

    .service-title{
        font-size:13px;
        min-height:38px;
    }

    .logo{
        font-size:22px;
    }

    .balance-box{
        width:100%;
        margin-top:12px;
    }

    .dist-btn{
        width:100%;
        justify-content:center;
    }
}

</style>

</head>

<body>

<!-- ================= HEADER ================= -->

<div class="topbar">

<div class="container-fluid">

<div class="d-flex flex-wrap justify-content-between align-items-center gap-3">

<div>

<div class="logo">
HarGharRojgar
</div>

<div class="sub-text">
Welcome, <?= htmlspecialchars($customerName) ?>
</div>

</div>

<div class="d-flex flex-wrap align-items-center gap-3">

<div class="balance-box">

<h6>Available Balance</h6>

<h3>₹ <?= $balance ?></h3>

</div>

<a href="https://www.hargharrojgar.in/admin/index"
target="_blank"
class="logout-btn">
Portal 1.0
</a>

<a href="logout.php" class="logout-btn">
Logout
</a>

</div>

</div>

<!-- ================= DISTRIBUTOR PANEL ================= -->

<?php if($customertype == 'Distributor'){ ?>

<div class="distributor-bar">

<a href="AddRetailer.php" class="dist-btn">
👤 Add Retailer
</a>

<a href="showall.php" class="dist-btn">
📋 View Retailers
</a>

</div>

<?php } ?>

</div>

</div>

<!-- ================= DASHBOARD ================= -->

<div class="dashboard">

<div class="service-grid">

<!-- ================= MOBILE TO PAN ================= -->

<?php if(serviceStatus($ahk_conn,'mobile_to_pan')){ ?>

<a href="mm2p.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/pann.jfif">
</div>

<div class="service-title">Mobile To PAN Find</div>

<div class="service-sub">
Find PAN by mobile number
</div>

</div>

</a>

<?php } ?>

<!-- ================= CHALLAN ================= -->

<?php if(serviceStatus($ahk_conn,'vehicle_challan_verify')){ ?>

<a href="challan.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/car.png">
</div>

<div class="service-title">Challan Find</div>

<div class="service-sub">
Vehicle challan details
</div>

</div>

</a>

<?php } ?>

<!-- ================= RC MOBILE ================= -->

<?php if(serviceStatus($ahk_conn,'rc')){ ?>

<a href="rcm.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/Yamaha-Bike-PNG.png">
</div>

<div class="service-title">RC Mobile Link</div>

<div class="service-sub">
Link mobile with RC
</div>

</div>

</a>

<?php } ?>

<!-- ================= POLLUTION ================= -->

<?php if(serviceStatus($ahk_conn,'2pucc')){ ?>

<a href="pucc.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/1000398837.jpg">
</div>

<div class="service-title">Pollution Certificate</div>

<div class="service-sub">
Car & Bike PUC
</div>

</div>

</a>

<?php } ?>

<!-- ================= BIKE INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'bikein')){ ?>

<a href="bike_insur.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="../admin/img/bikee.jpg">
</div>

<div class="service-title">2 Wheeler Insurance</div>

<div class="service-sub">
Bike insurance service
</div>

</div>

</a>

<?php } ?>

<!-- ================= CAR INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'carin')){ ?>

<a href="car_insur.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="../admin/img/Car.png">
</div>

<div class="service-title">4 Wheeler Insurance</div>

<div class="service-sub">
Car insurance service
</div>

</div>

</a>

<?php } ?>
<!-- ================= aadhar 2 pan INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'dddhar')){ ?>

<a href="Aa2p.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/pann.jfif">
</div>

<div class="service-title">Aadhaar To PAN</div>

<div class="service-sub">Find PAN number</div>


</div>

</a>

<?php } ?>
<!-- ================= aadhar 2 pan INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'rc_vehical')){ ?>

<a href="rc_pdf.php" class="service-link">

<div class="service-card">

<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/Yamaha-Bike-PNG.png">
</div>

<div class="service-title">RC PDF Download</div>
<div class="service-sub">Download RC instantly</div>


</div>

</a>

<?php } ?>
<!-- ================= aadhar 2 pan INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'dl_gf_instant')){ ?>

<a href="dl_pdf.php" class="service-link">

<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/dlaa.jpg">
</div>

<div class="service-title">Driving Licence PDF</div>
<div class="service-sub">Download DL PDF</div>

</div>

</a>

<?php } ?>
<!-- ================= aadhar 2 pan INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'dl')){ ?>

<a href="dlupdate.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/dd.jpg">
</div>

<div class="service-title">DL Mobile Link</div>
<div class="service-sub">Update DL mobile</div>

</div>

</a>

<?php } ?>
<!-- ================= aadhar 2 pan INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'ration_pdf')){ ?>

<a href="ration_print.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/ration1.png">
</div>

<div class="service-title">Ration Card PDF</div>
<div class="service-sub">Download ration card</div>
</div>

</a>

<?php } ?>
<!-- ================= aadhar 2 pan INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'mvcc')){ ?>

<!-- VOTER -->

<a href="mvcc.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/sssss.jpg">
</div>

<div class="service-title">Voter Mobile Link</div>
<div class="service-sub">Update voter mobile</div>

</div>
</a>
<?php } ?>
<!-- ================= aadhar 2 pan INSURANCE ================= -->

<?php if(serviceStatus($ahk_conn,'vcc')){ ?>

<!-- VOTER -->

<a href="vcc.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/sssss.jpg">
</div>

<div class="service-title">Download Voter PDF</div>
<div class="service-sub">Get voter card PDF</div>

</div>
</a>
<?php } ?>


<?php if(serviceStatus($ahk_conn,'farmer_pdf')){ ?>

<!-- VOTER -->
<!-- FARMER -->

<a href="farmer.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/farmer.png">
</div>

<div class="service-title">Farmer Card</div>
<div class="service-sub">Farmer Agristack card</div>

</div>
</a>

<?php } ?>



<?php if(serviceStatus($ahk_conn,'aadhar')){ ?>
<!-- FARMER -->

<a href="reg.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/farmer.png">
</div>

<div class="service-title">Farmer Registry</div>
<div class="service-sub">Mismatch correction</div>

</div>
</a>
<?php } ?>


<?php if(serviceStatus($ahk_conn,'pan_details_verify')){ ?>
<!-- FARMER -->

<a href="Pan_details.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/pann.jfif">
</div>

<div class="service-title">PAN Details</div>
<div class="service-sub">Full Detail</div>

</div>
</a>

<?php } ?>
<?php if(serviceStatus($ahk_conn,'aadhaar_to_ration')){ ?>
<!-- FARMER -->

<a href="aadhar2ration.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="img/ration1.png">
</div>

<div class="service-title">Aadhar 2 Ration No</div>
<div class="service-sub">Ration No</div>

</div>
</a>

<?php } ?>


<?php if(serviceStatus($ahk_conn,'ll_exam')){ ?>
<!-- FARMER -->

<a href="aadhar2ration.php" class="service-link">
<div class="service-card">
<span class="live-badge">LIVE</span>

<div class="icon-box">
<img src="../admin/img/exam.png">
</div>

<div class="service-title">LL Exam</div>
<div class="service-sub">LL Exam Pass</div>

</div>
</a>

<?php } ?>

</div>

</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

</body>
</html>