<?php

use App\Enums\ContactStatus;
use App\Models\ContactSubmission;
use Flux\Flux;
use Illuminate\Validation\Rule;
use Livewire\Component;

return new class extends Component {
    public ContactSubmission $contactSubmission;

    public string $status = '';

    public function mount(ContactSubmission $contactSubmission): void
    {
        $this->contactSubmission = $contactSubmission;
        $this->status = $contactSubmission->status?->value ?? ContactStatus::New->value;
    }

    /**
     * Update the submission's status. This is the only write action in the
     * legacy admin panel; Livewire re-renders in place rather than issuing a
     * raw POST, so a browser refresh can no longer re-submit the change.
     */
    public function updateStatus(): void
    {
        $validated = $this->validate([
            'status' => ['required', 'string', Rule::enum(ContactStatus::class)],
        ]);

        $this->contactSubmission->update([
            'status' => ContactStatus::from($validated['status']),
        ]);

        Flux::toast(variant: 'success', text: __('Status updated successfully!'));
    }

    public function render(): mixed
    {
        return $this->view()->title(__('Contact Submission #:id', ['id' => $this->contactSubmission->id]));
    }

    protected function view($data = [])
    {
        return app('view')->file('/Users/dineshmali/code/pushpvatikaflorist1/storage/framework/views/livewire/views/69d1002c.blade.php', $data);
    }
}; 