<?php
$CURRENT_SECTION = 'tenant';
include '../inc/header.php'; ?>

// 샘플 데이터
$roles = [
    1 => ['id'=>1, 'name'=>'최고관리자', 'desc'=>'회사 전체 관리권한'],
    2 => ['id'=>2, 'name'=>'일반관리자', 'desc'=>'부서/사용자/업무 관리'],
    3 => ['id'=>3, 'name'=>'일반직원', 'desc'=>'일반 사용 권한'],
];

$role_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$role = isset($roles[$role_id]) ? $roles[$role_id] : null;

if (!$role) {
    echo '<div class="alert alert-danger mt-4 text-center">해당 역할을 찾을 수 없습니다.</div>';
    include '../inc/footer.php';
    exit;
}
?>

    <div class="container" style="max-width:500px; margin-top:40px;">
        <div class="card shadow p-4">
            <h4 class="mb-3 text-center">역할 정보 수정</h4>
            <form id="roleEditForm" method="post" action="/tenant/tenant/role_edit_process.php" autocomplete="off">
                <input type="hidden" name="role_id" value="<?= htmlspecialchars($role['id']) ?>">
                <div class="mb-3">
                    <label class="form-label">역할명 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" name="role_name" maxlength="30" value="<?= htmlspecialchars($role['name']) ?>" required>
                </div>
                <div class="mb-3">
                    <label class="form-label">설명</label>
                    <input type="text" class="form-control" name="role_desc" maxlength="100" value="<?= htmlspecialchars($role['desc']) ?>">
                </div>
                <div class="d-flex gap-2">
                    <button type="submit" class="btn btn-primary w-50">수정</button>
                    <a href="/tenant/tenant/role_list.php" class="btn btn-secondary w-50">취소</a>
                </div>
            </form>
        </div>
    </div>

    <script>
        $(function(){
            $('#roleEditForm').on('submit', function(e){
                var name = $('[name="role_name"]').val().trim();
                if (name.length < 2) {
                    alert('역할명을 2글자 이상 입력하세요.');
                    $('[name="role_name"]').focus();
                    e.preventDefault(); return false;
                }
            });
        });
    </script>

<?php include '../inc/footer.php'; ?>
