<?php

namespace App\Datatables\Admin\Core\Mail;

use App\Datatables\ParentDataTable as DataTable;
use App\Models\Core\Mail\MailLog;
use App\Repositories\Core\Mail\MailParser;
use Yajra\DataTables\Html\Column;

class MailLogsDataTable extends DataTable
{
    public $model_name = 'mail_logs';

    public $sortedColumn = 0;

    public $sortedOrder = 'desc';

    public $stateSave = true;

    public function query(MailLog $model)
    {
        return $this->buildQuery($model);
    }

    public function modifier($datatables)
    {
        $datatables
            ->editColumn('sent_to', function (MailLog $log) {
                return MailParser::getToEmail($log->event);
            })
            ->editColumn('subject', function (MailLog $log) {
                return MailParser::getSubject($log->event);
            })
            ->rawColumns(['action']);

        return parent::modifier($datatables);
    }

    public function getHtmlButtons()
    {
        return self::getButtonShow();
    }

    protected function getColumns()
    {
        return [
            Column::make('created_at')->title(__('sent')),
            Column::make('sent_to')->title(__('user')),
            Column::make('subject')->title(__('subject')),
            $this->makeColumnButtons()->width('60'),
        ];
    }
}
