<?php
/**
 * Title: Campaign Archive Card
 * Slug: crowdfunding-platform/campaign-archive-card
 * Categories: posts, crowdfunding_platform
 * Description: Single campaign card for use in Query Loop blocks on archive pages. Displays campaign image, title, description, progress bar, funding stats, and CTA button. Extensible via filters for crowdfunding plugin integration.
 * Keywords: campaign, crowdfunding, archive, card, funding
 * Block Types: core/post-template
 * Inserter: no
 */
?>
<!-- wp:group {"className":"pattern-campaign-card"} -->
<div class="wp-block-group pattern-campaign-card">

	<!-- wp:group {"className":"campaign-image-container"} -->
	<div class="wp-block-group campaign-image-container">
		<!-- wp:post-featured-image {"isLink":true,"aspectRatio":"1","style":{"border":{"radius":"0px"}}} /-->

		<?php
		$post_id = get_the_ID();
		$category = apply_filters( 'crowdfunding_platform_campaign_category', __( 'Category', 'crowdfunding-platform' ), $post_id );
		$status_badge = apply_filters( 'crowdfunding_platform_campaign_status_badge', '', $post_id );
		?>

		<?php if ( !empty( $category ) ) : ?>
		<!-- wp:paragraph {"className":"campaign-category-badge badge-overlay badge-bottom-left","fontSize":"tiny"} -->
		<p class="campaign-category-badge badge-overlay badge-bottom-left has-tiny-font-size"><?php echo esc_html( $category ); ?></p>
		<!-- /wp:paragraph -->
		<?php endif; ?>

		<?php if ( !empty( $status_badge ) ) : ?>
		<!-- wp:html -->
		<?php echo wp_kses_post( $status_badge ); ?>
		<!-- /wp:html -->
		<?php endif; ?>
	</div>
	<!-- /wp:group -->

	<!-- wp:post-title {"isLink":true,"level":3,"fontSize":"bigger"} /-->

	<?php
	$description = apply_filters( 'crowdfunding_platform_campaign_description', '', $post_id );
	?>
	<?php if ( !empty( $description ) ) : ?>
	<!-- wp:paragraph {"textColor":"secondary","fontSize":"base"} -->
	<p class="has-secondary-color has-text-color has-base-font-size"><?php echo wp_kses_post( wp_trim_words( $description, 30 ) ); ?></p>
	<!-- /wp:paragraph -->
	<?php else : ?>
	<!-- wp:post-excerpt {"moreText":"","showMoreOnNewLine":false,"excerptLength":30,"textColor":"secondary","fontSize":"base"} /-->
	<?php endif; ?>

	<!-- wp:group {"layout":{"type":"constrained"}} -->
	<div class="wp-block-group">
		<?php
		$amount_raised = apply_filters( 'crowdfunding_platform_campaign_amount_raised', '$0 ' . __( 'raised', 'crowdfunding-platform' ), $post_id );
		$goal = apply_filters( 'crowdfunding_platform_campaign_goal', __( 'of $0 goal', 'crowdfunding-platform' ), $post_id );
		$progress_bar = apply_filters( 'crowdfunding_platform_campaign_progress_bar', '<div class="theme-progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-label="' . esc_attr__( 'Campaign progress: 0%', 'crowdfunding-platform' ) . '" style="--progress-value: 0;"><div class="theme-progress-fill"></div></div>', $post_id );
		$time_remaining = apply_filters( 'crowdfunding_platform_campaign_time_remaining', '', $post_id );
		?>

		<!-- wp:paragraph {"fontSize":"big"} -->
		<p class="has-big-font-size"><?php echo wp_kses_post( $amount_raised ); ?></p>
		<!-- /wp:paragraph -->

		<!-- wp:paragraph {"textColor":"secondary","fontSize":"tiny"} -->
		<p class="has-secondary-color has-text-color has-tiny-font-size"><?php echo esc_html( $goal ); ?></p>
		<!-- /wp:paragraph -->

		<!-- wp:html -->
		<?php echo wp_kses_post( $progress_bar ); ?>
		<!-- /wp:html -->

		<?php if ( !empty( $time_remaining ) ) : ?>
		<!-- wp:paragraph {"textColor":"primary","fontSize":"tiny"} -->
		<p class="has-primary-color has-text-color has-tiny-font-size"><?php echo wp_kses_post( $time_remaining ); ?></p>
		<!-- /wp:paragraph -->
		<?php endif; ?>
	</div>
	<!-- /wp:group -->

	<!-- wp:buttons -->
	<div class="wp-block-buttons">
		<?php $button_text = apply_filters( 'crowdfunding_platform_campaign_button_text', __( 'View Campaign', 'crowdfunding-platform' ), $post_id ); ?>
		<!-- wp:button {"width":100} -->
		<div class="wp-block-button has-custom-width wp-block-button__width-100"><a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" class="wp-block-button__link wp-element-button"><?php echo esc_html( $button_text ); ?></a></div>
		<!-- /wp:button -->
	</div>
	<!-- /wp:buttons -->

</div>
<!-- /wp:group -->
