<?php

namespace App\Http\Controllers;

use App\Models\Agendamento;
use App\Models\Datepicker;
use Barryvdh\DomPDF\Facade as PDF;
use Carbon\Carbon;
use Illuminate\Http\Request;

class DatepickerController extends Controller
{
    public function create()
    {
        return view('datepicker');
    }

    public function datepicker(Request $request)
    {
        $datepicker = new Datepicker();
        $datepicker->cpf = $request->get('cpf');
        $datepicker->data = $request->get('data');
        $datepicker->hora = $request->get('hora');
        $datepicker->detentor = $request->get('detentor');
        $datepicker->escritorio = $request->get('escritorio');
        $datepicker->titulo = $request->get('titulo');
        $datepicker->municipio = $request->get('municipio');
        $datepicker->atendido = $request->get('atendido');
        $datepicker->save();

        return view('dadosAtendimento')->with([
            'cpf' => $request->get('cpf'),
            'detentor' => $request->get('detentor'),
            'data' => $request->get('data'),
            'id' => $request->get('id'),
            'hora' => $request->get('hora'),
            'escritorio' => $request->get('escritorio'),
            'titulo' => $request->get('titulo'),
            'municipio' => $request->get('municipio'),
            'atendido' => $request->get('atendido'),
        ]);
    }

   
    public function datepickerAgendamento(Request $request)
    {
        $datepicker = new Datepicker();
        $datepicker->tecnico_id = $request->get('tecnico_id');
        $datepicker->save();

        return view('admin.pages.agendamentos.show')->with([
            'tecnico_id' => $request->get('tecnico_id'),
        ]);
    }

    // public function createPDF(Request $request) {
    //     // retreive all records from db
    //     $datepicker = new Datepicker();
    //     $datepicker->cpf = $request->get('cpf');
  
    //     // share data to view
    //     // view()->share('dadosAtendimento',  $datepicker->cpf);
    //     $pdf = PDF::loadView('pdf',  $datepicker->cpf);
  
    //     // download PDF file with download method
    //     return $pdf->download('pdf_file.pdf');
    //   }
}
