<?php

namespace App\Livewire\Forms;

use App\Models\Room;
use App\Models\Branch;
use App\Enums\RoomType;

use Livewire\Component;
use Illuminate\Database\Eloquent\Collection;



class RoomGridForm extends Component
{
    public $branchName="";
    public array $roomTypes;
    

    public function mount()
    {
        $this->roomTypes = ['all' => '全部'] + collect(RoomType::cases())->mapWithKeys(fn($e) => [$e->value => $e->labels()])->toArray();
    }

    public function render()
    {
        $branch = Branch::first();
        $this->branchName = $branch->name ?? '';
        
        $rooms = collect(); // 預設為空集合
        $floors = [];

        if ($branch) {
            $rooms = Room::where('branch_id', $branch->id)->get();
            $floors = $rooms->pluck('floor')->unique()->sort()->values()->toArray();
        }
        
        return view('livewire.forms.room-grid-form', [
            'rooms' => $rooms,
            'floors' => $floors,
        ]);
    }
}
