<div class="segments-list" id="note-segments-list">

    <?php
    $previousHeading = null;
    $previousSubHeading = null;
    ?>
    @foreach($note->segments as $segment)
        <?php
//        if ($segment->subheading !== $previousSubHeading) {
//            if (!empty($previousSubHeading)) {
//                echo '</div></div>'; // <!-- end the previous parent section -->
//            }
//            if (!empty($segment->subheading)) {
//                echo '<div class="note-content-node note-content-heading">' .
//                    '<a class="c-pointer">' . $segment->subheading . '</a>' .
//                    '<div class="note-content-children">'; // <!-- open new node -->
//            }
//            $previousSubHeading = $segment->subheading;
//        }
        if ($segment->heading !== $previousHeading) {
            if (!empty($previousHeading)) {
                echo '</div></div>'; // <!-- end the previous parent section -->
            }
            if (!empty($segment->heading)) {
                echo '<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 -->
            }
            $previousHeading = $segment->heading;
        }
        ?>
        <div class="{{$segment->segmentTemplate->internal_name === 'medrisk_vigilence' ? 'd-none' : ''}}">
            @include('app.patient.note.segment')
        </div>
    @endforeach
    <?php
//    if (!empty($previousSubHeading)) {
//        echo '</div></div>'; // <!-- close any open parent section -->
//    }
    if (!empty($previousHeading)) {
        echo '</div></div>'; // <!-- close any open parent section -->
    }
    ?>
</div>
@include('app.patient.note.segment_script')