<?php include('header.php'); ?>

<div class="container-fluid cyber-container">
    <div class="row">
        <div class="col-md-12">
            <div class="cyber-panel">
                <div class="cyber-panel-header">
                    <div class="cyber-title">
                    <h3><i class="fas fa-exchange-alt"></i> Cookie Converter</h3>
                        <div class="cyber-title-decoration"></div>
                    </div>
                </div>
                <div class="cyber-panel-body">
                    <div class="cyber-alert">
                        <i class="fas fa-info-circle"></i>
                        <span>Convert cookies between Netscape and JSON formats</span>
                    </div>

                    <form method="POST" class="cyber-form">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="cyber-form-group">
                                    <label>
                                        <i class="fas fa-cookie"></i>
                                        Netscape Format
                                    </label>
                                    <textarea name="netscape_cookies" id="textarea1" class="cyber-textarea" rows="10" placeholder="Paste Netscape format cookies here..."><?php echo isset($_POST['netscape_cookies']) ? htmlspecialchars($_POST['netscape_cookies']) : ''; ?></textarea>
                                    <div class="cyber-form-actions">
                                        <button type="button" class="cyber-button" onclick="clearInput('textarea1')">
                                            <i class="fas fa-eraser"></i>
                                            <span>Clear</span>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="cyber-form-group">
                                    <label>
                                        <i class="fas fa-code"></i>
                                        JSON Format
                                    </label>
                                    <textarea name="json_cookies" id="textarea2" class="cyber-textarea" rows="10" placeholder="JSON format will appear here..." readonly></textarea>
                                    <div class="cyber-form-actions">
                                        <button type="button" class="cyber-button" onclick="copyToClipboard('textarea2')">
                                            <i class="fas fa-copy"></i>
                                            <span>Copy</span>
                                        </button>
                                        <button type="button" class="cyber-button" onclick="clearOutput('textarea2')">
                                            <i class="fas fa-eraser"></i>
                                            <span>Clear</span>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="cyber-actions">
                            <button type="button" class="cyber-button primary" onclick="NetscapeToJson()">
                                <i class="fas fa-sync"></i>
                                <span>Convert to JSON</span>
                            </button>
                        </div>
                    </form>

                    <div id="copySuccess" class="cyber-notification success" style="display: none;">
                        <i class="fas fa-check-circle"></i>
                        <span>Copied to clipboard!</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
/* Import cyberpunk font */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700&display=swap');

/* Base styles */
html, body {
    background: #0a0a0f !important;
    color: #ffffff;
    margin: 0;
    padding: 0;
    height: 100%;
    min-height: 100vh;
}

/* Container positioning */
.container-fluid {
    background: #0a0a0f;
    min-height: 100vh;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.row {
    width: 100%;
    max-width: 1200px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
}

.col-md-12 {
    width: 100%;
    padding: 0 15px;
}

/* Panel Styling */
.cyber-panel {
    background: linear-gradient(165deg, #12151C 0%, #0a0a0f 100%);
    border: 1px solid rgba(33, 150, 243, 0.3);
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(33, 150, 243, 0.1);
    overflow: hidden;
    position: relative;
    margin: 0 auto 2rem auto;
    width: 100%;
}

.cyber-panel-header {
    background: linear-gradient(90deg, #0d1117 0%, #161b22 100%);
    padding: 20px;
    border-bottom: 1px solid rgba(33, 150, 243, 0.3);
}

.cyber-panel-header h3 {
    color: #2196F3;
    font-family: 'Orbitron', sans-serif;
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
}

.cyber-panel-body {
    padding: 20px;
    background: transparent;
}

/* Alert Styling */
.cyber-alert {
    background: rgba(33, 150, 243, 0.05);
    border: 1px solid rgba(33, 150, 243, 0.3);
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #2196F3;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    letter-spacing: 0.5px;
}

/* Form Styling */
.cyber-form-group {
    margin-bottom: 25px;
}

.cyber-form-group label {
    color: #2196F3;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    margin-bottom: 10px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.cyber-textarea {
    width: 100%;
    min-height: 200px;
    background: rgba(33, 150, 243, 0.05);
    border: 1px solid rgba(33, 150, 243, 0.3);
    border-radius: 6px;
    padding: 15px;
    color: #ffffff;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 15px;
}

.cyber-textarea:focus {
    outline: none;
    border-color: #2196F3;
    box-shadow: 0 0 15px rgba(33, 150, 243, 0.2);
}

/* Button Styling */
.cyber-button {
    background: transparent;
    border: 1px solid #2196F3;
    border-radius: 6px;
    color: #2196F3;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    padding: 10px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    text-decoration: none;
}

.cyber-button.primary {
    background: #2196F3;
    color: #ffffff;
}

.cyber-button.danger {
    border-color: #ff4444;
    color: #ff4444;
}

.cyber-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(33, 150, 243, 0.2);
}

.cyber-actions {
    display: flex;
    gap: 15px;
    margin: 25px 0;
    flex-wrap: wrap;
    justify-content: flex-start;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .container-fluid {
        padding: 1rem;
    }
    
    .cyber-form .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 1rem;
    }
    
    .cyber-panel {
        margin-bottom: 1rem;
    }
    
    .cyber-panel-header {
        padding: 15px;
    }
    
    .cyber-panel-header h3 {
        font-size: 18px;
    }
    
    .cyber-panel-body {
        padding: 15px;
    }
    
    .cyber-textarea {
        min-height: 150px;
    }
    
    .cyber-actions {
        justify-content: center;
    }
}

/* Notification Styling */
.cyber-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Orbitron', sans-serif;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
    background: rgba(33, 150, 243, 0.1);
    border: 1px solid rgba(33, 150, 243, 0.3);
}

.cyber-notification.success {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: #4CAF50;
}

.cyber-notification.error {
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid rgba(244, 67, 54, 0.3);
    color: #f44336;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
</style>

<script>
function NetscapeToJson() {
var textArea2 = document.getElementById("textarea2");
textArea2.value = '';
var arrObjects = [];
var textArea1 = document.getElementById("textarea1");
var arrayOfLines = textArea1.value.split("\n");
    
    try {
        for (var i = 0; i < arrayOfLines.length; i++) {
            if (arrayOfLines[i].trim() === '') continue;
            
            var kuka = arrayOfLines[i].split("\t");
            if (kuka.length < 7) {
                throw new Error("Invalid format at line " + (i + 1));
            }
            
            var cook = {
                domain: kuka[0],
                httpOnly: kuka[1] === "TRUE",
                path: kuka[2],
                secure: kuka[3] === "TRUE",
                expirationDate: parseInt(kuka[4]),
                name: kuka[5],
                value: kuka[6]
            };
            
            arrObjects.push(cook);
        }
        
        var cookieStr = JSON.stringify(arrObjects, null, 2);
textArea2.value = cookieStr;
        textArea2.style.borderColor = '#2ecc71';

        // No history tracking - removed
    } catch (error) {
        textArea2.value = "Error: " + error.message;
        textArea2.style.borderColor = '#e74c3c';
    }
}

function copyToClipboard(elementId) {
    var textarea = document.getElementById(elementId);
    if (!textarea.value) return; // Don't show message if nothing to copy
    
    textarea.select();
    document.execCommand('copy');
    
    var success = document.getElementById('copySuccess');
    success.style.display = 'flex';
    
    // Remove any existing animation
    success.style.animation = 'none';
    success.offsetHeight; // Trigger reflow
    success.style.animation = 'fadeInOut 2s ease';
    
    // Hide after animation
    setTimeout(function() {
        success.style.display = 'none';
    }, 2000);
}

function clearInput(elementId) {
    if (confirm('Are you sure you want to clear the input?')) {
        document.getElementById(elementId).value = '';
    }
}

function clearOutput(elementId) {
    document.getElementById(elementId).value = '';
}

// Ensure textareas use monospace font and don't wrap
window.onload = function() {
    document.getElementById("textarea1").wrap = 'off';
    document.getElementById("textarea2").wrap = 'off';
}
</script>

<?php include('footer.php'); ?>