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

    <div class="container" style="max-width:600px; margin-top:40px; margin-bottom:40px;">
        <div class="card shadow p-4">
            <form id="tenantJoinForm" method="post" action="/tenant/tenant/join_process.php" enctype="multipart/form-data" autocomplete="off">
                <h3 class="mb-4 text-center">회사(테넌트) 가입</h3>

                <div class="mb-3">
                    <label class="form-label">회사/조직명 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" name="company_name" maxlength="100" required>
                </div>
                <div class="mb-3">
                    <label class="form-label">회사 코드 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" name="code" maxlength="50" required placeholder="영문/숫자, 고유식별코드">
                </div>
                <div class="mb-3">
                    <label class="form-label">대표 이메일</label>
                    <input type="email" class="form-control" name="email" maxlength="80">
                </div>
                <div class="mb-3">
                    <label class="form-label">대표 전화번호</label>
                    <input type="text" class="form-control" name="phone" maxlength="20">
                </div>
                <div class="mb-3">
                    <label class="form-label">주소</label>
                    <input type="text" class="form-control" name="address" maxlength="255">
                </div>
                <div class="mb-3">
                    <label class="form-label">사업자등록번호</label>
                    <input type="text" class="form-control" name="business_num" maxlength="12" placeholder="10자리(숫자만)">
                </div>
                <div class="mb-3">
                    <label class="form-label">법인등록번호</label>
                    <input type="text" class="form-control" name="corp_reg_no" maxlength="13">
                </div>
                <div class="mb-3">
                    <label class="form-label">대표자명</label>
                    <input type="text" class="form-control" name="ceo_name" maxlength="50">
                </div>
                <div class="mb-3">
                    <label class="form-label">홈페이지 주소</label>
                    <input type="url" class="form-control" name="homepage" maxlength="255" placeholder="https://">
                </div>
                <div class="mb-3">
                    <label class="form-label">팩스번호</label>
                    <input type="text" class="form-control" name="fax" maxlength="30">
                </div>
                <div class="mb-3">
                    <label class="form-label">회사 로고</label>
                    <input type="file" class="form-control" name="logo" accept="image/*">
                </div>
                <div class="mb-3">
                    <label class="form-label">관리자 메모</label>
                    <textarea class="form-control" name="admin_memo" maxlength="500" rows="2"></textarea>
                </div>
                <div class="mb-3">
                    <label class="form-label">최대 사용자 수</label>
                    <input type="number" class="form-control" name="max_users" min="1" max="999" value="10">
                </div>
                <button type="submit" class="btn btn-primary w-100 mt-2">가입하기</button>
            </form>
        </div>
    </div>

    <script>
        $(function(){
            $('#tenantJoinForm').on('submit', function(e){
                var code = $('[name="code"]').val().trim();
                if (!/^[a-zA-Z0-9_-]+$/.test(code)) {
                    alert('회사 코드는 영문, 숫자, -, _만 사용할 수 있습니다.');
                    $('[name="code"]').focus();
                    e.preventDefault(); return false;
                }
                var biz = $('[name="business_num"]').val();
                if (biz && !/^\d{10}$/.test(biz)) {
                    alert('사업자등록번호는 10자리 숫자만 입력하세요.');
                    $('[name="business_num"]').focus();
                    e.preventDefault(); return false;
                }
                // 기타 밸리데이션 추가 가능
            });
        });
    </script>

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