<?php $__env->startSection('title', 'Satuan Obat - SI Apotek'); ?>

<?php $__env->startSection('content'); ?>
<h2 class="my-6 text-2xl font-semibold text-gray-700">Manajemen Satuan Obat</h2>

<?php if(session('success')): ?>
<div class="p-4 mb-4 text-sm text-emerald-700 bg-emerald-100 rounded-lg flex items-center gap-2" role="alert">
    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
    <?php echo e(session('success')); ?>

</div>
<?php endif; ?>

<div class="grid md:grid-cols-3 gap-6">
    <!-- Form Tambah -->
    <div class="bg-white rounded-lg shadow-sm border border-gray-100 p-6 h-fit">
        <h3 class="text-lg font-semibold text-gray-700 mb-4">Tambah Satuan</h3>
        <form action="<?php echo e(route('units.store')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <div class="mb-4">
                <label class="block text-sm font-medium text-gray-700 mb-1">Nama Satuan</label>
                <input type="text" name="name" class="w-full px-4 py-2 border rounded-lg focus:ring-emerald-500 focus:border-emerald-500 transition-colors" placeholder="Contoh: Strip, Botol..." required>
            </div>
            <button type="submit" class="w-full bg-emerald-600 text-white py-2 rounded-lg hover:bg-emerald-700 transition font-semibold shadow-sm">Simpan</button>
        </form>
    </div>

    <!-- Tabel Data -->
    <div class="md:col-span-2 bg-white rounded-lg shadow-sm border border-gray-100 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full whitespace-no-wrap">
                <thead>
                    <tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b bg-gray-50">
                        <th class="px-4 py-3 w-16">No</th>
                        <th class="px-4 py-3">Nama Satuan</th>
                        <th class="px-4 py-3 text-right">Aksi</th>
                    </tr>
                </thead>
                <tbody class="divide-y">
                    <?php $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr class="text-gray-700 hover:bg-gray-50 transition-colors">
                        <td class="px-4 py-3 text-sm"><?php echo e($loop->iteration); ?></td>
                        <td class="px-4 py-3 text-sm font-medium"><?php echo e($unit->name); ?></td>
                        <td class="px-4 py-3 text-sm text-right">
                            <div class="flex justify-end gap-2">
                                <!-- Edit -->
                                <div x-data="{ openEdit: false }">
                                    <button @click="openEdit = true" class="px-3 py-1 text-sm font-medium leading-5 text-emerald-600 bg-emerald-100 rounded-lg hover:bg-emerald-200 transition-colors">Edit</button>
                                    
                                    <div x-show="openEdit" class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50 backdrop-blur-sm" x-cloak>
                                        <div @click.away="openEdit = false" class="bg-white rounded-2xl p-6 w-96 text-left shadow-xl transform transition-all">
                                            <h3 class="text-lg font-bold text-gray-800 mb-4">Edit Satuan</h3>
                                            <form action="<?php echo e(route('units.update', $unit->id)); ?>" method="POST">
                                                <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                                                <div class="mb-4">
                                                    <label class="block text-sm font-medium text-gray-700 mb-1">Nama Satuan</label>
                                                    <input type="text" name="name" value="<?php echo e($unit->name); ?>" class="w-full px-4 py-2 border rounded-lg focus:ring-emerald-500 focus:border-emerald-500" required>
                                                </div>
                                                <div class="flex justify-end gap-2 mt-6">
                                                    <button type="button" @click="openEdit = false" class="px-4 py-2 text-sm font-medium text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors">Batal</button>
                                                    <button type="submit" class="px-4 py-2 text-sm font-medium text-white bg-emerald-600 rounded-lg hover:bg-emerald-700 transition-colors shadow-sm">Simpan Perubahan</button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>

                                <!-- Delete -->
                                <form action="<?php echo e(route('units.destroy', $unit->id)); ?>" method="POST" onsubmit="return confirm('Yakin ingin menghapus satuan ini?');" class="inline">
                                    <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                                    <button type="submit" class="px-3 py-1 text-sm font-medium leading-5 text-red-600 bg-red-100 rounded-lg hover:bg-red-200 transition-colors">Hapus</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\PROJECT\xampp\htdocs\apoteks\resources\views/master/units.blade.php ENDPATH**/ ?>