/**
 * Customer Quick Login
 *
 * @author   Torey <b.zagajski@torey.eu>
 * @copyright 2026 torey.eu
 * @license  Commercial / Proprietary License
 * 
 * Wszelkie prawa zastrzeżone. Kopiowanie, modyfikowanie i rozpowszechnianie 
 * tego pliku bez zgody autora jest surowo zabronione.
 * 
 * All rights reserved. You may not modify, copy or distribute this file 
 * without explicit permission from the author.
 */

.cql-modal .modal-dialog{
margin: 150px auto 30px;
max-width: 490px;
}

@media (max-width: 767px){
.cql-modal .modal-dialog{
margin: 80px 10px;
max-width: 490px;
}}

.cql-modal .modal-content { 
border-radius: 0px; 
padding: 10px;
border: 0px;
}

.cql-tabs {
font-size: .925rem;
display: flex; 
list-style: none; 
padding: 0; 
margin: 0 0 1.5rem 0; 
border-bottom: 2px solid #eee; 
}
							
.cql-tab-btn { 
flex: 1; 
text-align: center; 
padding: 10px; 
cursor: pointer; 
font-weight: 400; 
color: #888; 
transition: all 0.3s;
text-transform: uppercase;
}

.cql-tab-btn.cql-active { 
text-transform: uppercase;	
color: var(--headings-color); 
border-bottom: 2px solid var(--theme-color-default); 
margin-bottom: -2px; 
}

.cql-form-wrapper { 
display: none; 
}

.cql-form-wrapper.cql-active { 
display: block; 
}

.cql-title {
text-transform: uppercase;
margin-bottom: 1.5rem;
margin-top: .3rem;
font-size: 1.2rem; 
font-weight: 400; 
text-align: center; 
}

.cql-password-wrapper { 
position: relative;  
}

.cql-toggle-password { 
position: absolute; 
right: 10px; 
top: 12px; 
cursor: pointer; 
color: #666; 
user-select: none; 
}

.cql-msg { 
padding: 10px; 
margin-bottom: 15px; 
border-radius: 4px; 
font-size: 0.825rem; 
}

.cql-success { 
background-color: #d4edda; 
color: #155724; 
border: 1px solid #c3e6cb; 
}

.cql-error { 
background-color: #f8d7da; 
color: #721c24; 
border: 1px solid #f5c6cb; 
}

.cql-submit-btn { 
width: 100%; 
padding: 10px; 
}

.cql-submit-btn.loading { 
opacity: 0.7; 
pointer-events: none; 
}

.cql-checkbox label {
line-height: 18px;
text-align: start;
display: flex; 
align-items: center; 
gap: 8px;
}

@media (max-width: 767px){
.cql-checkbox label {
font-size: 12px;
}}
	
.cql-password-strength { 
display: none;
height: 4px; 
background-color: #eee; 
border-radius: 2px; 
overflow: hidden; 
margin-top: 5px; 
}

.cql-strength-bar { 
height: 100%; 
width: 0%;
background-color: transparent; 
transition: width 0.3s, 
background-color 0.3s; 
}

.cql-modal .modal-header {
padding: 0px;
border-bottom: none;
}

.cql-align-right {
	margin-top: 15px;
    text-align: right;
    display: block;
    width: 100%;
}

.cql-align-left {
    text-align: left;
    display: block;
    width: 100%;
}

.cql-align-center {
    text-align: center;
    display: block;
    width: 100%;
}

.cql-modal .modal-body {
padding: 0px 10px;
}

.cql-gdpr-text {
line-height: 18px;
text-align: right; 
margin-bottom: 20px; 
margin-top: -5px;
}

@media (max-width: 767px){
.cql-gdpr-text {
font-size: 12px;
}}

.cql-form .form-control {
    padding: 15px 10px;
}

.cql-modal .close {
    font-size: 2rem;
    font-weight: 400;
    line-height: inherit;
}



JavaScript
/**
 * Customer Quick Login
 *
 * @author   Torey <b.zagajski@torey.eu>
 * @copyright 2026 torey.eu
 * @license  Commercial / Proprietary License
 * 
 * Wszelkie prawa zastrzeżone. Kopiowanie, modyfikowanie i rozpowszechnianie 
 * tego pliku bez zgody autora jest surowo zabronione.
 * 
 * All rights reserved. You may not modify, copy or distribute this file 
 * without explicit permission from the author.
 */

$(document).ready(function() {
    // Pokaż modal po kliknięciu w przycisk nawigacji
    $(document).on('click', '.cql-btn-toggle', function(e) {
        e.preventDefault();
        $('#cql-modal').modal('show');
    });

    // Przełączanie między zakładkami (Tab Style)
    $(document).on('click', '.cql-tab-btn, .cql-switch-btn', function(e) {
        e.preventDefault();
        var target = $(this).data('target');
        
        $('.cql-tab-btn').removeClass('cql-active');
        $('.cql-tab-btn[data-target="'+target+'"]').addClass('cql-active');

        $('.cql-form-wrapper').removeClass('cql-active');
        $('.cql-'+target+'-form').addClass('cql-active');

        // Zresetuj widok w przypadku przełączania podczas odzyskiwania hasła
        $('#cql-login-form').show();
        $('.cql-reset-form').hide();
    });

    // Przełączanie na zapomniane hasło i powrót
    $(document).on('click', '.cql-forgot-password-btn', function(e) {
        e.preventDefault();
        $('#cql-login-form').slideUp('fast', function() {
            $('.cql-reset-form').slideDown('fast');
        });
    });

    $(document).on('click', '.cql-back-login-btn', function(e) {
        e.preventDefault();
        $('.cql-reset-form').slideUp('fast', function() {
            $('#cql-login-form').slideDown('fast');
        });
    });

    // Pokaż / Ukryj hasło
    $(document).on('click', '.cql-toggle-password', function() {
        var input = $(this).siblings('.cql-pass-input');
        if (input.attr('type') === 'password') {
            input.attr('type', 'text');
            $(this).html('&#xE8F5;'); // Ikona przekreślonego oka
        } else {
            input.attr('type', 'password');
            $(this).html('&#xE8F4;'); // Ikona oka
        }
    });

    // Funkcja do obsługi formularzy AJAX
    function handleCqlAjaxSubmit(formSelector, actionName) {
        $(document).on('submit', formSelector, function(e) {
            e.preventDefault();
            var $form = $(this);
            var $btn = $form.find('.cql-submit-btn');
            var originalText = $btn.find('.cql-btn-text').text();
            
            $form.find('.cql-msg').hide().html('');
            $btn.addClass('loading').find('.cql-btn-text').text('...');

            var formData = $form.serializeArray();
            formData.push({name: 'ajax', value: 1});
            formData.push({name: 'action', value: actionName});

            $.ajax({
                type: 'POST',
                url: cql_ajax_url,
                data: $.param(formData),
                dataType: 'json',
                success: function(response) {
                    $btn.removeClass('loading').find('.cql-btn-text').text(originalText);

                    if (response.errors && response.errors.length > 0) {
                        $form.find('.cql-error').html(response.errors.join('<br>')).fadeIn();
                    } else if (response.success && response.success.length > 0) {
                        $form.find('.cql-success').html(response.success.join('<br>')).fadeIn();
                        $form.find('input:not([type="checkbox"])').val(''); // Wyczyść form

                        // Jeśli to login/register i mamy redirect
                        if (actionName === 'customer-login' || actionName === 'create-account') {
                            setTimeout(function() {
                                if (typeof cql_redirect !== 'undefined' && cql_redirect == 1) {
                                    window.location.replace(cql_myaccount_url);
                                } else {
                                    location.reload();
                                }
                            }, 1000);
                        }
                    }
                },
                error: function() {
                    $btn.removeClass('loading').find('.cql-btn-text').text(originalText);
                    $form.find('.cql-error').text('Server error. Please try again later.').fadeIn();
                }
            });
        });
    }

    // Inicjalizacja AJAX dla 3 formularzy
    handleCqlAjaxSubmit('#cql-login-form', 'customer-login');
    handleCqlAjaxSubmit('#cql-register-form', 'create-account');
    handleCqlAjaxSubmit('#cql-reset-form', 'reset-pass');
});
				