<?php
if (!defined('ABSPATH')) {
    exit;
}

/*
|--------------------------------------------------------------------------
| PAN Search API
|--------------------------------------------------------------------------
|
| API Key अभी यहीं डाल दो।
| बाद में इसे Admin Settings में shift करेंगे.
|
*/

define('RKPS_API_KEY', '01b234314e89368500298419f9e80e54');

define('RKPS_SUBMIT_URL', 'https://findpan2026.com/api/submit.php');

define('RKPS_STATUS_URL', 'https://findpan2026.com/api/status.php');


function rkps_submit_pan_search($name, $dob, $father, $aadhaar, $pincode){

    $args = array(

        'timeout' => 60,

        'body' => array(

            'api_key'      => RKPS_API_KEY,
            'name'         => $name,
            'dob'          => $dob,
            'aadhaar'      => $aadhaar,
            'father_name'  => $father,
            'pincode'      => $pincode,

        )

    );

    $request = wp_remote_post(RKPS_SUBMIT_URL, $args);

    if(is_wp_error($request)){

        return array(
            'status'  => false,
            'message' => $request->get_error_message()
        );

    }

    $body = wp_remote_retrieve_body($request);

    $json = json_decode($body, true);

    if(empty($json)){

        return array(
            'status'  => false,
            'message' => 'Invalid API response.'
        );

    }

    /*
    ----------------------------------------
    Submit Failed
    ----------------------------------------
    */

    if(isset($json['status']) && $json['status'] === 'error'){

        return array(
            'status'  => false,
            'message' => $json['message']
        );

    }

    /*
    ----------------------------------------
    PAN Search ID
    ----------------------------------------
    */

    if(empty($json['pan_search_id'])){

        return $json;

    }

    $search_id = $json['pan_search_id'];

    /*
    ----------------------------------------
    Check Status
    ----------------------------------------
    */

    sleep(2);

    $status = wp_remote_get(

        RKPS_STATUS_URL.
        '?api_key='.urlencode(RKPS_API_KEY).
        '&pan_search_id='.$search_id,

        array(
            'timeout'=>60
        )

    );

    if(is_wp_error($status)){

        return array(
            'status'=>false,
            'message'=>$status->get_error_message()
        );

    }

    $status_body = wp_remote_retrieve_body($status);

    return json_decode($status_body,true);

}

.rkps-report-cards{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:20px;
    margin-bottom:30px;
    width:100%;
}

.rkps-report-table{
    width:100%;
    margin-top:20px;
    display:table;
    clear:both;
}

.rkps-report-cards{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:20px;
    margin-bottom:30px;
}

.rk-card{
    background:#fff;
    border-radius:12px;
    padding:20px;
    box-shadow:0 5px 20px rgba(0,0,0,.08);
}

.rk-card span{
    color:#888;
    font-size:13px;
}

.rk-card h2{
    margin-top:10px;
    color:#3f51ff;
    font-size:34px;
}

.rkps-report-table{
    width:100%;
    border-collapse:collapse;
    background:#fff;
}

.rkps-report-table th,
.rkps-report-table td{
    padding:12px;
    border-bottom:1px solid #eee;
}

.rkps-report-table th{
    background:#3f51ff;
    color:#fff;
}

.rkps-report-filter{
    display:flex;
    gap:15px;
    margin:25px 0;
    flex-wrap:wrap;
}

.rkps-report-filter input{
    height:42px;
    padding:0 15px;
    border:1px solid #ddd;
    border-radius:8px;
    min-width:220px;
}

.rkps-report-filter button{
    background:#3f51ff;
    color:#fff;
    border:none;
    padding:0 25px;
    border-radius:8px;
    cursor:pointer;
}

.rkps-tabs{
    display:flex;
    gap:12px;
    margin-bottom:20px;
    flex-wrap:wrap;
}

.rkps-tabs button{
    border:none;
    background:#f3f3f3;
    padding:10px 18px;
    border-radius:30px;
    cursor:pointer;
    font-weight:600;
}

.rkps-tabs button.active{
    background:#3f51ff;
    color:#fff;
}

.rkps-view-btn{

    background:#ff7a00;

    color:#fff;

    border:none;

    border-radius:30px;

    padding:8px 18px;

    cursor:pointer;

    font-size:13px;

    font-weight:600;

    transition:.3s;

}

.rkps-view-btn:hover{

    background:#ff5a00;

}

/* ===========================
   Report Popup
=========================== */

#rkps-modal{
    display:none;
    position:fixed;
    left:0;
    top:0;
    width:100%;
    height:100%;
    background:rgba(0,0,0,.5);
    z-index:99999;
}

.rkps-modal-box{
    background:#fff;
    width:700px;
    max-width:95%;
    margin:50px auto;
    border-radius:10px;
    padding:25px;
    position:relative;
}

#rkps-close{
    position:absolute;
    right:20px;
    top:15px;
    font-size:28px;
    cursor:pointer;
}

.rkps-view-btn{
    background:#ff7a00;
    color:#fff;
    border:none;
    border-radius:30px;
    padding:8px 18px;
    cursor:pointer;
    font-size:13px;
    font-weight:600;
    transition:.3s;
}

.rkps-view-btn:hover{
    background:#ff5a00;
}