<?php 
$title = __('users.create', 'Create User');
ob_start(); 
?>

<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="fas fa-plus"></i> <?= __('users.create_new', 'Create New User') ?>
                </h5>
            </div>
            <div class="card-body">
                <form method="POST" action="/samanta_crm/users" id="createUserForm">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="name" class="form-label"><?= __('common.name', 'Name') ?> *</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="email" class="form-label"><?= __('common.email', 'Email') ?> *</label>
                                <input type="email" class="form-control" id="email" name="email" required>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="password" class="form-label"><?= __('common.password', 'Password') ?> *</label>
                                <input type="password" class="form-control" id="password" name="password" required minlength="6">
                                <div class="form-text"><?= __('users.password_min', 'Minimum 6 characters') ?></div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="confirm_password" class="form-label"><?= __('common.confirm_password', 'Confirm Password') ?> *</label>
                                <input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="role" class="form-label"><?= __('users.role', 'Role') ?></label>
                                <select class="form-select" id="role" name="role">
                                    <option value="user"><?= __('users.role_user', 'User') ?></option>
                                    <option value="admin"><?= __('users.role_admin', 'Administrator') ?></option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="user_type_id" class="form-label"><?= __('common.type', 'Type') ?></label>
                                <select class="form-select" id="user_type_id" name="user_type_id">
                                    <option value=""><?= __('users.select_type', 'Select User Type (Optional)') ?></option>
                                    <?php foreach ($userTypes as $userType): ?>
                                    <option value="<?= $userType['id'] ?>" style="color: <?= htmlspecialchars($userType['color']) ?>;">
                                        <?= htmlspecialchars($userType['name']) ?>
                                    </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                        </div>
                    </div>
                    
                    <div class="d-flex justify-content-between">
                        <a href="/samanta_crm/users" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> <?= __('common.back', 'Back') ?>
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> <?= __('users.create_btn', 'Create') ?> <?= __('users.user', 'User') ?>
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php 
$content = ob_get_clean();
$scripts = '
<script>
document.getElementById("createUserForm").addEventListener("submit", function(e) {
    const password = document.getElementById("password").value;
    const confirmPassword = document.getElementById("confirm_password").value;
    
    if (password !== confirmPassword) {
        e.preventDefault();
        alert("' . __('users.password_mismatch', 'Passwords do not match!') . '");
        return false;
    }
});
</script>
';
include '../app/Views/layout.php'; 
?>


