<?php

/**
 * Server-side rendering of the `pbg/icon-box` block.
 *
 * @package WordPress
 */

/**
 * Get Icon Box Block CSS
 *
 * Return Frontend CSS for Icon Box.
 *
 * @access public
 *
 * @param string $attr option attribute.
 * @param string $unique_id option For block ID.
 */
function get_premium_icon_box_css_style($attr, $unique_id)
{
    $css = new Premium_Blocks_css();

    $variation_name = $css->pbg_get_value($attr, 'variation.name');

    // Non-responsive shadows and icon positioning.
    $css->set_selector('.' . $unique_id . " .premium-icon-box-content");
    $css->pbg_render_shadow($attr, 'containerShadow', 'box-shadow');

    $css->set_selector('.' . $unique_id . " .premium-icon-box-content:hover");
    $css->pbg_render_shadow($attr, 'containerHoverShadow', 'box-shadow');

    $css->set_selector('.' . $unique_id . ' .is-style-var1-icon');
    $css->pbg_render_range($attr, 'iconRange', 'left', null, null, '% !important');

    $css->set_selector('.' . $unique_id . ' .is-style-horizontal1-icon');
    $css->pbg_render_range($attr, 'iconHorRange', 'top', null, null, '% !important');

    $css->render_responsive(function ($css, $device) use ($attr, $unique_id, $variation_name) {
        // Container style.
        $css->set_selector('.' . $unique_id . ' .premium-icon-box-content');
        $css->pbg_render_background($attr, 'containerBackground', $device);
        $css->pbg_render_value($attr, 'align', 'text-align', $device);
        $css->pbg_render_border($attr, 'containerBorder', $device);
        $css->pbg_render_spacing($attr, 'containerPadding', 'padding', $device);
        $css->pbg_render_spacing($attr, 'containerMargin', 'margin', $device);
        if ($variation_name === 'horizontal') {
            $css->pbg_render_value($attr, 'verticalAlign', 'align-items', $device);
        }

        $css->set_selector('.' . $unique_id . ' .premium-icon-container');
        $css->pbg_render_value($attr, 'align', 'text-align', $device);

        $css->set_selector('.' . $unique_id . ' .premium-button-group_wrap');
        $css->pbg_render_align_self($attr, 'align', 'justify-content', $device);

        $css->set_selector('.' . $unique_id . ' .premium-icon-box-content:hover');
        $css->pbg_render_background($attr, 'containerHoverBackground', $device);
        $css->pbg_render_border($attr, 'containerHoverBorder', $device, $device === 'Desktop' ? null : null, $device === 'Desktop' ? '!important' : null);
    });
    return $css->css_output();
}

/**
 * Renders the `premium/icon-box` block on server.
 *
 * @param array    $attributes The block attributes.
 * @param string   $content    The saved content.
 * @param WP_Block $block      The parsed block.
 *
 * @return string Returns the post content with the legacy widget added.
 */
function render_block_pbg_icon_box($attributes, $content, $block)
{

    return $content;
}




/**
 * Register the icon_box block.
 *
 * @uses render_block_pbg_icon_box()
 * @throws WP_Error An WP_Error exception parsing the block definition.
 */
function register_block_pbg_icon_box()
{
    if (! function_exists('register_block_type')) {
        return;
    }
    register_block_type(
        PREMIUM_BLOCKS_PATH . '/blocks-config/icon-box',
        array(
            'render_callback' => 'render_block_pbg_icon_box',
        )
    );
}

register_block_pbg_icon_box();
