@use('Modules\CabBooking\Enums\RoleEnum')

@php
$symbol = getDefaultCurrencySymbol();
$roleName = getCurrentRoleName();
@endphp

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ env('APP_NAME') }} - {{ __('cabbooking::static.rides.invoice') }}</title>
    <style>
        body {
            font-family: Inter, sans-serif, DejaVu Sans;
            margin: 0;
            padding: 0;
            line-height: 1.6;
            color: #1F1F1F;
        }

        .top-table {
            position: absolute !important;
            top: -5% !important;
            left: -7% !important;
            height: 100px;
            width: 100%;
        }

        .exit-table {
            position: absolute !important;
            bottom: -5% !important;
            right: -7% !important;
            height: 100px;
            width: 100%;
        }

        .ride-details {
            display: flex !important;
            justify-content: center;
            align-items: center;
            flex-direction: row;
            position: relative;
        }

        .ride-details img {
            width: 350px;
            height: 180px;
            position: absolute;
            top: 0;
            right: -10%;
        }

        .text-primary {
            color: #030712;
            font-weight: 700;
        }

        .dark-color {
            color: #1F1F1F;
        }

        .common-color {
            color: #8F8F8F;
        }

        .invoice-header h1 {
            margin: 0;
            font-size: 70px;
            color: #030712;
        }

        .invoice-header div {
            text-align: right;
            font-size: 18px;
        }

        .all-details {
            display: flex;
            align-items: center;
            justify-content: space-between
        }

        .invoice-id {
            background-color: #EEEEEE;
            padding: 0px 20px 0px 20px;
            margin-right: -80px;
            border-radius: 50px;
            transform: translate(50%, 0);
        }

        .invoice-id p {
            text-align: left;
            margin-bottom: 5px
        }

        .invoice-id p span {
            margin-left: 20px;
        }

        .invoice-data {
            margin-top: -60px;
        }

        .invoice-data td {
            border: unset;
            background-color: unset;
            text-align: right;
            padding: 0;
        }

        .section-title {
            margin-top: 15px;
            margin-bottom: 5px;
            color: #030712;
        }

        p {
            margin: 0;
            padding-bottom: 6px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            border: unset;
            border-radius: 10px;
        }

        .table-details td {
            padding: 0;
            border: unset;
            background-color: unset;
            text-align: start !important;
        }

        th,
        td {
            padding: 10px;
            border: 1px solid #EEEEEE;
        }

        th {
            background: #ECECEC;
        }

        .table-Description td {
            text-align: center
        }

        tbody td {
            background-color: #FAFAFA;
            color: #8F8F8F;
        }

        tfoot td {
            font-weight: bold;
            text-align: right;
            background: #ECECEC;
            border: unset;
            text-align: center;
        }

        .total {
            background: #f5f5f5;
        }

        .footer-content .section-title {
            margin-top: 10px;
        }
    </style>
</head>
@use('Modules\CabBooking\Enums\ServiceCategoryEnum')

<body>
    <img src="{{ public_path('modules/cabbooking/images/top.png') }}" alt="" class="top-table">
    <div class="invoice-container">
        <table class="invoice-data">
            <tbody class="invoice-header">
                <tr>
                    <td></td>
                    <td>
                        <h1>{{ __('cabbooking::static.invoice.invoice_title') }}</h1>
                        <div class="invoice-id common-color">
                            <p> {{ __('cabbooking::static.rides.ride_number') }}:
                                {{ $ride->ride_number }}<span>{{ __('cabbooking::static.invoice.date') }}:
                                    {{ $ride->created_at->format('d/m/Y') }}</span></p>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
        <table class="table-details">
            <tbody>
                <tr>
                    <td>
                        <div class="invoice-data">
                            <div class="invoice-to">
                                <p class="common-color">{{ __('cabbooking::static.invoice.invoice_to') }}</p>
                                <p class="dark-color">{{ __('cabbooking::static.invoice.name') }}: <span
                                        class="text-primary">{{ $ride->rider['name'] }}</span></p>
                            </div>

                            <div class="ride-details">
                                <div class="">
                                    <h3 class="section-title">{{ __('cabbooking::static.invoice.ride_details') }}:</h3>
                                    <p class="dark-color">{{ __('cabbooking::static.invoice.service') }}: <span
                                            class="common-color">{{ $ride->service['name'] ?? 'N/A' }} | <span
                                                class="dark-color">{{ __('cabbooking::static.invoice.service_category') }}:</span> <span
                                                class="common-color">{{ $ride->service_category['name'] ?? 'N/A' }}</span></span>
                                    </p>
                                    <p class="dark-color">{{ __('cabbooking::static.invoice.pickup_time') }}: <span
                                            class="common-color">{{ $ride?->start_time }} | <span
                                                class="dark-color">{{ __('cabbooking::static.invoice.drop_off_time') }}:</span> <span
                                                class="common-color">{{ $ride->end_time }}</span></span></p>
                                    <p class="dark-color">{{ __('cabbooking::static.invoice.pickup_location') }}: <span
                                            class="common-color">{{ $ride->locations[0] ?? 'N/A' }}</span></p>
                                    <p class="dark-color">{{ __('cabbooking::static.invoice.drop_off_location') }}:
                                        <span class="common-color">{{ $ride->locations[1] ?? 'N/A' }}</span>
                                    </p>
                                </div>
                                <img src="{{ public_path('modules/cabbooking/images/cab-yellow.png') }}" alt="">
                            </div>
                            <div class="vehicle">
                                <h3 class="section-title">{{ __('cabbooking::static.invoice.vehicle_driver_info') }}:
                                </h3>
                                <p class="dark-color">{{ __('cabbooking::static.invoice.driver_name') }}: <span
                                        class="common-color">{{ $ride?->driver['name'] ?? 'N/A' }}</span></p>
                                <p class="dark-color">{{ __('cabbooking::static.invoice.vehicle_type') }}: <span
                                        class="common-color">{{ $ride->vehicle_type->vehicle_info->vehicle->name ??
                                        'N/A' }}
                                        |</span>
                                    <span class="dark-color">{{ __('cabbooking::static.invoice.vehicle_model') }}:</span> <span
                                        class="common-color">{{ $ride->vehicle_type->vehicle_info['model'] ?? 'N/A' }}</span>
                                </p>
                                <p class="dark-color">{{ __('cabbooking::static.invoice.vehicle_number') }}: <span
                                        class="common-color">{{ $ride->vehicle_type->vehicle_info['plate_number'] ??
                                        'N/A' }}</span>
                                </p>
                            </div>
                        </div>
                    </td>
                    <td>
                </tr>
            </tbody>
        </table>
        <table class="table-Description">
            <thead>
                <tr>
                    <th>{{ __('cabbooking::static.invoice.description') }}</th>
                    <th>{{ __('cabbooking::static.invoice.amount') }}</th>
                </tr>
            </thead>
            <tbody>
                @php

                $isPackage = $ride?->service_category?->slug == ServiceCategoryEnum::PACKAGE;
                $isRental = $ride?->service_category?->slug == ServiceCategoryEnum::RENTAL;
                @endphp
                <tr>
                    <td>{{ __('cabbooking::static.invoice.base_fare') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->ride_fare, 2) }}</td>
                </tr>
                @if ($ride->additional_distance_charge > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.additional_distance_charge') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->additional_distance_charge, 2)
                        }}
                    </td>
                </tr>
                @endif
                @if ($ride->additional_minute_charge > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.additional_minute_charge') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->additional_minute_charge, 2) }}
                    </td>
                </tr>
                @endif
                @if ($ride->additional_weight_charge > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.additional_weight_charge') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->additional_weight_charge, 2) }}
                    </td>
                </tr>
                @endif
                @if ($isPackage)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.extra_charge') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format(round($ride?->extra_charge, 2), 2) }}
                    </td>
                </tr>
                @endif
                @if ($isRental)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.vehicle_charge') }}</td>
                    <td>
                        {{ $ride?->currency_symbol ?? $symbol }}{{ number_format(round($ride?->vehicle_per_day_price, 2)
                        * $ride?->no_of_days, 2) }}
                        ({{ round($ride?->vehicle_per_day_price, 2) }} * {{ $ride?->no_of_days }}
                        {{ __('cabbooking::static.rides.days') }})
                    </td>
                </tr>
                <tr>
                    <td>{{ __('cabbooking::static.invoice.driver_charge') }}</td>
                    <td>
                        {{ $ride?->currency_symbol ?? $symbol }}{{ number_format(round($ride?->driver_per_day_charge, 2)
                        * $ride?->no_of_days, 2) }}
                        ({{ round($ride?->driver_per_day_charge, 2) }} * {{ $ride?->no_of_days }}
                        {{ __('cabbooking::static.rides.days') }})
                    </td>
                </tr>
                @endif
                @if ($ride->waiting_charges > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.waiting_charge') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->waiting_charges, 2) }}
                    </td>
                </tr>
                @endif
                @if ($ride->bid_extra_amount > 0)
                    <tr>
                        <td>{{ __('cabbooking::static.invoice.extra_bid_amount') }}</td>
                        <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->bid_extra_amount, 2) }}
                        </td>
                    </tr>
                @endif
                @if ($ride->total_extra_charge > 0)
                    <tr>
                        <td>{{ __('cabbooking::static.invoice.total_extra_charges') }}</td>
                        <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->total_extra_charge, 2) }}
                        </td>
                    </tr>
                @endif
                @if ($ride->preference_charge > 0)
                    <tr>
                        <td>{{ __('cabbooking::static.invoice.total_preference_charges') }}</td>
                        <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->preference_charge, 2) }}
                        </td>
                    </tr>
                @endif
                @if ($ride->driver_tips > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.driver_tips') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format(round($ride->driver_tips, 2), 2) }}
                    </td>
                </tr>
                @endif
                @if ($roleName == RoleEnum::RIDER)
                @if ($ride->driver_cancellation_charge > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.driver_cancellation_charge') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->driver_cancellation_charge, 2)
                        }}
                    </td>
                </tr>
                @endif
                @if ($ride->rider_cancellation_charge > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.rider_cancellation_charge') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->rider_cancellation_charge, 2) }}
                    </td>
                </tr>
                @endif
                <tr>
                    <td>{{ __('cabbooking::static.invoice.subtotal') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format(round($ride?->sub_total, 2), 2) }}
                    </td>
                </tr>
                @if ($ride?->coupon_total_discount > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.coupon_discount') }} @if ($ride?->coupon?->code)
                        (#{{ $ride?->coupon?->code }})
                        @endif
                    </td>
                    <td>-{{ $ride?->currency_symbol ?? $symbol }}{{ number_format(round($ride?->coupon_total_discount,
                        2), 2) }}
                    </td>
                </tr>
                @endif
                @if ($ride->platform_fees > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.platform_fee') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->platform_fees, 2) }}
                    </td>
                </tr>
                @endif
                @if ($ride->tax > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.tax') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format(round($ride->tax, 2), 2) }}
                    </td>
                </tr>
                @endif
                @if ($ride->commission > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.commission') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->commission, 2) }}</td>
                </tr>
                </tr>
                @endif
                @if ($ride->processing_fee > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.processing_fee') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->processing_fee, 2) }}
                    </td>
                </tr>
                @endif
                @if ($roleName == RoleEnum::DRIVER)
                @if ($ride->driver_commission > 0)
                <tr>
                    <td>{{ __('cabbooking::static.invoice.driver_commission') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ number_format($ride->driver_commission, 2) }}
                    </td>
                </tr>
                @endif
                @endif
                @endif
            </tbody>
            <tfoot>
                <tr class="total">
                    <td colspan="1">{{ __('cabbooking::static.invoice.total') }}</td>
                    <td>{{ $ride?->currency_symbol ?? $symbol }}{{ $ride->total }}</td>
                </tr>
            </tfoot>
        </table>
        <div class="payment-method">
            <h3 class="section-title">{{ __('cabbooking::static.invoice.payment_details') }}:</h3>
            <p>{{ __('cabbooking::static.invoice.payment_method') }}: <span class="common-color">{{
                    $ride->payment_method }}</span>
                {{ __('cabbooking::static.invoice.payment_status') }}: <span class="common-color">{{
                    $ride->payment_status }}</span>
            </p>
        </div>
        <div class="footer-content">
            <h3 class="section-title">{{ __('cabbooking::static.invoice.thank_you') }}</h3>
            <p class="common-color">{{ __('cabbooking::static.invoice.thank_you_msg') }}</p>
        </div>
        <img src="{{ public_path('modules/cabbooking/images/exit.png') }}" class="exit-table" alt="">
    </div>
</body>

</html>
