<?php $iName = $segment->segmentTemplate->internal_name; ?>
<?php $isLSSegment = strpos($iName, 'lifestyle_') === 0; ?>
<?php $isOmegaHistorySegment = strpos($iName, 'omega_history_') === 0; ?>

<div class="border-bottom note-section visit-segment {{$note->is_signed_by_hcp ? '' : 'edit-trigger'}} {{strpos($iName, 'lifestyle_') === 0 && $iName !== 'lifestyle_general' ? 'zero-height' : ''}}"
     data-segment-uid="{{ $segment->uid }}"
     data-segment-template-uid="{{ $segment->segmentTemplate->uid }}"
     data-segment-template-name="{{ $segment->segmentTemplate->internal_name }}">

    <div class="d-flex align-items-baseline bg-light text-secondary p-2" style="border-bottom: 1px solid #dee2e6;">

    <!-- title -->

        @if($iName === 'medrisk_vigilence')
            <div class="font-weight-bold text-center flex-grow-1">
                <div class="on-hover-hide font-weight-normal text-info font-weight-bold text-center pt-2 font-size-11">MRV</div>
                <span class="on-hover-only text-left">MedRisk Vigilence</span>
            </div>
        @else
            <span class="font-weight-bold d-flex align-items-center {{$isLSSegment || $iName === 'medrisk_vigilence' ? '' : 'xxxmb-2'}}" style="">
                <span style="color: black; text-decoration: underline; font-size: 13px;">
		@if($isLSSegment && $iName === 'lifestyle_general')
                    Lifestyle
                @else
                    {{$segment->display_title}}
                @endif
		</span>
                @if($segment->heading && $iName !== 'medrisk_vigilence')
                    <span class="text-secondary ml-2 text-sm font-weight-normal">({{$segment->heading}})</span>
                @endif
            </span>
        @endif

        @if($isLSSegment)
            @if($iName === 'lifestyle_general')
                <a href="#" class="ls-segment-trigger ml-2" data-target="lifestyle_general">General</a>
                <span class="mx-2 text-secondary text-sm">|</span>
                <a href="#" class="ls-segment-trigger" data-target="lifestyle_nutrition">Nutrition</a>
                <span class="mx-2 text-secondary text-sm">|</span>
                <a href="#" class="ls-segment-trigger" data-target="lifestyle_physical_activity">Physical Act.</a>
                <span class="mx-2 text-secondary text-sm">|</span>
                <a href="#" class="ls-segment-trigger" data-target="lifestyle_sleep">Sleep</a>
                <span class="mx-2 text-secondary text-sm">|</span>
                <a href="#" class="ls-segment-trigger" data-target="lifestyle_social">Social Relns.</a>
                <span class="mx-2 text-secondary text-sm">|</span>
                <a href="#" class="ls-segment-trigger" data-target="lifestyle_substances">Subst. Use</a>
                <span class="mx-2 text-secondary text-sm">|</span>
                <a href="#" class="ls-segment-trigger" data-target="lifestyle_stress">Stress</a>
            @else
                <span class="text-info ml-auto font-weight-normal">(click to view)</span>
            @endif
        @endif

        @if(!$note->is_signed_by_hcp && !$isLSSegment)
            <a class="edit-trigger d-none if-edit c-pointer ml-3">
                <i class="fas fa-caret-up font-size-16"></i>
            </a>

            <!-- refresh -->
            <a class="ml-3 font-weight-normal refresh-segment text-primary c-pointer {{$iName === 'medrisk_vigilence' ? 'on-hover-only' : ''}} screen-only"
               data-segment-uid="{{$segment->uid}}"
               title="Update with latest patient data">
                <i class="fa fa-sync on-hover-opaque"></i>
            </a>

           
            <!-- if intake - link to plan segment-->
            <?php
            $isIntake = strpos($iName, 'intake_') === 0;
            ?>
            @if($isIntake)
                <?php
                $targetSegment = 'plan_' . substr($iName, 7);
                ?>
                <a class="segment-trigger ml-3"
                   href="#"
                   data-target="{{$targetSegment}}">
                    Changes During this Visit (Plan)
                </a>
            @endif

            <!-- if plan - link to intake segment-->
            <?php
            $isPlan = strpos($iName, 'plan_') === 0 && $iName !== 'plan_free_text' && $iName !== 'plan_free_text_v2';
            ?>
            @if($isPlan)
                <?php
                $targetSegment = 'intake_' . substr($iName, 5);
                ?>
                <a class="segment-trigger ml-3"
                   href="#"
                   data-target="{{$targetSegment}}">
                    Back to Intake (Subjective)
                </a>
            @endif

            {{--@include('app/patient/note/_templates-v2-index', ['sectionInternalName' => $segment->segmentTemplate->internal_name])--}}

        @endif

        {{-- if segment has log feature, link --}}
        @if($pro->pro_type === 'ADMIN' && file_exists(resource_path("views/app/patient/segment-templates/{$segment->segmentTemplate->internal_name}/log.blade.php")))
            <a native="" target="_blank"
               class="c-pointer ml-3 text-decoration-none"
               open-in-stag-popup=""
               title="{{$segment->display_title}} - Change Log"
               popup-style="medium"
               href="/note-segment-view/{{$patient->uid}}/{{$note->uid}}/{{$segment->uid}}/<?= $segment->segmentTemplate->internal_name ?>/log">
                <span>Change Log</span>
            </a>
        @endif

    </div>

    <?php if(!$isLSSegment): ?>

    <div class="d-none if-not-edit inset-comment summary-container {{$iName === 'medrisk_vigilence' ? 'px-0' : 'p-2 pl-4'}}">
        @if($note->is_signed_by_hcp && $segment->accepted_suggestion_summary_html)
            {!! $segment->accepted_suggestion_summary_html !!}
        @else 
            {!! $segment->summary_html !!}
        @endif 
    </div>


    <?php
    $wizardPowered = [
        'intake_medications',
        'plan_medications',
        'intake_problems',
        'plan_problems',
        'intake_goals',
        'plan_goals',
        'intake_allergies',
        'plan_allergies',
        'intake_care_team',
        'plan_care_team',
        'intake_supplements',
        'plan_supplements',
        'omega_'
    ];
    if(!in_array($iName, $wizardPowered) && $iName !== 'ros' && $iName !== 'omega_ros' && !$isOmegaHistorySegment) { ?>
    <div class="d-none if-edit edit-container">
        {!! $segment->edit_html !!}
    </div>
    <?php } ?>

    <?php endif ?>

    <!-- popup hack for LS segments -->
    <?php if($isLSSegment): ?>
    <div class="stag-popup stag-popup-md"
         stag-popup-key="segment-popup-<?= $segment->segmentTemplate->internal_name ?>">
        <div class="stag-popup-content">
            <h3 class="stag-popup-title m-neg-3 px-3 mt-0 pb-3 border-bottom mb-3 pt-1">
                <span class="d-inline-flex align-items-center">
                    @if($segment->subheading)
                        {{$segment->subheading}}
                        <i class="text-secondary text-sm fa fa-arrow-right mx-2"></i>
                    @endif
                    {{$segment->display_title}}
                </span>
                <a href="#" class="ml-auto text-secondary" onclick="event.stopPropagation(); return closeStagPopup()">
                    <i class="fa fa-times-circle"></i>
                </a>
            </h3>
            <div class="ls-segment-edit-html">
                {!! $segment->edit_html !!}
            </div>
        </div>
    </div>
    <?php endif ?>

    {{-- popup trigger --}}
    {{--
    <div class="d-none">
        <a native="" target="_blank"
           class="c-pointer d-inline-flex align-items-center ml-3 text-decoration-none <?= $segment->segmentTemplate->internal_name ?>-trigger"
           open-in-stag-popup="" update-parent=""
           mc-initer="<?= $segment->segmentTemplate->internal_name ?>_{{$patient->id}}"
           title="{{$segment->subheading ? $segment->subheading . ' / ' : ''}}{{$segment->display_title}}"
           popup-style="wide overflow-visible"
           href="/note-segment-view/{{$patient->uid}}/{{$note->uid}}/{{$segment->uid}}/<?= $segment->segmentTemplate->internal_name ?>/edit">
            <i class="fa fa-bolt mr-1"></i>
            <span>Manage</span>
        </a>
        <script>
        addMCInitializer('<?= $segment->segmentTemplate->internal_name ?>_{{$patient->id}}', function() {
            window.segmentInitializers['<?= $segment->segmentTemplate->internal_name ?>'].call(window);
        }, '.<?= $segment->segmentTemplate->internal_name ?>-trigger');
        </script>
    </div>
    --}}

</div>

