<?php

namespace App\Livewire;

use App\Enums\OrderStatus;
use App\Enums\OrderType;
use App\Models\Customer;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Carbon;
use Livewire\Component;

class CreateOrder extends Component
{
    public Collection $customers;

    public string $selectedCustomer;

    public $contacts;

    public function mount(Collection $customers): void
    {
        $this->customers = $customers;
        $this->contacts  = $customers->first()->contacts;
    }

    public function getContacts(): void
    {
        $this->contacts = Customer::find($this->selectedCustomer)->contacts;
    }

    public function render(): View
    {
        return view('livewire.create-order', [
            'contacts'     => $this->contacts,
            'order_types'  => OrderType::cases(),
            'order_status' => OrderStatus::cases(),
            'customers'    => $this->customers,
            'today'        => Carbon::today()->format('Y-m-d'),
            'due_default'  => Carbon::today()->addDay(10)->format('Y-m-d'),
        ]);
    }
}