<!-- Tenant Selector Card -->
<div class="bg-white rounded-lg shadow overflow-hidden">
    <div class="p-6">
        <div class="flex items-center justify-between">
            <!-- 좌측: 테넌트 선택 -->
            <div class="flex items-center gap-4">
                <div class="flex items-center gap-2">
                    <svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                    </svg>
                    <label for="tenant-select" class="text-sm font-medium text-gray-700">테넌트 선택:</label>
                </div>

                <form action="{{ route('tenant.switch') }}" method="POST" id="tenant-switch-form">
                    @csrf
                    <select
                        name="tenant_id"
                        id="tenant-select"
                        onchange="document.getElementById('tenant-switch-form').submit()"
                        class="border-gray-300 rounded-lg text-sm focus:ring-primary focus:border-primary min-w-[200px]"
                    >
                        <option value="all" {{ session('selected_tenant_id') === null ? 'selected' : '' }}>
                            전체 보기
                        </option>
                        @if($globalTenants->isNotEmpty())
                            <option disabled>─────────</option>
                        @endif
                        @foreach($globalTenants as $tenant)
                            <option value="{{ $tenant->id }}" {{ session('selected_tenant_id') == $tenant->id ? 'selected' : '' }}>
                                {{ $tenant->company_name }}
                            </option>
                        @endforeach
                    </select>
                </form>
            </div>

            <!-- 우측: 현재 테넌트 정보 -->
            <div class="flex items-center gap-2">
                @if(session('selected_tenant_id'))
                    @php
                        $currentTenant = $globalTenants->firstWhere('id', session('selected_tenant_id'));
                    @endphp
                    @if($currentTenant)
                        <span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-primary/10 text-primary cursor-pointer hover:bg-primary/20"
                              data-context-menu="tenant"
                              data-entity-id="{{ $currentTenant->id }}"
                              data-entity-name="{{ $currentTenant->company_name }}"
                              title="클릭하여 메뉴 열기">
                            <svg class="w-4 h-4 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                            </svg>
                            {{ $currentTenant->company_name }} 데이터만 표시 중
                        </span>
                    @endif
                @else
                    <span class="text-xs text-gray-500">
                        전체 테넌트 데이터 표시 중
                    </span>
                @endif
            </div>
        </div>
    </div>
</div>
