

<?php $__env->startSection('title', 'Editar evento'); ?>

<?php $__env->startPush('head'); ?>
<style>
  .thumb-img{
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    border-radius: .5rem;
  }
  .bg-preview{
    max-width: 100%;
    height: auto;
    border-radius: .75rem;
    border: 1px solid rgba(255,255,255,.08);
  }
  .card-surface{ background:#12161d; border:1px solid rgba(255,255,255,.06); }
  .btn-accent{ background:#9ae6b4; color:#0b0e13; border:none; }
  .btn-accent:hover{ background:#b7f0c8; color:#0b0e13; }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
  <div class="d-flex align-items-center justify-content-between mb-3">
    <h1 class="h4 m-0">Editar: <?php echo e($event->titulo); ?></h1>
    <div class="d-flex gap-2">
      <?php if(Route::has('events.index')): ?>
        <a href="<?php echo e(route('events.index')); ?>" class="btn btn-outline-light">Mis eventos</a>
      <?php endif; ?>
      <?php if(Route::has('preview.form')): ?>
        <a href="<?php echo e(route('preview.form', $event->slug)); ?>" target="_blank" class="btn btn-outline-light">Ver preview</a>
      <?php endif; ?>
    </div>
  </div>

  <?php if(session('ok')): ?>
    <div class="alert alert-success"><?php echo e(session('ok')); ?></div>
  <?php endif; ?>

  
  <div class="card card-surface mb-4 rounded-4">
    <div class="card-body">
      <form method="POST" action="<?php echo e(route('events.update', $event)); ?>" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>
        <?php echo method_field('PUT'); ?>

        <div class="row g-3">
          <div class="col-md-7">
            <div class="mb-3">
              <label class="form-label">Título</label>
              <input type="text" name="titulo" class="form-control <?php $__errorArgs = ['titulo'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                     value="<?php echo e(old('titulo', $event->titulo)); ?>" required>
              <?php $__errorArgs = ['titulo'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <div class="invalid-feedback"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            </div>

            <div class="form-check form-switch mb-2">
              <input class="form-check-input" type="checkbox" role="switch" id="prevEnabled"
                     name="is_preview_enabled" value="1"
                     <?php echo e(old('is_preview_enabled', $event->is_preview_enabled) ? 'checked' : ''); ?>>
              <label class="form-check-label" for="prevEnabled">Habilitar página de preview</label>
            </div>

            <div class="form-check form-switch mb-3">
              <input class="form-check-input" type="checkbox" role="switch" id="guestUpload"
                     name="guest_upload_enabled" value="1"
                     <?php echo e(old('guest_upload_enabled', $event->guest_upload_enabled) ? 'checked' : ''); ?>>
              <label class="form-check-label" for="guestUpload">
                Permitir que invitados autenticados suban imágenes al validar el código
              </label>
            </div>

            <div class="mb-3">
              <label class="form-label">Actualizar código de preview (opcional)</label>
              <input type="password" name="preview_code"
                     class="form-control <?php $__errorArgs = ['preview_code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                     placeholder="Ej: 123456 (deja vacío para no cambiar)">
              <?php $__errorArgs = ['preview_code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <div class="invalid-feedback"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
              <small class="text-muted">El código se guarda en hash. Para cambiarlo, ingrésalo aquí.</small>
            </div>

            <div class="mb-3">
              <label class="form-label">URL de preview</label>
              <div class="input-group">
                <input type="text" class="form-control" value="<?php echo e(route('preview.form', $event->slug)); ?>" readonly>
                <a target="_blank" href="<?php echo e(route('preview.form', $event->slug)); ?>" class="btn btn-outline-light">Abrir</a>
              </div>
              <small class="text-muted">Comparte este enlace con tus invitados; deberán ingresar el código para acceder.</small>
            </div>

            <div class="mb-3">
              <label class="form-label">Color de fondo (respaldo)</label><br>
              <input type="color" name="bg_color" class="form-control form-control-color d-inline-block"
                     value="<?php echo e(old('bg_color', $event->bg_color ?? '#0b0e13')); ?>" title="Elige un color">
              <small class="text-muted ms-2">Se usa si no hay imagen de fondo, o como base.</small>
            </div>
          </div>

          <div class="col-md-5">
            <label class="form-label">Fondo personalizado (opcional)</label>
            <input type="file" name="bg_image" class="form-control <?php $__errorArgs = ['bg_image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                   accept="image/*" id="bg_input">
            <?php $__errorArgs = ['bg_image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <div class="invalid-feedback"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
            <small class="text-muted">Formatos: jpg, jpeg, png, webp. Máx 8MB.</small>

            <div class="mt-3">
              <img id="bg_preview"
                   src="<?php echo e($event->bg_image_path ? asset('storage/'.$event->bg_image_path) : ''); ?>"
                   alt=""
                   class="bg-preview"
                   style="<?php echo e($event->bg_image_path ? '' : 'display:none;'); ?>">
            </div>

            <?php if($event->bg_image_path): ?>
              <div class="mt-2">
                <a class="btn btn-sm btn-outline-light"
                   href="<?php echo e(route('events.edit', $event)); ?>?remove_bg=1"
                   onclick="event.preventDefault(); document.getElementById('remove-bg-form').submit();">
                  Quitar fondo
                </a>
              </div>
            <?php endif; ?>
          </div>
        </div>

        <div class="d-flex gap-2 mt-4">
          <button class="btn btn-primary">Guardar cambios</button>
          
          <button type="button" class="btn btn-danger"
                  onclick="if(confirm('¿Eliminar evento?')) document.getElementById('delete-event-form').submit();">
            Eliminar evento
          </button>
        </div>
      </form>
    </div>
  </div>

  
  <?php if($event->bg_image_path): ?>
    <form id="remove-bg-form" method="POST" action="<?php echo e(route('events.update', $event)); ?>" class="d-none">
      <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
      <input type="hidden" name="remove_bg" value="1">
      <input type="hidden" name="titulo" value="<?php echo e($event->titulo); ?>">
      <input type="hidden" name="is_preview_enabled" value="<?php echo e($event->is_preview_enabled ? 1 : 0); ?>">
      <input type="hidden" name="guest_upload_enabled" value="<?php echo e($event->guest_upload_enabled ? 1 : 0); ?>">
      <input type="hidden" name="bg_color" value="<?php echo e($event->bg_color); ?>">
    </form>
  <?php endif; ?>

  
  <form id="delete-event-form" method="POST" action="<?php echo e(route('events.destroy', $event)); ?>" class="d-none">
    <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
  </form>

  
  <div class="card card-surface mb-4 rounded-4">
    <div class="card-body">
      <h3 id="upload" class="h5 mb-3">Subir imágenes</h3>
      <form method="POST" action="<?php echo e(route('events.images.store', $event)); ?>" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>
        <input type="file" name="images[]" multiple accept="image/*" class="form-control mb-2" required>
        <?php $__errorArgs = ['images.*'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <div class="text-danger small mb-2"><?php echo e($message); ?></div> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
        <button class="btn btn-success">Subir</button>
      </form>
      <small class="text-muted d-block mt-2">Formatos permitidos: jpg, jpeg, png, webp. Máx 8MB por archivo.</small>
      <small class="text-muted d-block">Los invitados autenticados con código podrán subir desde el enlace público /p/<?php echo e($event->slug); ?>.</small>
    </div>
  </div>

  
  <div class="card card-surface rounded-4">
    <div class="card-body">
      <h3 class="h5 mb-3">Imágenes del evento</h3>

      <?php if($event->images->isEmpty()): ?>
        <p class="text-muted mb-0">Aún no hay imágenes.</p>
      <?php else: ?>
        <div class="row g-3">
          <?php $__currentLoopData = $event->images->sortBy(['order','id']); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $img): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="col-6 col-md-4 col-lg-3">
              <div class="border rounded-3 p-2 h-100 d-flex flex-column">
                <img src="<?php echo e(asset('storage/' . $img->path)); ?>" alt="Imagen" class="thumb-img mb-2">
                <div class="d-flex justify-content-between align-items-center mt-auto">
                  <small class="text-muted text-truncate me-2" title="<?php echo e($img->original_name ?? 'Imagen'); ?>">
                    <?php echo e($img->original_name ?? 'Imagen'); ?>

                  </small>
                  <form method="POST" action="<?php echo e(route('events.images.destroy', [$event, $img])); ?>"
                        onsubmit="return confirm('¿Eliminar esta imagen?')">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('DELETE'); ?>
                    <button class="btn btn-sm btn-danger">Eliminar</button>
                  </form>
                </div>
              </div>
            </div>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
      <?php endif; ?>
    </div>
  </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
  // Vista previa inmediata del fondo seleccionado
  document.getElementById('bg_input')?.addEventListener('change', function (e) {
    const [file] = e.target.files || [];
    const prev = document.getElementById('bg_preview');
    if (file) {
      prev.src = URL.createObjectURL(file);
      prev.style.display = 'block';
    }
  });

  // Si vino ?remove_bg=1 por GET por error, prevenir recarga con estado
  if (window.location.search.includes('remove_bg=1')) {
    const url = new URL(window.location.href);
    url.searchParams.delete('remove_bg');
    window.history.replaceState({}, '', url.toString());
  }
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\jaran\Documents\Marketing Digital\Laravel\eventos\resources\views/events/edit.blade.php ENDPATH**/ ?>