<?php

namespace App\Livewire\Projects\Tabs;

use App\Models\Project;
use Livewire\Component;

class Exports extends Component
{
    public Project $project;
    public $formData = [];

    public $showDownloadTifsModal = false;
    public $showDownloadMosaicsModal = false;


    public function mount()
    {
        $this->formData = [
            'start_date' => now()->subDays(6)->format('Y-m-d'),
            'end_date'   => now()->subDay()->format('Y-m-d'),
        ];
    }



    public function render()
    {
        return view('livewire.projects.tabs.exports');
    }

    public function downloadRds()
    {
        return $this->project->getRdsAsDownload();
    }

    public function downloadTifs()
    {
        $startDate = \Carbon\Carbon::parse($this->formData['start_date']);
        $endDate = \Carbon\Carbon::parse($this->formData['end_date']);
        $this->showDownloadTifsModal = false;
        return $this->project->getTifsAsZip(
            $startDate, $endDate
        );
    }

    public function downloadMosaics()
    {
        $startDate = \Carbon\Carbon::parse($this->formData['start_date']);
        $endDate = \Carbon\Carbon::parse($this->formData['end_date']);
        $this->showDownloadMosaicsModal = false;
        return $this->project->getMosaicsAsZip(
            $startDate, $endDate
        );
    }
}
