@extends('layout')

@section('title', __('store.auth_login_title'))

@push('scripts')
@vite('resources/js/common/password-toggle.js')
@endpush

@section('content')
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-md-6 col-lg-5">
            <div class="card shadow">
                <div class="card-body p-4">
                    <h2 class="text-center mb-4">{{ __('store.auth_login_title') }}</h2>

                    @if(session('message'))
                        <div class="alert alert-info">
                            {{ session('message') }}
                        </div>
                    @endif

                    @if($errors->any())
                        <div class="alert alert-danger">
                            <ul class="mb-0">
                                @foreach($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif

                    <form method="POST" action="{{ route('store.auth.login') }}">
                        @csrf

                        <div class="mb-3">
                            <label for="email" class="form-label">{{ __('store.auth_email') }}</label>
                            <input type="email" class="form-control @error('email') is-invalid @enderror"
                                   id="email" name="email" value="{{ request('email', old('email')) }}" required autofocus {{ request('lock_email') ? 'readonly' : '' }}>
                            @if(request('lock_email'))
                                <input type="hidden" name="email" value="{{ request('email') }}">
                            @endif
                            @error('email')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label for="password" class="form-label">{{ __('store.auth_password') }}</label>
                            <div class="input-group">
                                <input type="password" class="form-control @error('password') is-invalid @enderror"
                                       id="password" name="password" required>
                                <button class="btn btn-outline-secondary js-password-toggle" type="button" tabindex="-1"
                                        aria-label="{{ __('auth.password_show') }}"
                                        data-show-label="{{ __('auth.password_show') }}"
                                        data-hide-label="{{ __('auth.password_hide') }}">
                                    <i class="fas fa-eye"></i>
                                </button>
                                @error('password')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <div class="mb-3 form-check">
                            <input type="checkbox" class="form-check-input" id="remember" name="remember">
                            <label class="form-check-label" for="remember">
                                {{ __('store.auth_remember_me') }}
                            </label>
                        </div>

                        <x-captcha form="login_forms" />

                        <div class="d-grid mb-3">
                            <button type="submit" class="btn btn-primary btn-lg">
                                <i class="fas fa-sign-in-alt me-2"></i>
                                {{ __('store.auth_login') }}
                            </button>
                        </div>

                        <div class="text-center">
                            <p class="mb-2">
                                <a href="{{ route('store.auth.forgot-password') }}" class="text-decoration-none">
                                    {{ __('store.auth_forgot_password') }}
                                </a>
                            </p>
                            @if($allowClientRegistration)
                            <p class="mb-0">
                                {{ __('store.auth_no_account') }}
                                <a href="{{ route('store.auth.register') }}" class="text-decoration-none fw-bold">
                                    {{ __('store.auth_register_here') }}
                                </a>
                            </p>
                            @endif
                        </div>
                    </form>

                    
                    @php
                        $hasSocialProviders = collect($socialProviders)->filter(function($provider) {
                            return $provider['enabled'];
                        })->isNotEmpty();
                    @endphp

                    @if($hasSocialProviders)
                    <hr class="my-4">
                    <div class="text-center">
                        <p class="mb-3 text-muted">{{ __('store.auth_or_login_with') }}</p>
                        <div class="d-flex justify-content-center gap-2 flex-wrap">
                            @foreach($socialProviders as $provider => $config)
                                @if($config['enabled'])
                                    <a href="{{ route('store.auth.social', $provider) }}"
                                       class="btn {{ $config['class'] }}"
                                       title="{{ __('store.auth_login_with', ['provider' => $config['name']]) }}">
                                        <i class="{{ $config['icon'] }} me-1"></i> {{ $config['name'] }}
                                    </a>
                                @endif
                            @endforeach
                        </div>
                    </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection