<?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/>.
 *
 */


namespace DJExtensions\Yootheme\DJToggle\Transform;
defined('_JEXEC') or die;

class RowTransform
{
    /**
     * Transform callback.
     *
     * @param object $node
     * @param array $params
     */
    public function __invoke($node, array $params)
    {
        $sections = $node->children;

        foreach ($sections as $section) {
            if ($section->type !== 'section' || (!isset($section->props->djsectionsanywhere->enabled) || !$section->props->djsectionsanywhere->enabled)) continue;

            $attributes = explode(PHP_EOL, $section->props->attributes ?? '');

            if (isset($section->props->djsectionsanywhere->initial) && $section->props->djsectionsanywhere->initial) {
                if ($section->props->djsectionsanywhere->type != 'Modal') {
                    if (!in_array('hidden', $attributes)) {
                        $attributes[] = 'hidden';
                    }
                }

            }





            if ($section->props->djsectionsanywhere->type == 'Modal') {
                $section->type = 'djsectionsanywhere_modal';
            }else {
                if (!in_array('dj-toggle', $attributes)) {
                    $attributes[] = 'dj-toggle';
                }
            }
            $section->props->attributes = implode(PHP_EOL, $attributes);
        }

    }
}
