<?php

namespace App\Exports;

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

class ClientExport implements FromCollection, WithHeadings
{
    /**
     * Headings for the export.
     */
    public function headings(): array
    {
        return ['Sr.', 'Company Name', 'Owner Name', 'Email', 'Phone', 'Logo', 'Address', 'Status'];
    }

    /**
     * Collection of rows for Excel export.
     */
    public function collection()
    {
        $data = Client::latest('email')
->whereNull('deleted_at')
->get();

        // Add serial numbers
        $sr = 1;
        return $data->map(function ($row) use (&$sr) {
            return [
                $sr++,
                strip_tags($row->company_name), strip_tags($row->owner_name), strip_tags($row->email), strip_tags($row->phone), strip_tags($row->logo), strip_tags($row->address), strip_tags($row->status)
            ];
        });
    }
}
