<?php
/**
* Custom Functions.
*
* @package Omega Digital Store
*/

if( !function_exists( 'omega_digital_store_sanitize_sidebar_option' ) ) :

    // Sidebar Option Sanitize.
    function omega_digital_store_sanitize_sidebar_option( $omega_digital_store_input ){

        $omega_digital_store_metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $omega_digital_store_input,$omega_digital_store_metabox_options ) ){

            return $omega_digital_store_input;

        }

        return;

    }

endif;

if ( ! function_exists( 'omega_digital_store_sanitize_checkbox' ) ) :

	/**
	 * Sanitize checkbox.
	 */
	function omega_digital_store_sanitize_checkbox( $omega_digital_store_checked ) {

		return ( ( isset( $omega_digital_store_checked ) && true === $omega_digital_store_checked ) ? true : false );

	}

endif;


if ( ! function_exists( 'omega_digital_store_sanitize_select' ) ) :

    /**
     * Sanitize select.
     */
    function omega_digital_store_sanitize_select( $omega_digital_store_input, $omega_digital_store_setting ) {
        $omega_digital_store_input = sanitize_text_field( $omega_digital_store_input );
        $choices = $omega_digital_store_setting->manager->get_control( $omega_digital_store_setting->id )->choices;
        return ( array_key_exists( $omega_digital_store_input, $choices ) ? $omega_digital_store_input : $omega_digital_store_setting->default );
    }

endif;

if( !function_exists( 'omega_digital_store_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $omega_digital_store_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function omega_digital_store_sanitize_pagination_type( $omega_digital_store_input ) {
        // Define valid options for the pagination type.
        $omega_digital_store_valid_options = array( 'numeric', 'newer_older' ); // Update valid options to include 'newer_older'

        // If the input is one of the valid options, return it. Otherwise, return the default option ('numeric').
        if ( in_array( $omega_digital_store_input, $omega_digital_store_valid_options, true ) ) {
            return $omega_digital_store_input;
        } else {
            // Return 'numeric' as the fallback if the input is invalid.
            return 'numeric';
        }
    }

endif;


// Sanitize the enable/disable setting for pagination
if( !function_exists('omega_digital_store_sanitize_enable_pagination') ) :
    function omega_digital_store_sanitize_enable_pagination( $omega_digital_store_input ) {
        return (bool) $omega_digital_store_input;
    }
endif;

if( !function_exists( 'omega_digital_store_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function omega_digital_store_sanitize_pagination_meta( $omega_digital_store_input ){

        $omega_digital_store_metabox_options = array( 'Center','Right','Left');
        if( in_array( $omega_digital_store_input,$omega_digital_store_metabox_options ) ){

            return $omega_digital_store_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'omega_digital_store_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function omega_digital_store_sanitize_copyright_alignment_meta( $omega_digital_store_input ){

        $omega_digital_store_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $omega_digital_store_input,$omega_digital_store_metabox_options ) ){

            return $omega_digital_store_input;

        }else{

            return '';

        }
    }

endif;