<?php

namespace App\DataTables;

use App\Country;
use App\User;
use Yajra\DataTables\Services\DataTable;

class SettingCountryDataTable extends DataTable
{

    public function dataTable($query)
    {
       return datatables()
            ->eloquent($query)
            ->addColumn('action', function ($row){
                return '<div class="btn-group">' .
                '<a style="text-decoration: none" title="Edit Country" class="btn btn-sm btn-primary" href="' . route('admin.setting.countries.edit', ['id'=>$row->id]).'"><i class="fa fa-pencil"></i> Edit</a>' .
                '<a style="text-decoration: none" title="Delete Country" class="btn btn-sm btn-danger" href="' . route('admin.setting.countries.delete', ['id'=>$row->id]) . '"' .
                'onclick="return confirm(\'Do you want to delete this country?\')"><i class="fa fa-trash"></i> Delete</a>' .
                '<a style="text-decoration: none" title="Manage Networks" class="btn btn-sm btn-info" href="' . route('admin.setting.countries.networks', ['country_id'=>$row->id]).'"><i class="fa fa-wifi"></i> Networks</a>' .
                '</div>';
            });

    }

    /**
     * Get the query object to be processed by dataTables.
     *
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
     */
    public function query()
    {
        $query = Country::orderBy('name');

        return $this->applyScopes($query);
    }

    /**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\Datatables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
                    ->columns($this->getColumns())
                    ->ajax('')
                    ->addAction(['width' => '230px'])
                    ->parameters($this->getBuilderParameters());
    }

    /**
     * Get columns.
     *
     * @return array
     */
    protected function getColumns()
    {
        return [
            'name' => ['title'=> 'Country Name'],
        ];
    }

    /**
     * Get filename for export.
     *
     * @return string
     */
    protected function filename()
    {
        return 'settingcountries_' . time();
    }
}
