<?php
/**
 * Marble St functions and definitions.
 *
 * @package Marble_St
 * @since 1.0.0
 */


if ( ! function_exists( 'marble_st_enqueue_styles' ) ) :
	function marble_st_enqueue_styles() {
		wp_enqueue_style(
			'marble-st-style',
			get_parent_theme_file_uri( 'style.css' ),
			array(),
			wp_get_theme()->get( 'Version' )
		);
	}
endif;
add_action( 'wp_enqueue_scripts', 'marble_st_enqueue_styles' );

if ( ! function_exists( 'marble_st_pattern_categories' ) ) :
	function marble_st_pattern_categories() {
		register_block_pattern_category(
			'marble-st',
			array(
				'label' => __( 'Marble St', 'marble-st' ),
			)
		);
	}
endif;
add_action( 'init', 'marble_st_pattern_categories' );

/**
 * Remove default WordPress block patterns and remote patterns.
 */
add_action( 'after_setup_theme', function() {
	remove_theme_support( 'core-block-patterns' );
} );


// --- Marble St Admin Notice ---

function marble_st_setup_notice() {
	$notice_option_name = 'marble_st_setup_notice_dismissed';
	$is_dismissed = get_option( $notice_option_name );

	if ( ! $is_dismissed ) {
		$notice_text = '
		<div class="msn-wrap">
			<div class="msn-top">
				<img src="' . esc_url( get_template_directory_uri() . '/assets/images/localstarter-logo.jpg' ) . '" class="msn-logo" alt="Local Starter Themes" />
				<span class="msn-tag">LocalStarter Themes</span>
			</div>
			<div class="msn-body">
				<strong class="msn-title">' . __( 'Thanks for using Marble St!', 'marble-st' ) . '</strong>
				<p class="msn-desc">' . __( 'We built this theme to help local businesses — cafés, bars, tea houses, and other venues — have a beautiful, modern website without the hassle. Hope it works great for you!', 'marble-st' ) . '</p>
				<p class="msn-desc msn-desc--pro">' . __( 'Want to take it further? <strong>Marble St PRO</strong> gives you 66 patterns, 22 color styles, and 6 full-page homepage designs — everything you need to build a stunning site fast.', 'marble-st' ) . '</p>
				<div class="msn-stats">
					<div class="msn-stat"><span class="msn-stat-num">66</span><span class="msn-stat-label">' . __( 'Patterns', 'marble-st' ) . '</span></div>
					<div class="msn-stat"><span class="msn-stat-num">22</span><span class="msn-stat-label">' . __( 'Color Styles', 'marble-st' ) . '</span></div>
					<div class="msn-stat"><span class="msn-stat-num">6</span><span class="msn-stat-label">' . __( 'Homepages', 'marble-st' ) . '</span></div>
					<div class="msn-stat"><span class="msn-stat-num">$39</span><span class="msn-stat-label">' . __( '/ year', 'marble-st' ) . '</span></div>
				</div>
				<div class="msn-actions">
					<a href="https://localstarterthemes.com/theme/marble-st-pro/?utm_source=marble-st-notice" class="msn-btn" target="_blank">' . __( 'Get Marble St PRO', 'marble-st' ) . '</a>
					<span class="msn-contact">' . __( 'Need help with your site or theme?', 'marble-st' ) . ' <a href="mailto:hello@localstarterthemes.com">hello@localstarterthemes.com</a></span>
				</div>
			</div>
		</div>';
		echo '<div id="marble-st-notice" class="notice is-dismissible">' . wp_kses_post( $notice_text ) . '</div>';
	}
}
add_action( 'admin_notices', 'marble_st_setup_notice' );

function marble_st_notice_script() {
	if ( ! wp_script_is( 'jquery', 'done' ) ) {
		wp_enqueue_script( 'jquery' );
	}
	wp_enqueue_script( 'marble-st-notice-script', get_template_directory_uri() . '/assets/js/admin-notice.js', array( 'jquery' ), '', true );
}
add_action( 'admin_enqueue_scripts', 'marble_st_notice_script' );

function marble_st_enqueue_notice_styles() {
	$notice_option_name = 'marble_st_setup_notice_dismissed';
	$is_dismissed = get_option( $notice_option_name );
	if ( ! $is_dismissed ) {
		wp_enqueue_style( 'marble-st-admin-notice', get_template_directory_uri() . '/assets/css/admin-notice.css', array(), wp_get_theme()->get( 'Version' ) );
	}
}
add_action( 'admin_enqueue_scripts', 'marble_st_enqueue_notice_styles' );

function marble_st_dismiss_notice() {
	update_option( 'marble_st_setup_notice_dismissed', true );
	wp_die();
}
add_action( 'wp_ajax_marble_st_dismiss_notice', 'marble_st_dismiss_notice' );


// --- Marble St About Page ---

function marble_st_add_about_page() {
	add_theme_page(
		__( 'About Marble St', 'marble-st' ),
		__( 'About Marble St', 'marble-st' ),
		'edit_theme_options',
		'marble-st-about',
		'marble_st_about_page_html'
	);
}
add_action( 'admin_menu', 'marble_st_add_about_page' );

function marble_st_about_page_styles( $hook ) {
	if ( 'appearance_page_marble-st-about' !== $hook ) {
		return;
	}
	wp_enqueue_style( 'marble-st-about-page', get_template_directory_uri() . '/assets/css/admin-about.css', array(), wp_get_theme()->get( 'Version' ) );
}
add_action( 'admin_enqueue_scripts', 'marble_st_about_page_styles' );

function marble_st_about_page_html() {
	$version = wp_get_theme()->get( 'Version' );
	?>
	<div class="wrap mst-about-wrap">

		<div class="mst-header">
			<p class="mst-theme-label"><?php esc_html_e( 'WordPress Block Theme', 'marble-st' ); ?></p>
			<h1 class="mst-page-title"><?php esc_html_e( 'Marble St', 'marble-st' ); ?> <span class="mst-version">v<?php echo esc_html( $version ); ?></span></h1>
			<p class="mst-header-desc"><?php esc_html_e( 'A minimal monochromatic block theme for local venues — coffee shops, tea houses, bars, bakeries, and cafes.', 'marble-st' ); ?></p>
		</div>

		<div class="mst-grid">

			<div class="mst-card mst-card--pro">
				<p class="mst-label"><?php esc_html_e( 'Premium', 'marble-st' ); ?></p>
				<h2><?php esc_html_e( 'Upgrade to Marble St PRO', 'marble-st' ); ?></h2>
				<p><?php esc_html_e( 'Fast, minimalistic and functional — everything you need to build a stunning local venue website. No page builders, no lock-in, 100% native WordPress.', 'marble-st' ); ?></p>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'Ready-made patterns', 'marble-st' ); ?></span>
					<span class="mst-detail-value">66</span>
				</div>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'Color styles', 'marble-st' ); ?></span>
					<span class="mst-detail-value">22</span>
				</div>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'Starter homepages', 'marble-st' ); ?></span>
					<span class="mst-detail-value">6</span>
				</div>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'License', 'marble-st' ); ?></span>
					<span class="mst-detail-value"><?php esc_html_e( 'From $39 / year', 'marble-st' ); ?></span>
				</div>
				<div class="mst-actions">
					<a href="https://localstarterthemes.com/theme/marble-st-pro/?utm_source=marble-st-about" class="mst-btn mst-btn--primary" target="_blank">
						<?php esc_html_e( 'Get Marble St PRO', 'marble-st' ); ?>
					</a>
				</div>
			</div>

			<div class="mst-card">
				<p class="mst-label"><?php esc_html_e( 'Support', 'marble-st' ); ?></p>
				<h2><?php esc_html_e( 'Need Help With Your Site?', 'marble-st' ); ?></h2>
				<p><?php esc_html_e( 'We offer website setup assistance, theme customization, and ongoing support for local businesses.', 'marble-st' ); ?></p>
				<div class="mst-help">
					<p class="mst-help-title"><?php esc_html_e( 'Resources', 'marble-st' ); ?></p>
					<ul>
						<li><a href="https://localstarterthemes.com/?utm_source=marble-st-about" target="_blank">localstarterthemes.com</a></li>
						<li><a href="https://localstarterthemes.com/support/?utm_source=marble-st-about" target="_blank"><?php esc_html_e( 'Contact & Support', 'marble-st' ); ?></a></li>
					</ul>
				</div>
			</div>

			<div class="mst-card mst-card--wide">
				<p class="mst-label"><?php esc_html_e( 'Theme Info', 'marble-st' ); ?></p>
				<h2><?php esc_html_e( 'About This Theme', 'marble-st' ); ?></h2>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'Version', 'marble-st' ); ?></span>
					<span class="mst-detail-value"><?php echo esc_html( $version ); ?></span>
				</div>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'Author', 'marble-st' ); ?></span>
					<span class="mst-detail-value"><a href="https://localstarterthemes.com" target="_blank">Local Starter Themes</a></span>
				</div>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'License', 'marble-st' ); ?></span>
					<span class="mst-detail-value">GPL v2+</span>
				</div>
				<div class="mst-detail">
					<span class="mst-detail-label"><?php esc_html_e( 'Requires WordPress', 'marble-st' ); ?></span>
					<span class="mst-detail-value">6.4+</span>
				</div>
			</div>

		</div>
	</div>
	<?php
}

