<?php
/**
 * PDF Smart Viewer Widget for Elementor
 *
 * @package ElementorPDFSmartViewer
 * @version 1.0.4
 */

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;

if (!defined('ABSPATH')) {
    exit;
}

class PDFSMVIF_PDF_Smart_Viewer_Widget extends Widget_Base {

    public function get_name() {
        return 'pdf_smart_viewer';
    }

    public function get_title() {
        return esc_html__('PDF Smart Viewer for Elementor', 'pdf-smart-viewer-for-elementor');
    }

    public function get_icon() {
        return 'eicon-document-file';
    }

    public function get_categories() {
        return ['general'];
    }

    public function get_keywords() {
        return ['pdf', 'viewer', 'document', 'file', 'smart'];
    }

    public function get_script_depends() {
        return ['pdfjs-lib', 'pdf-smart-viewer-for-elementor'];
    }

    public function get_style_depends() {
        return ['pdf-smart-viewer-for-elementor'];
    }

    protected function register_controls() {
        // Content Section
        $this->start_controls_section(
            'content_section',
            [
                'label' => esc_html__('Content', 'pdf-smart-viewer-for-elementor'),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'pdf_source',
            [
                'label' => esc_html__('PDF Source', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SELECT,
                'default' => 'url',
                'options' => [
                    'url' => esc_html__('URL', 'pdf-smart-viewer-for-elementor'),
                    'file' => esc_html__('Upload File', 'pdf-smart-viewer-for-elementor'),
                ],
            ]
        );

        $this->add_control(
            'pdf_url',
            [
                'label' => esc_html__('PDF File URL', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::TEXT,
                'input_type' => 'url',
                'placeholder' => 'https://example.com/your-file.pdf',
                'label_block' => true,
                'condition' => [
                    'pdf_source' => 'url',
                ],
            ]
        );

        $this->add_control(
            'pdf_file',
            [
                'label' => esc_html__('Upload PDF File', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::MEDIA,
                'media_type' => 'application/pdf',
                'condition' => [
                    'pdf_source' => 'file',
                ],
            ]
        );

        $this->add_control(
            'initial_zoom',
            [
                'label' => esc_html__('Initial Zoom Level', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['%'],
                'range' => [
                    '%' => [
                        'min' => 25,
                        'max' => 300,
                        'step' => 25,
                    ],
                ],
                'default' => [
                    'unit' => '%',
                    'size' => 100,
                ],
            ]
        );

        $this->add_control(
            'show_controls',
            [
                'label' => esc_html__('Show Controls', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'pdf-smart-viewer-for-elementor'),
                'label_off' => esc_html__('Hide', 'pdf-smart-viewer-for-elementor'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'show_zoom_controls',
            [
                'label' => esc_html__('Show Zoom Controls', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'pdf-smart-viewer-for-elementor'),
                'label_off' => esc_html__('Hide', 'pdf-smart-viewer-for-elementor'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'show_controls' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'show_fullscreen',
            [
                'label' => esc_html__('Show Fullscreen Button', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'pdf-smart-viewer-for-elementor'),
                'label_off' => esc_html__('Hide', 'pdf-smart-viewer-for-elementor'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'show_controls' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'show_download',
            [
                'label' => esc_html__('Show Download Button', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'pdf-smart-viewer-for-elementor'),
                'label_off' => esc_html__('Hide', 'pdf-smart-viewer-for-elementor'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'show_controls' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'show_print',
            [
                'label' => esc_html__('Show Print Button', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'pdf-smart-viewer-for-elementor'),
                'label_off' => esc_html__('Hide', 'pdf-smart-viewer-for-elementor'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'show_controls' => 'yes',
                ],
            ]
        );

        $this->add_control(
            'show_page_info',
            [
                'label' => esc_html__('Show Page Information', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'pdf-smart-viewer-for-elementor'),
                'label_off' => esc_html__('Hide', 'pdf-smart-viewer-for-elementor'),
                'return_value' => 'yes',
                'default' => 'yes',
                'condition' => [
                    'show_controls' => 'yes',
                ],
            ]
        );

        $this->end_controls_section();

        // Style Section - Container
        $this->start_controls_section(
            'style_container_section',
            [
                'label' => esc_html__('Container', 'pdf-smart-viewer-for-elementor'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'container_height',
            [
                'label' => esc_html__('Height', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'vh', '%'],
                'range' => [
                    'px' => [
                        'min' => 200,
                        'max' => 1000,
                        'step' => 10,
                    ],
                    'vh' => [
                        'min' => 20,
                        'max' => 100,
                        'step' => 5,
                    ],
                    '%' => [
                        'min' => 20,
                        'max' => 100,
                        'step' => 5,
                    ],
                ],
                'default' => [
                    'unit' => '%',
                    'size' => 100,
                ],
                'selectors' => [
                    '{{WRAPPER}} .epsv-container' => 'height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'container_background',
                'label' => esc_html__('Background', 'pdf-smart-viewer-for-elementor'),
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .epsv-container',
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'container_border',
                'label' => esc_html__('Border', 'pdf-smart-viewer-for-elementor'),
                'selector' => '{{WRAPPER}} .epsv-container',
            ]
        );

        $this->add_responsive_control(
            'container_border_radius',
            [
                'label' => esc_html__('Border Radius', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .epsv-container' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'container_box_shadow',
                'label' => esc_html__('Box Shadow', 'pdf-smart-viewer-for-elementor'),
                'selector' => '{{WRAPPER}} .epsv-container',
            ]
        );

        $this->add_responsive_control(
            'container_padding',
            [
                'label' => esc_html__('Padding', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .epsv-container' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();

        // Style Section - Controls
        $this->start_controls_section(
            'style_controls_section',
            [
                'label' => esc_html__('Controls', 'pdf-smart-viewer-for-elementor'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'controls_background_color',
            [
                'label' => esc_html__('Background Color', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .epsv-controls' => 'background-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'controls_text_color',
            [
                'label' => esc_html__('Text Color', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .epsv-controls' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'controls_typography',
                'label' => esc_html__('Typography', 'pdf-smart-viewer-for-elementor'),
                'selector' => '{{WRAPPER}} .epsv-controls',
            ]
        );

        $this->add_responsive_control(
            'controls_padding',
            [
                'label' => esc_html__('Padding', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .epsv-controls' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();

        // Style Section - Buttons
        $this->start_controls_section(
            'style_buttons_section',
            [
                'label' => esc_html__('Buttons', 'pdf-smart-viewer-for-elementor'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->start_controls_tabs('button_styles');

        $this->start_controls_tab(
            'button_normal',
            [
                'label' => esc_html__('Normal', 'pdf-smart-viewer-for-elementor'),
            ]
        );

        $this->add_control(
            'button_background_color',
            [
                'label' => esc_html__('Background Color', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .epsv-btn' => 'background-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_text_color',
            [
                'label' => esc_html__('Text Color', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .epsv-btn' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->end_controls_tab();

        $this->start_controls_tab(
            'button_hover',
            [
                'label' => esc_html__('Hover', 'pdf-smart-viewer-for-elementor'),
            ]
        );

        $this->add_control(
            'button_background_color_hover',
            [
                'label' => esc_html__('Background Color', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .epsv-btn:hover' => 'background-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'button_text_color_hover',
            [
                'label' => esc_html__('Text Color', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .epsv-btn:hover' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'button_typography',
                'label' => esc_html__('Typography', 'pdf-smart-viewer-for-elementor'),
                'selector' => '{{WRAPPER}} .epsv-btn',
                'separator' => 'before',
            ]
        );

        $this->add_responsive_control(
            'button_padding',
            [
                'label' => esc_html__('Padding', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .epsv-btn' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'button_border',
                'label' => esc_html__('Border', 'pdf-smart-viewer-for-elementor'),
                'selector' => '{{WRAPPER}} .epsv-btn',
            ]
        );

        $this->add_responsive_control(
            'button_border_radius',
            [
                'label' => esc_html__('Border Radius', 'pdf-smart-viewer-for-elementor'),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .epsv-btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();
    }

    /**
     * Check if remote PDFs are allowed
     */
    private function is_remote_pdf_allowed() {
        return get_option('pdfsmvif_enable_remote_pdfs', false);
    }

    /**
     * Check if URL is remote (not local)
     */
    private function is_remote_url($url) {
        $site_url = home_url();
        $parsed_url = parse_url($url);
        $parsed_site_url = parse_url($site_url);
        
        // Check if it's a different domain
        if (isset($parsed_url['host']) && isset($parsed_site_url['host'])) {
            return $parsed_url['host'] !== $parsed_site_url['host'];
        }
        
        // If we can't parse the URL, assume it's remote if it doesn't start with site URL
        return strpos($url, $site_url) !== 0;
    }

    /**
     * Validate remote PDF URL
     */
    private function validate_remote_pdf($url) {
        // Basic URL validation
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
            return false;
        }

        // Check if URL ends with .pdf
        if (strtolower(pathinfo($url, PATHINFO_EXTENSION)) !== 'pdf') {
            return false;
        }

        // For trusted domains and cloud storage, be more lenient
        $is_trusted_domain = $this->is_cloud_storage_url($url);
        
        if ($is_trusted_domain) {
            // For trusted domains, just check if URL is accessible
            $response = wp_remote_head($url, array(
                'timeout' => 15,
                'user-agent' => 'Mozilla/5.0 (compatible; PDF Smart Viewer)',
                'sslverify' => false // Some services have SSL issues
            ));

            if (is_wp_error($response)) {
                return false;
            }

            $status_code = wp_remote_retrieve_response_code($response);
            // Accept 200, 206 (partial content), and sometimes 403 (if file exists but access is restricted)
            if (!in_array($status_code, array(200, 206, 403))) {
                return false;
            }

            // For trusted domains, don't strictly require PDF content-type
            // Many services don't send proper content-type headers
            return true;
        } else {
            // For regular URLs, do full validation
            $response = wp_remote_head($url, array(
                'timeout' => 10,
                'user-agent' => 'Mozilla/5.0 (compatible; PDF Smart Viewer)',
                'sslverify' => false
            ));

            if (is_wp_error($response)) {
                return false;
            }

            $status_code = wp_remote_retrieve_response_code($response);
            if ($status_code !== 200) {
                return false;
            }

            // Check content type
            $content_type = wp_remote_retrieve_header($response, 'content-type');
            if ($content_type && strpos($content_type, 'application/pdf') === false) {
                return false;
            }

            return true;
        }
    }

    /**
     * Check if URL is from a known cloud storage service or trusted domain
     */
    private function is_cloud_storage_url($url) {
        $trusted_domains = array(
            // Cloud storage services
            'digitaloceanspaces.com',
            'amazonaws.com',
            's3.amazonaws.com',
            's3.',
            'cloudfront.net',
            'googleapis.com',
            'googleusercontent.com',
            'dropbox.com',
            'drive.google.com',
            'onedrive.live.com',
            'blob.core.windows.net',
            // Well-known trusted domains
            'adobe.com',
            'microsoft.com',
            'apple.com',
            'google.com',
            'github.com',
            'wordpress.org',
            'mozilla.org',
            'w3.org',
            'ietf.org'
        );

        $parsed_url = parse_url($url);
        if (!isset($parsed_url['host'])) {
            return false;
        }

        $host = strtolower($parsed_url['host']);
        
        foreach ($trusted_domains as $domain) {
            if (strpos($host, $domain) !== false) {
                return true;
            }
        }

        return false;
    }

    protected function render() {
        $settings = $this->get_settings_for_display();

        // Get PDF URL
        $pdf_url = '';
        if ($settings['pdf_source'] === 'url' && !empty($settings['pdf_url'])) {
            $pdf_url = esc_url($settings['pdf_url']);
            
            // Check if it's a remote URL and if remote PDFs are allowed
            if ($this->is_remote_url($pdf_url) && !$this->is_remote_pdf_allowed()) {
                echo '<div class="epsv-error epsv-upgrade-prompt">';
                echo '<h3>' . esc_html__('Remote PDF Support - Premium Feature', 'pdf-smart-viewer-for-elementor') . '</h3>';
                echo '<p>' . esc_html__('Embedding PDFs from external URLs (Google Drive, Dropbox, etc.) is a premium feature.', 'pdf-smart-viewer-for-elementor') . '</p>';
                echo '<p><strong>' . esc_html__('Upgrade to Pro to enable this feature!', 'pdf-smart-viewer-for-elementor') . '</strong></p>';
                echo '<a href="' . esc_url(admin_url('admin.php?page=pdf-smart-viewer-settings')) . '" class="button button-primary">' . esc_html__('Go to Settings', 'pdf-smart-viewer-for-elementor') . '</a>';
                echo '</div>';
                return;
            }
            
            // For trusted domains, skip server-side validation to avoid CORS issues
            // Let PDF.js handle the loading and validation on the client side
            if ($this->is_remote_url($pdf_url) && !$this->is_cloud_storage_url($pdf_url)) {
                // Only validate non-trusted domains to prevent abuse
                if (!$this->validate_remote_pdf($pdf_url)) {
                    echo '<div class="epsv-error">';
                    echo '<h3>' . esc_html__('PDF Validation Failed', 'pdf-smart-viewer-for-elementor') . '</h3>';
                    echo '<p>' . esc_html__('The PDF URL could not be validated. This might be due to:', 'pdf-smart-viewer-for-elementor') . '</p>';
                    echo '<ul>';
                    echo '<li>' . esc_html__('The file does not exist or is not accessible', 'pdf-smart-viewer-for-elementor') . '</li>';
                    echo '<li>' . esc_html__('The server is blocking external requests', 'pdf-smart-viewer-for-elementor') . '</li>';
                    echo '<li>' . esc_html__('CORS (Cross-Origin Resource Sharing) restrictions', 'pdf-smart-viewer-for-elementor') . '</li>';
                    echo '<li>' . esc_html__('SSL/TLS certificate issues', 'pdf-smart-viewer-for-elementor') . '</li>';
                    echo '</ul>';
                    echo '</div>';
                    return;
                }
            }
        } elseif ($settings['pdf_source'] === 'file' && !empty($settings['pdf_file']['url'])) {
            $pdf_url = esc_url($settings['pdf_file']['url']);
        }

        if (empty($pdf_url)) {
            echo '<div class="epsv-error">' . esc_html__('Please select a PDF file or enter a PDF URL.', 'pdf-smart-viewer-for-elementor') . '</div>';
            return;
        }

        // Get settings
        $initial_zoom = $settings['initial_zoom']['size'] / 100;
        $show_controls = $settings['show_controls'] === 'yes';
        $show_zoom_controls = $settings['show_zoom_controls'] === 'yes';
        $show_fullscreen = $settings['show_fullscreen'] === 'yes';
        $show_download = $settings['show_download'] === 'yes';
        $show_print = $settings['show_print'] === 'yes';
        $show_page_info = $settings['show_page_info'] === 'yes';

        // Generate unique ID
        $widget_id = 'epsv-' . $this->get_id();

        ?>
        <div class="epsv-container" id="<?php echo esc_attr($widget_id); ?>"
            data-pdf-url="<?php echo esc_attr($pdf_url); ?>"
            data-widget-id="<?php echo esc_attr($this->get_id()); ?>"
            data-initial-zoom="<?php echo esc_attr($initial_zoom); ?>"
            data-show-zoom="<?php echo esc_attr($show_zoom_controls ? 'true' : 'false'); ?>"
            data-show-fullscreen="<?php echo esc_attr($show_fullscreen ? 'true' : 'false'); ?>"
            data-show-download="<?php echo esc_attr($show_download ? 'true' : 'false'); ?>"
            data-show-print="<?php echo esc_attr($show_print ? 'true' : 'false'); ?>"
            data-show-page-info="<?php echo esc_attr($show_page_info ? 'true' : 'false'); ?>">

            <div class="epsv-viewer">
                <canvas class="epsv-canvas"></canvas>
                <div class="epsv-loading">
                    <div class="epsv-spinner"></div>
                    <p><?php esc_html_e('Loading PDF...', 'pdf-smart-viewer-for-elementor'); ?></p>
                </div>
                <div class="epsv-error" style="display: none;">
                    <p><?php esc_html_e('Error loading PDF. Please check the URL or file.', 'pdf-smart-viewer-for-elementor'); ?></p>
                </div>
            </div>

            <?php if ($show_controls): ?>
                <div class="epsv-controls">
                    <div class="epsv-controls-left">
                        <button class="epsv-btn epsv-zoom-out" title="<?php esc_attr_e('Zoom Out', 'pdf-smart-viewer-for-elementor'); ?>">
                            <span class="epsv-icon">−</span>
                        </button>
                        <button class="epsv-btn epsv-zoom-in" title="<?php esc_attr_e('Zoom In', 'pdf-smart-viewer-for-elementor'); ?>">
                            <span class="epsv-icon">+</span>
                        </button>
                    </div>
                    <div class="epsv-controls-center">
                        <button class="epsv-btn epsv-prev" title="<?php esc_attr_e('Previous Page', 'pdf-smart-viewer-for-elementor'); ?>">
                            <span class="epsv-icon">&#8592;</span>
                        </button>
                        <?php if ($show_page_info): ?>
                            <div class="epsv-page-info">
                                <span class="epsv-page-current">1</span>
                                <span class="epsv-page-separator">/</span>
                                <span class="epsv-page-total">1</span>
                            </div>
                        <?php endif; ?>
                        <button class="epsv-btn epsv-next" title="<?php esc_attr_e('Next Page', 'pdf-smart-viewer-for-elementor'); ?>">
                            <span class="epsv-icon">&#8594;</span>
                        </button>
                    </div>
                    <div class="epsv-controls-right">
                        <?php if ($show_fullscreen): ?>
                            <button class="epsv-btn epsv-fullscreen" title="<?php esc_attr_e('Fullscreen', 'pdf-smart-viewer-for-elementor'); ?>">
                                <span class="epsv-icon">⛶</span>
                            </button>
                        <?php endif; ?>
                        <?php if ($show_download): ?>
                            <button class="epsv-btn epsv-download" title="<?php esc_attr_e('Download', 'pdf-smart-viewer-for-elementor'); ?>">
                                <span class="epsv-icon">↓</span>
                            </button>
                        <?php endif; ?>
                        <?php if ($show_print): ?>
                            <button class="epsv-btn epsv-print" title="<?php esc_attr_e('Print', 'pdf-smart-viewer-for-elementor'); ?>">
                                <span class="epsv-icon">🖨</span>
                            </button>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endif; ?>
        </div>
        <?php
    }
} 