'', 'description' => '', 'phase_id' => null, 'fields' => [], ]; public $fieldTypes = [ 'text' => 'Texto corto', 'textarea' => 'Texto largo', 'integer' => 'Número entero', 'decimal' => 'Número decimal', 'percentage' => 'Porcentaje (0-100)', 'boolean' => 'Sí/No (checkbox)', 'date' => 'Fecha', 'select' => 'Lista desplegable', ]; public function mount(Project $project) { $this->project = $project; $this->loadPhases(); $this->loadTemplates(); } public function loadPhases() { $this->phases = $this->project->phases()->orderBy('name')->get(); } public function loadTemplates() { $this->templates = InspectionTemplate::where('project_id', $this->project->id)->get(); } public function newTemplate() { $this->resetForm(); $this->editingTemplate = null; $this->showForm = true; } public function editTemplate($id) { $template = InspectionTemplate::find($id); $this->form = $template->only(['name', 'description', 'phase_id', 'fields']); $this->editingTemplate = $id; $this->showForm = true; } public function cancelForm() { $this->showForm = false; $this->resetForm(); } public function resetForm() { $this->form = [ 'name' => '', 'description' => '', 'phase_id' => null, 'fields' => [], ]; $this->editingTemplate = null; } public function addField() { $this->form['fields'][] = [ 'name' => '', 'label' => '', 'type' => 'text', 'options' => [], 'required' => false, 'min' => null, 'max' => null, 'step' => null, ]; } public function removeField($index) { unset($this->form['fields'][$index]); $this->form['fields'] = array_values($this->form['fields']); } public function saveTemplate() { $this->validate([ 'form.name' => 'required|string|max:255', 'form.phase_id' => 'nullable|exists:phases,id', 'form.fields' => 'array', ]); if ($this->editingTemplate) { $template = InspectionTemplate::find($this->editingTemplate); $template->update($this->form); session()->flash('message', 'Template actualizado'); } else { InspectionTemplate::create([ 'name' => $this->form['name'], 'description' => $this->form['description'], 'project_id' => $this->project->id, 'phase_id' => $this->form['phase_id'], 'fields' => $this->form['fields'], ]); session()->flash('message', 'Template creado'); } $this->cancelForm(); $this->loadTemplates(); } public function deleteTemplate($id) { InspectionTemplate::find($id)->delete(); $this->loadTemplates(); session()->flash('message', 'Template eliminado'); } public function render() { return view('livewire.template-manager'); } }