<?php
/**
 * WeCodeArt Framework
 *
 * WARNING: This file is part of the core WeCodeArt Framework. DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package		WeCodeArt Framework
 * @subpackage  Gutenberg CSS Frontend
 * @copyright   Copyright (c) 2025, WeCodeArt Framework
 * @since		5.0.0
 * @version		6.3.7
 */

namespace WeCodeArt\Gutenberg\Styles\Blocks;

defined( 'ABSPATH' ) || exit;

use WeCodeArt\Singleton;
use WeCodeArt\Gutenberg\Styles\Processor;
use function WeCodeArt\Functions\get_prop;

/**
 * Block CSS Processor
 */
class Social extends Processor {
	/**
	 * Parses an output and creates the styles array for it.
	 *
	 * @return 	void
	 */
	protected function process_style(): void {
		$declarations 	= [];
		$selector 		= join( '>', [ $this->get_selector( ':not(.is-style-logos-only)' ), '.wp-block-social-link' ] );
		$classnames 	= explode( ' ', get_prop( $this->attrs, 'className', '' ) );

		if( in_array( 'is-style-logos-only', $classnames ) ) {
			$selector	= join( '>', [ $this->get_selector( '.is-style-logos-only' ), '.wp-block-social-link' ] );
		}

		// Background Color 
		if ( $value = get_prop( $this->attrs, 'customIconBackgroundColor' ) ) {
			$declarations['background-color'] = $value;
		} else if ( $value = get_prop( $this->attrs, 'iconBackgroundColor' ) ) { // To be removed when GB merged into core.
			$declarations['background-color'] = sprintf( 'var(--wp--preset--color--%s)', $value );
		}

		// Icon color
		if ( $value = get_prop( $this->attrs, 'customIconColor' ) ) {
			$declarations['color'] = $value;
		} else if ( $value = get_prop( $this->attrs, 'iconColor' ) ) { // To be removed when GB merged into core.
			$declarations['color'] = sprintf( 'var(--wp--preset--color--%s)', $value );
		}

		// Size
		if ( $value = get_prop( $this->attrs, 'size' ) ) {
			$value = explode( '-', $value );
			$declarations['font-size'] = sprintf( 'var(--wp--preset--font-size--%s)', $value[1] );
		}

		if( ! empty( $declarations ) ) {
			$this->add_declarations( $declarations, $selector );
		}

		parent::process_style();
	}
}