<?php
/**
 * Admin Settings Page for Elementor PDF Smart Viewer
 *
 * @package ElementorPDFSmartViewer
 * @version 1.0.4
 */

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

// Handle form submission with proper sanitization
if (isset($_POST['pdfsmvif_save_settings']) && 
    isset($_POST['pdfsmvif_nonce']) && 
    wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['pdfsmvif_nonce'])), 'pdfsmvif_save_settings')) {
    
    if (isset($_POST['pdfsmvif_default_zoom'])) {
        update_option('pdfsmvif_default_zoom', sanitize_text_field(wp_unslash($_POST['pdfsmvif_default_zoom'])));
    }
    update_option('pdfsmvif_enable_download', isset($_POST['pdfsmvif_enable_download']) ? '1' : '0');
    update_option('pdfsmvif_enable_fullscreen', isset($_POST['pdfsmvif_enable_fullscreen']) ? '1' : '0');
    update_option('pdfsmvif_enable_print', isset($_POST['pdfsmvif_enable_print']) ? '1' : '0');
    update_option('pdfsmvif_enable_zoom_controls', isset($_POST['pdfsmvif_enable_zoom_controls']) ? '1' : '0');
    update_option('pdfsmvif_enable_page_info', isset($_POST['pdfsmvif_enable_page_info']) ? '1' : '0');
    // Remote PDF support moved to coming soon - no longer configurable
    // update_option('pdfsmvif_enable_remote_pdfs', isset($_POST['pdfsmvif_enable_remote_pdfs']) ? '1' : '0');
    if (isset($_POST['pdfsmvif_default_height'])) {
        update_option('pdfsmvif_default_height', sanitize_text_field(wp_unslash($_POST['pdfsmvif_default_height'])));
    }
    
    echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__('Settings saved successfully!', 'pdf-smart-viewer-for-elementor') . '</p></div>';
}

// Get current settings
$default_zoom = get_option('pdfsmvif_default_zoom', '1');
$enable_download = get_option('pdfsmvif_enable_download', '1');
$enable_fullscreen = get_option('pdfsmvif_enable_fullscreen', '1');
$enable_print = get_option('pdfsmvif_enable_print', '1');
$enable_zoom_controls = get_option('pdfsmvif_enable_zoom_controls', '1');
$enable_page_info = get_option('pdfsmvif_enable_page_info', '1');
$enable_remote_pdfs = get_option('pdfsmvif_enable_remote_pdfs', '1');
$default_height = get_option('pdfsmvif_default_height', '100%');
?>

<div class="wrap">
    <h1><?php esc_html_e('PDF Smart Viewer Settings', 'pdf-smart-viewer-for-elementor'); ?></h1>
    
    <div class="pdfsmvif-admin-container">
        <div class="pdfsmvif-admin-main">
            <form method="post" action="">
                <?php wp_nonce_field('pdfsmvif_save_settings', 'pdfsmvif_nonce'); ?>
                
                <table class="form-table">
                    <tr>
                        <th scope="row">
                            <label for="pdfsmvif_default_zoom"><?php esc_html_e('Default Zoom Level', 'pdf-smart-viewer-for-elementor'); ?></label>
                        </th>
                        <td>
                            <select name="pdfsmvif_default_zoom" id="pdfsmvif_default_zoom">
                                <option value="0.25" <?php selected($default_zoom, '0.25'); ?>><?php esc_html_e('25%', 'pdf-smart-viewer-for-elementor'); ?></option>
                                <option value="0.5" <?php selected($default_zoom, '0.5'); ?>><?php esc_html_e('50%', 'pdf-smart-viewer-for-elementor'); ?></option>
                                <option value="0.75" <?php selected($default_zoom, '0.75'); ?>><?php esc_html_e('75%', 'pdf-smart-viewer-for-elementor'); ?></option>
                                <option value="1" <?php selected($default_zoom, '1'); ?>><?php esc_html_e('100%', 'pdf-smart-viewer-for-elementor'); ?></option>
                                <option value="1.25" <?php selected($default_zoom, '1.25'); ?>><?php esc_html_e('125%', 'pdf-smart-viewer-for-elementor'); ?></option>
                                <option value="1.5" <?php selected($default_zoom, '1.5'); ?>><?php esc_html_e('150%', 'pdf-smart-viewer-for-elementor'); ?></option>
                                <option value="2" <?php selected($default_zoom, '2'); ?>><?php esc_html_e('200%', 'pdf-smart-viewer-for-elementor'); ?></option>
                            </select>
                            <p class="description"><?php esc_html_e('Default zoom level when the PDF viewer loads.', 'pdf-smart-viewer-for-elementor'); ?></p>
                        </td>
                    </tr>
                    
                    <tr>
                        <th scope="row">
                            <label for="pdfsmvif_default_height"><?php esc_html_e('Default Height', 'pdf-smart-viewer-for-elementor'); ?></label>
                        </th>
                        <td>
                            <input type="text" name="pdfsmvif_default_height" id="pdfsmvif_default_height" value="<?php echo esc_attr($default_height); ?>" class="regular-text" />
                            <p class="description"><?php esc_html_e('Default height for the PDF viewer (e.g., 100%, 600px, 80vh).', 'pdf-smart-viewer-for-elementor'); ?></p>
                        </td>
                    </tr>
                    
                    <tr>
                        <th scope="row"><?php esc_html_e('Default Features', 'pdf-smart-viewer-for-elementor'); ?></th>
                        <td>
                            <fieldset>
                                <label>
                                    <input type="checkbox" name="pdfsmvif_enable_download" value="1" <?php checked($enable_download, '1'); ?> />
                                    <?php esc_html_e('Enable download button by default', 'pdf-smart-viewer-for-elementor'); ?>
                                </label><br>
                                
                                <label>
                                    <input type="checkbox" name="pdfsmvif_enable_fullscreen" value="1" <?php checked($enable_fullscreen, '1'); ?> />
                                    <?php esc_html_e('Enable fullscreen button by default', 'pdf-smart-viewer-for-elementor'); ?>
                                </label><br>
                                
                                <label>
                                    <input type="checkbox" name="pdfsmvif_enable_print" value="1" <?php checked($enable_print, '1'); ?> />
                                    <?php esc_html_e('Enable print button by default', 'pdf-smart-viewer-for-elementor'); ?>
                                </label><br>
                                
                                <label>
                                    <input type="checkbox" name="pdfsmvif_enable_zoom_controls" value="1" <?php checked($enable_zoom_controls, '1'); ?> />
                                    <?php esc_html_e('Enable zoom controls by default', 'pdf-smart-viewer-for-elementor'); ?>
                                </label><br>
                                
                                <label>
                                    <input type="checkbox" name="pdfsmvif_enable_page_info" value="1" <?php checked($enable_page_info, '1'); ?> />
                                    <?php esc_html_e('Show page information by default', 'pdf-smart-viewer-for-elementor'); ?>
                                </label>
                            </fieldset>
                        </td>
                    </tr>
                    
                    <tr>
                        <th scope="row"><?php esc_html_e('Coming Soon', 'pdf-smart-viewer-for-elementor'); ?></th>
                        <td>
                            <div style="background: #f0f8ff; border: 1px solid #b3d9ff; border-radius: 4px; padding: 15px; margin: 10px 0;">
                                <h4 style="margin: 0 0 10px 0; color: #0066cc;"><?php esc_html_e('Remote PDF Support (Pro Feature)', 'pdf-smart-viewer-for-elementor'); ?></h4>
                                <p style="margin: 0 0 10px 0; color: #333;"><?php esc_html_e('Allow embedding PDFs from external URLs (Google Drive, Dropbox, etc.). This is a premium feature coming soon.', 'pdf-smart-viewer-for-elementor'); ?></p>
                                <ul style="margin: 0; padding-left: 20px; color: #666;">
                                    <li><?php esc_html_e('Cloud Storage Integration', 'pdf-smart-viewer-for-elementor'); ?></li>
                                    <li><?php esc_html_e('External URL Support', 'pdf-smart-viewer-for-elementor'); ?></li>
                                    <li><?php esc_html_e('CORS Handling', 'pdf-smart-viewer-for-elementor'); ?></li>
                                    <li><?php esc_html_e('Advanced Security', 'pdf-smart-viewer-for-elementor'); ?></li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    
                </table>
                
                <p class="submit">
                    <input type="submit" name="pdfsmvif_save_settings" class="button-primary" value="<?php esc_attr_e('Save Settings', 'pdf-smart-viewer-for-elementor'); ?>" />
                </p>
            </form>
        </div>
        
        <div class="pdfsmvif-admin-sidebar">
            <div class="pdfsmvif-admin-box">
                <h3><?php esc_html_e('Plugin Information', 'pdf-smart-viewer-for-elementor'); ?></h3>
                <p><strong><?php esc_html_e('Version:', 'pdf-smart-viewer-for-elementor'); ?></strong> <?php echo esc_html(PDFSMVIF_VERSION); ?></p>
                <p><strong><?php esc_html_e('Author:', 'pdf-smart-viewer-for-elementor'); ?></strong> Hamad - Lead Development and Operations @Deknows Inc</p>
                <p><strong><?php esc_html_e('Requires:', 'pdf-smart-viewer-for-elementor'); ?></strong> WordPress 5.0+, Elementor 3.0+</p>
            </div>
            
            <div class="pdfsmvif-admin-box">
                <h3><?php esc_html_e('Features', 'pdf-smart-viewer-for-elementor'); ?></h3>
                <ul>
                    <li><?php esc_html_e('Advanced zoom controls', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><?php esc_html_e('Fullscreen mode', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><?php esc_html_e('Download functionality', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><?php esc_html_e('Print support', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><?php esc_html_e('Keyboard navigation', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><?php esc_html_e('Responsive design', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><?php esc_html_e('Dark mode support', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><?php esc_html_e('Accessibility features', 'pdf-smart-viewer-for-elementor'); ?></li>
                    <li><strong><?php esc_html_e('Remote PDF Support (Coming Soon)', 'pdf-smart-viewer-for-elementor'); ?></strong> - <?php esc_html_e('Embed PDFs from external URLs', 'pdf-smart-viewer-for-elementor'); ?></li>
                </ul>
            </div>
            
            <div class="pdfsmvif-admin-box">
                <h3><?php esc_html_e('Support', 'pdf-smart-viewer-for-elementor'); ?></h3>
                <p><?php esc_html_e('Need help? Visit our documentation or contact support.', 'pdf-smart-viewer-for-elementor'); ?></p>
                <p><a href="https://deknows.com" target="_blank" class="button"><?php esc_html_e('Visit Website', 'pdf-smart-viewer-for-elementor'); ?></a></p>
            </div>
        </div>
    </div>
</div> 