Files
sirpremiumv2/resources/views/livewire/whatsapp/show-menus-bot.blade.php
T
2026-04-24 21:40:10 -05:00

251 lines
17 KiB
PHP

<div>
<div class="flex items-center justify-between mb-4">
<h1 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
<svg class="w-7 h-7 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h10"/>
</svg>
Menús del Bot
</h1>
<button wire:click="openMenuForm()"
class="bg-green-500 hover:bg-green-600 text-white text-sm px-4 py-2 rounded-lg flex items-center gap-2 transition">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
Nuevo Menú
</button>
</div>
{{-- Buscador --}}
<input wire:model.live.debounce.300ms="search" type="text" placeholder="Buscar menú..."
class="mb-4 border border-gray-300 rounded-lg px-4 py-2 text-sm w-full max-w-xs focus:outline-none focus:ring-2 focus:ring-green-400">
{{-- Tabla de menús --}}
<div class="bg-white rounded-xl shadow overflow-hidden mb-6">
<table class="w-full text-sm">
<thead class="bg-gray-50 border-b border-gray-200">
<tr>
<th class="px-4 py-3 text-left text-gray-600">Nombre</th>
<th class="px-4 py-3 text-left text-gray-600">Título</th>
<th class="px-4 py-3 text-center text-gray-600">Principal</th>
<th class="px-4 py-3 text-center text-gray-600">Activo</th>
<th class="px-4 py-3 text-center text-gray-600">Opciones</th>
<th class="px-4 py-3 text-center text-gray-600">Acciones</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse($menus as $menu)
<tr class="hover:bg-gray-50">
<td class="px-4 py-3 font-medium text-gray-800">{{ $menu->name }}</td>
<td class="px-4 py-3 text-gray-600">{{ $menu->title }}</td>
<td class="px-4 py-3 text-center">
@if($menu->is_main)
<span class="bg-green-100 text-green-700 text-xs px-2 py-0.5 rounded-full"></span>
@else
<span class="text-gray-400"></span>
@endif
</td>
<td class="px-4 py-3 text-center">
<span class="text-xs px-2 py-0.5 rounded-full {{ $menu->is_active ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-600' }}">
{{ $menu->is_active ? 'Activo' : 'Inactivo' }}
</span>
</td>
<td class="px-4 py-3 text-center">
<button wire:click="$set('viewMenuId', {{ $menu->id }})"
class="text-blue-500 hover:underline text-xs">
{{ $menu->options_count }} opcs.
</button>
</td>
<td class="px-4 py-3">
<div class="flex justify-center gap-2">
<button wire:click="openMenuForm({{ $menu->id }})"
class="text-yellow-500 hover:text-yellow-700 transition" title="Editar">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
</button>
<button wire:click="openOptionForm(null, {{ $menu->id }})"
class="text-green-500 hover:text-green-700 transition" title="Agregar opción">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
</button>
<button wire:click="deleteMenu({{ $menu->id }})"
wire:confirm="¿Eliminar este menú y todas sus opciones?"
class="text-red-400 hover:text-red-600 transition" title="Eliminar">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
</button>
</div>
</td>
</tr>
@empty
<tr><td colspan="6" class="px-4 py-8 text-center text-gray-400">No hay menús creados</td></tr>
@endforelse
</tbody>
</table>
</div>
{{-- Detalle opciones del menú seleccionado --}}
@if($viewMenu)
<div class="bg-white rounded-xl shadow p-4 mb-6">
<div class="flex items-center justify-between mb-3">
<h3 class="font-bold text-gray-800">Opciones del menú: <span class="text-green-600">{{ $viewMenu->name }}</span></h3>
<div class="flex gap-2">
<button wire:click="openOptionForm(null, {{ $viewMenu->id }})"
class="text-sm bg-green-500 hover:bg-green-600 text-white px-3 py-1 rounded-lg flex items-center gap-1">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
Agregar opción
</button>
<button wire:click="$set('viewMenuId', null)" class="text-sm text-gray-500 hover:text-gray-700">Cerrar</button>
</div>
</div>
<table class="w-full text-sm">
<thead class="bg-gray-50 border-b">
<tr>
<th class="px-3 py-2 text-left text-gray-600">#</th>
<th class="px-3 py-2 text-left text-gray-600">Título</th>
<th class="px-3 py-2 text-left text-gray-600">Acción</th>
<th class="px-3 py-2 text-left text-gray-600">Valor</th>
<th class="px-3 py-2 text-center text-gray-600">Activa</th>
<th class="px-3 py-2 text-center text-gray-600">Ops</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse($viewMenu->options as $opt)
<tr>
<td class="px-3 py-2 font-bold text-gray-700">{{ $opt->option_number }}</td>
<td class="px-3 py-2">{{ $opt->title }}</td>
<td class="px-3 py-2">
<span class="bg-blue-50 text-blue-700 text-xs px-2 py-0.5 rounded">{{ $opt->action_type }}</span>
</td>
<td class="px-3 py-2 text-gray-500 max-w-xs truncate">{{ $opt->action_value }}</td>
<td class="px-3 py-2 text-center">
<span class="text-xs {{ $opt->is_active ? 'text-green-600' : 'text-red-400' }}">{{ $opt->is_active ? '✓' : '✗' }}</span>
</td>
<td class="px-3 py-2">
<div class="flex justify-center gap-2">
<button wire:click="openOptionForm({{ $opt->id }})" class="text-yellow-500 hover:text-yellow-700">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
</button>
<button wire:click="deleteOption({{ $opt->id }})" wire:confirm="¿Eliminar esta opción?"
class="text-red-400 hover:text-red-600">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
</button>
</div>
</td>
</tr>
@empty
<tr><td colspan="6" class="px-3 py-4 text-center text-gray-400">Sin opciones</td></tr>
@endforelse
</tbody>
</table>
</div>
@endif
{{-- Modal: Formulario Menú --}}
@if($showMenuForm)
<div class="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl w-full max-w-lg p-6">
<h3 class="text-lg font-bold text-gray-800 mb-4">{{ $editMenuId ? 'Editar Menú' : 'Nuevo Menú' }}</h3>
<form wire:submit.prevent="saveMenu" class="space-y-4">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Nombre interno *</label>
<input wire:model="menuName" type="text" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
@error('menuName') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Título visible *</label>
<input wire:model="menuTitle" type="text" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
@error('menuTitle') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
</div>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Mensaje del menú *</label>
<textarea wire:model="menuMessage" rows="4"
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400 resize-none"></textarea>
@error('menuMessage') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Menú padre</label>
<select wire:model="menuParentId" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none">
<option value=""> Ninguno </option>
@foreach($allMenus as $m)
@if($m->id !== $editMenuId)
<option value="{{ $m->id }}">{{ $m->name }}</option>
@endif
@endforeach
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Orden</label>
<input wire:model="menuSortOrder" type="number" min="0"
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none">
</div>
</div>
<div class="flex gap-4">
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer">
<input wire:model="menuIsMain" type="checkbox" class="rounded"> Es menú principal
</label>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer">
<input wire:model="menuIsActive" type="checkbox" class="rounded"> Activo
</label>
</div>
<div class="flex justify-end gap-3 pt-2 border-t border-gray-100">
<button type="button" wire:click="resetMenuForm()" class="px-4 py-2 text-sm text-gray-600 hover:text-gray-800">Cancelar</button>
<button type="submit" class="bg-green-500 hover:bg-green-600 text-white text-sm px-4 py-2 rounded-lg">Guardar</button>
</div>
</form>
</div>
</div>
@endif
{{-- Modal: Formulario Opción --}}
@if($showOptionForm)
<div class="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl w-full max-w-lg p-6">
<h3 class="text-lg font-bold text-gray-800 mb-4">{{ $editOptionId ? 'Editar Opción' : 'Nueva Opción' }}</h3>
<form wire:submit.prevent="saveOption" class="space-y-4">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Número de opción *</label>
<input wire:model="optionNumber" type="number" min="1"
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Título *</label>
<input wire:model="optionTitle" type="text"
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
@error('optionTitle') <p class="text-red-500 text-xs">{{ $message }}</p> @enderror
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Tipo de acción</label>
<select wire:model="optionAction" class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none">
<option value="message">Mensaje</option>
<option value="submenu">Submenú</option>
<option value="template">Plantilla</option>
<option value="url">URL</option>
<option value="advisor">Asesor</option>
<option value="flow">Flujo</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Orden</label>
<input wire:model="optionSort" type="number" min="0"
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none">
</div>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">Valor de la acción</label>
<input wire:model="optionValue" type="text" placeholder="ID de submenú, texto, URL..."
class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-400">
</div>
<label class="flex items-center gap-2 text-sm text-gray-700 cursor-pointer">
<input wire:model="optionIsActive" type="checkbox" class="rounded"> Opción activa
</label>
<div class="flex justify-end gap-3 pt-2 border-t border-gray-100">
<button type="button" wire:click="resetOptionForm()" class="px-4 py-2 text-sm text-gray-600 hover:text-gray-800">Cancelar</button>
<button type="submit" class="bg-green-500 hover:bg-green-600 text-white text-sm px-4 py-2 rounded-lg">Guardar</button>
</div>
</form>
</div>
</div>
@endif
</div>