<?php
/**
 * Default options for the PinnerPress plugin.
 * 
 * This file defines all default options used by the plugin, to ensure
 * consistency between activation, reset, and any other places defaults are needed.
 * 
 * @link       https://pinnerpress.com
 * @since      0.1.0
 *
 * @package    PinnerPress
 */

// If this file is called directly, abort.
if (!defined('WPINC')) {
    die;
}

/**
 * Get default options for PinnerPress plugin
 * 
 * This function returns an array of all default option values
 * organized by tab for easy access.
 * 
 * @since 0.1.0
 * @return array Associative array of default options
 */
function pinnerpress_get_default_options() {
    return array(
        // General Tab options
        'general' => array(
            'pinnerpress_pinterest_url' => '',
            'pinnerpress_pinterest_display_name' => __('PinnerPress', 'pinnerpress'),
            'pinnerpress_profile_image' => '',
            'pinnerpress_disable_rich_pins' => 'off',
            'pinnerpress_follow_button_default_text' => __('Follow on Pinterest', 'pinnerpress'),
            'pinnerpress_follow_button_default_color' => '#E60023',
            'pinnerpress_follow_button_default_text_color' => '#ffffff',
            'pinnerpress_analytics_enabled' => '1',
            'pinnerpress_analytics_ignore_logged_in' => '1',
        ),
        
        // Pin Button Tab options
        'settings' => array(
            'pinnerpress_pin_button_status' => 'on',
            'pinnerpress_hover_button_style' => 'default',
            'pinnerpress_hover_button_position' => 'top-left',
            'pinnerpress_hover_button_shape' => 'round',
            'pinnerpress_hover_button_size' => 'medium',
            'pinnerpress_hover_button_color' => '#E60023',
            'pinnerpress_hover_button_text_color' => '#FFFFFF',
            'pinnerpress_image_shadow' => '1',
            'pinnerpress_custom_button_text' => '',
            'pinnerpress_minimum_image_size' => '250',
            'pinnerpress_exclude_gallery_minimum' => '0',
            'pinnerpress_size_filter_pin_buttons' => '1',
            'pinnerpress_size_filter_image_banners' => '1',
            'pinnerpress_pin_button_custom_selectors_enabled' => '0',
            'pinnerpress_pin_button_custom_selectors' => '',
            'pinnerpress_pin_button_find_images_in_selectors' => '0',
        ),
        
        // Follow Box Tab options
        'follow_box' => array(
            'pinnerpress_follow_box_status' => 'off',
            'pinnerpress_account_description' => __('Follow us on Pinterest for more inspiration!', 'pinnerpress'),
            'pinnerpress_follow_button_bg_color' => '#E60023',
            'pinnerpress_follow_button_text_color' => '#FFFFFF',
            'pinnerpress_follow_box_display_pin_click' => '1',
            'pinnerpress_follow_box_display_page_load' => '0',
            'pinnerpress_follow_box_allow_dismiss' => '0',
            'pinnerpress_header_image' => ''
        ),
        
        // Image Banner Tab options
        'banner' => array(
            'pinnerpress_banner_status' => 'off',
            'pinnerpress_banner_bg_color' => 'rgba(255, 255, 255, 0.5)',
            'pinnerpress_banner_text_color' => '#BD081C',
            'pinnerpress_banner_text' => __('Pin this', 'pinnerpress'),
            'pinnerpress_banner_opacity' => '50',
            'pinnerpress_banner_custom_selectors_enabled' => '0',
            'pinnerpress_banner_custom_selectors' => '',
            'pinnerpress_banner_find_images_in_selectors' => '0',
        ),
        
        // Call Out Banners Tab options
        'call_out' => array(
            'pinnerpress_call_out_status' => 'off',
            'pinnerpress_call_out_position' => 'bottom',
            'pinnerpress_call_out_display_posts' => '1',
            'pinnerpress_call_out_display_pages' => '0',
            'pinnerpress_call_out_style' => 'inline',
            'pinnerpress_call_out_bg_color' => '#E60023',
            'pinnerpress_call_out_border_color' => '#E60023',
            'pinnerpress_call_out_text_color' => '#FFFFFF',
            'pinnerpress_call_out_title' => __('Follow us on Pinterest', 'pinnerpress'),
            'pinnerpress_call_out_description' => '',
            'pinnerpress_call_out_button_text' => __('Follow', 'pinnerpress'),
            'pinnerpress_call_out_button_bg_color' => '#FFFFFF',
            'pinnerpress_call_out_button_text_color' => '#E60023',
            'pinnerpress_call_out_logo' => 'pinterest'
        ),

        // Filters Tab options
        'filters' => array(
            'pinnerpress_category_filter_pin_buttons' => '1',
            'pinnerpress_category_filter_image_banners' => '1',
            'pinnerpress_category_filter_call_out_banners' => '1',
            'pinnerpress_category_filter_follow_boxes' => '1',
            'pinnerpress_excluded_categories' => array(),
            'pinnerpress_size_filter_pin_buttons' => '1',
            'pinnerpress_size_filter_image_banners' => '1',
            'pinnerpress_minimum_image_size' => '250',
            'pinnerpress_exclude_gallery_minimum' => '0'
        ),
    );
}

/**
 * Set a single default option if it doesn't already exist
 * 
 * @since 0.1.0
 * @param string $option Option name
 * @param mixed $value Option value
 * @return bool True if option was added, false otherwise
 */
function pinnerpress_maybe_add_option($option, $value) {
    if (get_option($option) === false) {
        return add_option($option, $value);
    }
    return false;
}

/**
 * Set all default options for the plugin
 * 
 * @since 0.1.0
 */
function pinnerpress_set_default_options() {
    $defaults = pinnerpress_get_default_options();
    
    // Flatten the array to set all options
    foreach ($defaults as $tab => $options) {
        foreach ($options as $option => $value) {
            pinnerpress_maybe_add_option($option, $value);
        }
    }
}

/**
 * Reset options for a specific tab to defaults
 * 
 * @since 0.1.0
 * @param string $tab The tab to reset (general, settings, follow_box, banner, call_out)
 * @return bool True if options were reset, false otherwise
 */
function pinnerpress_reset_tab_options($tab) {
    $defaults = pinnerpress_get_default_options();
    
    // Check if the requested tab exists
    if (!isset($defaults[$tab])) {
        return false;
    }
    
    // Update each option for the tab with default values
    foreach ($defaults[$tab] as $option => $value) {
        update_option($option, $value);
    }
    
    // Ensure color options are explicitly set when resetting tabs
    if ($tab === 'general') {
        // General tab doesn't need special color handling currently
    } else if ($tab === 'settings') {
        // Pin Button Tab color options
        update_option('pinnerpress_hover_button_color', '#E60023');
        update_option('pinnerpress_hover_button_text_color', '#FFFFFF');
        update_option('pinnerpress_hover_button_size', 'medium');
    } else if ($tab === 'follow_box') {
        // Follow Box Tab color options
        update_option('pinnerpress_follow_button_bg_color', '#E60023');
        update_option('pinnerpress_follow_button_text_color', '#FFFFFF');
    } else if ($tab === 'banner') {
        // Image Banner Tab color options
        update_option('pinnerpress_banner_bg_color', 'rgba(255, 255, 255, 0.5)');
        update_option('pinnerpress_banner_text_color', '#BD081C');
        update_option('pinnerpress_banner_opacity', '50');
    } else if ($tab === 'call_out') {
        // Call Out Banners Tab color options
        update_option('pinnerpress_call_out_bg_color', '#E60023');
        update_option('pinnerpress_call_out_border_color', '#E60023');
        update_option('pinnerpress_call_out_text_color', '#FFFFFF');
        update_option('pinnerpress_call_out_button_bg_color', '#FFFFFF');
        update_option('pinnerpress_call_out_button_text_color', '#E60023');
    }
    
    return true;
}

/**
 * Set all color values to their defaults
 * 
 * This function can be called from the admin page or during troubleshooting
 * to reset all color options to their default values.
 * 
 * @since 0.1.0
 */
function pinnerpress_reset_all_color_options() {
    // Pin Button Tab color options
    update_option('pinnerpress_hover_button_color', '#E60023');
    update_option('pinnerpress_hover_button_text_color', '#FFFFFF');
    update_option('pinnerpress_hover_button_size', 'medium');
    
    // Follow Box Tab color options
    update_option('pinnerpress_follow_button_bg_color', '#E60023');
    update_option('pinnerpress_follow_button_text_color', '#FFFFFF');
    
    // Image Banner Tab color options
    update_option('pinnerpress_banner_bg_color', 'rgba(255, 255, 255, 0.5)');
    update_option('pinnerpress_banner_text_color', '#BD081C');
    
    // Call Out Banners Tab color options
    update_option('pinnerpress_call_out_bg_color', '#E60023');
    update_option('pinnerpress_call_out_border_color', '#E60023');
    update_option('pinnerpress_call_out_text_color', '#FFFFFF');
    update_option('pinnerpress_call_out_button_bg_color', '#FFFFFF');
    update_option('pinnerpress_call_out_button_text_color', '#E60023');
} 