<?php $attributes ??= new \Illuminate\View\ComponentAttributeBag;

$__newAttributes = [];
$__propNames = \Illuminate\View\ComponentAttributeBag::extractPropNames(([
  'title' => 'Bloque',
  'name' => 'bloque',
  'required' => true,
  'accept' => 'image/*',
  'currentUrl' => null,
  'descripcion' => null,
  'imgLabel' => 'Imagen (JPG/PNG/WebP)',
  'descLabel' => 'Descripción',
]));

foreach ($attributes->all() as $__key => $__value) {
    if (in_array($__key, $__propNames)) {
        $$__key = $$__key ?? $__value;
    } else {
        $__newAttributes[$__key] = $__value;
    }
}

$attributes = new \Illuminate\View\ComponentAttributeBag($__newAttributes);

unset($__propNames);
unset($__newAttributes);

foreach (array_filter(([
  'title' => 'Bloque',
  'name' => 'bloque',
  'required' => true,
  'accept' => 'image/*',
  'currentUrl' => null,
  'descripcion' => null,
  'imgLabel' => 'Imagen (JPG/PNG/WebP)',
  'descLabel' => 'Descripción',
]), 'is_string', ARRAY_FILTER_USE_KEY) as $__key => $__value) {
    $$__key = $$__key ?? $__value;
}

$__defined_vars = get_defined_vars();

foreach ($attributes->all() as $__key => $__value) {
    if (array_key_exists($__key, $__defined_vars)) unset($$__key);
}

unset($__defined_vars, $__key, $__value); ?>

<?php
  $id = preg_replace('/[^a-z0-9_]/i','_', $name);
  $req = filter_var($required, FILTER_VALIDATE_BOOLEAN);
?>

<div <?php echo e($attributes->merge(['class' => 'mt-6 border rounded-lg p-4'])); ?>

     x-data="{
       previewUrl: null,
       onFileChange(e) {
         const f = e.target.files?.[0];
         if (!f) { this.clear(); return; }
         this.previewUrl && URL.revokeObjectURL(this.previewUrl);
         this.previewUrl = URL.createObjectURL(f);
       },
       clear() {
         const input = $refs.file_<?php echo e($id); ?>;
         if (input) { input.value = ''; }
         if (this.previewUrl) { URL.revokeObjectURL(this.previewUrl); }
         this.previewUrl = null;
       }
     }">

  <h3 class="field is-required"><?php echo e($title); ?></h3>

  <div class="grid md:grid-cols-2 gap-4">
    <div>
      <label class="block text-sm text-gray-600 mb-1">
        <?php echo e($imgLabel); ?> <?php if($req): ?>*<?php endif; ?>
      </label>
      <input type="file"
             x-ref="file_<?php echo e($id); ?>"
             name="<?php echo e($name); ?>[imagen]"
             accept="<?php echo e($accept); ?>"
             class="block w-full border rounded p-2"
             style="color:black"
             @change="onFileChange"
             <?php if($req): ?> required <?php endif; ?>>
      <div class="mt-3" x-show="previewUrl">
        <img :src="previewUrl" alt="Vista previa" class="max-h-56 rounded border">
        <div class="mt-2">
          <button type="button" class="text-sm px-2 py-1 border rounded" @click="clear()">Quitar imagen</button>
        </div>
      </div>
      <?php if($currentUrl): ?>
        <div class="mt-2 text-sm">
          <span class="text-gray-600">Actual:</span>
          <a href="<?php echo e($currentUrl); ?>" target="_blank" class="text-blue-600 underline">ver imagen</a>
        </div>
      <?php endif; ?>
    </div>

    <div>
      <label class="field-label"><?php echo e($descLabel); ?> <?php if($req): ?>*<?php endif; ?></label>
      <textarea name="<?php echo e($name); ?>[descripcion]" rows="6"
                class="w-full border rounded p-2"
                style="color:black"
                placeholder="Escribe aquí..."
                <?php if($req): ?> required <?php endif; ?>><?php echo e(old($name.'.descripcion', $descripcion)); ?></textarea>
    </div>
  </div>
</div>
<?php /**PATH C:\xampp\htdocs\Auditoria-app\resources\views/components/upload-descripcion.blade.php ENDPATH**/ ?>