<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Table - Product Specs
 *
 * @package AxcelersBlocks
 */

$axcelersblocks_specs_responsive = static function ( $desktop, $tablet = null, $mobile = null ) {
	return array(
		'desktop' => $desktop,
		'tablet'  => null === $tablet ? $desktop : $tablet,
		'mobile'  => null === $mobile ? ( null === $tablet ? $desktop : $tablet ) : $mobile,
	);
};

$axcelersblocks_specs_spacing = static function ( $top, $right, $bottom, $left, $linked = false ) {
	return array(
		'desktop' => array(
			'top'              => $top,
			'right'            => $right,
			'bottom'           => $bottom,
			'left'             => $left,
			'isVHActive'       => false,
			'isSidesAllActive' => $linked,
		),
		'tablet'  => array(
			'top'              => $top,
			'right'            => $right,
			'bottom'           => $bottom,
			'left'             => $left,
			'isVHActive'       => false,
			'isSidesAllActive' => $linked,
		),
		'mobile'  => array(
			'top'              => $top,
			'right'            => $right,
			'bottom'           => $bottom,
			'left'             => $left,
			'isVHActive'       => false,
			'isSidesAllActive' => $linked,
		),
	);
};

$axcelersblocks_specs_border = static function ( $sides ) {
	return array(
		'desktop' => array(
			'width'        => '',
			'style'        => '',
			'color'        => '',
			'sides'        => $sides,
			'isLinkActive' => false,
		),
		'tablet'  => array(
			'width'        => '',
			'style'        => '',
			'color'        => '',
			'sides'        => $sides,
			'isLinkActive' => false,
		),
		'mobile'  => array(
			'width'        => '',
			'style'        => '',
			'color'        => '',
			'sides'        => $sides,
			'isLinkActive' => false,
		),
	);
};

$axcelersblocks_specs_cell_border = $axcelersblocks_specs_border(
	array(
		'right'  => array(
			'width' => '1px',
			'style' => 'solid',
			'color' => '#E4E7EC',
		),
		'bottom' => array(
			'width' => '1px',
			'style' => 'solid',
			'color' => '#E4E7EC',
		),
	)
);

$axcelersblocks_specs_zero_margin = $axcelersblocks_specs_spacing( '0px', '0px', '0px', '0px', true );

$axcelersblocks_specs_bodycopy = static function ( $class, $content, $options = array() ) use ( $axcelersblocks_specs_responsive, $axcelersblocks_specs_zero_margin ) {
	$attrs = array_merge(
		array(
			'content'     => $content,
			'tagName'     => 'p',
			'uniqueClass' => $class,
			'margin'      => $axcelersblocks_specs_zero_margin,
			'fontSize'    => $axcelersblocks_specs_responsive( '15px', '15px', '14px' ),
			'lineHeight'  => $axcelersblocks_specs_responsive( '1.55', '1.55', '1.55' ),
			'fontWeight'  => $axcelersblocks_specs_responsive( '400' ),
			'textColor'   => $axcelersblocks_specs_responsive( '#475467' ),
		),
		$options
	);

	return '<!-- wp:axcelersblocks/bodycopy ' . wp_json_encode( $attrs ) . ' /-->';
};

$axcelersblocks_specs_cell = static function ( $class, $content, $options = array() ) use ( $axcelersblocks_specs_responsive, $axcelersblocks_specs_spacing, $axcelersblocks_specs_cell_border, $axcelersblocks_specs_bodycopy ) {
	$is_header = ! empty( $options['header'] );
	$is_label  = ! empty( $options['label'] );

	$cell_attrs = array(
		'uniqueClass'     => $class,
		'tagName'         => $is_header || $is_label ? 'th' : 'td',
		'padding'         => $options['padding'] ?? $axcelersblocks_specs_spacing( '18px', '20px', '18px', '20px' ),
		'backgroundColor' => $options['backgroundColor'] ?? $axcelersblocks_specs_responsive( $is_label ? '#F9FAFB' : '#FFFFFF' ),
		'border'          => $axcelersblocks_specs_cell_border,
		'verticalAlign'   => $axcelersblocks_specs_responsive( 'top' ),
		'textAlign'       => $options['textAlign'] ?? $axcelersblocks_specs_responsive( 'left' ),
	);

	if ( $is_header || $is_label ) {
		$cell_attrs['scope'] = $is_header ? 'col' : 'row';
	}

	$text_attrs = array(
		'fontWeight' => $axcelersblocks_specs_responsive( $options['fontWeight'] ?? ( $is_header || $is_label ? '700' : '400' ) ),
		'textColor'  => $axcelersblocks_specs_responsive( $options['textColor'] ?? ( $is_header ? '#FFFFFF' : ( $is_label ? '#111827' : '#475467' ) ) ),
		'fontSize'   => $axcelersblocks_specs_responsive( $options['fontSize'] ?? ( $is_header ? '14px' : '15px' ), $options['fontSize'] ?? ( $is_header ? '14px' : '15px' ), $options['mobileFontSize'] ?? '14px' ),
		'lineHeight' => $axcelersblocks_specs_responsive( $options['lineHeight'] ?? '1.5' ),
	);

	return '<!-- wp:axcelersblocks/table-cell ' . wp_json_encode( $cell_attrs ) . ' -->' .
		$axcelersblocks_specs_bodycopy( $class . '-text', $content, $text_attrs ) .
	'<!-- /wp:axcelersblocks/table-cell -->';
};

$axcelersblocks_specs_row = static function ( $class, $cells ) {
	return '<!-- wp:axcelersblocks/table-row {"uniqueClass":"' . esc_attr( $class ) . '"} -->' .
		implode( '', $cells ) .
	'<!-- /wp:axcelersblocks/table-row -->';
};

$axcelersblocks_specs_section = static function ( $class, $tag_name, $rows ) {
	return '<!-- wp:axcelersblocks/table-section {"uniqueClass":"' . esc_attr( $class ) . '","tagName":"' . esc_attr( $tag_name ) . '"} -->' .
		implode( '', $rows ) .
	'<!-- /wp:axcelersblocks/table-section -->';
};

return array(
	'title'         => __( 'AXB: Table - Product Specs', 'axcelersblocks' ),
	'description'   => __( 'A compact product specification table with row headers and clean attribute-driven styling.', 'axcelersblocks' ),
	'categories'    => array( 'axcelersblocks-table' ),
	'keywords'      => array( 'table', 'specs', 'specifications', 'product', 'details', 'axcelersblocks' ),
	'viewportWidth' => 1100,
	'content'       =>

	'<!-- wp:axcelersblocks/box {"tagName":"section","align":"full","uniqueClass":"axb-table-02","padding":{"desktop":{"top":"84px","right":"24px","bottom":"84px","left":"24px","isVHActive":false,"isSidesAllActive":true},"tablet":{"top":"70px","right":"20px","bottom":"70px","left":"20px","isVHActive":false,"isSidesAllActive":true},"mobile":{"top":"54px","right":"16px","bottom":"54px","left":"16px","isVHActive":false,"isSidesAllActive":true}},"backgroundColor":{"desktop":"#FFFFFF","tablet":"#FFFFFF","mobile":"#FFFFFF"}} -->' .

		'<!-- wp:axcelersblocks/box {"uniqueClass":"axb-table-02__container","maxWidth":{"desktop":"920px","tablet":"920px","mobile":"920px"},"margin":{"desktop":{"top":"","right":"auto","bottom":"","left":"auto","isVHActive":false,"isSidesAllActive":false},"tablet":{"top":"","right":"auto","bottom":"","left":"auto","isVHActive":false,"isSidesAllActive":false},"mobile":{"top":"","right":"auto","bottom":"","left":"auto","isVHActive":false,"isSidesAllActive":false}},"padding":{"desktop":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"tablet":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"mobile":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true}},"display":{"desktop":"flex","tablet":"flex","mobile":"flex"},"flexDirection":{"desktop":"column","tablet":"column","mobile":"column"},"rowGap":{"desktop":"26px","tablet":"24px","mobile":"20px"}} -->' .

			'<!-- wp:axcelersblocks/box {"uniqueClass":"axb-table-02__intro","maxWidth":{"desktop":"680px","tablet":"680px","mobile":"100%"},"padding":{"desktop":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"tablet":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"mobile":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true}},"display":{"desktop":"flex","tablet":"flex","mobile":"flex"},"flexDirection":{"desktop":"column","tablet":"column","mobile":"column"},"rowGap":{"desktop":"12px","tablet":"12px","mobile":"10px"}} -->' .
				'<!-- wp:axcelersblocks/heading {"content":"Product specifications","tagName":"h2","textAlign":{"desktop":"left","tablet":"left","mobile":"left"},"fontSize":{"desktop":"34px","tablet":"30px","mobile":"25px"},"lineHeight":{"desktop":"1.16","tablet":"1.2","mobile":"1.22"},"fontWeight":{"desktop":"700","tablet":"700","mobile":"700"},"textColor":{"desktop":"#111827","tablet":"#111827","mobile":"#111827"}} /-->' .
				'<!-- wp:axcelersblocks/bodycopy {"content":"Use this specs table to present product, service, or platform details in a structured format.","fontSize":{"desktop":"16px","tablet":"16px","mobile":"15px"},"lineHeight":{"desktop":"1.65","tablet":"1.65","mobile":"1.6"},"textColor":{"desktop":"#475467","tablet":"#475467","mobile":"#475467"},"margin":{"desktop":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"tablet":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"mobile":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true}}} /-->' .
			'<!-- /wp:axcelersblocks/box -->' .

			'<!-- wp:axcelersblocks/box {"uniqueClass":"axb-table-02__scroll","overflowX":{"desktop":"auto","tablet":"auto","mobile":"auto"},"overflowY":{"desktop":"hidden","tablet":"hidden","mobile":"hidden"},"backgroundColor":{"desktop":"#FFFFFF","tablet":"#FFFFFF","mobile":"#FFFFFF"},"borderRadius":{"desktop":{"value":"8px","corners":{},"isLinkActive":true},"tablet":{"value":"8px","corners":{},"isLinkActive":true},"mobile":{"value":"8px","corners":{},"isLinkActive":true}},"padding":{"desktop":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"tablet":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true},"mobile":{"top":"0px","right":"0px","bottom":"0px","left":"0px","isVHActive":false,"isSidesAllActive":true}}} -->' .

				'<!-- wp:axcelersblocks/table {"uniqueClass":"axb-table-02__table","cols":[{"width":"32%","backgroundColor":"#F9FAFB"},{"width":"68%"}],"borderSpacing":{"desktop":"0","tablet":"0","mobile":"0"},"width":{"desktop":"100%","tablet":"100%","mobile":"100%"},"minWidth":{"desktop":"640px","tablet":"640px","mobile":"620px"},"backgroundColor":{"desktop":"#FFFFFF","tablet":"#FFFFFF","mobile":"#FFFFFF"},"border":{"desktop":{"width":"","style":"","color":"","sides":{"top":{"width":"1px","style":"solid","color":"#E4E7EC"},"left":{"width":"1px","style":"solid","color":"#E4E7EC"}},"isLinkActive":false},"tablet":{"width":"","style":"","color":"","sides":{"top":{"width":"1px","style":"solid","color":"#E4E7EC"},"left":{"width":"1px","style":"solid","color":"#E4E7EC"}},"isLinkActive":false},"mobile":{"width":"","style":"","color":"","sides":{"top":{"width":"1px","style":"solid","color":"#E4E7EC"},"left":{"width":"1px","style":"solid","color":"#E4E7EC"}},"isLinkActive":false}}} -->' .

					$axcelersblocks_specs_section(
						'axb-table-02__head',
						'thead',
						array(
							$axcelersblocks_specs_row(
								'axb-table-02__head-row',
								array(
									$axcelersblocks_specs_cell( 'axb-table-02__h-spec', 'Specification', array( 'header' => true, 'backgroundColor' => $axcelersblocks_specs_responsive( '#111827' ) ) ),
									$axcelersblocks_specs_cell( 'axb-table-02__h-detail', 'Details', array( 'header' => true, 'backgroundColor' => $axcelersblocks_specs_responsive( '#111827' ) ) ),
								)
							),
						)
					) .

					$axcelersblocks_specs_section(
						'axb-table-02__body',
						'tbody',
						array(
							$axcelersblocks_specs_row(
								'axb-table-02__row-type',
								array(
									$axcelersblocks_specs_cell( 'axb-table-02__type-label', 'Product type', array( 'label' => true ) ),
									$axcelersblocks_specs_cell( 'axb-table-02__type-value', 'Design system block toolkit for building reusable WordPress sections.' ),
								)
							),
							$axcelersblocks_specs_row(
								'axb-table-02__row-use',
								array(
									$axcelersblocks_specs_cell( 'axb-table-02__use-label', 'Core use', array( 'label' => true ) ),
									$axcelersblocks_specs_cell( 'axb-table-02__use-value', 'Landing pages, pricing sections, editorial layouts, feature lists, and content-heavy pages.' ),
								)
							),
							$axcelersblocks_specs_row(
								'axb-table-02__row-responsive',
								array(
									$axcelersblocks_specs_cell( 'axb-table-02__responsive-label', 'Responsive controls', array( 'label' => true ) ),
									$axcelersblocks_specs_cell( 'axb-table-02__responsive-value', 'Desktop, tablet, and mobile values for spacing, typography, layout, borders, and sizing.' ),
								)
							),
							$axcelersblocks_specs_row(
								'axb-table-02__row-content',
								array(
									$axcelersblocks_specs_cell( 'axb-table-02__content-label', 'Content support', array( 'label' => true ) ),
									$axcelersblocks_specs_cell( 'axb-table-02__content-value', 'Text, media, buttons, lists, tables, and dynamic post or taxonomy content.' ),
								)
							),
							$axcelersblocks_specs_row(
								'axb-table-02__row-style',
								array(
									$axcelersblocks_specs_cell( 'axb-table-02__style-label', 'Styling options', array( 'label' => true ) ),
									$axcelersblocks_specs_cell( 'axb-table-02__style-value', 'Backgrounds, borders, radius, shadows, hover states, colors, and typographic hierarchy.' ),
								)
							),
							$axcelersblocks_specs_row(
								'axb-table-02__row-fit',
								array(
									$axcelersblocks_specs_cell( 'axb-table-02__fit-label', 'Recommended for', array( 'label' => true ) ),
									$axcelersblocks_specs_cell( 'axb-table-02__fit-value', 'Teams that need polished page sections while keeping every part editable in the block editor.' ),
								)
							),
						)
					) .

				'<!-- /wp:axcelersblocks/table -->' .

			'<!-- /wp:axcelersblocks/box -->' .

		'<!-- /wp:axcelersblocks/box -->' .

	'<!-- /wp:axcelersblocks/box -->',
);
