<?php
/**
 * @package DJ-SectionsAnywhere
 * @copyright Copyright (C) 2017  DJ-Extensions.com LTD, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 *
 * DJContentFilters is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DJContentFilters is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DJContentFilters. If not, see <http://www.gnu.org/licenses/>.
 *
 */
defined('_JEXEC') or die;
?>

<?php

$props['id'] = "js-{$this->uid()}";

$toggleAttributes = array(
    'target: #' . $props['target']
);

if($props['show_animation'] && $props['show_animation'] != 'false') {
    $animation = 'uk-animation-' . $props['show_animation'];

    if($props['show_animation'] && $props['show_animation'] != 'false') {
        $animation .= ', uk-animation-' . $props['hide_animation'];
    }
    $toggleAttributes[] = 'animation: ' . $animation;

}

// Button
$button = $this->el('a', [

    'class' => $this->expr([
        'el-content',
        'uk-width-1-1 {@fullwidth}',
        'uk-{button_style: link-\w+}' => ['button_style' => $props['button_style']],
        'uk-button uk-button-{!button_style: |link-\w+} [uk-button-{button_size}]' => ['button_style' => $props['button_style']],
        'uk-flex-inline uk-flex-center uk-flex-middle',
    ], $element),

    'title' => ['{link_title}'],
    'uk-toggle' => implode(';',$toggleAttributes),
    'dj-toggle-target' => '#' . $props['target']

]);
$initialLabel = (($props['initial_state'] == 'show') ? $props['show_btn'] : $props['hide_btn']);
$initialIcon = (($props['initial_state'] == 'show') ? $props['show_icon'] : $props['hide_icon']);

// Icon
$icon = $this->el('span', [

    'class' => [
        'uk-margin-small-right' => $props['icon_align'] == 'left',
        'uk-margin-small-left' =>$props['icon_align'] == 'right',
    ],
    'uk-icon' => $initialIcon,

]);



$icon->attr([
    'dj-toggle-hidden-icon' => $props['show_icon'],
]);


if($props['hide_icon']) {
    $icon->attr([
        'dj-toggle-shown-icon' => $props['hide_icon'],
    ]);
}

$label = $this->el('span', [
    'dj-toggle-hidden-label' => $props['show_btn']

]);

if($props['hide_btn']) {
    $label->attr([
        'dj-toggle-shown-label' => $props['hide_btn'],
    ]);
}
?>

<?= $button($props) ?>

<?php if ($props['show_icon'] && $props['icon_align'] == 'left') : ?>
    <?= $icon($props, '') ?>
<?php endif ?>

<?php if ($props['show_btn']) : ?>
    <?= $label($props, $initialLabel) ?>
<?php endif ?>

<?php if ($props['show_icon'] && $props['icon_align'] == 'right') : ?>
    <?= $icon($props, '') ?>
<?php endif ?>

</a>

