<?php $this->load->helper('az_config'); ?>
<!DOCTYPE html>
<html>
<head>
<title>Atur User Device</title>
<link rel="stylesheet" href="<?php echo base_url();?>assets/plugins/bootstrap/bootstrap.min.css">
<style>
body { padding: 20px; background: #f5f5f5; }
.container { max-width: 640px; margin: 0 auto; background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
h2 { color: #333; border-bottom: 2px solid #2196F3; padding-bottom: 10px; }
.devinfo { background: #eaf2fa; border-radius: 6px; padding: 10px 12px; margin-bottom: 15px; }
.err { color: #a94442; margin-bottom: 10px; }
</style>
</head>
<body>
<div class="container">
    <h2><i class="fa fa-users"></i> Atur User yang Boleh Login Otomatis</h2>

    <?php if ($this->session->flashdata('error')): ?>
        <div class="err"><?php echo $this->session->flashdata('error'); ?></div>
    <?php endif; ?>

    <div class="devinfo">
        <b>Device:</b> <?php echo htmlspecialchars($device->device_name); ?> &nbsp;|&nbsp;
        <b>Tipe:</b> <?php echo htmlspecialchars($device->device_type); ?> &nbsp;|&nbsp;
        <b>Outlet:</b> <?php echo htmlspecialchars($outlet_name); ?>
    </div>

    <form method="POST" action="<?php echo base_url();?>login_device/edit_users/<?php echo (int)$device->iddevice; ?>">
        <input type="hidden" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
        <div style="max-height:320px;overflow:auto;border:1px solid #ddd;border-radius:6px;padding:8px;margin-bottom:12px;">
            <?php foreach ($users as $u):
                $chk = in_array($u->iduser, $selected) ? 'checked' : ''; ?>
                <div style="padding:3px 0;">
                    <label style="font-weight:normal;">
                        <input type="checkbox" name="iduser[]" value="<?php echo (int)$u->iduser; ?>" <?php echo $chk; ?>>
                        <b><?php echo htmlspecialchars($u->name); ?></b> (<?php echo htmlspecialchars($u->username); ?>)
                        &mdash; <?php echo htmlspecialchars($u->role_name); ?> &mdash; <?php echo htmlspecialchars($u->outlet_name); ?>
                    </label>
                </div>
            <?php endforeach; ?>
        </div>
        <small class="text-muted">Centang user yang diizinkan login otomatis di device ini. Minimal 1. (Token device tidak berubah, jadi perangkat outlet tidak perlu aktivasi ulang.)</small>
        <hr>
        <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Simpan</button>
        <a href="<?php echo base_url();?>login_device/list_devices" class="btn btn-default">Batal</a>
    </form>
</div>
</body>
</html>