<?php if ( ! defined( 'ABSPATH' ) ) { exit; } ?>
<?php
$portal_access      = isset( $portal['access'] ) && is_array( $portal['access'] ) ? $portal['access'] : array();
$portal_creator     = isset( $portal['creator'] ) && is_array( $portal['creator'] ) ? $portal['creator'] : array();
$portal_invitation  = isset( $portal['invitation'] ) && is_array( $portal['invitation'] ) ? $portal['invitation'] : array();
$portal_current     = isset( $portal['currentUser'] ) && is_array( $portal['currentUser'] ) ? $portal['currentUser'] : array();
$portal_labels      = isset( $portal['i18n']['statusLabels'] ) && is_array( $portal['i18n']['statusLabels'] ) ? $portal['i18n']['statusLabels'] : array();
$portal_status      = isset( $portal_creator['status'] ) ? (string) $portal_creator['status'] : ( isset( $portal_access['status'] ) ? (string) $portal_access['status'] : '' );
$portal_status_text = isset( $portal_labels[ $portal_status ] ) ? (string) $portal_labels[ $portal_status ] : ucfirst( str_replace( '_', ' ', $portal_status ) );
$portal_name        = ! empty( $portal_creator['profile']['display_name'] ) ? (string) $portal_creator['profile']['display_name'] : ( ! empty( $portal_creator['display_name'] ) ? (string) $portal_creator['display_name'] : ( ! empty( $portal_current['name'] ) ? (string) $portal_current['name'] : '' ) );
$portal_email       = ! empty( $portal_creator['email'] ) ? (string) $portal_creator['email'] : ( ! empty( $portal_invitation['email'] ) ? (string) $portal_invitation['email'] : '' );
?>
<section class="ugcify-portal-shell" data-ugcify-portal data-state="<?php echo esc_attr( (string) ( $portal['state'] ?? 'unknown' ) ); ?>">
	<div class="ugcify-portal-shell__inner">
		<header class="ugcify-portal-shell__header">
			<div class="ugcify-portal-shell__copy">
				<?php if ( ! empty( $portal['eyebrow'] ) ) : ?>
					<span class="ugcify-portal-shell__eyebrow"><?php echo esc_html( (string) $portal['eyebrow'] ); ?></span>
				<?php endif; ?>
				<h2 class="ugcify-portal-shell__title"><?php echo esc_html( (string) ( $portal['title'] ?? __( 'Creator portal', 'ugcify' ) ) ); ?></h2>
				<?php if ( ! empty( $portal['description'] ) ) : ?>
					<p class="ugcify-portal-shell__description"><?php echo esc_html( (string) $portal['description'] ); ?></p>
				<?php endif; ?>
			</div>

			<?php if ( '' !== $portal_name || '' !== $portal_email ) : ?>
				<div class="ugcify-portal-shell__meta">
					<?php if ( '' !== $portal_name ) : ?>
						<strong class="ugcify-portal-shell__meta-name"><?php echo esc_html( $portal_name ); ?></strong>
					<?php endif; ?>
					<?php if ( '' !== $portal_email ) : ?>
						<span class="ugcify-portal-shell__meta-email"><?php echo esc_html( $portal_email ); ?></span>
					<?php endif; ?>
					<?php if ( '' !== $portal_status && 'registration' !== ( $portal['template'] ?? '' ) && 'login' !== ( $portal['template'] ?? '' ) ) : ?>
						<span class="ugcify-portal-status-badge is-<?php echo esc_attr( sanitize_html_class( $portal_status ) ); ?>"><?php echo esc_html( $portal_status_text ); ?></span>
					<?php endif; ?>
					<?php if ( ! empty( $portal_access['is_admin_preview'] ) ) : ?>
						<span class="ugcify-portal-status-badge is-admin-preview"><?php echo esc_html( $portal_labels['admin_preview'] ?? __( 'Admin preview', 'ugcify' ) ); ?></span>
					<?php endif; ?>
				</div>
			<?php endif; ?>
		</header>

		<?php if ( ! empty( $notice['message'] ) ) : ?>
			<div class="ugcify-form-alert<?php echo 'success' === ( $notice['type'] ?? '' ) ? ' is-success' : ''; ?>">
				<?php echo esc_html( (string) $notice['message'] ); ?>
			</div>
		<?php endif; ?>

		<div class="ugcify-portal-shell__body">
			<?php echo $body_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		</div>
	</div>
</section>