<?php
if (! defined('ABSPATH')) {
	exit; // Exit if accessed directly.
}
// Main theme setup function that initializes theme features
if (! function_exists('welding_for_elementor_setup')) :

	function welding_for_elementor_setup()
	{
		// Load theme text domain for translation
		load_theme_textdomain('welding-for-elementor', get_template_directory() . '/languages');

		// Add default RSS feed links to head
		add_theme_support('automatic-feed-links');

		// Let WordPress manage the document title
		add_theme_support('title-tag');

		// Enable featured images for posts and pages
		add_theme_support('post-thumbnails');

		add_theme_support('custom-logo', array(
			'height'               => 100,
			'width'                => 200,
			'flex-height'          => true,
			'flex-width'           => true,
			'unlink-homepage-logo' => false,
		));

		// Register navigation menu locations
		register_nav_menus(array(
			'main-menu' => __('Main Menu',      'welding-for-elementor'),
			'mobile-menu' => __('Mobile Menu',      'welding-for-elementor'),
		));

		// Switch default core markup to HTML5
		add_theme_support('html5', array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption'
		));

		// Enable support for different post formats like image, video, gallery, and audio
		add_theme_support('post-formats', array(
			'image',
			'video',
			'gallery',
			'audio',
		));

		// Disable widgets block editor
		remove_theme_support('widgets-block-editor');
	}
endif; // end welding_for_elementor_setup

// Hook the setup function to the 'after_setup_theme' action
add_action('after_setup_theme', 'welding_for_elementor_setup');

// Register widget areas
function welding_for_elementor_widgets_init()
{
	// Blog Sidebar
	register_sidebar(array(
		'name'          => __('Blog Sidebar', 'welding-for-elementor'),
		'id'            => 'blog-sidebar',
		'description'   => __('This widget will display in blog sidebar.', 'welding-for-elementor'),
		'before_widget' => '<div id="%1$s" class="tr-sidebar-widget p-20 tr-radius mb-45 fix %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="tr-sidebar-widget-title mb-20">',
		'after_title'   => '</h3>',
	));
	// Footer widget areas
	register_sidebar(array(
		'name'          => __('Footer widget 01', 'welding-for-elementor'),
		'id'            => 'footer-widget-1',
		'description'   => __('This widget will display in footer widget 01.', 'welding-for-elementor'),
		'before_widget' => '<div id="%1$s" class="tr-footer-widget tr-footer-col-1 mb-50 fix %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="tr-footer-widget-title mb-20">',
		'after_title'   => '</h3>',
	));
	register_sidebar(array(
		'name'          => __('Footer widget 02', 'welding-for-elementor'),
		'id'            => 'footer-widget-2',
		'description'   => __('This widget will display in footer widget 02.', 'welding-for-elementor'),
		'before_widget' => '<div id="%1$s" class="tr-footer-widget tr-footer-col-2 mb-50 fix %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="tr-footer-widget-title mb-20">',
		'after_title'   => '</h3>',
	));
	register_sidebar(array(
		'name'          => __('Footer widget 03', 'welding-for-elementor'),
		'id'            => 'footer-widget-3',
		'description'   => __('This widget will display in footer widget 03.', 'welding-for-elementor'),
		'before_widget' => '<div id="%1$s" class="tr-footer-widget tr-footer-col-3 mb-50 fix %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="tr-footer-widget-title mb-20">',
		'after_title'   => '</h3>',
	));
	register_sidebar(array(
		'name'          => __('Footer widget 04', 'welding-for-elementor'),
		'id'            => 'footer-widget-4',
		'description'   => __('This widget will display in footer widget 04.', 'welding-for-elementor'),
		'before_widget' => '<div id="%1$s" class="tr-footer-widget tr-footer-col-4 mb-50 fix %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="tr-footer-widget-title mb-20">',
		'after_title'   => '</h3>',
	));
}
add_action('widgets_init', 'welding_for_elementor_widgets_init');


// Enqueue theme stylesheets and JavaScript files
function welding_for_elementor_theme_scripts()
{
	// CSS Files
	wp_enqueue_style('bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '5.3.3', 'all');
	wp_enqueue_style('font-awesome', get_template_directory_uri() . '/assets/fontawesome/css/font-awesome.min.css', array(), '4.7.0', 'all');
	wp_enqueue_style('welding-for-elementor-main', get_template_directory_uri() . '/assets/css/style.css', array(), '1.0', 'all');
	wp_enqueue_style('welding-for-elementor-style', get_stylesheet_uri()); //root folder stylesheet

	// JS Files
	wp_enqueue_script('bootstrap-bundle', get_template_directory_uri() . '/assets/js/bootstrap.bundle.js', array('jquery'), '5.3.3', true);
	wp_enqueue_script('welding-for-elementor-main', get_template_directory_uri() . '/assets/js/main.js', array('masonry', 'imagesloaded'), '1.0', true);
}

// Enable threaded comments when needed
if (is_singular() && comments_open() && get_option('thread_comments')) {
	wp_enqueue_script('comment-reply');
}

// Hook scripts function to the wp_enqueue_scripts action
add_action('wp_enqueue_scripts', 'welding_for_elementor_theme_scripts');

 // Enqueue admin scripts and styles.
function welding_for_elementor_enqueue_admin_scripts()
{
	// Only enqueue on admin pages.
	if (! is_admin()) {
		return;
	}

	wp_enqueue_style(
		'welding-for-elementor-admin-notice-css',
		get_template_directory_uri() . '/assets/css/admin-notice.css',
		[],
		'1.0.0',
		'all'
	);

	wp_enqueue_script(
		'welding-for-elementor-admin-notice',
		get_template_directory_uri() . '/assets/js/admin-notice.js',
		[],
		'1.0.0',
		true
	);
	
}
add_action('admin_enqueue_scripts', 'welding_for_elementor_enqueue_admin_scripts');
// Include admin notice
require_once('inc/admin-notice.php');

// Include Kirki customizer settings if Kirki plugin is active
if (class_exists('Kirki')) {
	require_once('inc/welding-for-elementor-kirki.php');
}
// Include nav walker class
require_once('inc/nav-walker.php');
// Include TGM plugin activation class and plugin registration file
require_once('inc/class-tgm-plugin-activation.php');
require_once('inc/add_plugin.php');
// Include template function
require_once('inc/template-function.php');


// Blog excerpt settings
add_filter('excerpt_length', function () {
	return 20;
}, 999);
add_filter('excerpt_more', function () {
	return '...';
});

// Preloader markup
function welding_for_elementor_preloader()
{
?>
	<div id="tr-preloader">
		<div class="tr-preloader"></div>
	</div>
<?php
}
if (get_theme_mod('welding_for_elementor_preloader', true)) {
	add_action('wp_body_open', 'welding_for_elementor_preloader');
}

// Scrollbar CSS based on customizer settings
function welding_for_elementor_scrollbar_css()
{

	if (! get_theme_mod('welding_for_elementor_scrollbar_enable', true)) return;

	$thumb = sanitize_hex_color(get_theme_mod('welding_for_elementor_scrollbar_thumb', '#FF6B00'));
	$track = sanitize_hex_color(get_theme_mod('welding_for_elementor_scrollbar_track', '#1a1a1b'));
?>
	<style>
		/* Firefox */
		* {
			scrollbar-width: thin;
			scrollbar-color: <?php echo esc_attr($thumb); ?> <?php echo esc_attr($track); ?>;
		}

		/* Chrome, Edge, Safari */
		*::-webkit-scrollbar {
			width: 8px;
			height: 8px;
		}

		*::-webkit-scrollbar-thumb {
			background-color: <?php echo esc_attr($thumb); ?>;
			border-radius: 10px;
		}

		*::-webkit-scrollbar-track {
			background-color: <?php echo esc_attr($track); ?>;
		}
	</style>
<?php
}
add_action('wp_head', 'welding_for_elementor_scrollbar_css');
