@extends('layout')

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

@section('content')
<div class="container py-5">
    <div class="row">
        <div class="col-md-8 mx-auto">
            <x-clientarea.page-header
                icon="fas fa-handshake"
                :title="__('store.affiliate_activate')"
            >
                <a href="{{ route('store.auth.dashboard') }}" class="btn btn-outline-secondary">
                    <i class="fas fa-arrow-left me-2"></i>{{ __('store.clientarea_nav_dashboard') }}
                </a>
            </x-clientarea.page-header>

            <div class="card border-0 shadow-sm">
                <div class="card-body text-center py-5">
                    <i class="fas fa-handshake fa-3x text-primary mb-3"></i>
                    <h4>{{ __('store.affiliate_activate') }}</h4>
                    <p class="text-muted mb-3">{{ __('store.affiliate_activate_description') }}</p>

                    
                    <div class="row justify-content-center mb-4">
                        <div class="col-md-8">
                            <div class="card border-0 shadow-sm">
                                <div class="card-body">
                                    <ul class="list-unstyled text-start mb-0">
                                        <li class="mb-2">
                                            <i class="fas fa-check-circle text-success me-2"></i>
                                            {{ __('store.affiliate_benefit_commission', ['rate' => number_format($defaultRate, 0)]) }}
                                        </li>
                                        <li class="mb-2">
                                            <i class="fas fa-check-circle text-success me-2"></i>
                                            {{ __('store.affiliate_benefit_tracking') }}
                                        </li>
                                        <li class="mb-2">
                                            <i class="fas fa-check-circle text-success me-2"></i>
                                            {{ __('store.affiliate_benefit_reports') }}
                                        </li>
                                        @if($bonusDeposit > 0)
                                        <li class="mb-2">
                                            <i class="fas fa-gift text-warning me-2"></i>
                                            {{ __('store.affiliate_benefit_bonus', ['amount' => number_format($bonusDeposit, 2)]) }}
                                        </li>
                                        @endif
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>

                    <p class="text-muted mb-4">{{ __('store.affiliate_description') }}</p>

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

                        @php
                            $affiliateContract = \App\Models\Contract::active()
                                ->ofType(\App\Enums\ContractType::AFFILIATE_AGREEMENT)
                                ->ordered()->first();
                        @endphp

                        @if ($affiliateContract)
                            @php
                                $slug = $affiliateContract->getTranslation('slug', app()->getLocale()) ?: $affiliateContract->slug;
                            @endphp
                            <div class="form-check mb-3 text-start">
                                <input type="checkbox"
                                       name="affiliate_agreement_accepted"
                                       id="affiliate_agreement_accepted"
                                       value="1"
                                       class="form-check-input @error('affiliate_agreement_accepted') is-invalid @enderror"
                                       {{ old('affiliate_agreement_accepted') ? 'checked' : '' }}
                                       @if ($affiliateContract->requires_acceptance) required @endif>
                                <label for="affiliate_agreement_accepted" class="form-check-label">
                                    {!! __('store.affiliate_accept_agreement', [
                                        'link' => '<a href="'.route('legal.contract.show', $slug).'" target="_blank">'.e($affiliateContract->getTranslation('title')).'</a>'
                                    ]) !!}
                                    @if ($affiliateContract->requires_acceptance)<span class="text-danger">*</span>@endif
                                </label>
                                @error('affiliate_agreement_accepted')
                                    <div class="invalid-feedback d-block">{{ $message }}</div>
                                @enderror
                            </div>
                        @endif

                        <button type="submit" class="btn btn-primary btn-lg">
                            <i class="fas fa-rocket me-2"></i>{{ __('store.affiliate_activate') }}
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
