// Edocman Lite Public JavaScript

jQuery(document).ready(function($) {
    
    // Smooth scroll for document links
    $('.document-title a, .category-title a').on('click', function(e) {
        // Allow default behavior for now
    });
    
    // Download tracking (optional enhancement)
    $('.download-button').on('click', function() {
        // Track download analytics if needed
        console.log('Document download initiated');
    });
    
    // View button tracking (optional enhancement)
    $('.view-button').on('click', function() {
        // Track view analytics if needed
        console.log('Document view initiated');
    });

    // Front-end: delete user's own document
    $(document).on('click', '.edocman-lite-delete-my-doc', function(e) {
        e.preventDefault();
        if ( ! confirm( edocman_lite_public.confirm_delete ) ) {
            return;
        }
        var $link  = $(this);
        var docId  = $link.data('document-id');
        var nonce  = $link.data('nonce');

        $.post( edocman_lite_public.ajax_url, {
            action      : 'edocman_lite_delete_my_document',
            document_id : docId,
            nonce       : nonce
        }, function(response) {
            if (response.success) {
                $link.closest('tr').fadeOut(300, function() { $(this).remove(); });
            } else {
                var msg = response.data && response.data.message
                    ? response.data.message
                    : edocman_lite_public.error_delete;
                alert(msg);
            }
        });
    });

});
