'' !== $g[0] || [] !== $g[1] ) );
$group = static fn ( string $title ): string => sprintf( '%2$s', min( 6, $level + 1 ), esc_html( $title ) );
$root = static fn ( string $class ): array => [ 'class' => $class . ( $highlighted ? ' is-highlighted' : '' ), 'data-rooster-ui' => 'rooster-one/plan' ] + ( '' !== $anchor ? [ 'id' => $anchor ] : [] );
$top = $highlighted && '' !== $badge ? '' . esc_html( $badge ) . '' : '';
if ( 'tier' === (string) ( $attributes['layout'] ?? '' ) ) {
$tone = AIEO_Engine_Blocks::tone( (string) ( $attributes['tone'] ?? '' ), 'one' );
$tagline = trim( (string) ( $attributes['tagline'] ?? '' ) );
$period = trim( (string) ( $attributes['period'] ?? '' ) );
$note = trim( (string) ( $attributes['note'] ?? '' ) );
$rows = AIEO_Engine_Blocks::lines( (string) ( $attributes['volume'] ?? '' ) );
$inner = $top . ( '' !== $name ? sprintf( '%3$s', $level, esc_attr( AIEO_Engine_Blocks::tone_classes( $tone ) ), esc_html( $name ) ) : '' );
if ( '' !== $tagline ) {
$inner .= '
' . esc_html( $tagline ) . '
';
}
if ( '' !== $price ) {
$inner .= '' . esc_html( $price ) . ''
. ( '' !== $period ? '' . esc_html( $period ) . '' : '' ) . '
';
}
if ( '' !== $note ) {
$place = '' === $price ? ' is-first' : ( $rows ? ' is-before-volume' : '' );
$inner .= '' . AIEO_Engine_Blocks::inline( $note ) . '
';
}
if ( $rows ) {
$cell = static fn ( string $text ): string => preg_match( '/^(.*\S)\s+((?:\x{2212}|-)\d+(?:[.,]\d+)?%)$/u', $text, $m )
? esc_html( $m[1] ) . ' ' . esc_html( $m[2] ) . ''
: esc_html( $text );
$table = '';
foreach ( $rows as $r => $row ) {
$tag = 0 === $r ? 'th' : 'td';
$table .= '';
foreach ( array_map( 'trim', explode( '|', $row ) ) as $text ) {
$table .= '<' . $tag . ( 'th' === $tag ? ' scope="col"' : '' ) . '>' . $cell( $text ) . '' . $tag . '>';
}
$table .= '
';
}
$caption = trim( (string) ( $attributes['volumeCaption'] ?? '' ) );
$fine = trim( (string) ( $attributes['volumeNote'] ?? '' ) );
$inner .= ''
. ( '' !== $caption ? '
' . esc_html( $caption ) . '' : '' )
. '
'
. ( '' !== $fine ? '
' . esc_html( $fine ) . '
' : '' )
. '
';
}
foreach ( $groups as [ $title, $items ] ) {
$inner .= ( '' !== $title ? $group( $title ) : '' )
. ( $items ? '- ' . implode( '
- ', array_map( [ 'AIEO_Engine_Blocks', 'inline' ], $items ) ) . '
' : '' );
}
$cta = trim( (string) ( $attributes['ctaText'] ?? '' ) );
$href = trim( (string) ( $attributes['ctaHref'] ?? '' ) );
if ( '' !== $cta && '' !== $href ) {
$other = (string) wp_parse_url( $href, PHP_URL_HOST );
$external = '' !== $other && $other !== (string) wp_parse_url( home_url( '/' ), PHP_URL_HOST );
$kind = 'outline' === (string) ( $attributes['ctaStyle'] ?? '' ) ? 'outline' : 'primary';
$inner .= '' . esc_html( $cta )
. ( $external ? ' ' . esc_html__( '(opens in a new tab)', 'ai-eshop-optimizer' ) . '' : '' ) . '';
}
$wrapper = AIEO_Engine_Blocks::wrapper( $library, $root( 'rooster-plan-card rooster-plan-card--tier' ) );
AIEO_Engine_Blocks::out( sprintf( '%2$s
', $wrapper, $inner ) );
return;
}
$tagline = trim( (string) ( $attributes['tagline'] ?? '' ) );
$period = trim( (string) ( $attributes['period'] ?? '' ) );
$note = trim( (string) ( $attributes['note'] ?? '' ) );
$cta = trim( (string) ( $attributes['ctaText'] ?? '' ) );
$href = trim( (string) ( $attributes['ctaHref'] ?? '' ) );
$wrapper = AIEO_Engine_Blocks::wrapper( $library, $root( 'rooster-plan-card' ) );
$inner = $top;
if ( '' !== $name ) {
$inner .= sprintf( '%2$s', $level, esc_html( $name ) );
}
if ( '' !== $tagline ) {
$inner .= '' . esc_html( $tagline ) . '
';
}
if ( '' !== $price ) {
$inner .= '' . esc_html( $price ) . ''
. ( '' !== $period ? '' . esc_html( $period ) . '' : '' ) . '
';
}
if ( '' !== $note ) {
$inner .= '' . AIEO_Engine_Blocks::inline( $note ) . '
';
}
foreach ( $groups as [ $title, $items ] ) {
$inner .= '' !== $title ? $group( $title ) : '';
if ( $items ) {
$inner .= '';
foreach ( $items as $feature ) {
$inner .= '- ' . AIEO_Engine_Blocks::inline( $feature ) . '
';
}
$inner .= '
';
}
}
if ( '' !== $cta && '' !== $href ) {
$inner .= '';
}
AIEO_Engine_Blocks::out( sprintf( '%2$s
', $wrapper, $inner ) );