<?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 	Entry\Meta\Terms
 * @since 		5.0.0
 * @version		6.4.5
 */

defined( 'ABSPATH' ) || exit;

use function WeCodeArt\Functions\get_prop;

/**
 * @param   int     $post_id    Current post ID
 * @param   int     $count      Terms number
 * @param   string  $terms      Terms markup
 * @param   int     $primary    Primary Category
 * @param   array   $attributes Block attributes
 */

$attributes = isset( $attributes ) ? $attributes : [];
$classnames = [];

if( isset( $primary ) ) {
    $classnames[] = 'wp-block-post-terms--has-primary';
}

if( $value = get_prop( $attributes, 'textAlign' ) ) {
    $classnames[] = 'has-text-align-' . $value;
}

$icon_name = ( isset( $primary ) || $count === 1 ) ? 'folder' : 'folders';
if( isset( $icon ) ) {
    $icon_name = $icon;
}

?>
<div <?php echo get_block_wrapper_attributes( [ 'class' => implode( ' ', $classnames ) ] ); ?>><?php

    wecodeart( 'dom' )->SVG::render( $icon_name, [
        'class' => 'wp-block-post-terms__icon fa-fw'
    ] );

    ?>
    <span class="screen-reader-text"><?php

        esc_html_e( 'Posted in', 'wecodeart' );
    
    ?></span><?php
    if( isset( $primary ) ) {
        
        printf( 
            '<a class="wp-block-post-terms__link" href="%s" rel="category tag">%s</a>', 
            esc_url( get_term_link( $primary ) ),
            esc_html( get_term_by( 'id', $primary, 'category' )->name )
        );

    } else {

        echo wp_kses_post( $terms );

    }
?></div>