<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithTitle;

class ContactsExport implements FromCollection, WithTitle, WithHeadings, WithMapping
{
    use Exportable;

    protected $data;

    public function __construct(Collection $data)
    {
        $this->data = $data;
    }

    public function collection()
    {
        return $this->data;
    }


    public function headings(): array
    {
        return [
            __('Profile ID'),
            __('Profile type'),
            __('Name'),
            __('Full name'),
            __('Location'),
            __('Last interaction'),
            __('Has star'),
            __('Has bookmark'),
            __('Has transaction'),
            __('Has conversation'),
            __('Star count'),
            __('Bookmark count'),
            __('Transaction count'),
            __('Message count'),
        ];
    }

    public function map($contact): array
    {
        return [
            $contact['profile_id'],
            __($contact['profile_type_name']),
            $contact['name'],
            $contact['full_name'] ?? '',
            $contact['location'] ?? '',
            $contact['last_interaction'] ?? '',
            $contact['has_star'] ? __('Yes') : __('No'),
            $contact['has_bookmark'] ? __('Yes') : __('No'),
            $contact['has_transaction'] ? __('Yes') : __('No'),
            $contact['has_conversation'] ? __('Yes') : __('No'),
            $contact['star_count'] ?? 0,
            $contact['bookmark_count'] ?? 0,
            $contact['transaction_count'] ?? 0,
            $contact['message_count'] ?? 0,
        ];
    }

    public function title(): string
    {
        return __('Contacts');
    }
}
