@extends('admin.layouts.app')

@section('title', __('dashboard.member_details'))

@section('content')
<x-admin.page-header title="{{ __('dashboard.member_details') }}" :breadcrumbs="[__('dashboard.members') => route('admin.members.index'), __('dashboard.details') => '']" />

<div class="row justify-content-center">
    <div class="col-xl-12">
        <!-- Header Card -->
        <div class="card bg-primary bg-gradient mb-4">
            <div class="card-body">
                <div class="d-flex align-items-center">
                    <div class="avatar-lg bg-white bg-opacity-25 rounded d-flex align-items-center justify-content-center me-4" style="width: 80px; height: 80px;">
                        @if($member->image)
                            <img src="{{ asset('storage/' . $member->image) }}" alt="{{ $member->name }}" class="rounded" style="width: 100%; height: 100%; object-fit: cover;">
                        @else
                            <i class="ri-user-line text-white fs-1"></i>
                        @endif
                    </div>
                    <div>
                        <h3 class="mb-1 text-white">{{ $member->name }}</h3>
                        <p class="text-white-50 mb-0"><i class="ri-phone-line me-1"></i> {{ $member->phone }}</p>
                        @if($member->email)
                            <p class="text-white-50 mb-0"><i class="ri-mail-line me-1"></i> {{ $member->email }}</p>
                        @endif
                    </div>

                    <div class="ms-auto text-end">
                        {!! \App\Enums\MemberStatusEnum::badge($member->status) !!}
                        <span class="badge bg-info ms-1">{{ \App\Enums\MemberTypeEnum::label($member->member_type) }}</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Info Card -->
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">{{ __('dashboard.general_info') }}</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <x-view-col label="{{ __('dashboard.id') }}" :value="$member->id"/>
                    <x-view-col label="{{ __('dashboard.name') }}" :value="$member->name"/>
                    <x-view-col label="{{ __('dashboard.phone') }}" :value="$member->phone ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.email') }}" :value="$member->email ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.static_entry_qr') }}" :value="$member->static_entry_qr_enabled ? __('dashboard.static_entry_qr_yes') : __('dashboard.static_entry_qr_no')"/>
                    <x-view-col label="{{ __('dashboard.qr_code') }}" :value="$member->qr_code ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.qr_code_static') }}" :value="$member->qr_code_static ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.date_of_birth') }}" :value="$member->dob?->format('Y-m-d') ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.address') }}" :value="$member->address ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.start_date_subscription') }}" :value="$member->start_date_subscription?->format('Y-m-d') ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.end_date_subscription') }}" :value="$member->end_date_subscription?->format('Y-m-d') ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.created_at') }}" :value="$member->created_at"/>
                    <x-view-col label="{{ __('dashboard.updated_at') }}" :value="$member->updated_at"/>
                </div>
            </div>
        </div>

        <div class="card mb-4">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="card-title mb-0">{{ __('dashboard.dependents') }}</h5>
                <a href="{{ route('admin.dependents.create') }}?member_id={{ $member->id }}" class="btn btn-sm btn-success">
                    <i class="ri-add-line"></i> {{ __('dashboard.add_dependent') }}
                </a>
            </div>
            <div class="card-body">
                @if($member->dependents->isNotEmpty())
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ __('dashboard.name') }}</th>
                                    <th>{{ __('dashboard.relationship') }}</th>
                                    <th>{{ __('dashboard.phone') }}</th>
                                    <th>{{ __('dashboard.status') }}</th>
                                    <th>{{ __('dashboard.actions') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($member->dependents as $dependent)
                                <tr>
                                    <td>{{ $dependent->name }}</td>
                                    <td>{{ \App\Enums\RelationEnum::label($dependent->relation) }}</td>
                                    <td>{{ $dependent->phone ?? '-' }}</td>
                                    <td>{!! \App\Enums\MemberStatusEnum::badge($dependent->status) !!}</td>
                                    <td>
                                        <a href="{{ route('admin.dependents.show', $dependent) }}" class="btn btn-sm btn-soft-info"><i class="ri-eye-line"></i></a>
                                        <a href="{{ route('admin.dependents.edit', $dependent) }}" class="btn btn-sm btn-soft-primary"><i class="ri-pencil-line"></i></a>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="text-muted">{{ __('No dependents found for this member.') }}</div>
                @endif
            </div>
        </div>

        @if($member->parkings->isNotEmpty())
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">{{ __('dashboard.parkings') }}</h5>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>{{ __('dashboard.car_number') }}</th>
                                <th>{{ __('dashboard.make') }}</th>
                                <th>{{ __('dashboard.model') }}</th>
                                <th>{{ __('dashboard.qr_code') }}</th>
                                <th>{{ __('dashboard.status') }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($member->parkings as $parking)
                            <tr>
                                <td><a href="{{ route('admin.parkings.show', $parking) }}">{{ $parking->car_number }}</a></td>
                                <td>{{ $parking->make ?? '-' }}</td>
                                <td>{{ $parking->model ?? '-' }}</td>
                                <td>{{ $parking->qr_code ?? '-' }}</td>
                                <td>{!! \App\Enums\ParkingStatusEnum::badge($parking->status) !!}</td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        @endif
    </div>
</div>
@endsection
