<?php

defined( 'ABSPATH' ) || exit;

/**
 * Spacing Shortcode.
 */
if ( ! class_exists( 'Vcex_Spacing_Shortcode' ) ) {

	class Vcex_Spacing_Shortcode extends TotalThemeCore\Vcex\Shortcode_Abstract {

		/**
		 * Shortcode tag.
		 */
		public const TAG = 'vcex_spacing';

		/**
		 * Main constructor.
		 */
		public function __construct() {
			parent::__construct();
		}

		/**
		 * Shortcode title.
		 */
		public static function get_title(): string {
			return esc_html__( 'Spacing', 'total-theme-core' );
		}

		/**
		 * Shortcode description.
		 */
		public static function get_description(): string {
			return esc_html__( 'Adds spacing anywhere you need it', 'total-theme-core' );
		}

		/**
		 * Array of shortcode parameters.
		 */
		public static function get_params_list(): array {
			return [
				[
					'type' => 'vcex_text',
					'responsive' => true,
					'admin_label' => true,
					'heading' => esc_html__( 'Size', 'total-theme-core' ),
					'description' => self::param_description( 'height' ),
					'param_name' => 'size',
					'placeholder' => '30px',
				],
				[
					'type' => 'vcex_text',
					'heading' => esc_html__( 'Extra class name', 'total-theme-core' ),
					'description' => self::param_description( 'el_class' ),
					'param_name' => 'class',
				],
				[
					'type' => 'vcex_select',
					'heading' => esc_html__( 'Visibility', 'total-theme-core' ),
					'param_name' => 'visibility',
				],
				// Deprecated fields
				[ 'type' => 'hidden', 'param_name' => 'responsive' ],
				[ 'type' => 'hidden', 'param_name' => 'size_responsive' ],
			];
		}

		/**
		 * Parses deprecated params.
		 */
		public static function parse_deprecated_attributes( $atts = [] ) {
			if ( empty( $atts ) || ! is_array( $atts ) ) {
				return $atts; // Guard: invalid shortcode attributes
			}
			if ( isset( $atts['responsive'] ) && 'true' === $atts['responsive'] ) {
				if ( ! empty( $atts['size_responsive'] ) ) {
					$atts['size'] = $atts['size_responsive'];
					unset( $atts['size_responsive'] );
				}
				unset( $atts['responsive'] );
			}
			return $atts;
		}

	}

}

new Vcex_Spacing_Shortcode;

if ( class_exists( 'WPBakeryShortCode' ) && ! class_exists( 'WPBakeryShortCode_Vcex_Spacing' ) ) {
	class WPBakeryShortCode_Vcex_Spacing extends WPBakeryShortCode {}
}
