<?php 

/* ----------------------------------------------------------------------------- */
/* Setting Sections And Fields */
/* ----------------------------------------------------------------------------- */ 

function endless_addons_initialize_global_options() {  
    add_settings_section( 'page_1_section', '', '', 'endless-addons-menu-slug-1' );
    add_settings_section( 'page_2_section', '', '', 'endless-addons-menu-slug-2' );
    add_settings_section( 'page_3_section', '', '', 'endless-addons-menu-slug-3' );
    add_settings_section( 'page_4_section', '', '', 'endless-addons-menu-slug-4' );
    add_settings_section( 'page_5_section', '', '', 'endless-addons-menu-slug-5' );
    add_settings_section( 'page_6_section', '', '', 'endless-addons-menu-slug-6' );

    require plugin_dir_path( __FILE__ ) . 'options/option-1.php';
    require plugin_dir_path( __FILE__ ) . 'options/option-2.php';
    require plugin_dir_path( __FILE__ ) . 'options/option-3.php';
    require plugin_dir_path( __FILE__ ) . 'options/option-4.php';
    require plugin_dir_path( __FILE__ ) . 'options/option-5.php';
    require plugin_dir_path( __FILE__ ) . 'options/option-6.php';    

}
add_action('admin_init', 'endless_addons_initialize_global_options');

    require plugin_dir_path( __FILE__ ) . 'fields/field-1.php';
    require plugin_dir_path( __FILE__ ) . 'fields/field-2.php';
    require plugin_dir_path( __FILE__ ) . 'fields/field-3.php';
    require plugin_dir_path( __FILE__ ) . 'fields/field-4.php';
    require plugin_dir_path( __FILE__ ) . 'fields/field-5.php';
    require plugin_dir_path( __FILE__ ) . 'fields/field-6.php';

/* ----------------------------------------------------------------------------- */
/* Add Menu Page */
/* ----------------------------------------------------------------------------- */ 

function endless_addons_menu() {
    add_menu_page( __('Endless Addons', 'endless-addons'), __('Endless Addons', 'endless-addons'), 'manage_options', 'endless-addons-plugin-options', 'endless_addons_plugin_menu_page', plugins_url('/endless-addons-for-elementor/admin/img/icon-2.png'), '58' );
}
add_action('admin_menu', 'endless_addons_menu');

function endless_addons_plugin_menu_page() {
        ?>
        <?php  
        if( isset( $_GET[ 'tab' ] ) ) {  
            $active_tab = $_GET[ 'tab' ];  
        } else {
            $active_tab = 'tab_general';
        }
        ?>  
        <div class="endad-wrap">
            <div class="endad-top-header">
                <div class="endad-top-header-left">
                    <div class="endad-top-header-logo">
                        <img src="<?php echo plugin_dir_url( dirname( __FILE__ ) ) . 'admin/img/logo.png'; ?>" alt="Logo" />
                    </div>
                </div>
                <div class="endad-top-header-right">
                    <a href="https://endless-addons.com" target="_blank" rel="nofollow" class="endad-btn">
                        <?php echo esc_html__('Check Demo', 'endless-addons'); ?>
                    </a>
                </div>
            </div>
            <?php settings_errors(); ?> 
            <div class="endad-nav-tab-wrapper">
                <ul class="endad-nav-tab">  
                    <li><a href="?page=endless-addons-plugin-options&tab=tab_general" class="endad-nav-tab <?php echo $active_tab == 'tab_general' ? 'endad-nav-tab-active' : ''; ?>"><?php echo esc_html__('General', 'endless-addons'); ?></a></li>  <li><a href="?page=endless-addons-plugin-options&tab=tab_widgets" class="endad-nav-tab <?php echo $active_tab == 'tab_widgets' ? 'endad-nav-tab-active' : ''; ?>"><?php echo esc_html__('Widgets', 'endless-addons'); ?></a></li> 
                    <li><a href="?page=endless-addons-plugin-options&tab=tab_features" class="endad-nav-tab <?php echo $active_tab == 'tab_features' ? 'endad-nav-tab-active' : ''; ?>"><?php echo esc_html__('Features', 'endless-addons'); ?></a></li> 
                    <!--<li><a href="?page=endless-addons-plugin-options&tab=tab_four" class="endad-nav-tab <?php echo $active_tab == 'tab_four' ? 'endad-nav-tab-active' : ''; ?>"><?php echo esc_html__('Review', 'endless-addons'); ?></a></li> 
                    <li><a href="?page=endless-addons-plugin-options&tab=tab_five" class="endad-nav-tab <?php echo $active_tab == 'tab_five' ? 'endad-nav-tab-active' : ''; ?>"><?php echo esc_html__('Support', 'endless-addons'); ?></a></li>-->
                    <li><a href="?page=endless-addons-plugin-options&tab=tab_premium" class="endad-nav-tab <?php echo $active_tab == 'tab_premium' ? 'endad-nav-tab-active' : ''; ?>"><?php echo esc_html__('Premium', 'endless-addons'); ?></a></li> 
                </ul>   
                <form method="post" class="endad-nav-tab-content" action="options.php"> 
                <?php
                    if( $active_tab == 'tab_general' ) { ?>
                        <div class="endad-nav-tab-general"> 
                        <?php settings_fields( 'setting-group-1' );
                        do_settings_sections( 'endless-addons-menu-slug-1' ); ?>
                        </div>
                    <?php } 
                    else if( $active_tab == 'tab_widgets' )  { ?>
                        <div class="endad-nav-tab-widgets">
                            <h2><?php echo esc_html__('Enable/Disable All Endless Widgets', 'endless-addons'); ?></h2>
                            <div class="endad-nav-tab-btn-group">
                                <button type="button" class="btn-show-all-widget"><?php echo esc_html__('Enable All', 'endless-addons'); ?></button>
                                <button type="button" class="btn-hide-all-widget"><?php echo esc_html__('Disable All', 'endless-addons'); ?></button>
                            </div>
                            <?php submit_button('', 'primary', 'ea-submit-btn'); ?>
                            <?php settings_fields( 'setting-group-2' );
                            do_settings_sections( 'endless-addons-menu-slug-2' );
                            submit_button('', 'primary', 'ea-submit-btn'); ?>
                        </div>
                    <?php }
                    else if( $active_tab == 'tab_features' )  { ?>
                        <div class="endad-nav-tab-features">
                            <?php settings_fields( 'setting-group-3' );
                            do_settings_sections( 'endless-addons-menu-slug-3' ); ?>
                        </div>
                    <?php }
                    /*else if( $active_tab == 'tab_four' )  {
                        settings_fields( 'setting-group-4' );
                        do_settings_sections( 'endless-addons-menu-slug-4' );
                    }
                    else if( $active_tab == 'tab_five' )  {
                        settings_fields( 'setting-group-5' );
                        do_settings_sections( 'endless-addons-menu-slug-5' );
                    }*/
                    else if( $active_tab == 'tab_premium' )  { ?>
                        <div class="endad-nav-tab-premium">
                        <?php 
                            settings_fields( 'setting-group-6' );
                            do_settings_sections( 'endless-addons-menu-slug-6' );
                        ?>
                        </div> 
                    <?php } ?>
                </form> 
            </div>
        </div>
    <?php
}
