<?php
/**
 * Reusable Page Header partial.
 *
 * Variables expected (set before include):
 *   $costudio_header_title    string   Page title (required)
 *   $costudio_header_subtitle string   Subtitle text (optional, defaults to pipeline tagline)
 *   $costudio_header_back_url string   URL for back button (optional — omit to hide)
 *   $costudio_header_right    string   Pre-escaped HTML for right-side actions (optional)
 *   $costudio_header_icon     string   Emoji icon (optional, defaults to factory)
 *   $costudio_header_icon_url string   Image URL for brand mark (optional)
 *   $costudio_header_classes  string   Extra CSS classes on the root element (optional)
 *
 * @package Contentosapp_Studio
 * @since   3.1.0
 */

defined( 'ABSPATH' ) || exit;
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- Included admin template; local presentation variables are scoped to the including page.

$_title    = isset( $costudio_header_title )    ? $costudio_header_title    : __( 'Contentosapp Studio', 'contentosapp-studio' );
$_subtitle = isset( $costudio_header_subtitle ) ? $costudio_header_subtitle : __( 'AI-powered content production pipeline with 7 specialized agents', 'contentosapp-studio' );
$_icon     = isset( $costudio_header_icon )     ? $costudio_header_icon     : '🏭';
$_icon_url = isset( $costudio_header_icon_url ) ? $costudio_header_icon_url : '';
$_back_url = isset( $costudio_header_back_url ) ? $costudio_header_back_url : '';
$_right    = isset( $costudio_header_right )    ? $costudio_header_right    : '';
$_classes  = isset( $costudio_header_classes )  ? $costudio_header_classes  : '';
$_is_hero  = ! empty( $costudio_header_is_hero );
?>
<div class="cts-page-header cts-page-header--brand-card fos-detalhe-page-header <?php echo esc_attr( $_is_hero ? 'cts-page-header--hero' : '' ); ?> <?php echo esc_attr( $_classes ); ?>">
	<div class="cts-page-header__brand">
		<?php if ( $_back_url ) : ?>
			<a href="<?php echo esc_url( $_back_url ); ?>" class="fos-page-header-back fos-detalhe-page-header__back" title="<?php esc_attr_e( 'Back', 'contentosapp-studio' ); ?>">
				<span class="dashicons dashicons-arrow-left-alt2" aria-hidden="true"></span>
			</a>
		<?php endif; ?>
		<div class="cts-page-header__icon">
			<?php if ( $_icon_url ) : ?>
				<?php $_icon_src = 0 === strpos( $_icon_url, 'data:image/' ) ? esc_attr( $_icon_url ) : esc_url( $_icon_url ); ?>
				<img src="<?php echo esc_attr( $_icon_src ); ?>" alt="" class="cts-page-header__icon-img" aria-hidden="true">
			<?php else : ?>
				<?php echo esc_html( $_icon ); ?>
			<?php endif; ?>
		</div>
		<div class="cts-page-header__text">
			<h1 class="cts-page-header__title"><?php echo esc_html( $_title ); ?></h1>
			<p class="cts-page-header__sub"><?php echo esc_html( $_subtitle ); ?></p>
		</div>
	</div>
	<?php if ( $_right ) : ?>
		<div class="cts-page-header__right">
			<?php echo wp_kses_post( $_right ); ?>
		</div>
	<?php endif; ?>
</div>
