<?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 ProfileTagsExport 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 [
            __('Tag ID'),
            __('Tag'),
            __('Category'),
            __('Category path'),
            __('Locale'),
        ];
    }

    public function map($tag): array
    {
        return [
            $tag['tag_id'] ?? '',
            $tag['tag'] ?? '',
            $tag['category'] ?? '',
            $tag['category_path'] ?? '',
            $tag['locale'] ?? '',
        ];
    }

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