
<?php $__env->startSection('title'); ?>
<?php echo $variables['header_routes']; ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card card-outline card-warning">
                    <div class="card-header">
                        <h3 class="card-title"><?php echo $variables['judul']; ?></h3>
                    </div>
                    <div class="card-body">
                        <!-- <form method="post" action="<?php echo e(route('users.store', $data->id, $variables['type'])); ?>" enctype="multipart/form-data"> -->
                        <form method="post" action="<?php echo e(route('users.store', [$data->id, $variables['type']])); ?>" enctype="multipart/form-data">
                            <?php echo csrf_field(); ?>
                            <?php if($variables['type'] == 'cp'): ?>
                            <div class="row">

                                <?php
                                $type = '';
                                if ($f_need_change_password && $f_need_change_password != '') {
                                $type = "style=display:none";
                                }
                                ?>

                                <div class="form-group col-md-4" <?php echo e($type); ?>>
                                    <label for="current_password" class="font-weight-bold">Password Lama</label>
                                    <input
                                        type="password"
                                        class="form-control form-control-sm"
                                        name="current_password"
                                        value="<?php echo e($f_need_change_password ?? ''); ?>"
                                        placeholder="">
                                    <?php if($errors->has('current_password')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('current_password')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-4">
                                    <label for="password" class="font-weight-bold">Password Baru</label>
                                    <input
                                        type="password"
                                        class="form-control form-control-sm"
                                        name="password"
                                        placeholder=""
                                        value="<?php echo e(old('password', '')); ?>">
                                    <?php if($errors->has('password')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('password')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-4">
                                    <label for="password_confirmation" class="font-weight-bold">Konfirmasi Password</label>
                                    <input
                                        type="password"
                                        class="form-control form-control-sm"
                                        name="password_confirmation"
                                        placeholder=""
                                        value="<?php echo e(old('password_confirmation', $data->password_confirmation ?? '')); ?>">
                                    <?php if($errors->has('password_confirmation')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('password_confirmation')); ?></span>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php elseif($variables['type'] == 'ema'): ?>
                            <div class="row">
                                <div class="form-group col-md-6">
                                    <label for="fullname" class="font-weight-bold">Nama Lengkap</label>
                                    <input value="<?php echo e(old('fullname', $data->fullname ?? '')); ?>" type="text" class="form-control form-control-sm" name="fullname" placeholder="">
                                    <?php if($errors->has('fullname')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('fullname')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="email" class="font-weight-bold">Email</label>
                                    <input value="<?php echo e(old('email', $data->email ?? '')); ?>" type="text" class="form-control form-control-sm" name="email" placeholder="">
                                    <?php if($errors->has('email')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('email')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="telephone" class="font-weight-bold">Telepon</label>
                                    <input value="<?php echo e(old('telephone', $data->telephone ?? '')); ?>" type="text" class="form-control form-control-sm" name="telephone" placeholder="">
                                    <?php if($errors->has('telephone')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('telephone')); ?></span>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <?php else: ?>
                            <div class="row">
                                <div class="form-group col-md-3">
                                    <label for="fullname" class="font-weight-bold">Fullname</label>
                                    <input value="<?php echo e(old('fullname', $data->fullname ?? '')); ?>" type="text" class="form-control form-control-sm" name="fullname" placeholder="">
                                    <?php if($errors->has('fullname')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('fullname')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="email" class="font-weight-bold">Email</label>
                                    <input value="<?php echo e(old('email', $data->email ?? '')); ?>" type="text" class="form-control form-control-sm" name="email" placeholder="">
                                    <?php if($errors->has('email')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('email')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="telephone" class="font-weight-bold">Telephone</label>
                                    <input value="<?php echo e(old('telephone', $data->telephone ?? '')); ?>" type="text" class="form-control form-control-sm" name="telephone" placeholder="">
                                    <?php if($errors->has('telephone')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('telephone')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="role_id" class="font-weight-bold">Role</label>
                                    <select name="role_id" class="form-control form-control-sm" required>
                                        <option value="">-- Pilih Role --</option>
                                        <?php $__currentLoopData = $variables['roles']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $comb): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($comb->id); ?>" <?php echo e(old('role_id', $variables['currentRole'] ?? '') == $comb->id ? 'selected' : ''); ?>>
                                            <?php echo e($comb->name); ?>

                                        </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <?php if($errors->has('role_id')): ?>
                                    <span class="text-danger"><?php echo e($errors->first('role_id')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <?php if(empty($data->username)): ?>
                                <div class="form-group col-md-3">
                                    <label for="username" class="font-weight-bold">Username</label>
                                    <input value="<?php echo e(old('username', $data->username ?? '')); ?>" type="text" class="form-control form-control-sm" name="username" placeholder="">
                                    <?php if($errors->has('username')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('username')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="password" class="font-weight-bold">Password</label>
                                    <input
                                        type="password"
                                        class="form-control form-control-sm"
                                        name="password"
                                        placeholder=""
                                        value="<?php echo e($data->password ?? ''); ?>">
                                    <?php if($errors->has('password')): ?>
                                    <span class="text-danger text-left"><?php echo e($errors->first('password')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <?php endif; ?>
                                <div class="form-group col-md-3">
                                    <label for="status" class="font-weight-bold">Status <span class="text-danger">*</span></label>
                                    <select name="status" class="form-control form-control-sm" required>
                                        <option value="Active" <?php echo e(old('status', $data->status ?? 'Active') == 'Active' ? 'selected' : ''); ?>>Aktif</option>
                                        <option value="Inactive" <?php echo e(old('status', $data->status ?? '') == 'Inactive' ? 'selected' : ''); ?>>Nonaktif</option>
                                    </select>
                                    <?php if($errors->has('status')): ?>
                                    <span class="text-danger"><?php echo e($errors->first('status')); ?></span>
                                    <?php endif; ?>
                                </div>
                                <div class="col-sm-12">
                                    <div class="card card-outline card-info">
                                        <div class="card-header">
                                            <h3 class="card-title">Hak Akses Khusus</h3>
                                            <div class="card-tools">
                                                <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                                                    <i class="fas fa-minus"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="card-body">
                                            <div class="form-check">
                                                <input 
                                                    class="form-check-input" 
                                                    type="checkbox" 
                                                    name="flag_backdate_so" 
                                                    id="flag_backdate_so" 
                                                    value="1" 
                                                    <?php echo e(old('flag_backdate_so', $data->flag_backdate_so ?? false) ? 'checked' : ''); ?>>
                                                <label class="form-check-label font-weight-bold" for="flag_backdate_so">
                                                    <i class="fas fa-calendar-alt text-warning"></i> Izinkan Backdate Stock Opname
                                                </label>
                                                <small class="form-text text-muted">
                                                    User dengan akses ini dapat membuat Stock Opname dengan tanggal sebelum hari ini (backdate).
                                                </small>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12">
                                    <div class="card card-outline card-warning">
                                        <div class="card-header">
                                            <h3 class="card-title">Akses Cabang</h3>

                                            <div class="card-tools">
                                                <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                                                    <i class="fas fa-minus"></i>
                                                </button>
                                            </div>
                                        </div>
                                        <div class="card-body">
                                            <div class="form-group">
                                                <div class="mb-2">
                                                    <button type="button" class="btn btn-sm btn-success" id="selectAllStores">
                                                        <i class="fas fa-check-double"></i> Pilih Semua
                                                    </button>
                                                    <button type="button" class="btn btn-sm btn-secondary" id="deselectAllStores">
                                                        <i class="fas fa-times"></i> Hapus Semua
                                                    </button>
                                                    <small class="text-muted ml-2">
                                                        <span id="selectedStoresCount">0</span> dari <span id="totalStoresCount"><?php echo e(count($variables['stores'])); ?></span> toko dipilih
                                                    </small>
                                                </div>
                                                <small class="text-info d-block mb-2">
                                                    <i class="fas fa-info-circle"></i> 
                                                    <strong>Tips:</strong> Gunakan Ctrl+Click untuk pilih multiple, Shift+Click untuk pilih range
                                                </small>
                                                <select 
                                                    required 
                                                    name="user_stores[]" 
                                                    id="user_stores" 
                                                    class="form-control" 
                                                    multiple 
                                                    size="15"
                                                    style="height: 300px;">
                                                    <?php $__currentLoopData = $variables['stores']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $comb): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($comb->id); ?>" <?php echo e((is_array(old('user_stores', $variables['user_stores'] ?? [])) && in_array($comb->id, old('user_stores', $variables['user_stores'] ?? []))) ? 'selected' : ''); ?>>
                                                        <?php echo e($comb->code); ?> - <?php echo e($comb->name); ?>

                                                    </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </div>
                                        </div>
                                        <!-- /.card-body -->
                                    </div>
                                    <!-- /.card -->
                                </div>
                            </div>
                            <?php endif; ?>
                            <button type="submit" class="btn btn-outline-info btn-sm button-cek-permission" data-permission="users.store"><i class="fas fa-save"></i> Simpan</button>
                            <a href="<?php echo e($data->id ? route('users.show',$data->id) : route('users.index')); ?>" class="btn btn-outline-warning btn-sm" data='back' onclick="return notificationBeforeBack(event, this);"><i class="fas fa-arrow-left"></i> Kembali</a>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
/* Custom styling for native multi-select */
#user_stores {
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    padding: 0.375rem;
}

#user_stores option {
    padding: 8px 12px;
    border-radius: 3px;
    margin-bottom: 2px;
    cursor: pointer;
}

#user_stores option:hover {
    background-color: #e9ecef;
}

#user_stores option:checked {
    background: linear-gradient(#ffc107, #ffc107);
    color: #000;
    font-weight: 500;
}

/* Firefox specific */
@-moz-document url-prefix() {
    #user_stores option:checked {
        background-color: #ffc107 !important;
        color: #000 !important;
    }
}
</style>

<script>
$(document).ready(function() {
    // Update selected count on load
    updateSelectedCount();
    
    // Update count when selection changes
    $('#user_stores').on('change', function() {
        updateSelectedCount();
    });
    
    // Select All button
    $('#selectAllStores').on('click', function() {
        $('#user_stores option').prop('selected', true);
        updateSelectedCount();
    });
    
    // Deselect All button
    $('#deselectAllStores').on('click', function() {
        $('#user_stores option').prop('selected', false);
        updateSelectedCount();
    });
    
    // Function to update selected count
    function updateSelectedCount() {
        var selectedCount = $('#user_stores option:selected').length;
        $('#selectedStoresCount').text(selectedCount);
        
        // Update button states
        if (selectedCount === 0) {
            $('#deselectAllStores').prop('disabled', true);
        } else {
            $('#deselectAllStores').prop('disabled', false);
        }
        
        var totalCount = $('#user_stores option').length;
        if (selectedCount === totalCount) {
            $('#selectAllStores').prop('disabled', true);
        } else {
            $('#selectAllStores').prop('disabled', false);
        }
    }
});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts/base_view', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\LSM\resources\views/users/form.blade.php ENDPATH**/ ?>