<?php

namespace App\Livewire;

use Illuminate\Support\Facades\Storage;
use Livewire\Component;

class PdfViewer extends Component
{
    public $pdfUrl;
    public $currentPage = 1;
    public $totalPages = 1;
    public $zoomLevel = 1;

    protected $listeners = ['pageChanged', 'annotationSaved'];

    public function mount($pdfId)
    {
        $this->pdfUrl = Storage::disk('pdfs')->temporaryUrl($pdfId, now()->addMinutes(30));
    }

    public function pageChanged($page)
    {
        $this->currentPage = $page;
    }

    public function annotationSaved($data)
    {
        // Procesar y guardar anotaciones
        $this->emit('refreshAnnotations');
    }

    public function render()
    {
        return view('livewire.pdf-viewer');
    }
}
