<?php
/**
 * Theme Palace options
 *
 * @package Theme Palace
 * @subpackage Newstation
 * @since Newstation 1.0.0
 */

/**
 * List of pages for page choices.
 * @return Array Array of page ids and name.
 */
function newstation_page_choices() {
    $pages = get_pages();
    $choices = array();
    $choices[0] = esc_html__( '--Select--', 'newstation' );
    foreach ( $pages as $page ) {
        $choices[ $page->ID ] = $page->post_title;
    }
    return  $choices;
}

/**
 * List of posts for post choices.
 * @return Array Array of post ids and name.
 */
function newstation_post_choices() {
    $posts = get_posts( array( 'numberposts' => -1 ) );
    $choices = array();
    $choices[0] = esc_html__( '--Select--', 'newstation' );
    foreach ( $posts as $post ) {
        $choices[ $post->ID ] = $post->post_title;
    }
    return  $choices;
}

/**
 * List of category for category choices.
 * @return Array Array of post ids and name.
 */
function newstation_category_choices() {
    $tax_args = array(
        'hierarchical' => 0,
        'taxonomy'     => 'category',
    );
    $taxonomies = get_categories( $tax_args );
    $choices = array();
    $choices[0] = esc_html__( '--Select--', 'newstation' );
    foreach ( $taxonomies as $tax ) {
        $choices[ $tax->term_id ] = $tax->name;
    }
    return  $choices;
}

/**
 * List of products for post choices.
 * @return Array Array of post ids and name.
 */
function newstationduct_choices() {
    $posts = get_posts( array( 'numberposts' => -1, 'post_type' => 'product' ) );
    $choices = array();
    $choices[0] = esc_html__( '--Select--', 'newstation' );
    foreach ( $posts as $post ) {
        $choices[ $post->ID ] = $post->post_title;
    }
    return  $choices;
}

/**
 * List of category for category choices.
 * @return Array Array of post ids and name.
 */
function newstationduct_category_choices() {
    $tax_args = array(
        'hierarchical' => 0,
        'taxonomy'     => 'product_cat',
    );
    $taxonomies = get_categories( $tax_args );
    $choices = array();
    $choices[0] = esc_html__( '--Select--', 'newstation' );
    foreach ( $taxonomies as $tax ) {
        $choices[ $tax->term_id ] = $tax->name;
    }
    return  $choices;
}

if ( ! function_exists( 'newstation_menus_section_content_type' ) ) :
    /**
     * Product Options
     * @return array site product options
     */
    function newstation_menus_section_content_type() {
        $newstation_menus_section_content_type = array(
            'category'  => esc_html__( 'Category', 'newstation' ),

        );

        if(class_exists('WooCommerce')){
            $newstation_menus_section_content_type = array_merge($newstation_menus_section_content_type, 
                array(
                    'product-category'   => esc_html__( 'Product Category', 'newstation' ),
                )
            );
        }

        $output = apply_filters( 'newstation_menus_section_content_type', $newstation_menus_section_content_type );

        return $output;
    }
endif;

if ( ! function_exists( 'newstation_typography_options' ) ) :
    /**
     * Returns list of typography
     * @return array font styles
     */
    function newstation_typography_options(){
        $font_family_arr = array();
        $font_family_arr[''] = esc_html__( '--Default--', 'newstation' );

        // Make the request
        $request = wp_remote_get( get_theme_file_uri( 'assets/webfonts.json' ) );

        if( is_wp_error( $request ) ) {
            return false; // Bail early
        }
        // Retrieve the data
        $body = wp_remote_retrieve_body( $request );
        $data = json_decode( $body );
        if ( ! empty( $data ) ) {
            foreach ( $data->items as $items => $fonts ) {
                $family_str_arr = explode( ' ', $fonts->family );
                $family_value = implode( '+', $family_str_arr );
                $font_family_arr[ $family_value ] = $fonts->family;
            }
        }

        return $font_family_arr;
    }
endif;

if ( ! function_exists( 'newstation_body_typography_options' ) ) :
    /**
     * Returns list of typography
     * @return array font styles
     */
    function newstation_body_typography_options(){
        $choices = array(
            'default'         => esc_html__( 'Default', 'newstation' ),
            'body-font-1'     => esc_html__( 'News Cycle', 'newstation' ),
            'body-font-2'     => esc_html__( 'Pontano Sans', 'newstation' ),
            'body-font-3'     => esc_html__( 'Gudea', 'newstation' ),
            'body-font-4'     => esc_html__( 'Quattrocento', 'newstation' ),
            'body-font-5'     => esc_html__( 'Khand', 'newstation' ),
        );

        $output = apply_filters( 'newstation_body_typography_options', $choices );
        if ( ! empty( $output ) ) {
            ksort( $output );
        }

        return $output;
    }
endif;

if ( ! function_exists( 'newstation_site_layout' ) ) :
    /**
     * Site Layout
     * @return array site layout options
     */
    function newstation_site_layout() {
        $newstation_site_layout = array(
            'wide'  => get_template_directory_uri() . '/assets/images/full.png',
            'boxed-layout' => get_template_directory_uri() . '/assets/images/boxed.png',
        );

        $output = apply_filters( 'newstation_site_layout', $newstation_site_layout );
        return $output;
    }
endif;

if ( ! function_exists( 'newstation_selected_sidebar' ) ) :
    /**
     * Sidebars options
     * @return array Sidbar positions
     */
    function newstation_selected_sidebar() {
        $newstation_selected_sidebar = array(
            'sidebar-1'             => esc_html__( 'Default Sidebar', 'newstation' ),
            'optional-sidebar'      => esc_html__( 'Optional Sidebar 1', 'newstation' ),
            'optional-sidebar-2'    => esc_html__( 'Optional Sidebar 2', 'newstation' ),
            'optional-sidebar-3'    => esc_html__( 'Optional Sidebar 3', 'newstation' ),
            'optional-sidebar-4'    => esc_html__( 'Optional Sidebar 4', 'newstation' ),
        );

        $output = apply_filters( 'newstation_selected_sidebar', $newstation_selected_sidebar );

        return $output;
    }
endif;

if ( ! function_exists( 'newstation_global_sidebar_position' ) ) :
    /**
     * Global Sidebar position
     * @return array Global Sidebar positions
     */
    function newstation_global_sidebar_position() {
        $newstation_global_sidebar_position = array(
            'right-sidebar' => get_template_directory_uri() . '/assets/images/right.png',
            'no-sidebar'    => get_template_directory_uri() . '/assets/images/full.png',
        );

        $output = apply_filters( 'newstation_global_sidebar_position', $newstation_global_sidebar_position );

        return $output;
    }
endif;

if ( ! function_exists( 'newstation_sidebar_position' ) ) :
    /**
     * Sidebar position
     * @return array Sidbar positions
     */
    function newstation_sidebar_position() {
        $newstation_sidebar_position = array(
            'right-sidebar' => get_template_directory_uri() . '/assets/images/right.png',
            'no-sidebar'    => get_template_directory_uri() . '/assets/images/full.png',
        );

        $output = apply_filters( 'newstation_sidebar_position', $newstation_sidebar_position );

        return $output;
    }
endif;

if ( ! function_exists( 'newstation_pagination_options' ) ) :
    /**
     * Pagination
     * @return array site pagination options
     */
    function newstation_pagination_options() {
        $newstation_pagination_options = array(
            'numeric'   => esc_html__( 'Numeric', 'newstation' ),
            'default'   => esc_html__( 'Default(Older/Newer)', 'newstation' ),
        );

        $output = apply_filters( 'newstation_pagination_options', $newstation_pagination_options );

        return $output;
    }
endif;

if ( ! function_exists( 'newstation_get_spinner_list' ) ) :
    /**
     * List of spinner icons options.
     * @return array List of all spinner icon options.
     */
    function newstation_get_spinner_list() {
        $arr = array(
            'default'               => esc_html__( 'Default', 'newstation' ),
            'spinner-wheel'         => esc_html__( 'Wheel', 'newstation' ),
            'spinner-double-circle' => esc_html__( 'Double Circle', 'newstation' ),
            'spinner-two-way'       => esc_html__( 'Two Way', 'newstation' ),
            'spinner-umbrella'      => esc_html__( 'Umbrella', 'newstation' ),
            'spinner-dots'          => esc_html__( 'Dots', 'newstation' ),
            'spinner-one-way'       => esc_html__( 'One Way', 'newstation' ),
            'spinner-fidget'        => esc_html__( 'Fidget', 'newstation' ),
        );
        return apply_filters( 'newstation_spinner_list', $arr );
    }
endif;

if ( ! function_exists( 'newstation_switch_options' ) ) :
    /**
     * List of custom Switch Control options
     * @return array List of switch control options.
     */
    function newstation_switch_options() {
        $arr = array(
            'on'        => esc_html__( 'Enable', 'newstation' ),
            'off'       => esc_html__( 'Disable', 'newstation' )
        );
        return apply_filters( 'newstation_switch_options', $arr );
    }
endif;

if ( ! function_exists( 'newstation_hide_options' ) ) :
    /**
     * List of custom Switch Control options
     * @return array List of switch control options.
     */
    function newstation_hide_options() {
        $arr = array(
            'on'        => esc_html__( 'Yes', 'newstation' ),
            'off'       => esc_html__( 'No', 'newstation' )
        );
        return apply_filters( 'newstation_hide_options', $arr );
    }
endif;

if ( ! function_exists( 'newstationduct_content_type' ) ) :
    /**
     * Product Options
     * @return array site product options
     */
    function newstationduct_content_type() {
        $newstationduct_content_type = array(
            'product'   => esc_html__( 'Product', 'newstation' ),
            'product-category'   => esc_html__( 'Product Category', 'newstation' ),
        );

        $output = apply_filters( 'newstationduct_content_type', $newstationduct_content_type );

        return $output;
    }

endif;