<?php

/**
 * Class PTFS_Shortcode
 * Handles the shortcode for displaying player transfers on the frontend.
 */
class PTFS_Shortcode {
    /**
     * Initialize shortcode registration.
     */
    public static function init() {
        add_shortcode( 'player-transfers', [__CLASS__, 'render_transfers'] );
    }

    /**
     * Render the player transfers based on shortcode attributes.
     *
     * @param array $atts Shortcode attributes.
     * @return string HTML output.
     */
    public static function render_transfers( $atts ) {
        wp_enqueue_style(
            'ptfs-style',
            PTFS_DIR . 'assets/css/ptfs-style.css',
            array(),
            'PTFS_VERSION'
        );
        wp_enqueue_script(
            'ptfs-script',
            PTFS_DIR . 'assets/js/ptfs-script.js',
            array(),
            'PTFS_VERSION',
            true
        );
        $atts = shortcode_atts( [
            'title'     => '',
            'season'    => '',
            'club_in'   => '',
            'club_out'  => '',
            'player'    => '',
            'date_from' => '',
            'date_to'   => '',
            'datatable' => false,
        ], $atts, 'player-transfers' );
        ob_start();
        if ( function_exists( 'sp_get_template' ) ) {
            sp_get_template(
                'player-transfers-table.php',
                $atts,
                '',
                PTFS_DIR . 'templates/'
            );
        } else {
            echo 'Error: sp_get_template function not found. Confirm that either SportsPress or SportsPress Pro is installed and activated.';
        }
        return ob_get_clean();
    }

}
