<?php
namespace Actirise\Includes;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

/**
 * ShortCode management class
 *
 * @link       https://actirise.com
 * @since      3.2.0
 * @package    actirise
 * @subpackage actirise/includes
 * @author     actirise <wordpress@actirise.com>
 */
final class ShortCode {
	/**
	 * ShortCode constructor.
	 */
	public function __construct() {
	}

	/**
	 * Initialize the shortcode functionality.
	 *
	 * This method registers the shortcode with WordPress.
	 *
	 * @since 3.2.0
	 * @return void
	 */
	public function init() {
		add_shortcode( 'actirise', array( $this, 'register_shortcode' ) );
	}

	/**
	 * Register the shortcode with WordPress.
	 *
	 * This method extracts the attributes and returns the HTML for the ad format.
	 *
	 * @since 3.2.0
	 * @param array<string, mixed> $atts Shortcode attributes.
	 * @return string HTML output for the ad format.
	 */
	public function register_shortcode( $atts ) {
		$slot   = isset( $atts['format'] ) && is_string( $atts['format'] ) ? $atts['format'] : '';
		$device = isset( $atts['device'] ) && is_string( $atts['device'] ) ? $atts['device'] : '';

		if ( ! empty( $slot ) && ! empty( $device ) ) {
			return actirise_generate_html_ad_format( strtolower( $slot ), strtolower( $device ), 'shortcode' );
		}

		return '';
	}
}
