<?php
/**
 * Admin view: ticket designs.
 *
 * @package BitForgeNet_Guest_Tickets
 */

defined( 'ABSPATH' ) || exit;

// This file is a template: it is included from a method -- never at file
// scope -- so everything declared here belongs to that method's variable
// scope and not to the global one. PHPCS reads each file on its own and has
// no way to see where the include happens, so it reads these as globals.
// Stated once, for the whole file, per this plugin's suppression rule.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

$templates = BFNET_Template::all( '' );
?>
<div class="wrap bfnet-admin">

	<?php
	$bfnet_title    = __( 'Ticket designs', 'bitforgenet-guest-tickets' );
	$bfnet_subtitle = __( 'The artwork your tickets are printed on. Data is engraved onto it at 300 dpi, then exported as PDF.', 'bitforgenet-guest-tickets' );
	include BFNET_PATH . 'admin/views/partial-masthead.php';
	?>

	<div class="bfnet-cols">
		<div>
			<div class="bfnet-panel">
				<div class="bfnet-panel__head"><h2><?php esc_html_e( 'Your designs', 'bitforgenet-guest-tickets' ); ?></h2></div>
				<div class="bfnet-panel__body">
					<?php if ( empty( $templates ) ) : ?>
						<div class="bfnet-empty-state">
							<h3><?php esc_html_e( 'No design yet', 'bitforgenet-guest-tickets' ); ?></h3>
							<p><?php esc_html_e( 'Generate one in a colour of your choice — it takes a second.', 'bitforgenet-guest-tickets' ); ?></p>
						</div>
					<?php else : ?>
						<div class="bfnet-designs">
							<?php foreach ( $templates as $template ) : ?>
								<div class="bfnet-design <?php echo $template->is_default ? 'is-default' : ''; ?>">
									<span class="bfnet-design__thumb">
										<img src="<?php echo esc_url( BFNET_Template::preview_url( $template ) ); ?>" alt="<?php echo esc_attr( $template->name ); ?>" loading="lazy">
									</span>
									<div class="bfnet-design__body">
										<p class="bfnet-design__name"><?php echo esc_html( $template->name ); ?></p>
										<p class="bfnet-design__meta">
											<?php echo esc_html( sprintf( '%d × %d px · %d dpi', (int) $template->width_px, (int) $template->height_px, (int) $template->dpi ) ); ?>
											<?php if ( $template->is_default ) : ?>
												<br><strong style="color:#a9871a"><?php esc_html_e( 'Default design', 'bitforgenet-guest-tickets' ); ?></strong>
											<?php endif; ?>
										</p>
										<div class="bfnet-actions">
											<?php
											/**
											 * What can be done to one design.
											 *
											 * Editing a design, replacing the default and deleting one
											 * are all studio work. A build with one built-in design has
											 * nothing to do to it, and shows no buttons rather than
											 * buttons that lead nowhere.
											 *
											 * @param object $template The design.
											 */
											do_action( 'bfnet_design_actions', $template );
											?>
										</div>
									</div>
								</div>
							<?php endforeach; ?>
						</div>
					<?php endif; ?>
				</div>
			</div>

			<?php
			/**
			 * Panels a studio module adds to this screen.
			 *
			 * Bringing your own artwork, choosing a colour variation and the
			 * artboard specification that goes with them all belong to the module
			 * that can act on them.
			 */
			do_action( 'bfnet_design_panels' );
			?>

		</div>
	</div>
</div>
