<?php
if (!defined('SPA_CENTRIC_VERSION')) {
    // Replace the version number of the theme on each release.
    define('SPA_CENTRIC_VERSION', wp_get_theme()->get('Version'));
}
define('SPA_CENTRIC_DEBUG', defined('WP_DEBUG') && WP_DEBUG === true);
define('SPA_CENTRIC_DIR', trailingslashit(get_template_directory()));
define('SPA_CENTRIC_URL', trailingslashit(get_template_directory_uri()));

if (!function_exists('SPA_CENTRIC_support')) :

    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * @since walker_fse 1.0.0
     *
     * @return void
     */
    function SPA_CENTRIC_support()
    {
        // Add default posts and comments RSS feed links to head.
        add_theme_support('automatic-feed-links');
        // Add support for block styles.
        add_theme_support('wp-block-styles');
        add_theme_support('post-thumbnails');
        // Enqueue editor styles.
        add_editor_style('style.css');
    }

endif;
add_action('after_setup_theme', 'SPA_CENTRIC_support');

/*----------------------------------------------------------------------------------
Enqueue Styles
-----------------------------------------------------------------------------------*/
if (!function_exists('SPA_CENTRIC_styles')) :
    function SPA_CENTRIC_styles()
    {
        // registering style for theme
        wp_enqueue_style('spa-centric-style', get_stylesheet_uri(), array(), SPA_CENTRIC_VERSION);
        wp_enqueue_style('spa-centric-blocks-style', get_template_directory_uri() . '/assets/css/blocks.css');
        if (is_rtl()) {
            wp_enqueue_style('spa-centric-rtl-css', get_template_directory_uri() . '/assets/css/rtl.css', 'rtl_css');
        }
        wp_enqueue_script('jquery');
        wp_enqueue_script('spa-centric-scripts', get_template_directory_uri() . '/assets/js/spa-centric-scripts.js', array(), SPA_CENTRIC_VERSION, true);
    }
endif;

add_action('wp_enqueue_scripts', 'SPA_CENTRIC_styles');

/**
 * Enqueue scripts for admin area
 */
function SPA_CENTRIC_admin_style()
{
    $hello_notice_current_screen = get_current_screen();
    if (!empty($_GET['page']) && 'about-spa-centric' === $_GET['page'] || $hello_notice_current_screen->id === 'themes' || $hello_notice_current_screen->id === 'dashboard') {
        wp_enqueue_style('spa-centric-admin-style', get_template_directory_uri() . '/assets/css/admin-style.css', array(), SPA_CENTRIC_VERSION, 'all');
        wp_enqueue_script('spa-centric-admin-scripts', get_template_directory_uri() . '/assets/js/spa-centric-admin-scripts.js', array(), SPA_CENTRIC_VERSION, true);
    }
}
add_action('admin_enqueue_scripts', 'SPA_CENTRIC_admin_style');

/**
 * Enqueue assets scripts for both backend and frontend
 */
function SPA_CENTRIC_block_assets()
{
    wp_enqueue_style('spa-centric-blocks-style', get_template_directory_uri() . '/assets/css/blocks.css');
}
add_action('enqueue_block_assets', 'SPA_CENTRIC_block_assets');

/**
 * Load core file.
 */
require_once get_template_directory() . '/inc/core/init.php';

if (!function_exists('SPA_CENTRIC_excerpt_more_postfix')) {
    function SPA_CENTRIC_excerpt_more_postfix($more)
    {
        if (is_admin()) {
            return $more;
        }
        return '...';
    }
    add_filter('excerpt_more', 'SPA_CENTRIC_excerpt_more_postfix');
}
function SPA_CENTRIC_add_woocommerce_support()
{
    add_theme_support('woocommerce');
}
add_action('after_setup_theme', 'SPA_CENTRIC_add_woocommerce_support');

function get_fse_editor_link() {
    if ( function_exists( 'get_admin_url' ) ) {
        $editor_link = get_admin_url( null, 'site-editor.php' );
        return $editor_link;
    }
    return null;
}


function SPA_CENTRIC_admin_notice_with_buttons() {
    $editor_link = get_fse_editor_link();
    ?>
    <div class="notice notice-info is-dismissible">
        <p><?php _e( 'Upgrade to Pro for more features!', 'spa-centric' ); ?></p>
        <p>
            <a href="https://www.themesionic.com/block-themes/salon-wordpress-theme/" target="_blank" class="button button-primary"><?php _e( 'Upgrade to Pro', 'spa-centric' ); ?></a>
            <a href="https://demo.themesionic.com/spa-centric-pro/" target="_blank" class="button"><?php _e( 'View Demo', 'spa-centric' ); ?></a>
            <a href="<?php echo esc_url( $editor_link ); ?>" target="_blank" class="button"><?php _e( 'Customize', 'spa-centric' ); ?></a>
        </p>
    </div>
    <?php
}
add_action( 'admin_notices', 'SPA_CENTRIC_admin_notice_with_buttons' );

function SPA_CENTRIC_admin_notice_styles() {
    wp_enqueue_style( 'spa-centric-admin-notice', get_template_directory_uri() . '/assets/css/custom-admin-notice.css' );
}
add_action( 'admin_enqueue_scripts', 'SPA_CENTRIC_admin_notice_styles' );



