@extends('admin.layouts.app')

@section('title', __('admin/coupons.show_title'))

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header
        :title="__('admin/coupons.show_title')"
        :subtitle="__('admin/coupons.show_subtitle')"
        icon="fas fa-tags"
        :buttons="[
            ['label' => __('admin/coupons.buttons_edit'), 'route' => route('admin.coupons.edit', $coupon), 'icon' => 'fas fa-edit', 'color' => 'outline-primary'],
            ['label' => __('admin/coupons.buttons_back'), 'route' => route('admin.coupons.index'), 'icon' => 'fas fa-arrow-left', 'color' => 'outline-secondary'],
        ]"
    />

    <x-admin.card>
        <div class="row">
            <!-- Sol Kolon - Temel Bilgiler -->
            <div class="col-md-6">
                <h5 class="mb-3">{{ __('admin/coupons.fields_basic_info') }}</h5>

                <table class="table table-borderless">
                    <tr>
                        <th width="150">{{ __('admin/coupons.fields_code') }}:</th>
                        <td><span class="badge bg-primary fs-6">{{ $coupon->code }}</span></td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_name') }}:</th>
                        <td>{{ $coupon->name }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_description') }}:</th>
                        <td>{{ $coupon->description ?: '-' }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_type') }}:</th>
                        <td>
                            @if($coupon->type === 'percentage')
                                <span class="badge bg-info">{{ __('admin/coupons.types_percentage') }}</span>
                            @else
                                <span class="badge bg-warning">{{ __('admin/coupons.types_fixed') }}</span>
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_discount_value') }}:</th>
                        <td>
                            @if($coupon->type === 'percentage')
                                %{{ $coupon->discount_value }}
                            @else
                                {{ $coupon->discount_value }} {{ $coupon->currency->code }}
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_currency') }}:</th>
                        <td>{{ $coupon->currency->code }} - {{ $coupon->currency->name }}</td>
                    </tr>
                </table>
            </div>

            <!-- Sag Kolon - Kosullar ve Durum -->
            <div class="col-md-6">
                <h5 class="mb-3">{{ __('admin/coupons.fields_conditions') }}</h5>

                <table class="table table-borderless">
                    <tr>
                        <th width="150">{{ __('admin/coupons.fields_min_order_amount') }}:</th>
                        <td>{{ $coupon->min_order_amount ? $coupon->min_order_amount . ' ' . $coupon->currency->code : '-' }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_max_discount_amount') }}:</th>
                        <td>{{ $coupon->max_discount_amount ? $coupon->max_discount_amount . ' ' . $coupon->currency->code : '-' }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_usage_limit') }}:</th>
                        <td>{{ $coupon->usage_limit ?: __('admin/coupons.placeholders_unlimited') }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_usage_count') }}:</th>
                        <td>{{ $coupon->usage_count }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_starts_at') }}:</th>
                        <td>{{ $coupon->starts_at ? $coupon->starts_at->format($dateTimeFormat) : '-' }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_expires_at') }}:</th>
                        <td>{{ $coupon->expires_at ? $coupon->expires_at->format($dateTimeFormat) : '-' }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_is_active') }}:</th>
                        <td>
                            @if($coupon->is_active)
                                <span class="badge bg-success">{{ __('admin/coupons.statuses_active') }}</span>
                            @else
                                <span class="badge bg-danger">{{ __('admin/coupons.statuses_inactive') }}</span>
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_created_by') }}:</th>
                        <td>{{ $coupon->createdByAdmin?->name ?? '-' }}</td>
                    </tr>
                    <tr>
                        <th>{{ __('admin/coupons.fields_created_at') }}:</th>
                        <td>{{ $coupon->created_at->format($dateTimeFormat) }}</td>
                    </tr>
                </table>
            </div>
        </div>

        <!-- Kriterler Bolumu -->
        <div class="row mt-4">
            <div class="col-12">
                <h5 class="mb-3">{{ __('admin/coupons.criteria_title') }}</h5>

                @if($coupon->criteria->count() > 0)
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ __('admin/coupons.criteria_types_title') }}</th>
                                    <th>{{ __('admin/coupons.criteria_operators_title') }}</th>
                                    <th>{{ __('admin/coupons.criteria_values') }}</th>
                                    <th>{{ __('admin/coupons.criteria_required') }}</th>
                                    <th>{{ __('admin/coupons.criteria_order') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($coupon->criteria->sortBy('order') as $criterion)
                                    <tr>
                                        <td>
                                            <span class="badge bg-secondary">
                                                {{ $criterion->criteria_type_text }}
                                            </span>
                                        </td>
                                        <td>
                                            <span class="badge bg-info">
                                                {{ $criterion->operator_text }}
                                            </span>
                                        </td>
                                        <td>{{ $criterion->criteria_value_text }}</td>
                                        <td>
                                            @if($criterion->is_required)
                                                <span class="badge bg-success">{{ __('admin/common.yes') }}</span>
                                            @else
                                                <span class="badge bg-warning">{{ __('admin/common.no') }}</span>
                                            @endif
                                        </td>
                                        <td>{{ $criterion->order }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="alert alert-info">
                        {{ __('admin/coupons.criteria_no_criteria') }}
                    </div>
                @endif
            </div>
        </div>

        <!-- Kullanim Gecmisi -->
        <div class="row mt-4">
            <div class="col-12">
                <h5 class="mb-3">{{ __('admin/coupons.usage_title') }}</h5>

                @if($coupon->usages->count() > 0)
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ __('admin/coupons.usage_fields_client') }}</th>
                                    <th>{{ __('admin/coupons.usage_fields_order') }}</th>
                                    <th>{{ __('admin/coupons.usage_fields_discount_amount') }}</th>
                                    <th>{{ __('admin/coupons.usage_fields_original_amount') }}</th>
                                    <th>{{ __('admin/coupons.usage_fields_final_amount') }}</th>
                                    <th>{{ __('admin/coupons.usage_fields_used_at') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($coupon->usages->sortByDesc('used_at') as $usage)
                                    <tr>
                                        <td>{{ $usage->client->full_name ?? $usage->client->email }}</td>
                                        <td>
                                            @if($usage->order)
                                                <a href="{{ route('admin.orders.show', $usage->order) }}" class="text-decoration-none">
                                                    #{{ $usage->order->id }}
                                                </a>
                                            @else
                                                -
                                            @endif
                                        </td>
                                        <td class="text-danger">-{{ $usage->discount_amount }} {{ $usage->currency->code }}</td>
                                        <td>{{ $usage->original_amount }} {{ $usage->currency->code }}</td>
                                        <td class="text-success">{{ $usage->final_amount }} {{ $usage->currency->code }}</td>
                                        <td>{{ $usage->used_at->format($dateTimeFormat) }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="alert alert-info">
                        {{ __('admin/coupons.usage_no_usage') }}
                    </div>
                @endif
            </div>
        </div>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
    // No translations needed - show page has no JS file
</script>
@endpush
