<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Invice</title>

    <style>
        body.ltr {
            direction: ltr;
            font-family: 'Tahoma', sans-serif;
            margin: 20px;
        }

        body.rtl {
            direction: rtl;
            font-family: 'Tahoma', sans-serif;
            margin: 20px;
        }


           table td {
                border-top: 1px solid #333;
                border-bottom: 1px solid #333;
                border-left: none;
                border-right: none;
                padding: 6px 10px;
            }

            table th {
                border: none;
                padding: 6px 10px;
            }

            table {
                border-collapse: collapse;
                width: 100%;
            }

</style>
    </style>
</head>
<body onload="window.print()" class="{{ app()->getLocale() === 'en' ? 'ltr' : 'rtl' }}">

    @php
        if ($product instanceof \App\Coat) {
            $orderLabel = trans('file.Coat');
        } elseif ($product instanceof \App\Pant) {
            $orderLabel = trans('file.Pant');
        } elseif ($product instanceof \App\Dress) {
            $orderLabel = trans('file.Dress');
        } elseif ($product instanceof \App\Curtain) {
            $orderLabel = trans('file.Curtain');
        } else {
            $orderLabel = trans('file.Waiscoat');
        }
    @endphp
    @php
        if ($product instanceof \App\Curtain && $product->tailor) {
            $product->loadMissing('beddingDetails');
            $feeBreakdown = $product->tailor->curtainFeeBreakdown($product);
        } else {
            $fee = (float) optional($product->tailor)->tailor_fee;
            $qty = (float) ($product->qty ?? 1);
            $feeBreakdown = [
                'rows' => [[
                    'label' => trans('file.Tailor fee'),
                    'qty' => $qty,
                    'unit_fee' => $fee,
                    'total' => $fee * $qty,
                ]],
                'total' => $fee * $qty,
            ];
        }
    @endphp

    <div class="container">
        <div class="date" style="text-align: right;">{{ $product->tailoringProduct->created_at->format('m/d/Y') }}</div>
        <div class="wrapper" style="border:2px solid #000;">

        <table>
        <tbody>
            @if($product)
                <tr>
                    <td><strong>{{ trans('file.tailor Name') }}</strong></td>
                    <td><strong>{{ $product->tailor->name }}</strong></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>{{ trans('file.Completion Date') }}</td>
                    <td>{{ $product->tailoringProduct->completion_date->format('m-d-Y') }}</td>
                    <td>{{ $product->tailoringProduct->code }}</td>
                    <td></td>
                </tr>
                <tr>
                    <td>{{ trans('file.Customer Name') }}</td>
                    <td>{{ $product->tailoringProduct->customer->name }}</td>
                    <td>{{ trans('file.Type') }}</td>
                    <td>{{ $orderLabel }}</td>
                </tr>
                @foreach($feeBreakdown['rows'] as $row)
                    <tr>
                        <td>{{ $row['label'] }}</td>
                        <td><strong>{{ \App\Support\NumberFormatter::natural($row['qty']) }}</strong></td>
                        <td><strong>{{ \App\Support\NumberFormatter::natural($row['unit_fee']) }}</strong></td>
                        <td><strong>{{ \App\Support\NumberFormatter::natural($row['total']) }}</strong></td>
                    </tr>
                @endforeach
                <tr>
                    <td colspan="3"><strong>{{ trans('file.Total Tailor Fee') }}</strong></td>
                    <td><strong>{{ \App\Support\NumberFormatter::natural($feeBreakdown['total']) }}</strong></td>
                </tr>
                @endif
        </tbody>

        </div>

    </div>



</body>
</html>
