<!DOCTYPE html>
<html>

<head>
    <title>Report</title>
</head>

<body>
    <h1>{{ $reportType }} Report</h1>

    @if ($data->isEmpty())
        <p>No data available</p>
    @else

    @if ($reportType === 'Total Subscribed')
    <table>
        <thead>
            <tr>
                <th>Sr No.</th>
                <th>Subscription ID</th>
                <th> Name</th>
                <th> Email </th>
                <th> Phone Number </th>
                <th>State</th>
                <th>Subscription Date and Time</th>
                <th> Next Subscription Date and Time </th>
            </tr>
        </thead>
        <tbody>
            @foreach($data as $subscription)
            <tr>
                <td>{{ $loop->iteration }}</td>
                <td>{{ $subscription->id }}</td>
                <td>{{ $subscription->iamPrincipal->first_name ?? 'N/A' }} {{ $subscription->iamPrincipal->last_name ?? 'N/A' }} </td>
                <td>{{ $subscription->iamPrincipal->email_address}}</td>
                <td>{{ $subscription->iamPrincipal->phone_number}}</td>
                <td>{{ $subscription->iamPrincipal->state->name ?? 'N/A' }}</td>
                <td>{{\Carbon\Carbon::parse($subscription->created_at)->format('m/d/Y H:i')}}</td>
                <td>{{\Carbon\Carbon::parse($subscription->next_payment_date)->format('m/d/Y H:i')}}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
    @elseif ($reportType === 'Total Users')
    <table>
        <thead>
            <tr>
                <th>Sr No.</th>
                <th>Customer ID</th>
                <th>Customer Name</th>
                <th>Customer Email </th>
                <th>Customer Phone Number</th>
                <th>State</th>
                <th>Customer Join Date Time</th>
            </tr>
        </thead>
        <tbody>
            @foreach($data as $user)
            <tr>
                <td>{{ $loop->iteration }}</td>
                <td>{{ $user->id }}</td>
                <td>{{ $user->first_name }}  {{ $user->last_name }}</td>
                <td>{{ $user->email_address }}</td>
                <td>{{ $user->phone_number }}</td>
                <td>{{ $user->state->name }}</td>
                <td>{{ \Carbon\Carbon::parse($user->created_at)->format('m/d/Y H:i') }}</td>

            </tr>
            @endforeach
        </tbody>
    </table>
    @elseif ($reportType === 'Redemptions')
    <table>
        <thead>
            <tr>
                <th>Sr No.</th>
                <th>Redemption ID</th>
                <th>Restaurant Name</th>
                <th>Customer Name</th>
                <th>Customer Email </th>
                <th>Customer Phone Number </th>
                <th>State</th>
                <th>Redemption Date  Time</th>
            </tr>
        </thead>
        <tbody>
            @foreach($data as $redemption)
            <tr>
                <td>{{ $loop->iteration }}</td>
                <td>{{ $redemption->id }}</td>
                <td>{{ $redemption->restaurant->name }}</td>
                <td>{{ $redemption->customer->first_name }} {{ $redemption->customer->last_name }}</td>
                <td>{{ $redemption->customer->email_address }}</td>
                <td>{{ $redemption->customer->phone_number }}</td>
                <td>{{ $redemption->customer->state->name }}</td>
                <td>{{\Carbon\Carbon::parse($redemption->created_at)->format('m/d/Y H:i')}} </td>
            </tr>
            @endforeach
        </tbody>
    </table>
    @elseif ($reportType === 'Redemptions for Specific Restaurants')
    <table>
        <thead>
            <tr>
                <th>Sr No.</th>
                <th>Redemption ID</th>
                <th>Restaurant Name</th>
                <th>Customer Name</th>
                <th>Customer Email</th>
                <th>Customer Phone Number </th>
                <th>State</th>
                <th>Redemption Date  Time</th>
            </tr>
        </thead>
        <tbody>
            @foreach($data as $redemption)
            <tr>
                <td>{{ $loop->iteration }}</td>
                <td>{{ $redemption->id }}</td>
                <td>{{ $redemption->restaurant->name }}</td>
                <td>{{ $redemption->customer->first_name }} {{ $redemption->customer->last_name }}</td>
                <td>{{ $redemption->customer->email_address }}</td>
                <td>{{ $redemption->customer->phone_number }}</td>
                <td>{{ $redemption->customer->state->name }}</td>
                <td>{{\Carbon\Carbon::parse($redemption->created_at)->format('m/d/Y H:i')}} </td>
            </tr>
            @endforeach

        </tbody>
    </table>
    @elseif ($reportType === 'Subscriptions Cancelled')
    <table>
        <thead>
            <tr>
                <th>Sr No.</th>
                <th>Subscription ID</th>
                <th>Name</th>
                <th>Email</th>
                <th>Phone number</th>
                <th>State</th>
                <th>Subscription Status</th>
                <th>Subscription Cancel Date Time</th>
            </tr>
        </thead>
        <tbody>
            @foreach($data as $item)
            <tr>
                <td>{{ $loop->iteration }}</td>
                <td>{{ $item->id }}</td>
                <td>{{ $item->iamPrincipal->first_name }} {{ $item->iamPrincipal->last_name }}</td>
                <td>{{ $item->iamPrincipal->email_address }}</td>
                <td>{{ $item->iamPrincipal->phone_number }}</td>
                <td>{{ $item->iamPrincipal->state->name }}</td>
                <td>{{ $item->subscription_status }}</td>
                <td>{{ \Carbon\Carbon::parse($item->cancelled_at)->format('m/d/Y H:i') }}</td>
                </tr>
            @endforeach

        </tbody>
    </table>

    @elseif ($reportType === 'Referrals Made')
    <table>
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Email</th>
                <th>Phone Number</th>
                <th>State</th>
                <th>Referred Date Time</th>
            </tr>
        </thead>
        <tbody>
        @foreach($data as $referral)
        <tr>
                <td>{{ $referral->id }}</td>
                <td>{{ $referral->referredUser->first_name }} {{ $referral->referredUser->last_name }}</td>
                <td>{{ $referral->referredUser->email_address }}</td>
                <td>{{ $referral->referredUser->phone_number}}</td>
                <td>{{ $referral->referredUser->state->name }}</td>
                <td> {{ \Carbon\Carbon::parse($referral->referred_date_time)->format('m/d/Y H:i') }}</td>

                </tr>
        @endforeach

        </tbody>
    </table>

    @elseif ($reportType === 'Referees Joined')
    <table>
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Email</th>
                <th>Phone number</th>
                <th>State</th>
                <th>Referred Date Time</th>
            </tr>
        </thead>
        <tbody>
        @foreach($data as $referees)

            <tr>
                <td>{{$referees->id }}</td>
                <td>{{ $referees->refeersUser->first_name }} {{ $referees->refeersUser->last_name }}</td>
                <td>{{ $referees->refeersUser->email_address }}</td>
                <td>{{ $referees->refeersUser->phone_number}}</td>
                <td>{{ $referees->refeersUser->state->name }}</td>
                <td> {{ \Carbon\Carbon::parse($referees->referred_date_time)->format('m/d/Y H:i') }}</td>
            </tr>
        @endforeach

        </tbody>
    </table>
    @endif


    @endif
</body>

</html>


