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

    <div class="container" style="max-width:1100px; margin-top:24px;">
        <div class="card shadow-sm">
            <div class="card-header d-flex justify-content-between">
                <strong>결제(결재) 권자 설정</strong>
                <button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#ruleModal">규칙 추가</button>
            </div>
            <div class="card-body">
                <table class="table table-hover">
                    <thead class="table-light">
                    <tr><th>규칙명</th><th>금액 구간</th><th>구성원</th><th style="width:140px;">관리</th></tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>일반 결재</td>
                        <td>0 ~ 1,000만원</td>
                        <td><span class="badge bg-secondary">개발팀</span> <span class="badge bg-info text-dark">일반관리자</span> <span class="badge bg-dark">kevin</span></td>
                        <td><button class="btn btn-sm btn-outline-secondary">편집</button> <button class="btn btn-sm btn-outline-danger">삭제</button></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- 규칙 추가 모달 -->
    <div class="modal fade" id="ruleModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-lg"><div class="modal-content">
                <div class="modal-header"><h5 class="modal-title">결제 규칙 추가</h5><button class="btn-close" data-bs-dismiss="modal"></button></div>
                <div class="modal-body">
                    <div class="row g-3">
                        <div class="col-md-6"><label class="form-label">규칙명</label><input class="form-control" id="ruleName"></div>
                        <div class="col-md-3"><label class="form-label">최소금액</label><input class="form-control" id="minAmt" placeholder="원"></div>
                        <div class="col-md-3"><label class="form-label">최대금액</label><input class="form-control" id="maxAmt" placeholder="원"></div>
                        <div class="col-12">
                            <label class="form-label">구성원 추가</label>
                            <div class="d-flex gap-2">
                                <select class="form-select" id="memberType" style="max-width:160px;">
                                    <option value="department">부서</option>
                                    <option value="role">역할</option>
                                    <option value="user">개인</option>
                                </select>
                                <input class="form-control" id="memberKeyword" placeholder="이름/코드 검색">
                                <button class="btn btn-outline-secondary" id="btnFindMember">검색</button>
                                <button class="btn btn-outline-primary" id="btnAddMember">추가</button>
                            </div>
                            <div class="mt-2" id="memberChips"></div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
                    <button class="btn btn-primary" id="btnSaveRule">저장</button>
                </div>
            </div></div>
    </div>

    <script>
        $(function(){
            $('#btnSaveRule').on('click', ()=>{ alert('저장(샘플) — /api/permission/approval_rule_save.php'); $('#ruleModal').modal('hide'); });
            $('#btnAddMember').on('click', ()=>{
                const type = $('#memberType').val();
                const kw = $('#memberKeyword').val().trim() || (type==='department'?'개발팀': type==='role'?'일반관리자':'kevin');
                $('#memberChips').append(`<span class="badge bg-secondary me-1">${type}:${kw}</span>`);
            });
        });
    </script>

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