<?php

namespace App\Distributor\Controllers;

use App\Distributor\Repositories\RpcAlbum;
use App\Distributor\Repositories\SmmPostLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Admin;

class SmmPostLogController extends AdminController
{
    /**
     * page index
     */
    public function index(Content $content)
    {
        return $content
            ->header(admin_trans_label('post_log'))
            ->description()
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(SmmPostLog::with(['post', 'account']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('account.name', admin_trans_label('account_name'));
            $grid->column('media_name',admin_trans_label('media_name'));
            //$grid->column('post.message',admin_trans_label('post_message'))->width('30%');
            $grid->column('created_at');
            $grid->column('status')->using(admin_trans_array(config('dictionary.post_log_status')))->label([
                0 => 'gray',
                1 => 'info',
                2 => 'success',
                3 => 'orange1',
            ])->display(function ($value) {
                if ($this->status == 3 && $this->request_count <=2) {
                    return "<span class='label' style='background:#3085d6'>".admin_trans_label('retrying').'</span>';
                } else {
                    return $value;
                }
            });
            //$grid->column('remark')->width('15%');
            $grid->column('send_time', admin_trans_label('etd'))->sortable();
            $grid->disableRowSelector();
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->model()->where('dist_id', getDistributorId())->orderBy('id', 'desc');
        });
    }

    protected function detail($id)
    {
        return Show::make($id, SmmPostLog::with(['post', 'account']), function (Show $show) {
            $show->field('id');
            $show->field('account.name', admin_trans_label('account_name'));
            $show->field('media_name',admin_trans_label('media_name'));
            $show->field('post.message',admin_trans_label('post_message'));
            $show->field('remark');
            $show->field('send_time', admin_trans_label('etd'));
            $show->field('created_at');
            $show->field('status')->using(admin_trans_array(config('dictionary.post_log_status')));
            $show->disableDeleteButton();
        });
    }
}
