<?php
/**
 * Brooklyn Lite functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Brooklyn Lite
 */


if (!defined('BROOKLYN_LITE_WP')) {
	define( 'BROOKLYN_LITE_WP', wp_get_theme()->get( 'Name' ));
}
if (!defined('BROOKLYN_LITE_VER')) {
	define( 'BROOKLYN_LITE_VER', wp_get_theme()->get( 'Version' ));
}
if (!defined('BROOKLYN_LITE_CSS')) {
	define( 'BROOKLYN_LITE_CSS', get_template_directory_uri().'/assets/css/');
}
if (!defined('BROOKLYN_LITE_JS')) {
	define( 'BROOKLYN_LITE_JS', get_template_directory_uri().'/assets/js/');
}
if (!defined('BROOKLYN_LITE_PATH')) {
	define( 'BROOKLYN_LITE_PATH', get_template_directory());
}
if (!defined('PROWPTHEME_PATH')) {
	define( 'PROWPTHEME_PATH', get_template_directory() . '/inc/prowptheme/');
}
if (!defined('PROWPTHEME_THEME_URI')) {
	define( 'PROWPTHEME_THEME_URI', get_template_directory_uri() . '/inc/prowptheme/');
}
if (!defined('BROOKLYN_LITE_THEME_URI')) {
	define( 'BROOKLYN_LITE_THEME_URI', get_template_directory_uri());
}
if (!defined('AJAX_URL')) {
	define( 'AJAX_URL', esc_url_raw( admin_url('admin-ajax.php')));
}


if ( ! function_exists( 'brooklyn_lite_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function brooklyn_lite_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Brooklyn, use a find and replace
		 * to change 'brooklyn-lite' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'brooklyn-lite' );

		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );

		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support( 'post-thumbnails' );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus(
			array(
				'main-menu' => esc_html__( 'Main Menu', 'brooklyn-lite' ),
			)
		);

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support(
			'html5',
			array(
				'search-form',
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
				'style',
				'script',
			)
		);

		// Set up the WordPress core custom background feature.
		add_theme_support(
			'custom-background',
			apply_filters(
				'brooklyn_custom_background_args',
				array(
					'default-color' => 'ffffff',
					'default-image' => '',
				)
			)
		);

		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		// Block editor support.
		add_theme_support( 'wp-block-styles' );
		add_theme_support( 'responsive-embeds' );
		add_theme_support( 'align-wide' );

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support(
			'custom-logo',
			array(
				'height'      => 250,
				'width'       => 250,
				'flex-width'  => true,
				'flex-height' => true,
			)
		);
	}
endif;
add_action( 'after_setup_theme', 'brooklyn_lite_setup' );

/**
 * Register block styles.
 */
function brooklyn_lite_register_block_styles() {
	register_block_style(
		'core/button',
		array(
			'name'  => 'brooklyn-lite-flat',
			'label' => __( 'Flat', 'brooklyn-lite' ),
		)
	);
	register_block_style(
		'core/quote',
		array(
			'name'  => 'brooklyn-lite-bordered',
			'label' => __( 'Bordered', 'brooklyn-lite' ),
		)
	);
}
add_action( 'init', 'brooklyn_lite_register_block_styles' );

/**
 * Register block patterns.
 */
function brooklyn_lite_register_block_patterns() {
	register_block_pattern_category(
		'brooklyn-lite',
		array( 'label' => __( 'Brooklyn Lite', 'brooklyn-lite' ) )
	);

	register_block_pattern(
		'brooklyn-lite/call-to-action',
		array(
			'title'       => __( 'Call to Action', 'brooklyn-lite' ),
			'description' => __( 'A simple call to action section.', 'brooklyn-lite' ),
			'categories'  => array( 'brooklyn-lite' ),
			'content'     => '<!-- wp:group {"align":"wide","style":{"spacing":{"padding":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|50"}}},"layout":{"type":"constrained"}} --><div class="wp-block-group alignwide" style="padding-top:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--50)"><!-- wp:heading {"textAlign":"center"} --><h2 class="wp-block-heading has-text-align-center">' . esc_html__( 'Ready to get started?', 'brooklyn-lite' ) . '</h2><!-- /wp:heading --><!-- wp:paragraph {"align":"center"} --><p class="has-text-align-center">' . esc_html__( 'Create your stunning website today with Brooklyn Lite.', 'brooklyn-lite' ) . '</p><!-- /wp:paragraph --><!-- wp:buttons {"layout":{"type":"flex","justifyContent":"center"}} --><div class="wp-block-buttons"><!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link wp-element-button">' . esc_html__( 'Get Started', 'brooklyn-lite' ) . '</a></div><!-- /wp:button --></div><!-- /wp:buttons --></div><!-- /wp:group -->',
		)
	);
}
add_action( 'init', 'brooklyn_lite_register_block_patterns' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function brooklyn_lite_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'brooklyn_lite_content_width', 640 );
}
add_action( 'after_setup_theme', 'brooklyn_lite_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function brooklyn_lite_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'brooklyn-lite' ),
			'id'            => 'blog-sidebar',
			'description'   => esc_html__( 'Add widgets here.', 'brooklyn-lite' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);


	register_widget( 'ProWPTheme_Social' );
	register_widget( 'ProWPTheme_Recent_Posts' );
		
}
add_action( 'widgets_init', 'brooklyn_lite_widgets_init' );


// Google Fonts URL (uses customizer typography settings)
function brooklyn_lite_google_fonts_url() {
    $headings_font = get_theme_mod( 'headings_font_family', 'Muli' );
    $body_font     = get_theme_mod( 'body_font_family', 'Montserrat' );
    $weights       = '300,400,500,600,700';

    if ( 'off' === _x( 'on', 'Google font: on or off', 'brooklyn-lite' ) ) {
        return '';
    }

    $fonts = array();
    if ( $headings_font ) {
        $fonts[] = $headings_font . ':' . $weights;
    }
    if ( $body_font && $body_font !== $headings_font ) {
        $fonts[] = $body_font . ':' . $weights;
    }

    if ( empty( $fonts ) ) {
        return '';
    }

    return add_query_arg( 'family', urlencode( implode( '|', $fonts ) . '&display=swap' ), 'https://fonts.googleapis.com/css' );
}




/**
 * Enqueue scripts and styles.
 */
function brooklyn_lite_scripts() {

	//CSS
	wp_enqueue_style( 'brooklyn-lite-style', get_stylesheet_uri(), array(), BROOKLYN_LITE_VER );
	wp_enqueue_style( 'bootstrap', BROOKLYN_LITE_CSS . 'bootstrap.min.css');
	wp_enqueue_style( 'simple-line-icons', BROOKLYN_LITE_CSS . 'simple-line-icons.css');
	wp_enqueue_style( 'fontawesome', BROOKLYN_LITE_CSS . 'font-awesome.min.css');
	wp_enqueue_style( 'brooklyn-lite-themes', BROOKLYN_LITE_CSS . 'themes.css');
	wp_enqueue_style( 'brooklyn-lite-google-fonts', brooklyn_lite_google_fonts_url() );

	wp_style_add_data( 'brooklyn-lite-style', 'rtl', 'replace' );


	//JS
	wp_enqueue_script( 'popper', BROOKLYN_LITE_JS . 'popper.min.js', array('jquery'), '', true );
	wp_enqueue_script( 'bootstrap', BROOKLYN_LITE_JS . 'bootstrap.min.js', array('jquery'), '', true );
	wp_enqueue_script( 'brooklyn-lite-scripts', BROOKLYN_LITE_JS . 'scripts.js', array('jquery'), '', true );



    $brooklyn_lite_custom_css = '
    .edit-post-visual-editor.editor-styles-wrapper{ font-family: Muli;}

    .editor-post-title__block .editor-post-title__input,
    .editor-styles-wrapper h1,
    .editor-styles-wrapper h2,
    .editor-styles-wrapper h3,
    .editor-styles-wrapper h4,
    .editor-styles-wrapper h5,
    .editor-styles-wrapper h6{font-family:Prata;} 
    ';

    wp_add_inline_style( 'brooklyn_lite-editor-styles', $brooklyn_lite_custom_css );


	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'brooklyn_lite_scripts' );



/**
 * Load Theme Support on Init
 */
if(!( function_exists('brooklyn_lite_add_editor_styles') )){
	function brooklyn_lite_add_editor_styles() {
		/**
		 * Add WP Editor Styling
		 */
	    add_editor_style( array('inc/editor-style.css'), brooklyn_lite_google_fonts_url() );

		/**
		 * Set the content width in pixels, based on the theme's design and stylesheet.
		 *
		 * Priority 0 to make it available to lower priority callbacks.
		 *
		 * @global int $content_width
		 */
	    global $content_width;
	    if ( ! isset( $content_width ) ) $content_width = 1170;

	}
	add_action( 'init', 'brooklyn_lite_add_editor_styles', 10 );
}



// Includes Files
require get_template_directory() . '/inc/custom-header.php';
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/template-functions.php';
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/customizer/customizer-output.php';
if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) {
	require_once get_template_directory().'/inc/class-wp-bootstrap-navwalker.php';
}
require get_template_directory()  . '/inc/breadcrumb-trail.php';

if ( defined( 'JETPACK__VERSION' ) ) { 
	require get_template_directory() . '/inc/jetpack.php'; 
}
if ( class_exists( 'WooCommerce' ) ) { 
	require get_template_directory() . '/inc/woocommerce.php'; 
}
if ( ! class_exists( 'TGM_Plugin_Activation' ) ) {
	require_once( get_template_directory()  . '/inc/class-tgm-plugin-activation.php');
	require_once( get_template_directory()  . '/inc/required-plugins.php');
}


/* ProWP Theme Core */
require PROWPTHEME_PATH . 'pwpt-core.php';


/**
 * Admin notice
 */
require PROWPTHEME_PATH . 'notices/persist-admin-notices-dismissal.php';

function brooklyn_lite_welcome_admin_notice() {
	if ( ! PAnD::is_admin_notice_active( 'brooklyn-lite-welcome-forever' ) ) {
		return;
	}
	$welcome_url = admin_url( 'admin.php?page=brooklyn-lite-info.php' );
	$icon_url    = get_template_directory_uri() . '/assets/images/icon.svg';
	?>
	<style>
		.bl-welcome-notice {
			position: relative;
			margin: 20px 20px 15px 2px;
			padding: 0;
			border: none;
			border-radius: 10px;
			background: #ffffff;
			overflow: hidden;
			box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
			border: 1px solid #e8e8e8;
		}
		.bl-welcome-notice::before {
			content: '';
			position: absolute;
			top: 0;
			left: 0;
			bottom: 0;
			width: 4px;
			background: linear-gradient(180deg, #fdd300 0%, #f5a623 100%);
			border-radius: 10px 0 0 10px;
		}
		.bl-welcome-notice .notice-dismiss {
			top: 50%;
			right: 14px;
			transform: translateY(-50%);
			padding: 6px;
		}
		.bl-welcome-notice .notice-dismiss::before {
			color: #b0b0b0;
			font-size: 16px;
			transition: color 0.2s ease;
		}
		.bl-welcome-notice .notice-dismiss:hover::before {
			color: #333;
		}
		.bl-welcome-inner {
			position: relative;
			display: flex;
			align-items: center;
			gap: 20px;
			padding: 20px 48px 20px 24px;
		}
		.bl-welcome-badge {
			flex-shrink: 0;
			width: 48px;
			height: 48px;
			border-radius: 12px;
			background: linear-gradient(135deg, #fff8d6 0%, #fff3b8 100%);
			border: 1px solid rgba(253, 211, 0, 0.3);
			display: flex;
			align-items: center;
			justify-content: center;
		}
		.bl-welcome-badge img {
			width: 32px;
			height: 32px;
		}
		.bl-welcome-content {
			flex: 1;
			min-width: 0;
		}
		.bl-welcome-title {
			margin: 0 0 2px;
			font-size: 15px;
			font-weight: 600;
			color: #1d2327;
			letter-spacing: -0.01em;
			line-height: 1.4;
		}
		.bl-welcome-title span {
			color: #d4a800;
		}
		.bl-welcome-desc {
			margin: 0;
			font-size: 13px;
			color: #646970;
			line-height: 1.5;
		}
		.bl-welcome-actions {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			gap: 10px;
		}
		.bl-welcome-btn {
			display: inline-flex;
			align-items: center;
			gap: 6px;
			padding: 8px 20px;
			font-size: 13px;
			font-weight: 600;
			text-decoration: none;
			border-radius: 6px;
			transition: all 0.2s ease;
			white-space: nowrap;
			cursor: pointer;
		}
		.bl-welcome-btn-primary {
			background: #fdd300;
			color: #1d2327;
			border: 1px solid #e6bf00;
			box-shadow: 0 1px 2px rgba(253, 211, 0, 0.2);
		}
		.bl-welcome-btn-primary:hover,
		.bl-welcome-btn-primary:focus {
			background: #ffe433;
			color: #1d2327;
			border-color: #d4a800;
			box-shadow: 0 2px 6px rgba(253, 211, 0, 0.3);
			transform: translateY(-1px);
		}
		.bl-welcome-btn-primary:active {
			transform: translateY(0);
		}
		.bl-welcome-btn-primary svg {
			transition: transform 0.2s ease;
		}
		.bl-welcome-btn-primary:hover svg {
			transform: translateX(2px);
		}
		@media (max-width: 782px) {
			.bl-welcome-inner {
				flex-direction: column;
				align-items: flex-start;
				gap: 14px;
				padding: 18px 40px 18px 20px;
			}
		}
	</style>
	<div data-dismissible="brooklyn-lite-welcome-forever" class="bl-welcome-notice notice is-dismissible">
		<div class="bl-welcome-inner">
			<div class="bl-welcome-badge">
				<img src="<?php echo esc_url( $icon_url ); ?>" alt="Brooklyn Lite" />
			</div>
			<div class="bl-welcome-content">
				<h3 class="bl-welcome-title"><?php printf( esc_html__( 'Welcome to %sBrooklyn Lite%s', 'brooklyn-lite' ), '<span>', '</span>' ); ?></h3>
				<p class="bl-welcome-desc"><?php esc_html_e( 'Get started by exploring theme options, importing demo content, and customizing your site.', 'brooklyn-lite' ); ?></p>
			</div>
			<div class="bl-welcome-actions">
				<a href="<?php echo esc_url( $welcome_url ); ?>" class="bl-welcome-btn bl-welcome-btn-primary">
					<?php esc_html_e( 'Get Started', 'brooklyn-lite' ); ?>
					<svg width="14" height="14" viewBox="0 0 16 16" fill="none"><path d="M3 8h10M9 4l4 4-4 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
				</a>
			</div>
		</div>
	</div>
	<?php
}
add_action( 'admin_init', array( 'PAnD', 'init' ) );
add_action( 'admin_notices', 'brooklyn_lite_welcome_admin_notice' );