<?php

namespace ThimPress\ThimBlocks\Gutenberg\Blocks\SocialShare;

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

use ThimPress\ThimBlocks\Gutenberg\Blocks\AbstractBlockType;
use Throwable;

class SocialShareBlockType extends AbstractBlockType {

	public $block_name = 'social-share';

	public function get_supports(): array {
		return array(
			'align'                => array( 'wide', 'full', 'center' ),
			'color'                => array( 'text' => true ),
			'spacing'              => array(
				'margin'  => true,
				'padding' => true,
			),
			'layout'               => array(
				'allowSwitching' => true,
				'default'        => array(
					'type'           => 'flex',
					'justifyContent' => 'left',
					'orientation'    => 'horizontal',
				),
			),
			'__experimentalBorder' => array(
				'radius' => true,
				'width'  => true,
				'color'  => true,
				'style'  => true,
			),
		);
	}

	public function render_content_block_template( array $attributes, $content, $block ): string {
		$html = '';
		try {

			$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'thim-blocks-social-share' ) );

			ob_start();
			echo '<div ' . wp_kses_post( $wrapper_attributes ) . '>';
			echo $content;
			echo '</div>';
			$html = ob_get_clean();

		} catch ( Throwable $e ) {
			return $html;
		}

		return $html;
	}

}
