<?php
/**
 * Front-end assets for the lightbox + bookshelf. Registered once; enqueued on
 * demand by whatever renders a lightbox trigger or a shelf.
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }

class Flipa_Frontend {

	public static function init() {
		add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register' ) );
	}

	public static function register() {
		wp_register_style( 'flipa-frontend', FLIPA_URL . 'assets/flipa-frontend.css', array(), (string) @filemtime( FLIPA_DIR . 'assets/flipa-frontend.css' ) );
		wp_register_script( 'flipa-frontend', FLIPA_URL . 'assets/flipa-frontend.js', array(), (string) @filemtime( FLIPA_DIR . 'assets/flipa-frontend.js' ), true );
	}

	/** Call from any renderer that outputs a lightbox trigger or a shelf. */
	public static function enqueue() {
		// register() runs on wp_enqueue_scripts; if a shortcode renders later, ensure they exist.
		if ( ! wp_style_is( 'flipa-frontend', 'registered' ) ) { self::register(); }
		wp_enqueue_style( 'flipa-frontend' );
		wp_enqueue_script( 'flipa-frontend' );
	}
}
