// ======================
// 🚀 TATKAL SAFER STATUS PANEL
// ======================

(function () {

    if (window.showStep) return;

    let panel = null;

    function createPanel() {

        if (panel) return panel;

        panel = document.createElement("div");

        panel.id = "tatkal-status-panel";

        panel.style.cssText = `
            position:fixed;
            top:20px;
            left:50%;
            transform:translateX(-50%);
            min-width:340px;
            max-width:500px;
            background:#111;
            color:#fff;
            border:2px solid #fb792b;
            border-radius:10px;
            font-family:Arial,sans-serif;
            z-index:2147483647;
            overflow:hidden;
            box-shadow:0 0 20px rgba(0,0,0,.45);
        `;

        panel.innerHTML = `
            <div style="
                background:#fb792b;
                color:#fff;
                padding:10px;
                font-size:16px;
                font-weight:bold;
                text-align:center;
            ">
                🚄 Tatkal Safer Extension tool 🚄
            </div>

            <div id="ts-step" style="
                padding:15px;
                text-align:center;
                font-size:16px;
                font-weight:bold;
                color:#00ff99;
            ">
                Waiting...
            </div>

            <div style="
                height:5px;
                background:#222;
            ">
                <div id="ts-bar" style="
                    width:0%;
                    height:100%;
                    background:#00ff99;
                    transition:.3s;
                "></div>
            </div>
        `;

        document.body.appendChild(panel);

        return panel;
    }

    const progress = {

        "Typing Username":10,
        "Typing Password":20,
        "Signing In":30,
        "Waiting Login":35,
        "Login Successful":40,
        "Searching Train":50,
        "Train Found":60,
        "Selecting Class":70,
        "Refreshing":75,
        "Checking AVL":80,
        "Booking":90,
        "Passenger":94,
        "Payment":97,
        "Booking Successful":100

    };

    window.showStep = function(msg){

        createPanel();

        let text = document.getElementById("ts-step");
        let bar = document.getElementById("ts-bar");

        text.innerHTML = msg;

        let width = 0;

        Object.keys(progress).forEach(k=>{

            if(msg.toLowerCase().includes(k.toLowerCase()))
                width = progress[k];

        });

        bar.style.width = width+"%";

        if(msg.includes("❌")){

            text.style.color="#ff4444";
            bar.style.background="#ff4444";

        }

        else if(msg.includes("⚠️")){

            text.style.color="#ffcc00";
            bar.style.background="#ffcc00";

        }

        else{

            text.style.color="#00ff99";
            bar.style.background="#00ff99";

        }

        console.log(msg);

    };

})();


showStep("✅ Booking Proccess Start... ");