<?php
    $segmentMap = [];
    foreach($note->segments as $segment):
        $segmentMap[$segment->segmentTemplate->internal_name] = $segment;
    endforeach;

    function renderVisitTemplateNode($node, $segMap) {
        if(is_array($node)){
            renderVisitTemplateGroup($node, $segMap);
        }else{
            renderNoteTemplateLeaf($node, $segMap);
        }
    }

    function renderVisitTemplateGroup($node, $segMap){
        ?>
        <table class="table table-sm table-bordered table-striped">
            <tr>
                <td>{{$node['heading']}}</td>
                <td>
                   <?php foreach($node['children'] as $child): ?>
                        <div>
                            <?php renderVisitTemplateNode($child, $segMap); ?>
                        </div>
                    <?php endforeach; ?>
                </td>
            </tr>
        </table>
        <?php
    }

    function renderNoteTemplateLeaf($leaf, $segMap){
        $segment = $segMap[$leaf];
        if(!$segment->edit_html && !$segment->summary_html) return;
         include('app/patient/note/segment/leaf.php');
         //echo($segment->summary_html);
    }
?>
<div class="row">
    <div class="col-md-9">
        <?php
            foreach($visitTemplateUiConfig as $node) renderVisitTemplateNode($node, $segmentMap);
        ?>
    </div>
    <div class="col-md-3">
        wizards here
    </div>
</div>
<div class="segments-list" id="note-segments-list">
</div>
@include('app.patient.note.segment_script')
