<?php
/**
 * File Path: templates/admin/dashboard-news.php
 *
 * Admin Dashboard — MBS News Feed partial (GC3-6, UX rev 1)
 *
 * @package MyBookShowroom
 * @since   1.1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// DASH-2A: Widget visibility gate.
if ( MBS_Dashboard_Widget_Prefs::is_widget_hidden( 'news-feed', get_current_user_id() ) ) {
	return;
}


$items = MBS_Admin_Dashboard::fetch_news_feed(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global
?>
<div class="mbs-dashboard-card">

	<div class="mbs-card-header">
		<h2><?php esc_html_e( 'MBS News', 'my-book-showroom' ); ?></h2>
		<button id="mbs-refresh-news"
		        type="button"
		        class="button button-small mbs-news-refresh"
		        data-nonce="<?php echo esc_attr( wp_create_nonce( 'mbs_refresh_news_feed' ) ); ?>">
			<?php esc_html_e( 'Refresh', 'my-book-showroom' ); ?>
		</button>
	</div>

	<ul id="mbs-news-list" class="mbs-news-list">
		<?php if ( ! empty( $items ) ) : ?>
			<?php foreach ( $items as $item ) : // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global?>
				<li>
					<a href="<?php echo esc_url( $item['url'] ); ?>" target="_blank" rel="noopener">
						<?php echo esc_html( $item['title'] ); ?>
					</a>
					<span class="mbs-news-source"><?php echo esc_html( $item['date'] ); ?></span>
				</li>
			<?php endforeach; ?>
		<?php else : ?>
			<li class="mbs-news-empty">
				<?php esc_html_e( 'No news items available.', 'my-book-showroom' ); ?>
			</li>
		<?php endif; ?>
	</ul>

</div><!-- news card -->
