<div class="d-flex rounded p-2 mb-3" style="border:1px grey dashed;">
    <div class="d-block text-center ms-auto" style="max-width:260px;">
        <a href="<?php echo URL_AI_ATTACHMENTS."/$filename"; ?>" data-fancybox="true">
            <img src="<?php echo URL_ASSETS; ?>/images/pdf-icon.png" alt="View Plan PDF" title="View Plan PDF" style="width:120px;height:120px;">
        </a>
        <div class="d-block text-truncate">
            <a href="<?php echo URL_AI_ATTACHMENTS."/$filename"; ?>" class="text-danger" data-fancybox="true">
                <span class="small"><?php echo $filename; ?></span>
            </a>
        </div>
    </div>
    <button id="selectionAutomaticGroupReset" type="button" class="btn-close ms-auto" title="Reset PDF"></button>
</div>
<div class="d-flex align-items-center justify-content-between">
    <h6>Custom</h6>
    <a id="selectionNewAutomaticGroup" class="btbAction p-0" type="button" data-action="click" data-target="new group" title="New group">
        <i class="bi bi-plus-circle text-danger"></i>
    </a>
</div>
<div id="newAutomaticGroupContainer" class="row align-items-center justify-content-center mb-3">
</div>
<?php
$i = 0;
$k = 1;
foreach ( $array as $level => $group ) :
?>

    <div id="<?php echo str_replace(' ', '-', $level); ?>" class="mb-3">
        <div class="d-flex align-items-center justify-content-between">
           <h6><?php echo $level; ?></h6>
        </div>
<?php
    foreach ( $group as $item ) :
        $itemLabel = str_replace(' ', '-', $item);
?>
        <div class="row align-items-center mb-1">
            <div class="col-1">
                <div class="form-check">
                    <input class="form-check-input selectionCheck" type="checkbox" name="selectionCheck[<?php echo $k; ?>]" value="" checked>
                </div>
            </div>
            <div class="col-11">
                <input type="text" value="<?php echo $item; ?> (<?php echo $level; ?>)" name="selectionText[<?php echo $k; ?>]" class="form-control selectionText">
            </div>
            <div class="col-1"></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">
            <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> -->
<?php
        $k++;
        $i++;
    endforeach;
?>
</div>
<?php
endforeach;
?>