<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
    <div id="wrapper">
        <div class="content">
            <div class="row">
                <?php if ($this->session->flashdata('debug')) {
                    ?>
                    <div class="col-lg-12">
                        <div class="alert alert-warning">
                            <?php echo $this->session->flashdata('debug'); ?>
                        </div>
                    </div>
                    <?php
                } ?>
                <div class="col-md-3">
                    <h4 class="tw-font-semibold tw-mt-0 tw-text-neutral-800">
                        <?php echo _l('settings'); ?>
                    </h4>
                    <ul class="nav navbar-pills navbar-pills-flat nav-tabs nav-stacked">
                        <?php
                        $i = 0;
                        foreach ($tabs as $group) { ?>
                            <li class="settings-group-<?php echo $group['slug']; ?><?php echo ($i === 0) ? ' active' : '' ?>">
                                <a href="<?php echo !empty($group['href']) && $group['href'] !== '#' ? $group['href'] : admin_url('propertybase/settings?group=' . $group['slug']); ?>"
                                   data-group="<?php echo $group['slug']; ?>">
                                    <i class="<?php echo $group['icon'] ?: 'fa-regular fa-circle-question'; ?> menu-icon"></i>
                                    <?php echo $group['name']; ?>

                                    <?php if (isset($group['badge'], $group['badge']['value']) && !empty($group['badge'])) { ?>
                                        <span
                                                class="badge pull-right
        <?= isset($group['badge']['type']) && $group['badge']['type'] != '' ? "bg-{$group['badge']['type']}" : 'bg-info' ?>" <?= (isset($group['badge']['type']) && $group['badge']['type'] == '') ||
                                        isset($group['badge']['color']) ? "style='background-color: {$group['badge']['color']}'" : '' ?>>
                                <?= $group['badge']['value'] ?>
                            </span>
                                    <?php } ?>

                                </a>
                            </li>
                            <?php $i++;
                        }
                        ?>
                    </ul>
                </div>
                <div class="col-md-9">
                    <h4 class="tw-font-semibold tw-mt-0 tw-text-neutral-800">
                        <?php echo _l($tab['name']); ?>
                    </h4>
                    <div class="panel_s">
                        <div class="panel-body">
                            <?php hooks()->do_action('propertybase_before_settings_group_view', $tab); ?>
                            <?php propertybase_load_view($tab['view'], ['tab' => $tab]) ?>
                            <?php hooks()->do_action('propertybase_after_settings_group_view', $tab); ?>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
<?php init_tail(); ?>
    <script>
        (function ($) {
            "use strict";

            $(function () {
                var slug = "<?php echo $tab['slug']; ?>";

                $(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
                    var settingsForm = $('#settings-form');

                    if (settingsForm.hasClass('custom-update-url')) {
                        return;
                    }

                    var tab = $(this).attr('href').slice(1);
                    settingsForm.attr('action', '<?php echo site_url($this->uri->uri_string()); ?>?group=' + slug +
                        '&active_tab=' + tab);
                });
            });

        })(jQuery);
    </script>

<?php hooks()->do_action('propertybase_settings_group_end', $tab); ?>