@extends('pdf.layout')

@section('title', __('Sales Return') . ' - ' . $saleReturn->return_number)
@section('doc_name', __('SALES RETURN RECEIPT'))
@section('doc_number', __('Return #') . ': ' . $saleReturn->return_number)

@section('content')
    <div style="margin-bottom: 20px;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 50%; vertical-align: top;">
                    <div class="fw-bold text-uppercase" style="margin-bottom: 5px; color: #666;">{{ __('Customer') }}:</div>
                    <div class="fw-bold" style="font-size: 14px;">{{ $saleReturn->sale->partner->name ?? __('Walk-in Customer') }}</div>
                    @if($saleReturn->sale->partner)
                        <p style="margin: 2px 0;">{{ $saleReturn->sale->partner->address }}</p>
                        <p style="margin: 2px 0;">{{ __('Phone') }}: {{ $saleReturn->sale->partner->phone }}</p>
                    @endif
                </td>
                <td style="width: 50%; vertical-align: top; text-align: right;">
                    <div class="fw-bold text-uppercase" style="margin-bottom: 5px; color: #666;">{{ __('Return Details') }}:</div>
                    <p style="margin: 2px 0;">{{ __('Original Invoice') }}: {{ $saleReturn->sale->sale_number }}</p>
                    <p style="margin: 2px 0;">{{ __('Return Date') }}: {{ $saleReturn->created_at->format('Y-m-d H:i') }}</p>
                    <p style="margin: 2px 0;">{{ __('Refund Type') }}: {{ ucfirst($saleReturn->refund_type) }}</p>
                    <p style="margin: 2px 0;">{{ __('Processed By') }}: {{ $saleReturn->user->name ?? 'System' }}</p>
                </td>
            </tr>
        </table>
    </div>

    <table class="data-table">
        <thead>
            <tr>
                <th style="width: 50px;">#</th>
                <th>{{ __('Description') }}</th>
                <th class="text-center" style="width: 80px;">{{ __('Qty Returned') }}</th>
                <th class="text-right" style="width: 100px;">{{ __('Refund Amount') }}</th>
            </tr>
        </thead>
        <tbody>
            @foreach($saleReturn->items as $index => $item)
                <tr>
                    <td>{{ $index + 1 }}</td>
                    <td>
                        <div class="fw-bold">{{ $item->product->localized_name ?? $item->product->name }}</div>
                        @if($item->product->sku)<small style="color: #666;">SKU: {{ $item->product->sku }}</small>@endif
                    </td>
                    <td class="text-center">{{ $item->quantity }}</td>
                    <td class="text-right">{{ number_format($item->total, 2) }}</td>
                </tr>
            @endforeach
        </tbody>
    </table>

    <div class="totals">
        <table>
            <tr class="totals-row totals-grand">
                <td class="text-right">{{ __('Total Refund') }}:</td>
                <td class="text-right">{{ number_format($saleReturn->total, 2) }} {{ $currency ?? 'EGP' }}</td>
            </tr>
        </table>
        <div style="clear: both;"></div>
    </div>

    @if($saleReturn->reason)
        <div style="margin-top: 30px; padding: 10px; border: 1px solid #eee; background-color: #fcfcfc;">
            <div class="fw-bold" style="margin-bottom: 5px;">{{ __('Reason for Return') }}:</div>
            <div style="font-style: italic;">{{ $saleReturn->reason }}</div>
        </div>
    @endif

    <div style="margin-top: 50px;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 50%; text-align: center;">
                    <div style="border-top: 1px solid #ccc; width: 150px; margin: 0 auto; margin-top: 40px;"></div>
                    <p>{{ __('Customer Signature') }}</p>
                </td>
                <td style="width: 50%; text-align: center;">
                    <div style="border-top: 1px solid #ccc; width: 150px; margin: 0 auto; margin-top: 40px;"></div>
                    <p>{{ __('Authorized Signature') }}</p>
                </td>
            </tr>
        </table>
    </div>
@endsection
