<?php

defined('_JEXEC') or die('resticted aceess');

AddonParser::addAddon('sp_counter', 'sp_counter_addon');
AddonParser::addAddon('sp_counter_item', 'sp_counter_item_addon');

function sp_counter_addon($atts, $content)
{

    $class = $column = $style = '';

    extract(spAddonAtts(array(
        'column' => '',
        "style" => '',
        "class" => '',
    ), $atts));
    ob_start();
    ?>

    <div class="counters-box <?php echo $class;?> <?php echo $style;?>">
        <div class="row">
            <?php
            $columns = 12 / $column;
            preg_match_all('/\[[^\]]*\]/i', $content, $matches);
            if (isset($matches[0]) && count($matches[0] > 0)) {
                foreach ($matches[0] as $item) {
                    ?>
                    <div class="content-box-percentage col-sm-<?php echo $columns;?> col-xs-6">
                        <?php echo AddonParser::spDoAddon($item);?>
                    </div>
                    <?php
                }
            } else {
                echo AddonParser::spDoAddon($content);
            }
            ?>
        </div>
    </div>

    <?php
    $html = ob_get_clean();
    return $html;
}

function sp_counter_item_addon($atts)
{
    $title = $number = '';
    extract(spAddonAtts(array(
        "title" => '',
        "number" => '',
    ), $atts));
    ob_start();
    ?>
    <div class="item">
        <div class="">
            <span class="display-percentage"><?php echo $number;?></span>
            <span class="counter-box-content"><?php echo $title;?></span>
        </div>
    </div>

    <?php
    $html = ob_get_clean();
    return $html;
}