

<?php $__env->startSection('title', 'Manage Units'); ?>

<?php $__env->startSection('admin-content'); ?>
<style>
    /* Specific Units Styles */
    .units-page .code-badge {
        font-family: 'Consolas', 'Monaco', monospace;
        background: #f1f8e9;
        color: #33691e;
        padding: 4px 10px;
        border-radius: 6px;
        border: 1px solid #dcedc8;
        font-size: 0.9rem;
    }
</style>

<div class="units-page">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold mb-1">Manage Units</h4>
            <p class="text-muted mb-0 small">Define measurement units for product listings</p>
        </div>
        <div class="d-flex gap-2">
            <button type="button" class="btn btn-primary shadow-sm btn-lg d-flex align-items-center gap-2" 
                    data-bs-toggle="modal" data-bs-target="#createUnitModal"
                    style="border-radius: 12px; font-size: 0.95rem;">
                <i class="bi bi-plus-lg"></i> Add Unit
            </button>
        </div>
    </div>

    <?php if(session('success')): ?>
        <div class="alert alert-success border-0 shadow-sm rounded-3 mb-4 d-flex align-items-center">
            <i class="bi bi-check-circle-fill me-2 fs-5"></i>
            <?php echo e(session('success')); ?>

            <button type="button" class="btn-close ms-auto" data-bs-dismiss="alert"></button>
        </div>
    <?php endif; ?>
    
    <?php if($errors->any()): ?>
        <div class="alert alert-danger border-0 shadow-sm rounded-3 mb-4">
            <ul class="mb-0 ps-3">
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($error); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
    <?php endif; ?>

    <!-- Stats Overview -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <div class="stat-card stat-card-primary d-flex align-items-center gap-3">
                <div class="stat-icon primary">
                    <i class="bi bi-rulers"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($units->count()); ?></div>
                    <div class="stat-label">Total Units</div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="stat-card stat-card-success d-flex align-items-center gap-3">
                <div class="stat-icon success">
                    <i class="bi bi-toggle-on"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($units->where('is_active', true)->count()); ?></div>
                    <div class="stat-label">Active</div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="stat-card stat-card-warning d-flex align-items-center gap-3">
                <div class="stat-icon secondary">
                    <i class="bi bi-toggle-off"></i>
                </div>
                <div>
                    <div class="stat-value"><?php echo e($units->where('is_active', false)->count()); ?></div>
                    <div class="stat-label">Inactive</div>
                </div>
            </div>
        </div>
    </div>

    <!-- Units Table -->
    <div class="data-table">
        <div class="table-responsive">
            <table class="table mb-0">
                <thead>
                    <tr>
                        <th class="ps-4">Unit Name</th>
                        <th>Short Code</th>
                        <th class="text-center">Status</th>
                        <th class="text-end pe-4">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td class="ps-4 fw-bold text-dark"><?php echo e($unit->name); ?></td>
                            <td><span class="code-badge"><?php echo e($unit->code); ?></span></td>
                            <td class="text-center">
                                <?php if($unit->is_active): ?>
                                    <span class="status-badge active">
                                        <i class="bi bi-check-circle-fill"></i> Active
                                    </span>
                                <?php else: ?>
                                    <span class="status-badge inactive">
                                        <i class="bi bi-slash-circle"></i> Inactive
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="text-end pe-4">
                                <div class="d-flex gap-1 justify-content-end">
                                    <button type="button" class="action-btn primary" title="Edit Unit" 
                                            data-bs-toggle="modal" data-bs-target="#editUnitModal<?php echo e($unit->id); ?>">
                                        <i class="bi bi-pencil"></i>
                                    </button>
                                    
                                    <form action="<?php echo e(route('admin.units.destroy', $unit->id)); ?>" method="POST" class="d-inline"
                                          onsubmit="return confirm('Delete this unit? Products using it might be affected.');">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="action-btn danger" title="Delete Unit">
                                            <i class="bi bi-trash"></i>
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="4" class="text-center py-5">
                                <div class="py-4">
                                    <i class="bi bi-rulers fs-1 text-muted opacity-50 d-block mb-3"></i>
                                    <h5 class="fw-bold text-muted">No Units Defined</h5>
                                    <p class="text-muted small mb-0">Create new units for product measurements</p>
                                </div>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- Create Modal -->
<div class="modal fade" id="createUnitModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow-lg" style="border-radius: 16px;">
            <div class="modal-header border-0 pb-0">
                <div>
                    <h5 class="modal-title fw-bold">Add New Unit</h5>
                    <p class="text-muted small mb-0">Create a new measurement unit</p>
                </div>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="<?php echo e(route('admin.units.store')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-body p-4">
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted">Unit Name</label>
                        <input type="text" name="name" class="form-control form-control-lg rounded-3" placeholder="e.g. Kilograms" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted">Unit Code (Symbol)</label>
                        <input type="text" name="code" class="form-control form-control-lg rounded-3" placeholder="e.g. kg" required>
                    </div>
                </div>
                <div class="modal-footer border-0 pt-0">
                    <button type="button" class="btn btn-light rounded-3" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary rounded-3 px-4 fw-bold">Create Unit</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Edit Modals (Loop) -->
<?php $__currentLoopData = $units; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $unit): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div class="modal fade" id="editUnitModal<?php echo e($unit->id); ?>" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow-lg" style="border-radius: 16px;">
             <div class="modal-header border-0 pb-0">
                <div>
                    <h5 class="modal-title fw-bold">Edit Unit</h5>
                    <p class="text-muted small mb-0">Update unit details</p>
                </div>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="<?php echo e(route('admin.units.update', $unit->id)); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PUT'); ?>
                <div class="modal-body p-4">
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted">Unit Name</label>
                        <input type="text" name="name" class="form-control form-control-lg rounded-3" value="<?php echo e($unit->name); ?>" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted">Unit Code</label>
                        <input type="text" name="code" class="form-control form-control-lg rounded-3" value="<?php echo e($unit->code); ?>" required>
                    </div>
                    <div class="form-check form-switch ps-0 mt-3 p-3 bg-light rounded-3 d-flex justify-content-between align-items-center">
                        <label class="form-check-label fw-bold ms-2" for="active<?php echo e($unit->id); ?>">Active Status</label>
                        <input class="form-check-input ms-0 float-none" type="checkbox" role="switch" id="active<?php echo e($unit->id); ?>" name="is_active" value="1" <?php echo e($unit->is_active ? 'checked' : ''); ?> style="width: 40px; height: 20px; cursor: pointer;">
                    </div>
                </div>
                <div class="modal-footer border-0 pt-0">
                    <button type="button" class="btn btn-light rounded-3" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary rounded-3 px-4">Save Changes</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/u281583269/domains/theminiport.com/public_html/resources/views/admin/units/index.blade.php ENDPATH**/ ?>