<?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\Blocks
 * @copyright   Copyright (c) 2025, WeCodeArt Framework
 * @since		6.2.0
 * @version		6.5.7
 */

namespace WeCodeArt\Gutenberg\Blocks\Design;

defined( 'ABSPATH' ) || exit;

use WeCodeArt\Singleton;
use WeCodeArt\Gutenberg\Blocks\Dynamic;
use function WeCodeArt\Functions\get_prop;

/**
 * Gutenberg details block.
 */
class Accordion extends Dynamic {

	use Singleton;

	/**
	 * Block namespace.
	 *
	 * @var string
	 */
	protected $namespace = 'core';

	/**
	 * Block name.
	 *
	 * @var string
	 */
	protected $block_name = 'accordion';

	/**
	 * Block args.
	 *
	 * @param	array $current	Existing register args
	 *
	 * @return 	array
	 */
	public function block_type_args( array $current ): array {
		$supports 	= get_prop( $current, [ 'supports' ], [] ); 

		return [
			'render_callback' 	=> [ $this, 'render' ],
			'supports'			=> wp_parse_args( [], $supports )
		];
	}

	/**
	 * Dynamically renders the `core/accordion` block.
	 *
	 * @param 	array 	$attributes	The attributes.
	 * @param 	string 	$content 	The block markup.
	 *
	 * @return 	string 	The block markup.
	 */
	public function render( array $attributes = [], string $content = '' ): string {
		return render_block_core_accordion( $attributes, wecodeart( 'dom' )::set_content( 
			$content, 
			[ 'class_name' => 'wp-block-accordion-heading__toggle-icon' ],
			apply_filters( 'wecodeart/filter/gutenberg/block/accordion/icon', self::icon() )
		) );
	}

	/**
	 * Accordion icon.
	 *
	 * @return 	string 	The icon HTML.
	 */
	public static function icon(): string {
		return <<<HTML
			<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="svg-inline">
				<path fill="currentColor" fill-rule="evenodd" d="M7 8.5a1 1 0 0 0-.707 1.707l5 5a1 1 0 0 0 1.414 0l5-5A1 1 0 0 0 17 8.5H7Z" clip-rule="evenodd"/>
			</svg>
		HTML;
	}

	/**
	 * Block styles
	 *
	 * @return 	string 	The block styles.
	 */
	public function styles(): string {
		return <<<CSS
			.wp-block-accordion {
				interpolate-size: allow-keywords;
				--wp--accordion-transition: all 0.15s ease;
				--wp--accordion-border-color: var(--wp--preset--color--accent);
				--wp--accordion-border-width: 1px;
				--wp--accordion-border-radius: 5px;
				--wp--accordion-inner-border-radius: calc(var(--wp--accordion-border-radius) - (var(--wp--accordion-border-width)));
				--wp--accordion-btn-padding-x: 1.25rem;
				--wp--accordion-btn-padding-y: 1rem;
				--wp--accordion-btn-color: ;
				--wp--accordion-btn-bg: ;
				--wp--accordion-btn-icon-transform: rotate(0deg);
				--wp--accordion-btn-icon-transition: transform 0.2s ease-in-out;
				--wp--accordion-btn-focus-border-color: var(--wp--preset--color--primary);
				--wp--accordion-btn-focus-box-shadow: 0 0 0 1px var(--wp--accordion-btn-focus-border-color);
				--wp--accordion-body-padding-x: 1.25rem;
				--wp--accordion-body-padding-y: 1rem;
				--wp--accordion-active-color: var(--wp--preset--color--primary);
				--wp--accordion-active-bg: var(--wp--preset--color--accent); 
			}

			.wp-block-accordion-panel { 
				padding: 0 var(--wp--accordion-body-padding-y) var(--wp--accordion-body-padding-x);
				visibility: hidden;
			} 
		CSS;
	}
}