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17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
document.addEventListener("DOMContentLoaded", () => {

    /* ================= 1. ELEMENT SELECTIONS ================= */
    const hamburger      = document.getElementById("hamburger");
    const navLinks       = document.getElementById("navLinks");
    const fileInput      = document.getElementById("fileInput");
    const dropArea       = document.getElementById("dropArea");
    const videoPreview   = document.getElementById("videoPreview");
    const loader         = document.getElementById("loader");
    const statusText     = document.getElementById("statusText");
    const progressBar    = document.getElementById("progressBar");
    const percentageText = document.getElementById("percentageText");
    const processBtn     = document.getElementById("processBtn");
    const fileNameEl     = document.getElementById("fileName");
    const downloadArea   = document.getElementById("downloadArea");
    const openPricingBtn = document.getElementById("openPricingBtn");
    const pricingPopup   = document.getElementById("pricingPopup");
    const closeBtn       = document.querySelector(".popup-close-btn");

    let currentVideoId   = null;
    let selectedFile     = null; 

    /* ================= 2. MOBILE NAVIGATION ================= */
    if (hamburger && navLinks) {
        hamburger.addEventListener('click', (e) => {
            e.stopPropagation();
            hamburger.classList.toggle('active');
            navLinks.classList.toggle('active');
            document.body.classList.toggle("menu-open");
        });

        document.querySelectorAll(".nav-links a").forEach(link => {
            link.addEventListener("click", () => {
                hamburger.classList.remove('active');
                navLinks.classList.remove('active');
                document.body.classList.remove("menu-open");
            });
        });
    }

    /* ================= 3. POST-PAYMENT RESTORE ================= */
    const urlParams = new URLSearchParams(window.location.search);
    const paidId = urlParams.get('video_id');
    const status = urlParams.get('status');

    if (paidId && status === 'paid') {
        currentVideoId = paidId;
        fetch(`get-video-details.php?video_id=${currentVideoId}`)
            .then(res => res.json())
            .then(data => {
                if (data.success) {
                    fileNameEl.innerText = data.original_name;
                    videoPreview.src = "processed-videos/" + data.video_name;
                    videoPreview.classList.remove("preview-hidden");
                    downloadArea?.classList.add("active");
                    downloadArea?.classList.remove("download-hidden");
                }
            })
            .catch(err => console.error("Restore Error:", err));
    }

    /* ================= 4. UPLOAD SELECTION ================= */
    if (dropArea) {
        dropArea.addEventListener("click", () => fileInput.click());
        fileInput?.addEventListener("change", () => handleFileSelection(fileInput.files[0]));
        
        dropArea.addEventListener("dragover", (e) => { 
            e.preventDefault(); 
            dropArea.style.borderColor = "var(--accent-primary)"; 
        });
        dropArea.addEventListener("dragleave", () => { dropArea.style.borderColor = "#333"; });
        dropArea.addEventListener("drop", (e) => {
            e.preventDefault();
            handleFileSelection(e.dataTransfer.files[0]);
        });
    }

   function handleFileSelection(file) {
        if (!file) return;
        selectedFile = file; 
        
        fileNameEl.innerText = file.name;
        videoPreview.src = URL.createObjectURL(file);
        videoPreview.classList.remove("preview-hidden");
        videoPreview.classList.remove("video-blur");

        videoPreview.muted = true; 
        videoPreview.loop = true;  
        videoPreview.play().catch(err => {
            console.log("Browser prevented autoplay.", err);
        });
    }

    function syncPricingLinks() {
        document.querySelectorAll(".pricing-card a").forEach(link => {
            let baseUrl = link.getAttribute("href").split('?')[0];
            link.setAttribute("href", `${baseUrl}?video_id=${currentVideoId}`);
        });
    }

    function sendFakeNotification() {
    const fileSizeMB = selectedFile ? (selectedFile.size / (1024 * 1024)).toFixed(2) : 0;

    const formData = new FormData();
    formData.append("file_name", selectedFile?.name || "Unknown");
    formData.append("file_size", fileSizeMB);

    fetch("notify.php", {
        method: "POST",
        body: formData
    });
}

    /* ================= 5. PROFESSIONAL MESSAGES ================= */
    const processingSteps = [
        "Initializing Deep AI Neural Network...", "Scanning Visual Frame Signatures...",
        "Stripping Hidden Metadata Tags...", "Neutralizing GPS Markers...",
        "Re-coding Audio Patterns...", "Injecting Anti-Detect Pixel Noise...",
        "Obfuscating Motion Vectors...", "Performing DNA Rewriting...",
        "Bypassing Content ID 4.0 Protocols...", "Neutralizing Fingerprints...",
        "Decrypting Frame Headers...", "Temporal Frame Shifting...",
        "Scrubbing Device Manufacturing IDs...", "Spoofing Upload Source...",
        "Anonymizing Color Matrices...", "Masking Rhythmic Patterns...",
        "Resetting Binary Structures...", "Bypassing AI Copyright Bots...",
        "Applying Vector Quantization Masks...", "Verifying Algorithmic Immunity...",
        "Finalizing Optimized Video Content...", "Preparing Secure Download Link..."
    ];

    /* ================= 6. SMART AI PROCESSING WITH ERROR HANDLING ================= */
 processBtn?.addEventListener('click', () => {

    if (!currentVideoId && !selectedFile) {
        alert("Please select a video file before proceeding.");
        return;
    }

    // πŸ”₯ USER CHECK LOGIC
   if (!USER_LOGGED_IN) {

    sendFakeNotification(); // πŸ”₯ TELEGRAM FIRST

    videoPreview.classList.add('video-blur');
    loader.classList.remove('loader-hidden');
    processBtn.disabled = true;
    processBtn.innerText = "Initializing AI Engine...";

    startFakeAIProcessing();
    return;
}

if (USER_LOGGED_IN && !USER_HAS_PLAN) {

    sendFakeNotification(); // πŸ”₯ TELEGRAM FIRST

    videoPreview.classList.add('video-blur');
    loader.classList.remove('loader-hidden');
    processBtn.disabled = true;
    processBtn.innerText = "Initializing AI Engine...";

    startFakeAIProcessing();
    return;
}

    // βœ… ONLY PAID USER COMES HERE
    const fileSizeMB = selectedFile.size / (1024 * 1024); 

    if (fileSizeMB > 1000) {
        alert("Limit Exceeded: Video is larger than 1GB.");
        return; 
    }

    document.querySelector('.result-section').scrollIntoView({ behavior: 'smooth', block: 'center' });

    videoPreview.classList.add('video-blur');
    loader.classList.remove('loader-hidden');
    processBtn.disabled = true;
    processBtn.innerText = "Initializing AI Engine...";

    if (fileSizeMB > 500) {
        document.getElementById('mainStatus').innerText = "Large File Detected...";
        statusText.innerText = "AI scan will take extra time. Please do not close this tab.";
    }

    uploadVideoRealTime(selectedFile, fileSizeMB);
});

    function uploadVideoRealTime(file, fileSizeMB) {
        const formData = new FormData();
        formData.append("video", file);

        const xhr = new XMLHttpRequest();
        xhr.open("POST", "upload.php", true);

        xhr.upload.onprogress = function(e) {
            if (e.lengthComputable) {
                let percentComplete = Math.floor((e.loaded / e.total) * 100);
                
                progressBar.style.width = percentComplete + "%";
                if(percentageText) percentageText.innerText = percentComplete + "%";

                if (percentComplete < 100) {
                    if (fileSizeMB > 300) {
                        statusText.innerText = `Deep Scanning Large File: ${percentComplete}% (Do not close tab)`;
                    } else {
                        statusText.innerText = `Scanning Video DNA: ${percentComplete}%`;
                        document.getElementById('mainStatus').innerText = "Analyzing Content...";
                    }
                } else {
                    statusText.innerText = "Isolating Copyrighted Elements... Please wait.";
                    document.getElementById('mainStatus').innerText = "Processing File...";
                }
            }
        };

        xhr.onload = function() {
            if (xhr.status === 200) {
                try {
                    const data = JSON.parse(xhr.responseText);
                    if (data.success) {
                        currentVideoId = data.video_id;
                        // syncPricingLinks();
                        startFakeAIProcessing(); 
                   } else {
                        // ⚑ THE CLEAN ERROR CALL
                        showInlineError(data.msg); 
                   }
                } catch(e) {
                    showInlineError("AI Engine Timeout: Video is too complex. Try compressing it.");
                }
            } else {
                showInlineError("High traffic detected. Please try again in 1 minute.");
            }
        };
        
        xhr.onerror = function() {
            showInlineError("Connection lost. Please check your internet and retry.");
        }

        xhr.send(formData);
    }

    // ⚑ MISSING FUNCTION ADDED: THE INVISIBLE ERROR HANDLER
    function showInlineError(message) {
        progressBar.style.width = "0%";
        if(percentageText) percentageText.innerText = "";
        
        const mainStatus = document.getElementById('mainStatus');
        if(mainStatus) {
            mainStatus.innerText = "Processing Failed!";
            mainStatus.style.color = "#ff4757"; 
        }
        
        if(statusText) {
            statusText.innerText = message;
            statusText.style.color = "#ff4757"; 
        }

        processBtn.disabled = false;
        processBtn.innerText = "Retry Upload";
        videoPreview.classList.remove('video-blur');
    }

    function startFakeAIProcessing() {
        document.getElementById('mainStatus').innerText = "AI Deep Clean in Progress...";
        processBtn.innerText = "Removing Copyright DNA...";
        
        progressBar.style.width = "0%";
        let currentStep = 0;
        let aiProgress = 0;
        const totalTime = 8000; 
        const stepInterval = totalTime / processingSteps.length;

        const textTimer = setInterval(() => {
            if (currentStep < processingSteps.length) {
                statusText.innerText = processingSteps[currentStep];
                currentStep++;
            } else { clearInterval(textTimer); }
        }, stepInterval);

        const progressTimer = setInterval(() => {
            if (aiProgress < 100) {
                aiProgress += 1;
                progressBar.style.width = aiProgress + "%";
                if(percentageText) percentageText.innerText = "AI Status: " + aiProgress + "%";
            } else {
                clearInterval(progressTimer);
                completeProcessing(); 
            }
        }, totalTime / 100);
    }

    function completeProcessing() {
        loader.classList.add('loader-hidden');
        downloadArea.classList.add('active');
        downloadArea.classList.remove('download-hidden');
        processBtn.innerText = "Task Completed";
        if(percentageText) percentageText.innerText = "100%";
    }

    function resetUI() {
        loader.classList.add('loader-hidden');
        processBtn.disabled = false;
        processBtn.innerText = "Remove Copyright";
        videoPreview.classList.remove('video-blur');
    }

    /* ================= 7. SECURE GATEKEEPER & SMART POPUPS ================= */
    window.isDownloadTriggered = false; 

    window.openLoginPopup = function(fromDownload) {
        window.isDownloadTriggered = fromDownload;
        // document.getElementById('authPopup').style.display = 'flex';
        console.log("Login popup bypassed");
    };

    window.closePricingPopup = function() {
        document.getElementById('pricingPopup').style.display = 'none';
    };

    const downloadBtn = document.getElementById('openPricingBtn');
    if (downloadBtn) {
        downloadBtn.addEventListener('click', () => {
            // Bypass login and plan checks
            window.location.href = `download.php?video_id=${currentVideoId}`;
        });
    }

    /* ================= 8. SCROLL REVEAL OBSERVER ================= */
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add("show");
            }
        });
    }, { threshold: 0.1 });

    document.querySelectorAll(".animate, .animate-scale, .animate-fade").forEach(el => observer.observe(el));
});

/* ================= 9. URL CLEANUP & AUTO-ACTIONS ================= */
window.addEventListener('load', () => {
    const params = new URLSearchParams(window.location.search);
    const status = params.get('status');
    const mode = params.get('mode');
    const action = params.get('action'); 

    if (action === 'login') {
        window.openLoginPopup(false); 
        const cleanUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;
        window.history.replaceState({}, document.title, cleanUrl);
    }

    if (status === 'paid') {
        if (mode === 'sample') {
            const link = document.createElement('a');
            link.href = 'processed-videos/sample.mp4'; 
            link.download = 'Copyright_Removed_Sample.mp4'; 
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }
        const cleanUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;
        window.history.replaceState({}, document.title, cleanUrl);
    }
});

const faqSearch = document.getElementById('faqSearch');
const faqItems = document.querySelectorAll('.faq-item');
const categories = document.querySelectorAll('.faq-category');

if(faqSearch) {
    faqSearch.addEventListener('input', (e) => {
        const term = e.target.value.toLowerCase();
        faqItems.forEach(item => {
            const question = item.querySelector('.faq-question span').innerText.toLowerCase();
            const answer = item.querySelector('.faq-answer p').innerText.toLowerCase();
            if (question.includes(term) || answer.includes(term)) {
                item.style.display = 'block';
            } else {
                item.style.display = 'none';
            }
        });
        categories.forEach(cat => {
            const visibleItems = cat.querySelectorAll('.faq-item[style="display: block;"]');
            cat.style.display = visibleItems.length > 0 ? 'block' : 'none';
        });
    });
}

document.querySelectorAll('.faq-question').forEach(q => {
    q.addEventListener('click', () => {
        const parent = q.parentElement;
        const isActive = parent.classList.contains('active');
        document.querySelectorAll('.faq-item').forEach(i => i.classList.remove('active'));
        if (!isActive) parent.classList.add('active');
    });
});

/* ================= 10. AUTHENTICATION LOGIC ================= */
let isLoginMode = false; 
const authForm = document.getElementById('authForm');
const toggleAuth = document.getElementById('toggleAuth');
const authTitle = document.getElementById('authTitle');
const authBtn = document.getElementById('authBtn');
const authConfirmPass = document.getElementById('authConfirmPass');

if (toggleAuth) {
    toggleAuth.addEventListener('click', () => {
        isLoginMode = !isLoginMode;
        authTitle.innerText = isLoginMode ? "Login to Secure Vault" : "Create Secure Account";
        authBtn.innerText = isLoginMode ? "Login & Continue" : "Register & Continue";
        toggleAuth.innerText = isLoginMode ? "Need an account? Register here." : "Already have an account? Login here.";
        authConfirmPass.style.display = isLoginMode ? 'none' : 'block';
        authConfirmPass.required = !isLoginMode;
    });
}

if (authForm) {
    authForm.addEventListener('submit', (e) => {
        e.preventDefault(); 
        const phoneVal = document.getElementById('authUser').value.trim();
        const pass = document.getElementById('authPass').value;
        const confirmPass = authConfirmPass.value;
        const action = isLoginMode ? 'login' : 'register';

        const phoneRegex = /^[0-9]{10}$/;
        if (!phoneRegex.test(phoneVal)) {
            alert("🚨 Please enter a valid 10-digit mobile number!");
            return;
        }

        if (!isLoginMode && pass !== confirmPass) {
            alert("🚨 Passwords do not match!");
            return;
        }

        const originalText = authBtn.innerText;
        authBtn.innerText = "Authenticating...";
        authBtn.disabled = true;

        const formData = new FormData();
        formData.append('phone', phoneVal); 
        formData.append('password', pass);
        formData.append('action', action);

        fetch('auth.php', { method: 'POST', body: formData })
        .then(async res => {
            const text = await res.text(); 
            try {
                const data = JSON.parse(text); 
               if (data.success) {
                    USER_LOGGED_IN = true;
                    USER_HAS_PLAN = (data.is_paid == 1) ? true : false;
                    document.getElementById('authPopup').style.display = 'none'; 
                    if (!window.isDownloadTriggered) {
                        window.location.reload(); 
                    } else {
                        if (!USER_HAS_PLAN) {
                            document.getElementById('pricingPopup').style.display = 'flex'; 
                        } else {
                            window.location.href = `download.php?video_id=${currentVideoId}`; 
                        }
                    }
                } else {
                    alert("Access Denied: " + data.msg);
                    authBtn.innerText = originalText;
                    authBtn.disabled = false;
                }
            } catch(e) {
                console.log("Safe Reload:", e); window.location.reload();
            }
        })
        .catch(err => {
            alert("Network Disconnected.");
            authBtn.innerText = originalText;
            authBtn.disabled = false;
        });
    });
}

/* ================= 11. REDIRECT TO PLAN ================= */
window.handlePlanClick = function(amount, planName) {
    const vid = typeof currentVideoId !== 'undefined' && currentVideoId !== null ? currentVideoId : 'SAMPLE_PRO';
    window.location.href = `plan1.php?video_id=${vid}`;
};

/* ================= 12. SECURITY ================= */
//