<?php
$templateIndex = json_decode(file_get_contents(storage_path('templates/index.json')));
$hasTemplates = false;
if(isset($templateIndex->{$sectionInternalName})) {
    $hasTemplates = true;
    $templateName = '';
    $defaultTemplateName = '';
    foreach($templateIndex->{$sectionInternalName} as $k => $templateSet) {
        if($templateName === '') $templateName = $k;
        if($templateSet->default) $defaultTemplateName = $k;
    }
    if($defaultTemplateName !== '') $templateName = $defaultTemplateName;
?>
    <span class="position-relative d-none if-edit ml-3 pl-3 border-left">
        <a href="#" class="note-templates-trigger">Templates</a>
        <div class="note-template-container">
            <div class="position-relative w-100">
                <div class="note-template-output">
                    <div class="font-weight-bold text-secondary">Result:</div>
                    <div class="note-template-output-text"></div>
                </div>
                <div class="note-template-buttons d-flex align-items-center">
                    <button class="btn btn-sm btn-default bg-white border text-primary border-primary note-template-apply-trigger">Apply</button>
                    <button class="btn btn-sm btn-default bg-light border text-secondary border-secondary note-template-close-trigger">Close</button>
                </div>
            </div>
            <div class="p-1 border border-bottom">
                <select class="form-control form-control-sm note-template-set-chooser" data-section="{{$sectionInternalName}}">
                    @foreach($templateIndex->{$sectionInternalName} as $k => $templateSet)
                        <option value="{{$k}}" {{$k === $templateName ? 'selected' : ''}}>{{$templateSet->name}}</option>
                    @endforeach
                </select>
            </div>
            {{--@include('app/patient/note/_template')--}}
        </div>
    </span>
<?php
}
?>


