<?php
$previousHeading = null;
$previousSubHeading = null;
?>
@foreach($segments as $segment)
    @if($segment->segmentTemplate->internal_name !== 'medrisk_vigilence')
        <?php
        if ($segment->heading !== $previousHeading) {
        if (!empty($previousHeading)) {
            echo '</div></div>'; // <!-- end the previous parent section -->
        }
        if (!empty($segment->heading)) {

        ?>
        <div class="note-content-node note-content-heading">
            <div class="py-2 px-3 border-bottom font-size-16 font-weight-bold bg-light text-secondary {{ $previousHeading ? 'mt-4 border-top' : '' }}">
                {{ $segment->heading }}
            </div>
            <div class="note-content-children ml-5 border-left">
                <!-- open new node -->
        <?php
        }
        $previousHeading = $segment->heading;
        }
        ?>
        @include('app.patient.note.segment-resolve')
    @endif
@endforeach
<?php
if (!empty($previousHeading)) {
    echo '</div></div>'; // <!-- close any open parent section -->
}
?>