@extends('layout')

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

@section('content')
<div class="container py-5">
    <div class="row">
        <div class="col-md-12">
            <x-clientarea.page-header
                icon="fas fa-file-signature"
                :title="__('store.contracts_title')"
                :subtitle="__('store.contracts_description')"
            />

            @if($contracts->count() > 0)
                @foreach($contracts as $contract)
                    <div class="card border-0 shadow-sm mb-3">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-start mb-2">
                                <div class="d-flex align-items-center gap-2">
                                    <h5 class="card-title mb-0">{{ $contract->getTranslation('title') }}</h5>
                                    
                                    <span class="badge bg-secondary bg-opacity-75">v{{ $contract->version }}</span>
                                    
                                    @if($contract->updated_at && $contract->updated_at->greaterThan(now()->subDays(30)))
                                        <span class="badge bg-success">{{ __('store.contracts_new_badge') }}</span>
                                    @endif
                                </div>
                                <div class="d-flex gap-2">
                                    @php
                                        $typeBadges = [
                                            'tos' => 'bg-primary',
                                            'privacy' => 'bg-info',
                                            'sla' => 'bg-warning',
                                            'aup' => 'bg-danger',
                                            'custom' => 'bg-secondary',
                                        ];
                                    @endphp
                                    <span class="badge {{ $typeBadges[$contract->type] ?? 'bg-secondary' }}">
                                        {{ __('store.contracts_type_' . $contract->type) }}
                                    </span>
                                    @if($contract->requires_acceptance)
                                        @if(isset($acceptances[$contract->id]))
                                            <span class="badge bg-success">
                                                <i class="fas fa-check me-1"></i>{{ __('store.contracts_accepted') }}
                                            </span>
                                        @else
                                            <span class="badge bg-warning text-dark">
                                                <i class="fas fa-exclamation-triangle me-1"></i>{{ __('store.contracts_acceptance_required') }}
                                            </span>
                                        @endif
                                    @else
                                        <span class="badge bg-secondary bg-opacity-50">
                                            <i class="fas fa-info-circle me-1"></i>{{ __('store.contracts_informational') }}
                                        </span>
                                    @endif
                                </div>
                            </div>

                            
                            @if($contract->requires_acceptance && !isset($acceptances[$contract->id]))
                                <div class="alert alert-warning py-2 px-3 mb-2 small">
                                    <i class="fas fa-exclamation-triangle me-1"></i>
                                    {{ __('store.contracts_acceptance_required_warning') }}
                                </div>
                            @endif

                            <div class="d-flex justify-content-between align-items-center mt-3">
                                <div class="text-muted">
                                    <small>
                                        <i class="fas fa-code-branch me-1"></i>{{ __('store.contracts_version') }}: {{ $contract->version }}
                                        @if($contract->effective_date)
                                            <span class="ms-3">
                                                <i class="fas fa-calendar-alt me-1"></i>{{ __('store.contracts_effective_date') }}: {{ $contract->effective_date->format($dateFormat) }}
                                            </span>
                                        @endif
                                        @if(isset($acceptances[$contract->id]))
                                            <span class="ms-3 text-success">
                                                <i class="fas fa-check-circle me-1"></i>{{ __('store.contracts_accepted_on', ['date' => $acceptances[$contract->id]->format($dateFormat)]) }}
                                            </span>
                                        @endif
                                    </small>
                                </div>
                                <a href="{{ route('store.auth.contracts.detail', $contract->getTranslation('slug', app()->getLocale()) ?: $contract->slug) }}" class="btn btn-sm btn-outline-primary">
                                    {{ __('store.contracts_view') }}
                                    <i class="fas fa-arrow-right ms-1"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                @endforeach
            @else
                <div class="card border-0 shadow-sm">
                    <div class="card-body text-center py-5">
                        <i class="fas fa-file-contract fa-3x text-muted mb-3"></i>
                        <h5>{{ __('store.contracts_no_contracts') }}</h5>
                    </div>
                </div>
            @endif
        </div>
    </div>
</div>
@endsection
