/*
 Theme Name:   Logistik Child
 Theme URI:    https://themeholy.com/wordpress/logistik/
 Description:  This is a child theme for Logistik - WordPress Theme
 Author:       Themeholy
 Author URI:   https://themeholy.com
 Template:     logistik
 Version:      1.0
 Tags:         two-columns, three-columns, left-sidebar, right-sidebar, flexible-header, custom-background, custom-colors, custom-header, custom-menu, theme-options, editor-style, featured-images, microformats, post-formats,  sticky-post, threaded-comments, translation-ready
 Text Domain:  logistik-child
*/

/*  [ Add your custom css below ]
- - - - - - - - - - - - - - - - - - - - */

/* Portfolio Section Mouse Scroll */
// Horizontal drag scroll for Elementor slider
function horizontal_drag_scroll_slider() {
    ?>
    <script>
    jQuery(document).ready(function($) {
        const slider = $('#ProjectSlide2 .slick-list')[0];
        let isDown = false;
        let startX;
        let scrollLeft;
        let velocity = 0;
        let lastX = 0;
        let momentumID;

        // Mouse down - start dragging
        $(slider).on('mousedown', function(e) {
            isDown = true;
            $(slider).addClass('active-drag');
            startX = e.pageX - slider.offsetLeft;
            scrollLeft = slider.scrollLeft;
            lastX = e.pageX;
            cancelMomentumTracking();
        });

        // Mouse leave - stop dragging
        $(slider).on('mouseleave', function() {
            isDown = false;
            $(slider).removeClass('active-drag');
            beginMomentumTracking();
        });

        // Mouse up - stop dragging
        $(slider).on('mouseup', function() {
            isDown = false;
            $(slider).removeClass('active-drag');
            beginMomentumTracking();
        });

        // Mouse move - perform dragging
        $(slider).on('mousemove', function(e) {
            if (!isDown) return;
            e.preventDefault();
            
            const x = e.pageX - slider.offsetLeft;
            const walk = (x - startX) * 2; // Scroll speed (adjust multiplier)
            const prevScrollLeft = slider.scrollLeft;
            slider.scrollLeft = scrollLeft - walk;
            
            // Calculate velocity for momentum
            velocity = slider.scrollLeft - prevScrollLeft;
            lastX = x;
        });

        // Prevent click events when dragging
        $(slider).on('click', 'a', function(e) {
            if (Math.abs(velocity) > 1) {
                e.preventDefault();
                return false;
            }
        });

        // Momentum scrolling
        function beginMomentumTracking() {
            cancelMomentumTracking();
            momentumID = requestAnimationFrame(momentumLoop);
        }

        function cancelMomentumTracking() {
            cancelAnimationFrame(momentumID);
        }

        function momentumLoop() {
            slider.scrollLeft += velocity;
            velocity *= 0.95; // Friction
            if (Math.abs(velocity) > 0.5) {
                momentumID = requestAnimationFrame(momentumLoop);
            }
        }
    });
    </script>
    <style>
    /* Horizontal scroll styles */
    #ProjectSlide2 .slick-list {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        cursor: grab !important;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    #ProjectSlide2 .slick-list.active-drag {
        cursor: grabbing !important;
        scroll-behavior: auto;
    }

    #ProjectSlide2 .slick-list::-webkit-scrollbar {
        display: none;
    }

    #ProjectSlide2 .slick-list {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    #ProjectSlide2 .slick-track {
        display: flex !important;
    }

    /* Disable text selection while dragging */
    #ProjectSlide2 .slick-list.active-drag * {
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
    }
    </style>
    <?php
}
add_action('wp_footer', 'horizontal_drag_scroll_slider', 999);

/* Portfolio Section Mouse Scroll */

