<?php

namespace App\Http\Controllers\Backend\Payments;

use App\DataTables\Payments\PaymentDataTable;
use App\DataTables\Payments\PaymentDataTableEditor;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class PaymentController extends Controller{

    public function __construct(){

        $this->middleware('permission:payment-list')
            ->only(["index"]);

        $this->middleware('permission:payment-show')
            ->only(["show"]);

        $this->middleware(['permission:payment-create','permission:payment-update','permission:payment-delete'])
            ->only(['dtEdit']);
    }

    public function index(){
        $title = __("Manage Payments");

        $menus = [
            [
                "title" => __("Payments"),
                "icon" => '',
                "href" => 'tab-content-1',
                "id" => 'tab-1',
                "styles" => "margin-left: 15px;",
                "tab-index" => 1,
                "url" => route("admin.payments.dt-list"),
                "permissions" =>  [],
                "content" => [
                    "file" => "backend.payments.tabs.payments",
                    "dataTable" => PaymentDataTable::class,
                    "table" => [
                        "id" => "payments-table",
                    ],
                ],
            ],
        ];

        return view('backend.payments.index',
            compact('title',"menus"));
    }

    public function dtList(PaymentDataTable $dataTable){
        return $dataTable->render("backend.payments.tabs.index");
    }

    public function dtEdit(PaymentDataTableEditor $editor){
        return $editor->process(request());
    }
}
