<?php

namespace App\Exports;

use App\Models\ManageFeedback;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class FeedbakExport implements FromCollection, WithHeadings
{
    public function collection()
    {
        return ManageFeedback::with(['principal', 'feedbackReaction'])->get()->map(function ($feedback) {
            return [
                'Customer Id' => $feedback->principal ? $feedback->principal->id : 'N/A',
                'First Name' => $feedback->principal ? $feedback->principal->first_name : 'N/A',
                'Last Name' => $feedback->principal ? $feedback->principal->last_name : 'N/A',
                'Feedback Reaction' => $feedback->feedbackReaction ? $feedback->feedbackReaction->feedback_reaction_title : 'N/A',
                'Comment' => $feedback->comment,
                'Date Received' => $feedback->created_at,
            ];
        });
    }

    public function headings(): array
    {
        return [
            'Customer Id',
            'First Name',
            'Last Name',
            'Feedback Reaction',
            'Comment',
            'Date Received'
        ];
    }
}
