<?php
/**
 * Plugin Settings
 *
 * @package cyberpress
 */

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

/**
 * CyberPress Settings Class
 */
class CyberPress_Settings {
    /**
     * Settings API instance
     *
     * @var object
     */
    public static $settings_api;

    /**
     * Names of custom posts used in the plugin
     *
     * @var array
     */
    public static $custom_post_names = array(
        'game',
        'player',
        'team',
        'match',
        'tournament',
    );

    /**
     * Names of settings for options for linking a page to a list of posts
     *
     * @var array
     */
    public static $page_list_option_names = array(
        'games',
        'players',
        'teams',
        'matches',
        'tournaments',
    );

    /**
     * CyberPress_Settings constructor.
     */
    public function __construct() {
        self::init_actions();
    }

    /**
     * Init actions
     */
    public static function init_actions() {
        self::$settings_api = new CyberPress_Settings_API();

        add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
        // add admin menu.
        add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
        // highlight admin menu items.
        add_filter( 'parent_file', array( __CLASS__, 'admin_menu_highlight_items' ) );
    }

    /**
     * Initialize the settings
     *
     * @return void
     */
    public static function admin_init() {
        // set the settings.
        self::$settings_api->set_sections( self::get_settings_sections() );
        self::$settings_api->set_fields( self::get_settings_fields() );

        // initialize settings.
        self::$settings_api->admin_init();
    }

    /**
     * Register the admin menu
     *
     * @return void
     */
    public static function admin_menu() {
        add_menu_page(
            esc_html__( 'CyberPress', 'cyberpress' ),
            esc_html__( 'CyberPress', 'cyberpress' ),
            'manage_options',
            'cyberpress',
            null,
            'dashicons-cyberpress',
            20
        );
        add_submenu_page(
            'cyberpress',
            esc_html__( 'Matches', 'cyberpress' ),
            esc_html__( 'Matches', 'cyberpress' ),
            'manage_options',
            'edit.php?post_type=match'
        );
        add_submenu_page(
            'cyberpress',
            esc_html__( 'Tournaments', 'cyberpress' ),
            esc_html__( 'Tournaments', 'cyberpress' ),
            'manage_options',
            'edit.php?post_type=tournament'
        );
        add_submenu_page(
            'cyberpress',
            esc_html__( 'Players', 'cyberpress' ),
            esc_html__( 'Players', 'cyberpress' ),
            'manage_options',
            'edit.php?post_type=player'
        );
        add_submenu_page(
            'cyberpress',
            esc_html__( 'Teams', 'cyberpress' ),
            esc_html__( 'Teams', 'cyberpress' ),
            'manage_options',
            'edit.php?post_type=team'
        );
        add_submenu_page(
            'cyberpress',
            esc_html__( 'Games', 'cyberpress' ),
            esc_html__( 'Games', 'cyberpress' ),
            'manage_options',
            'edit.php?post_type=game'
        );
        add_submenu_page(
            'cyberpress',
            esc_html__( 'Settings', 'cyberpress' ),
            esc_html__( 'Settings', 'cyberpress' ),
            'manage_options',
            'cyberpress-settings',
            array( __CLASS__, 'print_settings_page' )
        );
    }

    /**
     * Highlighting game custom menu items
     *
     * @param string $parent_file - parent file.
     *
     * @return string $parent_file
     */
    public static function admin_menu_highlight_items( $parent_file ) {
        global $current_screen, $submenu_file, $submenu;

        // Highlight menus.
        switch ( $current_screen->post_type ) {
            case 'match':
            case 'game':
            case 'team':
            case 'player':
            case 'tournament':
                $parent_file = 'cyberpress';
                break;
        }
        // Remove 'cyberpress' sub menu item.
        if ( isset( $submenu['cyberpress'] ) ) {
            unset( $submenu['cyberpress'][0] );
        }

        return $parent_file;
    }

    /**
     * Plugin settings sections
     *
     * @return array
     */
    public static function get_settings_sections() {
        $sections = array(
            array(
                'id'    => 'cyberpress_general',
                'title' => esc_html__( 'General', 'cyberpress' ),
            ),
            array(
                'id'    => 'cyberpress_games',
                'title' => esc_html__( 'Games', 'cyberpress' ),
            ),
            array(
                'id'    => 'cyberpress_matches',
                'title' => esc_html__( 'Matches', 'cyberpress' ),
            ),
            array(
                'id'    => 'cyberpress_tournaments',
                'title' => esc_html__( 'Tournaments', 'cyberpress' ),
            ),
            array(
                'id'    => 'cyberpress_players',
                'title' => esc_html__( 'Players', 'cyberpress' ),
            ),
            array(
                'id'    => 'cyberpress_teams',
                'title' => esc_html__( 'Teams', 'cyberpress' ),
            ),
        );

        return $sections;
    }

    /**
     * Returns all the settings fields
     *
     * @param bool $get_pages - Get Pages Options.
     *
     * @return array
     */
    public static function get_settings_fields( $get_pages = true ) {
        $pages                    = $get_pages ? self::get_pages() : array();
        $page_settings_fields     = array();
        $cyberpress_archive_pages = get_option( 'cyberpress_archive_pages' );
        $cyberpress_archive_pages = $cyberpress_archive_pages ? $cyberpress_archive_pages : array();

        if ( isset( $pages ) && ! empty( $pages ) && is_array( $pages ) && $get_pages ) {
            $games_page             = array_search( 'games', $cyberpress_archive_pages, true );
            $page_settings_fields[] = array(
                'name'       => 'games_list_page_id',
                'label'      => esc_html__( 'Games Archive', 'cyberpress' ),
                'type'       => 'select2',
                'find_pages' => true,
                'default'    => $games_page ? $games_page : '',
                'options'    => $pages,
            );

            $players_page           = array_search( 'players', $cyberpress_archive_pages, true );
            $page_settings_fields[] = array(
                'name'       => 'players_list_page_id',
                'label'      => esc_html__( 'Players Archive', 'cyberpress' ),
                'type'       => 'select2',
                'find_pages' => true,
                'default'    => $players_page ? $players_page : '',
                'options'    => $pages,
            );

            $teams_page             = array_search( 'teams', $cyberpress_archive_pages, true );
            $page_settings_fields[] = array(
                'name'       => 'teams_list_page_id',
                'label'      => esc_html__( 'Teams Archive', 'cyberpress' ),
                'type'       => 'select2',
                'find_pages' => true,
                'default'    => $teams_page ? $teams_page : '',
                'options'    => $pages,
            );

            $matches_page           = array_search( 'matches', $cyberpress_archive_pages, true );
            $page_settings_fields[] = array(
                'name'       => 'matches_list_page_id',
                'label'      => esc_html__( 'Matches Archive', 'cyberpress' ),
                'type'       => 'select2',
                'find_pages' => true,
                'default'    => $matches_page ? $matches_page : '',
                'options'    => $pages,
            );

            $tournaments_page       = array_search( 'tournaments', $cyberpress_archive_pages, true );
            $page_settings_fields[] = array(
                'name'       => 'tournaments_list_page_id',
                'label'      => esc_html__( 'Tournaments Archive', 'cyberpress' ),
                'type'       => 'select2',
                'find_pages' => true,
                'default'    => $tournaments_page ? $tournaments_page : '',
                'options'    => $pages,
            );
        } else {
            $page_settings_fields[] = array(
                'name'        => 'pages_not_found',
                'desc'        => esc_html__( 'There are no pages found on your site. You need to add pages to use it for archives of games, players, teams, matches, and tournaments.', 'cyberpress' ),
                'type'        => 'html',
            );
        }

        $image_sizes = array(
            'full' => 'full',
        );
        // @codingStandardsIgnoreLine
        $available_image_sizes = get_intermediate_image_sizes();
        foreach ( $available_image_sizes as $size ) {
            $image_sizes[ $size ] = $size;
        }

        $settings_fields = array(
            'cyberpress_general'     => $page_settings_fields,
            'cyberpress_games'       => array(
                array(
                    'name'    => 'games_archive_columns',
                    'label'   => esc_html__( 'Archive Columns', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 3,
                    'min'     => 1,
                    'max'     => 6,
                ),
                array(
                    'name'    => 'games_archive_count',
                    'label'   => esc_html__( 'Number of Games', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 10,
                    'min'     => 1,
                ),
                array(
                    'name'    => 'games_archive_thumbnail_size',
                    'label'   => esc_html__( 'Archive Thumbnail Size', 'cyberpress' ),
                    'type'    => 'select',
                    'default' => 'medium',
                    'options' => $image_sizes,
                ),
                array(
                    'name'    => 'games_archive_display_thumbnail',
                    'label'   => esc_html__( 'Display Game Thumbnail', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'games_archive_display_title',
                    'label'   => esc_html__( 'Display Game Title', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
            ),
            'cyberpress_matches'     => array(
                array(
                    'name'    => 'matches_archive_columns',
                    'label'   => esc_html__( 'Archive Columns', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 1,
                    'min'     => 1,
                    'max'     => 6,
                ),
                array(
                    'name'    => 'matches_archive_count',
                    'label'   => esc_html__( 'Number of Matches', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 6,
                    'min'     => 1,
                ),
                array(
                    'name'    => 'matches_archive_display_title',
                    'label'   => esc_html__( 'Display Match Title', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'off',
                ),
                array(
                    'name'  => 'matches_archive_participants',
                    'label' => esc_html__( 'Participants:', 'cyberpress' ),
                    'type'  => 'html',
                ),
                array(
                    'name'    => 'matches_archive_display_start_date',
                    'label'   => esc_html__( 'Display Match Start Date', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'matches_archive_display_points',
                    'label'   => esc_html__( 'Display Match Points', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'matches_archive_display_team_logo',
                    'label'   => esc_html__( 'Display Team Logo', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'matches_archive_display_team_name',
                    'label'   => esc_html__( 'Display Team Name', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'matches_archive_display_team_players',
                    'label'   => esc_html__( 'Display Team Players', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'off',
                ),
                array(
                    'name'  => 'matches_archive_meta',
                    'label' => esc_html__( 'Meta:', 'cyberpress' ),
                    'type'  => 'html',
                ),
                array(
                    'name'    => 'matches_archive_display_game',
                    'label'   => esc_html__( 'Display Game', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'matches_archive_display_tournament',
                    'label'   => esc_html__( 'Display Tournament', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'matches_archive_display_tournament_stage',
                    'label'   => esc_html__( 'Display Tournament Stage', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'matches_archive_display_meta_start_date',
                    'label'   => esc_html__( 'Display Match Start Date', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'off',
                ),
                array(
                    'name'    => 'matches_archive_display_meta_end_date',
                    'label'   => esc_html__( 'Display Match End Date', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'off',
                ),
                array(
                    'name'    => 'matches_archive_display_read_more',
                    'label'   => esc_html__( 'Display Read More Button', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'off',
                ),
            ),
            'cyberpress_tournaments' => array(
                array(
                    'name'    => 'tournaments_archive_columns',
                    'label'   => esc_html__( 'Archive Columns', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 3,
                    'min'     => 1,
                    'max'     => 4,
                ),
                array(
                    'name'    => 'tournaments_archive_count',
                    'label'   => esc_html__( 'Number of Tournaments', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 6,
                    'min'     => 1,
                ),
                array(
                    'name'    => 'tournament_archive_display_title',
                    'label'   => esc_html__( 'Display Tournament Title', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'tournament_archive_display_date',
                    'label'   => esc_html__( 'Display Tournament Date', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'tournament_archive_display_game',
                    'label'   => esc_html__( 'Display Tournament Game', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'tournament_archive_display_total_prize_pool',
                    'label'   => esc_html__( 'Display Tournament Total Prize Pool', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
            ),
            'cyberpress_players'     => array(
                array(
                    'name'    => 'players_archive_columns',
                    'label'   => esc_html__( 'Archive Columns', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 3,
                    'min'     => 1,
                    'max'     => 6,
                ),
                array(
                    'name'    => 'players_archive_count',
                    'label'   => esc_html__( 'Number of Players', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 6,
                    'min'     => 1,
                ),
                array(
                    'name'    => 'players_archive_thumbnail_size',
                    'label'   => esc_html__( 'Archive Thumbnail Size', 'cyberpress' ),
                    'type'    => 'select',
                    'default' => 'large',
                    'options' => $image_sizes,
                ),
                array(
                    'name'    => 'players_archive_display_thumbnail',
                    'label'   => esc_html__( 'Display Player Thumbnail', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'players_archive_display_title',
                    'label'   => esc_html__( 'Display Player Title', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'players_archive_display_full_name',
                    'label'   => esc_html__( 'Display Player Full Name', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'players_archive_display_gender',
                    'label'   => esc_html__( 'Display Player Gender', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'players_archive_display_country',
                    'label'   => esc_html__( 'Display Player Country', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'players_archive_display_age',
                    'label'   => esc_html__( 'Display Player Age', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
            ),
            'cyberpress_teams'       => array(
                array(
                    'name'    => 'teams_archive_columns',
                    'label'   => esc_html__( 'Archive Columns', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 3,
                    'min'     => 1,
                    'max'     => 6,
                ),
                array(
                    'name'    => 'teams_archive_count',
                    'label'   => esc_html__( 'Number of Teams', 'cyberpress' ),
                    'type'    => 'number',
                    'default' => 6,
                    'min'     => 1,
                ),
                array(
                    'name'    => 'teams_archive_thumbnail_size',
                    'label'   => esc_html__( 'Archive Thumbnail Size', 'cyberpress' ),
                    'type'    => 'select',
                    'default' => 'large',
                    'options' => $image_sizes,
                ),
                array(
                    'name'    => 'teams_archive_display_thumbnail',
                    'label'   => esc_html__( 'Display Team Thumbnail', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'teams_archive_display_title',
                    'label'   => esc_html__( 'Display Team Title', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'teams_archive_display_country',
                    'label'   => esc_html__( 'Display Team Country', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'teams_archive_display_founded',
                    'label'   => esc_html__( 'Display Team Founded Date', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'teams_archive_display_game',
                    'label'   => esc_html__( 'Display Team Game', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'    => 'teams_archive_display_count_of_players',
                    'label'   => esc_html__( 'Display Count of Team Players', 'cyberpress' ),
                    'type'    => 'checkbox',
                    'default' => 'on',
                ),
                array(
                    'name'     => 'teams_player_roles',
                    'label'    => esc_html__( 'Player Roles', 'cyberpress' ),
                    'type'     => 'repeatable',
                    'children' => array(
                        array(
                            'name'              => 'slug',
                            'label'             => esc_html__( 'Slug', 'cyberpress' ),
                            'type'              => 'text',
                        ),
                        array(
                            'name'              => 'name',
                            'label'             => esc_html__( 'Name', 'cyberpress' ),
                            'type'              => 'text',
                        ),
                    ),
                    'default'  => '{"slug":["lead","player","coach","substitute"],"name":["Team Lead","Player","Coach","Substitute"]}',
                ),
            ),
        );
        return $settings_fields;
    }


    /**
     * Get Option Value
     *
     * @param string $option - option name.
     * @param string $section - section name.
     *
     * @return bool|string
     */
    public static function get_option( $option, $section ) {
        $options = get_option( $section );
        $value   = false;

        if ( isset( $options[ $option ] ) ) {
            $value = $options[ $option ];
        } else {
            $options = self::get_settings_fields( false )[ $section ];

            if ( isset( $options ) && ! empty( $options ) && is_array( $options ) ) {
                foreach ( $options as $search_option ) {
                    if ( $search_option['name'] === $option ) {
                        $value = $search_option['default'];
                    }
                }
            }
        }

        return 'off' === $value ? false : ( 'on' === $value ? true : $value );
    }

    /**
     * Get Group Posts Option Values
     *
     * @param string $type - group type.
     * @return array|bool
     */
    public static function get_group_options( $type ) {
        $grouped_options = false;
        $section         = 'cyberpress_' . $type;
        switch ( $type ) {
            case 'games':
                $grouped_options = array(
                    'columns'               => self::get_option( 'games_archive_columns', $section ),
                    'count'                 => self::get_option( 'games_archive_count', $section ),
                    'displayMetaThumbnail'  => self::get_option( 'games_archive_display_thumbnail', $section ),
                    'displayMetaTitle'      => self::get_option( 'games_archive_display_title', $section ),
                    'displayPagination'     => true,
                );
                break;
            case 'players':
                $grouped_options = array(
                    'count'                         => self::get_option( 'players_archive_count', $section ),
                    'columns'                       => self::get_option( 'players_archive_columns', $section ),
                    'displayMetaThumbnail'          => self::get_option( 'players_archive_display_thumbnail', $section ),
                    'displayMetaTitle'              => self::get_option( 'players_archive_display_title', $section ),
                    'displayMetaFullName'           => self::get_option( 'players_archive_display_full_name', $section ),
                    'displayMetaGender'             => self::get_option( 'players_archive_display_gender', $section ),
                    'displayMetaCountry'            => self::get_option( 'players_archive_display_country', $section ),
                    'displayMetaAge'                => self::get_option( 'players_archive_display_age', $section ),
                    'displayPagination'             => true,
                );
                break;
            case 'teams':
                $grouped_options = array(
                    'count'                     => self::get_option( 'teams_archive_count', $section ),
                    'columns'                   => self::get_option( 'teams_archive_columns', $section ),
                    'displayMetaThumbnail'      => self::get_option( 'teams_archive_display_thumbnail', $section ),
                    'displayMetaTitle'          => self::get_option( 'teams_archive_display_title', $section ),
                    'displayMetaCountry'        => self::get_option( 'teams_archive_display_country', $section ),
                    'displayMetaFoundedDate'    => self::get_option( 'teams_archive_display_founded', $section ),
                    'displayMetaGameTitle'      => self::get_option( 'teams_archive_display_game', $section ),
                    'displayMetaCountOfPlayers' => self::get_option( 'teams_archive_display_count_of_players', $section ),
                    'displayPagination'         => true,
                );
                break;
            case 'matches':
                $grouped_options = array(
                    'count'                         => self::get_option( 'matches_archive_count', $section ),
                    'columns'                       => self::get_option( 'matches_archive_columns', $section ),
                    'displayMetaGame'               => self::get_option( 'matches_archive_display_game', $section ),
                    'displayMetaTournament'         => self::get_option( 'matches_archive_display_tournament', $section ),
                    'displayMetaTournamentStage'    => self::get_option( 'matches_archive_display_tournament_stage', $section ),
                    'displayMetaMatchStartDate'     => self::get_option( 'matches_archive_display_meta_start_date', $section ),
                    'displayMetaMatchEndDate'       => self::get_option( 'matches_archive_display_meta_end_date', $section ),
                    'displayMetaReadMoreButton'     => self::get_option( 'matches_archive_display_read_more', $section ),
                    'displayMatchTitle'             => self::get_option( 'matches_archive_display_title', $section ),
                    'displayMatchStartDate'         => self::get_option( 'matches_archive_display_start_date', $section ),
                    'displayMatchPoints'            => self::get_option( 'matches_archive_display_points', $section ),
                    'displayTeamLogo'               => self::get_option( 'matches_archive_display_team_logo', $section ),
                    'displayTeamName'               => self::get_option( 'matches_archive_display_team_name', $section ),
                    'displayTeamPlayers'            => self::get_option( 'matches_archive_display_team_players', $section ),
                    'displayPagination'             => true,
                );
                break;
            case 'tournaments':
                $grouped_options = array(
                    'count'                     => self::get_option( 'tournaments_archive_count', $section ),
                    'columns'                   => self::get_option( 'tournaments_archive_columns', $section ),
                    'displayMetaTitle'          => self::get_option( 'tournament_archive_display_title', $section ),
                    'displayMetaDate'           => self::get_option( 'tournament_archive_display_date', $section ),
                    'displayMetaGame'           => self::get_option( 'tournament_archive_display_game', $section ),
                    'displayMetaTotalPrizePool' => self::get_option( 'tournament_archive_display_total_prize_pool', $section ),
                    'displayPagination'         => true,
                );
                break;
        }
        return $grouped_options;
    }

    /**
     * Get all the pages
     *
     * @return array page names with key value pairs
     */
    public static function get_pages() {
        $args          = array(
            'sort_order'   => 'ASC',
            'sort_column'  => 'post_title',
            'hierarchical' => 1,
            'exclude'      => '',
            'include'      => '',
            // phpcs:ignore
            'meta_key'     => '',
            // phpcs:ignore
            'meta_value'   => '',
            'authors'      => '',
            'child_of'     => 0,
            'parent'       => -1,
            'exclude_tree' => '',
            'number'       => '',
            'offset'       => 0,
            'post_type'    => 'page',
            'post_status'  => 'publish',
        );
        $pages         = get_pages( $args );
        $pages_options = array();
        if ( $pages ) {
            $pages_options[] = esc_html__( '-- Select Page --', 'cyberpress' );
            foreach ( $pages as $page ) {
                $post_title                 = $page->post_title ? $page->post_title : $page->ID;
                $pages_options[ $page->ID ] = $post_title;
            }
        }
        wp_reset_postdata();
        return $pages_options;
    }

    /**
     * The plugin page handler
     *
     * @return void
     */
    public static function print_settings_page() {
        self::$settings_api->admin_enqueue_scripts();

        echo '<div class="wrap">';
        echo '<h2>' . esc_html__( 'CyberPress Settings', 'cyberpress' ) . '</h2>';

        self::$settings_api->show_navigation();
        self::$settings_api->show_forms();

        echo '</div>';
    }
}

new CyberPress_Settings();
