<?php

namespace App\Exports;

use Excel;
use App\Models\CallLog;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;

class CallLogExport implements WithMapping,FromCollection,WithHeadings
{
    private $call_types;

    protected $data;
    public function __construct($data)
    {
        $this->data = $data;
        $this->call_types=[
            'Unknown',
            'Incoming',
            'Outgoing',
            'Missed',
            'Voicemail',
            'Rejected',
            'Blocked',
            'Answered'
        ];
    }

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

    public function map($log): array
    {
        return [
            $log->id,
            date('d M Y h:i a', strtotime($log->date)),
            $log->name,
            $log->number,
            $this->call_types[$log->type]

        ];
    }

    public function headings(): array
    {
        return [
            'Id',
            'Date & Time',
            'Name',
            'Number',
            'Call Type'
        ];
    }
}
