<div id="groupContainer">
    <div class="hstack gap-2 mb-3">
        <div class="me-auto">
            <button id="selectionCollapseAll" class="btn btn-sm btn-danger btbAction" type="button" data-action="click" data-target="collapse all" title="Collapse all">
                <i class="bi bi-arrows-collapse"></i>
            </button>
            <button id="selectionExpandAll" class="btn btn-sm btn-danger btbAction" type="button" data-action="click" data-target="expand all" title="Expand all">
                <i class="bi bi-arrows-expand"></i>
            </button>
        </div>
        <div class="ms-auto">
            <button id="selectionNewGroup" class="btn btn-sm btn-danger btbAction" type="button" data-action="click" data-target="new group" title="New group">
                <i class="bi bi-plus"></i>
            </button>
        </div>
    </div>
    <div id="newGroupContainer">
    </div>
    <?php
    $i = 0;
    foreach ( $array as $level => $group ) :
    ?>
        <div id="<?php echo str_replace(' ', '-', $level); ?>">
            <h6><?php echo $level; ?></h6>
    <?php
        foreach ( $group as $item ) :
            $itemLabel = str_replace(' ', '-', $item);
    ?>
            <div class="row align-items-center my-1">
                <div class="col-1 d-flex justify-content-center">
                    <div class="form-check">
                        <input class="form-check-input" type="checkbox" value="" checked>
                    </div>
                </div>
                <div class="col-10">
                    <input type="text" value="<?php echo $item; ?>" class="form-control selectionGroup">
                </div>
                <div class="col-1 p-0">
                    <button class="btn p-0" type="button" data-bs-toggle="collapse" data-bs-target="#selectionGroupDefaults-<?php echo $i; ?>" aria-expanded="false" aria-controls="selectionGroupDefaults-<?php echo $i; ?>">
                        <i class="bi bi-arrows-expand text-danger"></i>
                    </button>
                </div>
            </div>
            <div id="selectionGroupDefaults-<?php echo $i; ?>" class="row align-items-center my-1 collapse mb-3">
                <div class="col-1"></div>
                <div class="col-10">
                    <div class="row">
                        <div class="row">
                            <div class="col-6">
                                <button class="text-danger btn p-0"><span class="uncheckAll small" data-group="<?php echo $i; ?>">Uncheck all</span></button> /
                                <button class="text-danger btn p-0"><span class="checkAll small" data-group="<?php echo $i; ?>">Check all</span></button>
                            </div>
                        </div>
                        <?php foreach ( $selectionCategories as $category ) : ?>
                            <div class="col-6 col-lg-3">
                                <div class="form-check">
                                    <input class="form-check-input selectionGroupDefaults-<?php echo $i; ?>" type="checkbox" value="" id="<?php echo $i; ?>">
                                    <label class="form-check-label" for="flexCheckChecked">
                                        <span class="small"><?php echo $category['title']; ?></span>
                                    </label>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                    
                </div>
                <div class="col-1"></div>
            </div>
        </div>
    <?php
            $i++;
        endforeach;
    ?>

    <hr>

    <?php
    endforeach;
    ?>
</div>