<?php
/**
 * File Path: templates/partials/lifecycle-state-label.php
 *
 * My Book Showroom — Lifecycle State Label
 *
 * Renders a subtle, informational text label reflecting the book's current
 * lifecycle state (F-024). Shown for FREE states only; 'coming_soon' is
 * handled exclusively by the coming-soon-badge.php partial (PRO).
 *
 * Postmeta: mbs_lifecycle_state
 * FREE states rendered here: draft | preorder | out_of_print | out_of_stock | discontinued
 * PRO state 'coming_soon': deliberately skipped -- badge handles presentation.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variables injected by mbs_get_template_part(); not global vars

if ( ! mbs_is_registered() ) {
	return;
}

if ( ! isset( $post_id ) ) {
	$post_id = get_the_ID();
}

$lifecycle_state = (string) MBS_Book_Meta_DAO::get( $post_id, 'mbs_lifecycle_state', '' );

// 'coming_soon' is handled by the badge — skip to avoid duplication.
// Empty string means the book is normally published — no label needed.
$renderable_states = array( 'draft', 'preorder', 'out_of_print', 'out_of_stock', 'discontinued' );

if ( ! in_array( $lifecycle_state, $renderable_states, true ) ) {
	return;
}

$state_labels = array(
	'draft'         => __( 'Work in Progress', 'my-book-showroom' ),
	'preorder'      => __( 'Available for Preorder', 'my-book-showroom' ),
	'out_of_print'  => __( 'Out of Print', 'my-book-showroom' ),
	'out_of_stock'  => __( 'Temporarily Out of Stock', 'my-book-showroom' ),
	'discontinued'  => __( 'No Longer Available', 'my-book-showroom' ),
);

$label = $state_labels[ $lifecycle_state ] ?? '';

if ( ! $label ) {
	return;
}
?>
<p class="mbs-lifecycle-label mbs-lifecycle--<?php echo esc_attr( $lifecycle_state ); ?>">
	<?php echo esc_html( $label ); ?>
</p>
