<?php
/**
 * [nr_brief] shortcode registration.
 *
 * @package Briefify
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Briefify_Shortcode
 */
class Briefify_Shortcode {

	/**
	 * @var Briefify_Form
	 */
	private $form;

	/**
	 * Constructor.
	 *
	 * @param Briefify_Form $form Form handler instance.
	 */
	public function __construct( Briefify_Form $form ) {
		$this->form = $form;

		add_shortcode( 'nr_brief', array( $this, 'render' ) );
	}

	/**
	 * Render the [nr_brief] shortcode.
	 *
	 * Usage: [nr_brief template="web|graphisme|coaching"]
	 *
	 * @param array $atts Shortcode attributes.
	 * @return string
	 */
	public function render( $atts ) {
		// Falls back to the configured default template — not hardcoded —
		// so the "default template" setting actually does something when a
		// shortcode is used without an explicit template attribute.
		$settings          = get_option( 'briefify_settings', array() );
		$default_template  = ! empty( $settings['default_template'] ) ? $settings['default_template'] : 'web';

		$atts = shortcode_atts(
			array(
				'template' => $default_template,
			),
			$atts,
			'nr_brief'
		);

		return $this->form->render_form( $atts );
	}
}
