<?php

use App\Enums\UserType;
use Livewire\Volt\Component;

new class extends Component
{
    public function with(): array
    {
        $user = auth()->user();

        return [
            'user' => $user,
            'isIndividual' => $user->user_type === UserType::Individual,
        ];
    }

    public function logout(): void
    {
        auth()->logout();
        session()->invalidate();
        session()->regenerateToken();

        $this->redirect(route('login'));
    }
}; ?>

<div class="space-y-6 p-6">
    <div class="mx-auto max-w-2xl">
        <flux:heading size="xl">{{ __('client.my_profile') }}</flux:heading>

        {{-- Account Type Badge --}}
        <div class="mt-4">
            @if ($isIndividual)
                <flux:badge color="sky">{{ __('profile.individual_account') }}</flux:badge>
            @else
                <flux:badge color="purple">{{ __('profile.company_account') }}</flux:badge>
            @endif
        </div>

        {{-- Profile Information Card --}}
        <div class="mt-6 rounded-lg border border-zinc-200 bg-white p-6 shadow-sm">
            @if ($isIndividual)
                <dl class="space-y-4">
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.full_name') }}</dt>
                        <dd class="text-lg font-medium">{{ $user->full_name }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.national_id') }}</dt>
                        <dd>{{ $user->national_id }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.email') }}</dt>
                        <dd>{{ $user->email }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.phone') }}</dt>
                        <dd>{{ $user->phone }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.preferred_language') }}</dt>
                        <dd>{{ $user->preferred_language === 'ar' ? __('profile.arabic') : __('profile.english') }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.member_since') }}</dt>
                        <dd>{{ $user->created_at->translatedFormat(app()->getLocale() === 'ar' ? 'j F Y' : 'F j, Y') }}</dd>
                    </div>
                </dl>
            @else
                <dl class="space-y-4">
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.company_name') }}</dt>
                        <dd class="text-lg font-medium">{{ $user->company_name }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.registration_number') }}</dt>
                        <dd>{{ $user->company_cert_number }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.contact_person') }}</dt>
                        <dd>{{ $user->contact_person_name }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.contact_person_id') }}</dt>
                        <dd>{{ $user->contact_person_id }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.email') }}</dt>
                        <dd>{{ $user->email }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.phone') }}</dt>
                        <dd>{{ $user->phone }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.preferred_language') }}</dt>
                        <dd>{{ $user->preferred_language === 'ar' ? __('profile.arabic') : __('profile.english') }}</dd>
                    </div>
                    <div>
                        <dt class="text-sm text-zinc-500">{{ __('profile.member_since') }}</dt>
                        <dd>{{ $user->created_at->translatedFormat(app()->getLocale() === 'ar' ? 'j F Y' : 'F j, Y') }}</dd>
                    </div>
                </dl>
            @endif
        </div>

        {{-- Contact Admin Message --}}
        <flux:callout class="mt-6">
            <flux:text>{{ __('client.contact_admin_to_update') }}</flux:text>
        </flux:callout>

        {{-- Logout Button --}}
        <div class="mt-6">
            <flux:button wire:click="logout" variant="danger">
                {{ __('auth.logout') }}
            </flux:button>
        </div>
    </div>
</div>
