<?php /** @var \IAWP\Plugin_Group[] $plugin_groups */  ?>
<?php /** @var \IAWP\Plugin_Group_Option[] $options */  ?>
<?php /** @var string $option_type */  ?>
<?php /** @var string $option_name */  ?>
<?php /** @var string $option_icon */  ?>

<?php /* Array indicies are used to add section headers. Make sure there are no gaps. */ ?>
<?php $options = array_values($options);  ?>

<?php 
$plugin_groups = array_filter($plugin_groups, function ($plugin_group) use ($options) {
 foreach ($options as $option) {
 if($option->is_member_of_plugin_group($plugin_group->id())) {
 return true;
 }
 }

 return false;
});
 ?>

<?php 
 // Only one group with one option? Don't render the button or modal.
 if(count($plugin_groups) === 1) {
 $plugin_group_options = array_filter($options, function ($option) use ($plugin_groups) {
 return $option->is_member_of_plugin_group($plugin_groups[0]->id());
 });

 if(count($plugin_group_options) === 1) {
 return;
 }
 }
 ?>

<div data-controller="plugin-group-options"
 data-plugin-group-options-option-type-value="<?php echo \htmlentities($option_type??'', ENT_QUOTES, 'UTF-8', false); ?>"
 class="button-modal-container"
>
 <?php /* Toggle button */ ?>
 <button id=""
 class="stats-toggle-button iawp-button"
 data-plugin-group-options-target="modalButton"
 data-action="plugin-group-options#toggleModal"
 >
 <span class="dashicons dashicons-<?php echo \htmlentities($option_icon??'', ENT_QUOTES, 'UTF-8', false); ?>"></span>
 <?php echo \htmlentities($option_name??'', ENT_QUOTES, 'UTF-8', false); ?>

 </button>

 <?php /* Toggle modal */ ?>
 <div data-plugin-group-options-target="modal"
 class="stats-toggle"
 >
 <div class="top title-small">
 <?php esc_html_e('Choose Stats to Display', 'independent-analytics'); ?>
 <span data-plugin-group-options-target="spinner" class="dashicons dashicons-update iawp-spin hidden"></span>
 </div>
 <div class="inner">
 <div id="stats-toggle-sidebar" class="sidebar">
 <ul>
 <?php $__currentLoopData = $plugin_groups; $this->addLoop($__currentLoopData);$this->getFirstLoop();
 foreach($__currentLoopData as $plugin_group): $loop = $this->incrementLoopIndices();  ?>
 <li>
 <a class="link-dark <?php echo \htmlentities($plugin_group->id() === 'general' ? 'current' : ''??'', ENT_QUOTES, 'UTF-8', false); ?>"
 data-option-id="<?php echo \htmlentities($plugin_group->id()??'', ENT_QUOTES, 'UTF-8', false); ?>"
 data-action="plugin-group-options#requestGroupChange"
 data-plugin-group-options-target="tab"
 href="#"
 >
 <span><?php echo \htmlentities($plugin_group->name()??'', ENT_QUOTES, 'UTF-8', false); ?></span>
 <?php if($plugin_group->requires_pro() && iawp_is_free()): ?>
 <span class="pro-label"><?php esc_html_e('PRO', 'independent-analytics'); ?></span>
 <?php endif; ?>
 </a>
 </li>
 <?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>
 </ul>
 </div>
 <div class="main">
 <?php $__currentLoopData = $plugin_groups; $this->addLoop($__currentLoopData);$this->getFirstLoop();
 foreach($__currentLoopData as $plugin_group): $loop = $this->incrementLoopIndices();  ?>
 <div class="checkbox-container <?php echo \htmlentities($plugin_group->id() === 'general' ? 'current' : ''??'', ENT_QUOTES, 'UTF-8', false); ?>"
 data-option-id="<?php echo \htmlentities($plugin_group->id()??'', ENT_QUOTES, 'UTF-8', false); ?>"
 data-plugin-group-options-target="checkboxContainer"
 <?php /*                             data-metric-category="<?php echo \htmlentities($plugin_group->id()??'', ENT_QUOTES, 'UTF-8', false); ?>"*/ ?>
 >
 <span class="metrics-title"><?php echo \htmlentities($plugin_group->name()??'', ENT_QUOTES, 'UTF-8', false); ?></span>

 <?php $__currentLoopData = $options; $this->addLoop($__currentLoopData);$this->getFirstLoop();
 foreach($__currentLoopData as $index => $option): $loop = $this->incrementLoopIndices();  ?>
 <?php if(!$option->is_subgroup_plugin_enabled() || !$option->is_member_of_plugin_group($plugin_group->id())): ?>
 <?php continue; ?>
 <?php endif; ?>

 <?php if(is_string($option->plugin_group_header()) && array_key_exists($index - 1, $options) && ($options[$index -1])->plugin_group_header() !== $option->plugin_group_header()): ?>
 <span class="metrics-subtitle"><?php echo \htmlentities($option->plugin_group_header()??'', ENT_QUOTES, 'UTF-8', false); ?></span>
 <?php endif; ?>

 <label class="<?php echo \htmlentities(!$option->is_group_plugin_enabled() ? 'disabled' : ''??'', ENT_QUOTES, 'UTF-8', false); ?>">
 <?php if(!$option->is_group_plugin_enabled()): ?>
 <input id="iawp_<?php echo \htmlentities($option_type??'', ENT_QUOTES, 'UTF-8', false); ?>_<?php echo \htmlentities($option->id()??'', ENT_QUOTES, 'UTF-8', false); ?>"
 type="checkbox" 
 disabled="disabled">
 <?php else: ?>
 <input id="iawp_<?php echo \htmlentities($option_type??'', ENT_QUOTES, 'UTF-8', false); ?>_<?php echo \htmlentities($option->id()??'', ENT_QUOTES, 'UTF-8', false); ?>"
 type="checkbox"
 data-action="plugin-group-options#toggleOption"
 data-plugin-group-options-target="checkbox"
 name="<?php echo \htmlentities($option->id()??'', ENT_QUOTES, 'UTF-8', false); ?>"
 <?php echo \htmlentities(checked(true, $option->is_visible(), true)??'', ENT_QUOTES, 'UTF-8', false); ?>

 />
 <?php endif; ?>
 <span><?php echo \htmlentities($option->name()??'', ENT_QUOTES, 'UTF-8', false); ?></span>
 </label>
 <?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>

 <?php if($plugin_group->requires_pro() && iawp_is_free()): ?>
 <div class="required-plugin-note">
 <p><?php echo \htmlentities($plugin_group->upgrade_message()??'', ENT_QUOTES, 'UTF-8', false); ?></p>
 <p><a href="<?php echo \htmlentities($plugin_group->upgrade_link()??'', ENT_QUOTES, 'UTF-8', false); ?>"
 class="link-purple"
 target="_blank"><?php esc_html_e('Learn more', 'independent-analytics'); ?></a>
 </p>
 </div>
 <?php elseif(!$plugin_group->has_active_group_plugins() && iawp_is_pro()): ?>
 <div class="required-plugin-note">
 <p><?php echo \htmlentities($plugin_group->activate_message()??'', ENT_QUOTES, 'UTF-8', false); ?></p>
 <p><a href="<?php echo \htmlentities($plugin_group->activate_link()??'', ENT_QUOTES, 'UTF-8', false); ?>"
 class="link-purple"
 target="_blank"><?php esc_html_e('Learn more', 'independent-analytics'); ?></a>
 </p>
 </div>
 <?php elseif(!$plugin_group->has_tracked_data()): ?>
 <div class="required-plugin-note">
 <p><?php echo \htmlentities($plugin_group->no_tracked_data_message()??'', ENT_QUOTES, 'UTF-8', false); ?></p>
 </div>
 <?php endif; ?>
 </div>
 <?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>
 </div>
 </div>
 </div>
</div>