{{-- Email khi đơn hàng được xác nhận (銀行振込) - Gửi cho user --}}
{{-- Based on: /public/requests/KIREI 本人確認修正リスト/email_fb_4_2.html --}}

<div style="font-family: Arial, sans-serif; font-size: 10pt; line-height: 1.5; max-width: 600px; margin: 0 auto;">
    <p>{{ $user->full_name ?? $user->name }} 様</p>
    <br>
    <p>この度は、「KIREI」をご利用いただき、誠にありがとうございます。</p>
    <br>
    <p>本人確認が完了し、ご注文商品のレンタルが可能となりましたので</p>
    @php
        $detail = $order->order_detail->first();
        $wearDate = $detail->wear_date ?? '未定';
    @endphp
    <p>本メールをもって、正式に【 {{ $wearDate }} 】のレンタルを承りました。</p>
    <br>
    <p>つきましては、ご注文内容を再度ご確認いただき、下記内容を参考にお支払いをお願い致します。</p>
    <br>
    <p>その他、ご不明な点がありましたらいつでもお気軽にお問い合わせください。</p>
    <br>

    <p>---------------------------------------------------------------------------------------------------------------------------</p>
    <p><strong>【銀行振り込み】</strong></p>
    <p style="margin-left: 20px;">ご着用予定日の【11日前】までに下記口座にお振込みください。</p>
    <br>
    <p style="margin-left: 20px;">銀　行　名：楽天銀行</p>
    <p style="margin-left: 20px;">支店番号：253 第三営業支店</p>
    <p style="margin-left: 20px;">預金科目：普通預金</p>
    <p style="margin-left: 20px;">口座番号：7489335</p>
    <p style="margin-left: 20px;">口座名義：株式会社もろふじ キレイ</p>
    <br>
    @php
        $paymentDeadline = '未定';
        if ($detail && $detail->wear_date) {
            $wearDateObj = \Carbon\Carbon::parse($detail->wear_date);
            $paymentDeadline = $wearDateObj->subDays(11)->format('Y/m/d');
        }
    @endphp
    <p style="margin-left: 20px;">ご請求金額：{{ number_format($order->total_price) }}円</p>
    <p style="margin-left: 20px;">お客様のお支払い期限は【 {{ $paymentDeadline }} 】です。</p>
    <br>
    <p style="margin-left: 20px;">お支払期限の1週間前までにお支払の確認がとれていない場合</p>
    <p style="margin-left: 20px;">当店より催促のご連絡をさせていただくことがあります。</p>
    <p>---------------------------------------------------------------------------------------------------------------------------</p>
    <br>

    <p><strong>■ご注文内容</strong></p>
    <p style="margin-left: 20px;">［受注番号] {{ $order->code }}</p>
    <p style="margin-left: 20px;">［ご注文者] {{ $user->full_name ?? $user->name }} 様</p>
    <br>
    @if($detail)
    <p style="margin-left: 20px;">［着用予定日] {{ $detail->wear_date ?? '未定' }}</p>
    @php
        $rentalPeriod = '未定';
        if ($detail->wear_date) {
            $wearDateObj = \Carbon\Carbon::parse($detail->wear_date);
            $productDeliveryDays = (int) config('rental_dates.product_delivery_days', 3);
            $defaultRentalNights = (int) config('rental_dates.default_rental_nights', 5);
            // レンタル期間 = お届け日(着用-3) ～ 返却期日(お届け+5泊=着用+2) = 5泊6日
            $rentalStart = $wearDateObj->copy()->subDays($productDeliveryDays);
            $rentalEnd = $rentalStart->copy()->addDays($defaultRentalNights);
            $rentalPeriod = $rentalStart->format('Y/m/d') . ' ～ ' . $rentalEnd->format('Y/m/d');
        }
    @endphp
    <p style="margin-left: 20px;">［レンタル期間：5泊6日] {{ $rentalPeriod }}</p>
    <br>
    @php
        $kimonoNumber = $detail->product_code ?? $detail->product_name ?? '-';
        // Loại bỏ phần "-product.size.size_" nếu có
        $kimonoNumber = preg_replace('/-product\.size\.size_?/', '', $kimonoNumber);
    @endphp
    <p style="margin-left: 20px;">［着物番号] {{ $kimonoNumber }}</p>
    @endif
    <p style="margin-left: 20px;">［決済方法] 銀行振込</p>
    @php
        $productPrice = 0;
        $optionPrice = 0;
        $shippingCost = 0;
        if ($order->order_detail) {
            foreach ($order->order_detail as $d) {
                $productPrice += $d->price ?? 0;
                $optionPrice += ($d->safe_pack ?? 0) + ($d->tabi ?? 0) + ($d->towel ?? 0);
                $shippingCost += $d->shipping_cost ?? 0;
            }
        }
    @endphp
    <p style="margin-left: 20px;">［商品価格] {{ number_format($productPrice) }}円</p>
    <p style="margin-left: 20px;">［オプション価格] {{ number_format($optionPrice) }}円</p>
    <p style="margin-left: 20px;">［送料] {{ number_format($shippingCost) }}円</p>
    <p style="margin-left: 20px;">［合計金額] {{ number_format($order->total_price) }}円</p>
    <br>
    <p style="margin-left: 40px;">ご注文内容に誤りがございましたら、お手数ですがお問い合わせください。</p>
    <br>
    <br>

    <p><strong>■レンタルの流れ（現在のステータス：【ご注文確定】）</strong></p>
    <br>
    <p style="margin-left: 20px;">ご注文確認</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">【 ご注文確定 】</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;"> お支払い</p>
    <p style="margin-left: 50px;">▼</p>
    @if($detail && $detail->wear_date)
    @php
        $wearDateObj = \Carbon\Carbon::parse($detail->wear_date);
        $storeShippingDays = (int) config('rental_dates.store_shipping_days', 10);
        $productDeliveryDays = (int) config('rental_dates.product_delivery_days', 3);
        $returnAfterDays = (int) config('rental_dates.return_after_days', 2);
        $storeArrivalAfterReturnDays = (int) config('rental_dates.store_arrival_after_return_days', 1);
        $shippingDate = $wearDateObj->copy()->subDays($storeShippingDays)->format('Y/m/d');
        $arrivalDate = $wearDateObj->copy()->subDays($productDeliveryDays)->format('Y/m/d');
        $returnDate = $wearDateObj->copy()->addDays($returnAfterDays)->format('Y/m/d');
        $storeArrivalDate = $wearDateObj->copy()->addDays($returnAfterDays + $storeArrivalAfterReturnDays)->format('Y/m/d');
    @endphp
    <p style="margin-left: 20px;">当店発送予定日： {{ $shippingDate }}</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">着物到着日： {{ $arrivalDate }}</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">ご着用予定日： {{ $wearDateObj->format('Y/m/d') }}</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">返却期日：{{ $returnDate }}</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">当店到着予定日： {{ $storeArrivalDate }}</p>
    @else
    <p style="margin-left: 20px;">当店発送予定日： 未定</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">着物到着日： 未定</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">ご着用予定日： 未定</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">返却期日：未定</p>
    <p style="margin-left: 40px;">▼</p>
    <p style="margin-left: 20px;">当店到着予定日： 未定</p>
    @endif
    <p style="margin-left: 50px;">▼</p>
    <p style="margin-left: 20px;"> お取引完了</p>
    <br>
    <br>

    <p>--------------------------------------------------------------------------</p>
    <p>【お問い合わせ先】</p>
    <p> 株式会社もろふじ「KIREI」</p>
    <p>（ホームページ URL）{{ config('app.url') }}</p>
    <p> メール：kirei@0944724272.com</p>
    <p> 電話：0944-75-1755</p>
    <p> 受付時間：月・火・木・金・土 (10：00 ～ 18:00)</p>
    <p>--------------------------------------------------------------------------</p>
</div>
