<?php 

add_action( 'admin_menu', 'business_coach_blocks_menu' );
add_action( 'admin_init', 'business_coach_blocks_register_settings' );

function business_coach_blocks_menu() {
    add_menu_page(
        'Theme Options',
        'Theme Option',
        'manage_options',
        'business_coach_blocks_theme_option',
        'business_coach_blocks_preloader_page_callback',
        'dashicons-screenoptions',
        30
    );
}

function business_coach_blocks_register_settings() {
    register_setting( 'business_coach_blocks_preloader_settings', 'business_coach_blocks_preloader_toggle' );
}

function business_coach_blocks_preloader_page_callback() {
    ?>
    <div class="menu-box">
        <h2><?php echo esc_html('Preloader Setting','business-coach-blocks'); ?></h2>
        <form method="post" action="options.php">
            <?php settings_fields( 'business_coach_blocks_preloader_settings' ); ?>
            <?php $toggle = get_option( 'business_coach_blocks_preloader_toggle', 'off' ); ?>
            <label for="business_coach_blocks_preloader_toggle">
                <input type="checkbox" id="business_coach_blocks_preloader_toggle" name="business_coach_blocks_preloader_toggle" <?php checked( $toggle, 'on' ); ?> />
                <?php echo esc_html('Enable Preloader','business-coach-blocks'); ?>
            </label>
            <?php submit_button(); ?>
        </form>
    </div>
    <?php
}