<?php

namespace ThimPress\ThimBlocks\Gutenberg\Blocks\IconList;

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

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

class IconListBlockType extends AbstractBlockType {

	public $block_name = 'icon-list';

	public function get_supports(): array {
		return array(
			'align'      => true,
			'html'       => false,
			'spacing'    => array(
				'margin'          => true,
				'padding'         => true,
				'blockGap'        => true,
				'defaultControls' => array(
					'margin'   => true,
					'padding'  => true,
					'blockGap' => true,
				),
			),
			'layout'     => array(
				'allowSwitching' => true,
				'default'        => array(
					'type'           => 'constrained',
					'justifyContent' => 'left',
				),
			),
			'typography' => array(
				'fontSize'        => true,
				'fontWeight'      => true,
				'fontStyle'       => true,
				'textTransform'   => true,
				'defaultControls' => array(
					'fontSize' => true,
				),
			),
			'color'      => array(
				'text'            => true,
				'link'            => true,
				'background'      => true,
				'defaultControls' => array(
					'text'       => true,
					'background' => true,
					'link'       => false,
				),
			),
		);
	}

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

		try {
			ob_start();
			echo $content;
			$html = ob_get_clean();

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

		return $html;
	}

}
