<?php

namespace App\Http\Controllers\Shop;

use App\Datatables\Shop\CustomerInvoicesDataTable;
use App\Repositories\Shop\InvoicePDF;
use App\Repositories\Shop\Invoices;

class InvoiceController extends Controller
{
    public function index(CustomerInvoicesDataTable $dataTable)
    {
        return $dataTable->render('Shop.Invoices.partials.list');
    }

    public function view($uuid)
    {
        $invoice = Invoices::view($uuid);

        if (! $invoice) {
            abort(404);
        }

        $data = [
            'invoice' => $invoice,
        ];

        return view('Shop.Invoices.view', $data);
    }

    public function pdf($uuid)
    {
        if (app()->bound('debugbar')) {
            app('debugbar')->disable();
        }

        return InvoicePDF::getByUUID($uuid);
    }
}
