{% include 'header.twig' %}

<style>
    #service_description,
    #service_average_time {
        padding: 13px;
        border-radius: 12px;
        color: #393e46;
        box-shadow:none;
        background-color: #f3f3f3;
    }
    svg {fill: #ffffff;}
    @media (min-width:992px){
        .totals-block__card-right{ background-color: #fff; }
    }
    
    .badge {
        margin: 0px;
        background: #0084ff;
        width: fit-content;
        padding: 5px 15px 5px ;
        border-radius: 100px;
        color: #ffffff;
        font-weight: 500;
        align-items: center;
        gap: 10px;
    }   
    
    #dropdown_for_search {
        display: none;
        max-height: 600px;
        overflow-y: auto;
        overflow-x: hidden;
        border: 1px solid #ddd;
        border-radius: 5px;
        padding: 5px;
        margin-top: 5px;
        box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.2);
        white-space: normal;
        word-wrap: break-word;
    }
    .dropdown-item {
        padding: 10px 12px;
        cursor: pointer;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        white-space: normal;
        word-break: break-word;
    }
    .badge.service_id_badge {
        margin-right: 8px;
        font-size: 12px;
    }
    #dropdown_for_search .text-center {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 50px;
        font-weight: bold;
    }
    
    /* === COMPACT QUICK FILTERS (2 LINES, NO SCROLL) === */
    .quick-filters-container {
        display: flex;
        flex-wrap: wrap;           /* Wraps to 2 lines automatically */
        justify-content: center;   /* Center align */
        gap: 6px;                  /* Small gap */
        margin-bottom: 18px;
    }
    .quick-filter-btn {
        background-color: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 50px;
        padding: 5px 12px;         /* Smaller padding */
        font-size: 12px;           /* Smaller text */
        font-weight: 500;
        color: #475569;
        display: flex;
        align-items: center;
        gap: 4px;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 1px 2px rgba(0,0,0,0.02);
        white-space: nowrap;       
    }
    .quick-filter-btn:hover {
        border-color: #cbd5e1;
        background-color: #f8fafc;
    }
    .quick-filter-btn.active-filter {
        border-color: #3b82f6;
        color: #1d4ed8;
        background-color: #eff6ff;
    }
    .quick-filter-btn i { font-size: 14px; }

    /* === PREMIUM ORDER ALERTS (SUCCESS/ERROR) === */
    .premium-alert {
        display: flex;
        align-items: flex-start;
        padding: 18px;
        border-radius: 12px;
        position: relative;
        box-shadow: 0 4px 15px rgba(0,0,0,0.05);
        margin-bottom: 25px;
    }
    .alert-success-box {
        background-color: #f0fdf4;
        border: 1px solid #bbf7d0;
        border-left: 5px solid #22c55e;
    }
    .alert-error-box {
        background-color: #fef2f2;
        border: 1px solid #fecaca;
        border-left: 5px solid #ef4444;
    }
    .premium-alert .icon-wrapper {
        font-size: 32px;
        margin-right: 15px;
        line-height: 1;
    }
    .alert-success-box .icon-wrapper { color: #16a34a; }
    .alert-error-box .icon-wrapper { color: #dc2626; }
    
    .premium-alert h4 {
        margin: 0 0 12px 0;
        font-size: 18px;
        font-weight: 700;
        color: #1f2937;
    }
    .order-details-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        font-size: 13px;
        color: #4b5563;
    }
    @media(min-width: 768px) {
        .order-details-grid { grid-template-columns: 1fr 1fr; }
    }
    .order-details-grid div {
        background: #ffffff;
        padding: 6px 10px;
        border-radius: 6px;
        border: 1px solid #e5e7eb;
    }
    .order-details-grid span {
        font-weight: 600;
        color: #374151;
        margin-right: 5px;
    }
    .premium-alert .close-btn {
        position: absolute;
        top: 12px;
        right: 15px;
        background: transparent;
        border: none;
        font-size: 24px;
        color: #9ca3af;
        cursor: pointer;
        padding: 0;
        line-height: 1;
    }
    .premium-alert .close-btn:hover { color: #4b5563; }
</style>

<div class="container-fluid">
    <!-- === ALIXDEAL DISCOUNT ALERT BOX === -->
     <!-- === ALIXDEAL DISCOUNT ALERT BOX === -->
  <div style="background-color: #ffedd5; border: 1px solid #fdba74; border-left: 4px solid #f97316; border-radius: 6px; padding: 12px 35px 12px 15px; margin: 15px 0; position: relative; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; box-shadow: 0 2px 5px rgba(249,115,22,0.1); font-family: Arial, sans-serif;">
    <span onclick="this.parentElement.style.display='none';" style="position: absolute; top: 8px; right: 12px; font-size: 22px; font-weight: bold; color: #ea580c; cursor: pointer; line-height: 1;" title="Close">&times;</span>
    <div style="color: #c2410c; font-size: 14px; margin: 0; line-height: 1.5;">
        <strong>🎉 BIG OFFER:</strong> 50% OFF For API Users & 20% OFF For Normal Users!
    </div>
    <a href="https://wa.me/918273147063?text=Hello%20Alixdeal,%20mujhe%20apna%20Discount%20offer%20chahiye!" target="_blank" style="background: linear-gradient(135deg, #25D366 0%, #128C7E 100%); color: #ffffff !important; padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: bold; text-decoration: none; display: inline-flex; align-items: center; border: 1px solid #1eaa50; box-shadow: 0 3px 6px rgba(37,211,102,0.3); white-space: nowrap;">
        <i class="fab fa-whatsapp" style="font-size: 16px; margin-right: 6px;"></i> Claim Discount
    </a>
</div>
   <!-- === ALIXDEAL DISCOUNT ALERT BOX === -->
   <!-- === ALIXDEAL DISCOUNT ALERT BOX === -->
    <section class="mt-4 mb-3"> 
        <p class="text-center fw-bold">
            We have Completed: <span class="text-primary">{{totalorders}}</span> Orders
            <br/> 
            <span class="text-danger"> <small>For Place Order need balance! <a href="/addfunds" class="link">Add Fund Now</a></small></span>            
        </p>
        
        <div class="nwoCard-row row row-cols-2 row-cols-md-2 row-cols-lg-4">
            <div class="col">
              <a href="/addfunds">
               <div class="card nwoCard animate_for_balance">
                    <div class="card-body">
                        <div class="icon"><i class="ri-money-dollar-circle-line"></i></div>
                        <div class="col-r">
                            <h3 class="title"><span class="text-warning">Add Funds</span></h3>
                            <p class="value">{{ user["balance"] }}</p>
                        </div>
                    </div>
                </div>
              </a>
            </div>
            <div class="col">
                <div class="card nwoCard">
                    <div class="card-body"> 
                    
                    {% if user_note %}
    <div class="admin-note-box">
        <h4 style="margin: 0 0 8px 0; color: #dc2626; font-weight: 800; font-size: 16px;">
            <i class="ri-notification-3-fill"></i> Important Admin Message
        </h4>
        <p style="margin: 0; color: #4b5563; font-size: 14px; line-height: 1.6;">{{ user_note }}</p>
    </div>
    {% endif %}
                        <div class="icon"><i class="ri-shopping-cart-fill"></i></div>
                        <div class="col-r">
                            <h3 class="title">Total Orders</h3>
                            <p class="value">{{totalorders}}</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col">
                <div class="card nwoCard">
                    <div class="card-body">
                        <div class="icon"><i class="ri-exchange-dollar-line"></i></div>
                        <div class="col-r">
                            <h3 class="title">Spending</h3>
                            <p class="value">{{ user["spent"] }}</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col">
                <div class="card nwoCard">
                    <div class="card-body">
                        <div class="icon"><i class="ri-shield-flash-line"></i></div>
                        <div class="col-r">
                            <h3 class="title">Status</h3>
                            <p class="value">NEW</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section id="noc-wrapper" style="display: block;">
        <section class="nwoMain mt-3">
            <div class="row">
                <div class="col-lg-6 mb-4 mb-lg-0">
                    <div class="card">
                        <div class="card-header">
                            <div class="row align-items-center">
                                <div class="col-auto mt-lg-0">
                                    <ul class="nwoNav nav nav-tabs" role="tablist">
                                        <li class="nav-item" role="presentation">
                                            <button class="nwoNavLink active smmspot-newOrderBtn" data-bs-toggle="tab" data-bs-target="#newOrder" type="button" role="tab" aria-selected="true">
                                                New Order 
                                            </button>
                                        </li>
                                        <li class="nav-item" role="presentation">
                                            <a class="nwoNavLink smmspot-favOrderBtn" type="button" href="/massorder">
                                                Mass Order
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>

                        <div class="card-body">
                            <!-- === NEW PREMIUM ALERTS START === -->
                            {% if error %}
                            <div class="premium-alert alert-error-box">
                                <div class="icon-wrapper"><i class="ri-error-warning-fill"></i></div>
                                <div>
                                    <h4>Oops! Something went wrong</h4>
                                    <p style="margin:0; font-size:14px; color:#4b5563;">{{ errorText }}</p>
                                </div>
                                <button type="button" class="close-btn" onclick="this.parentElement.style.display='none';">Ã—</button>
                            </div>
                            {% endif %}
                            
                            {% if data["order"]["success"] == 1 %}
                            <div class="premium-alert alert-success-box">
                                <div class="icon-wrapper"><i class="ri-checkbox-circle-fill"></i></div>
                                <div style="width: 100%;">
                                    <h4>Order Placed Successfully!</h4>
                                    <div class="order-details-grid">
                                        <div><span>{{ lang["neworder.success.id"] }}:</span> {{ data['order']['id'] }}</div>
                                        <div><span>{{ lang["neworder.success.service"] }}:</span> {{ data['order']['service'] }}</div>
                                        <div style="grid-column: 1 / -1; word-break: break-all;"><span>{{ lang["neworder.success.link"] }}:</span> {{ data['order']['link'] }}</div>
                                        <div><span>{{ lang["neworder.success.quantity"] }}:</span> {{ data['order']['quantity'] }}</div>
                                        <div><span>{{ lang["neworder.success.charge"] }}:</span> {{ data['order']['price'] }}</div>
                                        <div><span>{{ lang["neworder.success.balance"] }}:</span> {{ data['order']['balance'] }}</div>
                                    </div>
                                </div>
                                <button type="button" class="close-btn" onclick="this.parentElement.style.display='none';">Ã—</button>
                            </div>
                            {% endif %}
                            
                            {% if data["order"]["success"] == 2 %}
                            <div class="premium-alert alert-success-box">
                                <div class="icon-wrapper"><i class="ri-checkbox-circle-fill"></i></div>
                                <div style="width: 100%;">
                                    <h4>Subscription Placed Successfully!</h4>
                                    <div class="order-details-grid">
                                        <div><span>{{ lang["neworder.success.id"] }}:</span> {{ data['order']['id'] }}</div>
                                        <div><span>{{ lang["neworder.success.service"] }}:</span> {{ data['order']['service'] }}</div>
                                        <div style="grid-column: 1 / -1; word-break: break-all;"><span>{{ lang["neworder.success.username"] }}:</span> {{ data['order']['link'] }}</div>
                                        <div><span>{{ lang["neworder.success.quantity"] }}:</span> {{ data['order']['min'] }} - {{ data['order']['max'] }}</div>
                                        <div><span>{{ lang["neworder.success.posts"] }}:</span> {{ data['order']['posts'] }}</div>
                                        <div><span>{{ lang["neworder.success.delay"] }}:</span> {{ data['order']['delay'] }}</div>
                                    </div>
                                </div>
                                <button type="button" class="close-btn" onclick="this.parentElement.style.display='none';">Ã—</button>
                            </div>
                            {% endif %} 
                            <!-- === NEW PREMIUM ALERTS END === -->

                            <div class="tab-content">
                                <div class="tab-pane active" id="newOrder" role="tabpanel">
                                    <div class="smmspot-newOrderArea">
                                        <div class="smmspot-orderFormContainer">
                                            
                                            <form action="/" method="post" id="order-form">
                                                
                                                <!-- === COMPACT CATEGORY QUICK FILTERS === -->
                                                <div class="quick-filters-container">
                                                    <button type="button" class="quick-filter-btn active-filter" onclick="filterCategoryPanel('All', this)">
                                                        <i class="bi bi-grid-fill" style="color: #64748b;"></i> All
                                                    </button>
                                                    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Instagram', this)">
                                                        <i class="fab fa-instagram" style="color: #E1306C;"></i> Instagram
                                                    </button>
                                                    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('YouTube', this)">
                                                        <i class="fab fa-youtube" style="color: #FF0000;"></i> YouTube
                                                    </button>
                                                    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('TikTok', this)">
                                                        <i class="fab fa-tiktok" style="color: #000000;"></i> TikTok
                                                    </button>
                                                    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Facebook', this)">
                                                        <i class="fab fa-facebook" style="color: #1877F2;"></i> Facebook
                                                    </button>
                                                    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Telegram', this)">
                                                        <i class="fab fa-telegram" style="color: #0088cc;"></i> Telegram
                                                    </button>
                                                    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Twitter', this)">
                                                        <i class="fab fa-twitter" style="color: #1DA1F2;"></i> Twitter
                                                    </button>
                                                    <button type="button" class="quick-filter-btn" onclick="filterCategoryPanel('Whatsapp', this)">
                                                        <i class="fab fa-whatsapp" style="color: #25D366;"></i> WhatsApp
                                                    </button>
                                                </div>
                                                <!-- ================================== -->

                                                {% if settings.search_enabled == 1 %}
                                                <div class="form-group mb-4">
                                                    <div class="search_services_content">
                                                        <div class="input-group">
                                                            <input type="search" id="search_services_field" class="form-control" placeholder="Search by Service ID or Name">
                                                        </div>
                                                    </div>
                                                    <div id="dropdown_for_search" class="dropdown" style="display: none; max-height: 600px; overflow-y: auto; border: 1px solid #ddd; border-radius: 5px; padding: 5px; margin-top: 5px; box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.2);">
                                                        <div class="text-center" style="display: none;">Please Wait...</div>
                                                    </div>
                                                </div>
                                                {% endif %}
                                                
                                                <div class="mb-4">
                                                    <label for="orderform-category" class="control-label">{{ lang["neworder.category"] }}</label>
                                                    <select class="form-control" id="neworder_category" name="categories" data-select="true" data-select-search="true" data-select-search-placeholder="Search">
                                                        {{ category_html_simplify }}
                                                    </select>
                                                </div>

                                                <div class="mb-3">
                                                    <label for="orderform-service" class="control-label">{{ lang["neworder.service"] }}</label>
                                                    <select class="form-control" id="neworder_services" name="services" data-select="true" data-select-search="true" data-select-search-placeholder="Search">
                                                        <option value="1">No services found in this category</option>
                                                    </select>
                                                </div>

                                                <div class="mb-3 hidden fields" id="service_description" style="display: none;">
                                                    <label for="service_description" class="form-label">Description</label>
                                                    <div class="panel-body border-solid border-rounded"></div>
                                                </div>

                                                <div id="neworder_fields"></div>
                                      
                                                <div class="mb-3">
                                                    <label for="charge" class="form-label">Charge</label>
                                                    <input type="text" class="form-control" id="charge" value="" readonly>
                                                </div>
                                                
                                                <input type="hidden" name="csrf_token" value="{{ csrfToken }}">
                                                <button type="submit" class="btn btn-primary btn-100">Submit</button>
                                            </form>

                                        </div>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            
                <div class="col-lg-6">
                    <div class="card">
                        <div class="card-header">
                            <h2 class="card-title">
                                <span id=""></span>
                                <span id="s_name"></span>
                            </h2>
                            <center><font size="5" color="#fff"><b><i class="fal fa-newspaper mr-2"></i>Latest News</b></font></center>
                        </div>
                    </div>
                                        
                    {% if news %}
                    <div style="padding: 0px;" class="card mb-3">
                        <div class="ssw">
                            {% for new in news %}
                            <div class="news-item">
                                <div class="news-details">
                                    <p class="news-date"><i class="fad fa-calendar-alt mr-1" style="--fa-secondary-opacity: 0.65;"></i>{{ new['news_date'] }}</p>
                                    <h4 class="news-title">
                                        <span class="icon-container">
                                            <img width="30" class="news-icon-inline" src="{{ new['news_icon'] }}" alt="News Icon">
                                        </span>
                                        {{ new['news_title'] }}
                                    </h4>
                                    <div class="news-content">{{ new['news_content'] }}</div>
                                </div>
                            </div>
                            {% endfor %}
                        </div>
                    </div>
                    {% endif %}
                </div>

            </div>
        </section>
    </section>
</div>

<!-- === ADVANCED JS WITH MULTIPLE KEYWORDS === -->
<script>
document.addEventListener("DOMContentLoaded", function() {
    if(typeof jQuery !== 'undefined') {
        window.allCategoryOptions = jQuery('#neworder_category').html();
    }
});

function filterCategoryPanel(platform, btnElement) {
    if(typeof jQuery === 'undefined') return;

    jQuery('.quick-filter-btn').removeClass('active-filter');
    jQuery(btnElement).addClass('active-filter');

    let catSelect = jQuery('#neworder_category');
    
    if(window.allCategoryOptions) {
        catSelect.html(window.allCategoryOptions);
    }

    const keywords = {
        'Instagram': ['instagram', 'ig', 'insta'],
        'YouTube':   ['youtube', 'yt', 'views'],
        'TikTok':    ['tiktok', 'tik tok'],
        'Facebook':  ['facebook', 'fb'],
        'Telegram':  ['telegram', 'tg'],
        'Twitter':   ['twitter', 'x'],
        'Whatsapp':  ['whatsapp', 'wa']
    };

    if (platform !== 'All') {
        let searchWords = keywords[platform] || [platform.toLowerCase()];
        
        catSelect.find('option').each(function() {
            let text = jQuery(this).text().toLowerCase();
            let isMatch = false;
            
            for(let i=0; i<searchWords.length; i++) {
                if (text.includes(searchWords[i].toLowerCase())) {
                    isMatch = true;
                    break;
                }
            }
            
            if (!isMatch) {
                jQuery(this).remove(); 
            }
        });
    }

    catSelect.prop('selectedIndex', 0);
    catSelect.trigger('change'); 
    
    if (typeof jQuery.fn.selectpicker !== 'undefined') {
        catSelect.selectpicker('refresh');
    }
    if (typeof jQuery.fn.select2 !== 'undefined') {
        catSelect.trigger('change.select2');
    }
    
    let customContainer = jQuery('#select-category-container');
    if(customContainer.length) {
        catSelect.trigger('input');
    }
}
</script>

{% include 'footer.twig' %}