@extends('layout')

@section('title', $contract->getTranslation('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="$contract->getTranslation('title')"
                :subtitle="'v' . $contract->version"
            >
                @if(request()->boolean('gate'))
                    <a href="{{ route('store.auth.contracts.pending') }}" class="btn btn-outline-secondary">
                        <i class="fas fa-arrow-left me-2"></i>{{ __('store.contracts_back_to_pending') }}
                    </a>
                @else
                    <a href="{{ route('store.auth.contracts') }}" class="btn btn-outline-secondary">
                        <i class="fas fa-arrow-left me-2"></i>{{ __('store.contracts_back_to_list') }}
                    </a>
                @endif
                <button type="button" class="btn btn-outline-secondary btn-contract-print">
                    <i class="fas fa-print me-2"></i>{{ __('store.contracts_print') }}
                </button>
            </x-clientarea.page-header>

            
            @if($contract->requires_acceptance)
                @if($acceptance)
                    <div class="alert alert-success d-flex align-items-center mb-4">
                        <i class="fas fa-check-circle fa-lg me-3"></i>
                        <div>
                            <strong>{{ __('store.contracts_accepted_banner') }}</strong>
                            <br>
                            <small>
                                {{ __('store.contracts_accepted_on', ['date' => $acceptance->accepted_at->format($dateTimeFormat)]) }}
                                &middot;
                                {{ __('store.contracts_accepted_from', ['ip' => $acceptance->ip_address]) }}
                            </small>
                        </div>
                    </div>
                @else
                    <div class="alert alert-warning d-flex align-items-center mb-4">
                        <i class="fas fa-exclamation-triangle fa-lg me-3"></i>
                        <div>
                            <strong>{{ __('store.contracts_acceptance_required_warning') }}</strong>
                            <br>
                            <small>{{ __('store.contracts_acceptance_required_warning_desc') }}</small>
                        </div>
                    </div>
                @endif
            @else
                <div class="alert alert-info d-flex align-items-center mb-4">
                    <i class="fas fa-info-circle fa-lg me-3"></i>
                    <div>
                        <strong>{{ __('store.contracts_informational') }}</strong>
                        <br>
                        <small>{{ __('store.contracts_informational_desc') }}</small>
                    </div>
                </div>
            @endif

            <div class="card border-0 shadow-sm">
                <div class="card-body">
                    
                    <div class="d-flex justify-content-between align-items-start mb-3">
                        <div>
                            <h3 class="mb-1">{{ $contract->getTranslation('title') }}</h3>
                            <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
                            </div>
                        </div>
                        @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>
                    </div>

                    <hr>

                    
                    <div class="card border-0 shadow-sm mb-4" id="contract-toc-card" style="display: none;">
                        <div class="card-body py-3">
                            <h6 class="mb-2">
                                <i class="fas fa-list me-1"></i>{{ __('store.contracts_toc') }}
                            </h6>
                            <ul class="list-unstyled mb-0 small" id="contract-toc-list">
                                
                            </ul>
                        </div>
                    </div>

                    
                    <div class="contract-content" id="contract-content">
                        {!! $contract->getTranslation('content') !!}
                    </div>

                    <hr>

                    
                    @if($contract->requires_acceptance)
                        @if($acceptance)
                            <div class="alert alert-success mb-0">
                                <i class="fas fa-check-circle me-2"></i>
                                {{ __('store.contracts_accepted_on', ['date' => $acceptance->accepted_at->format($dateTimeFormat)]) }}
                                <span class="ms-2 text-muted">
                                    {{ __('store.contracts_accepted_from', ['ip' => $acceptance->ip_address]) }}
                                </span>
                            </div>
                        @else
                            <form action="{{ request()->boolean('gate') ? route('store.auth.contracts.pending.accept', $contract->slug) : route('store.auth.contracts.accept', $contract->getTranslation('slug', app()->getLocale()) ?: $contract->slug) }}" method="POST">
                                @csrf
                                <div class="d-flex justify-content-end">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fas fa-check me-1"></i>{{ __('store.contracts_accept_button') }}
                                    </button>
                                </div>
                            </form>
                        @endif
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('scripts')
@vite('resources/js/store/contract-show.js')
@endpush
