<?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		5.0.0
 * @version		6.0.0
 */

namespace WeCodeArt\Gutenberg\Blocks\Design;

defined( 'ABSPATH' ) || exit;

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

/**
 * Gutenberg Buttons blocks.
 */
class Buttons extends Dynamic {

	use Singleton;

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

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

	/**
	 * Init.
	 */
	public function init() {
		\register_block_style( $this->get_block_type(), [
			'name' 	=> 'group',
            'label'	=> __( 'Group', 'wecodeart' ),
			'inline_style' => static::get_style( 'group' )
		] );
	}

	/**
	 * Get Block styles
	 *
	 * @return 	string 	The block styles.
	 */
	public static function get_style( $class = 'group' ) {
		$inline = '';

		switch( $class ) :
			case 'group' :
				$inline = <<<CSS
					.wp-block-buttons.is-style-group {
						--wp--style--block-gap: 0px!important;
						gap: 0!important;
					}
					.wp-block-buttons.is-style-group:not(.is-vertical) .wp-block-button:not(:first-child) .wp-block-button__link {
						border-left: 0;
						border-top-left-radius: 0;
						border-bottom-left-radius: 0;
					}
					.wp-block-buttons.is-style-group:not(.is-vertical) .wp-block-button:not(:last-child) .wp-block-button__link {
						border-top-right-radius: 0;
						border-bottom-right-radius: 0;
					}
					.wp-block-buttons.is-style-group.is-vertical .wp-block-button:not(:first-child) {
						margin-top: -1px;
					}
					.wp-block-buttons.is-style-group.is-vertical .wp-block-button:not(:first-child) .wp-block-button__link {
						border-top-left-radius: 0;
						border-top-right-radius: 0;
					}
					.wp-block-buttons.is-style-group.is-vertical .wp-block-button:not(:last-child) .wp-block-button__link {
						border-bottom-left-radius: 0;
						border-bottom-right-radius: 0;
					}
				CSS;
				break;
			default :
				break;
		endswitch;

		return wecodeart( 'styles' )::compress( $inline );
	}

	/**
	 * Block styles
	 *
	 * @return 	string 	The block styles.
	 */
	public function styles() {
		return <<<CSS
			.wp-block-buttons {
				display: flex;
				flex-flow: row wrap;
				gap: var(--wp--style--block-gap, 1em);
			}
			.wp-block-buttons .wp-block-button {
				position: relative;
			}
			.wp-block-buttons .wp-block-button:hover,
			.wp-block-buttons .wp-block-button__link:is(:focus,:active,.active) {
				z-index: 1;
			}
		CSS;
	}
}
