<div class="note-lhs-tree pb-4 screen-only" id="note-lhs-tree">
    <?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-tree-node note-tree-heading">' .
                    '<a class="c-pointer">' . $segment->subheading . '</a>' .
                    '<div class="note-tree-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-tree-node note-tree-heading">' .
                    '<a class="c-pointer">' . $segment->heading . '</a>' .
                    '<div class="note-tree-children">'; // <!-- open new node -->
            }
            $previousHeading = $segment->heading;
        }
        echo '<div class="note-tree-node">' .
            '<a native target="_top" ' .
            'data-segment-uid="' . $segment->uid . '" ' .
            'data-segment-internal-name="' . $segment->segmentTemplate->internal_name . '" ' .
            'href="#" ' .
            'class="' . ($segment->display_title === 'MedRisk Vigilence' || $segment->subheading === 'Lifestyle' ? 'd-none' : '') . '">' . $segment->display_title . '</a>' .
            '</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 -->
    }
    ?>

    <hr>
    <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="ICDs" href="#">Claim ICDs</a></div>
    {{-- <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Handouts" href="#">Handouts</a></div> --}}
    @if(!$note->is_non_medical || true)
    <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Prescriptions" href="#">ERx &amp; Orders</a></div>
    @endif
    <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Incoming Reports" href="#">Incoming Reports</a></div>
    <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Remote Monitoring" href="#">Remote Monitoring</a></div>
    <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Supply Orders Summary" href="#">Supply Orders Summary</a></div>
    <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Vitals Settings" href="#">Vitals Settings</a></div>
    @if(!$note->is_non_medical || true)
        @if($pro->pro_type === 'ADMIN')
            <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Bills & Claims Summary" href="#">Bills & Claims Summary</a></div>
        @endif
        @if($note->method === 'IN_CLINIC' || $pro->pro_type === 'ADMIN')
            <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Pro/Payer Settings" href="#">Pro/Payer Settings</a></div>
        @endif
        @if($pro->pro_type === 'ADMIN' || ($note->hcpPro && $pro->id === $note->hcpPro->id))
            <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="HCP Bills" href="#">HCP Bills</a></div>
        @endif
        @if($pro->pro_type === 'ADMIN' || ($note->allyPro && $pro->id === $note->allyPro->id))
            <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="NA Bills" href="#">NA Bills</a></div>
        @endif
        @if($pro->pro_type === 'ADMIN')
            <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Invoices" href="#">Invoices</a></div>
        @endif
        <div class="note-tree-node"><a native="" target="_top" data-non-segment-target="Claims" href="#">Claims</a></div>
    @endif
    @if($note->is_signed_by_hcp)
        <div class="note-tree-node mb-3"><a native="" target="_top" data-non-segment-target="Addendums" href="#">Addendums</a></div>
    @endif
    <div class="note-tree-node mb-3"><a native="" target="_top" data-non-segment-target="Follow-up Appointment" href="#">Follow-up Appointment</a></div>
</div>