<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

add_stylesheet('<link rel="stylesheet" href="'.$skin_url.'/assets/css/bootstrap.min.css">',0);
add_stylesheet('<link rel="stylesheet" href="'.G5_JS_URL.'/font-awesome/css/font-awesome.min.css">',0);
add_stylesheet('<link rel="stylesheet" href="'.$skin_url.'/partner-darkmode.css">',0);

?>
<style>
	.partner-register-wrapper {
		padding: 40px 0;
		background: transparent;
	}
	.partner-register-container {
		max-width: 750px;
		margin: 0 auto;
		background: #fff;
		border-radius: 6px;
		overflow: hidden;
		box-shadow: 0 2px 15px rgba(0,0,0,0.06);
	}
	.partner-register-header {
		background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
		padding: 20px 15px;
		text-align: center;
	}
	.partner-register-header h3 {
		color: #fff;
		margin: 0;
		font-size: 20px;
		font-weight: 300;
		letter-spacing: 0.5px;
	}
	.partner-register-body {
		padding: 25px;
	}
	.partner-register-body .form-group {
		margin-bottom: 15px;
		clear: both;
	}
	.partner-register-body label {
		display: block;
		margin-bottom: 5px;
		font-weight: 600;
		color: #333;
		font-size: 13px;
	}
	.partner-register-body .form-control {
		height: 36px;
		border-radius: 4px;
		border: 1px solid #ddd;
		padding: 6px 10px;
		font-size: 13px;
		transition: all 0.3s;
		width: 100%;
		box-sizing: border-box;
	}
	.partner-register-body .form-control:focus {
		border-color: #667eea;
		box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.15);
		outline: 0;
	}
	.partner-register-body textarea.form-control {
		height: auto;
		resize: vertical;
	}
	.partner-register-body .has-feedback {
		position: relative;
	}
	.partner-register-body .has-feedback .form-control {
		padding-right: 35px;
	}
	.partner-register-body .form-control-feedback {
		position: absolute;
		top: 25px;
		right: 10px;
		width: 36px;
		height: 36px;
		line-height: 36px;
		text-align: center;
		pointer-events: none;
		color: #999;
		font-size: 14px;
	}
	.partner-register-body .input-group {
		display: flex !important;
		width: 100% !important;
		margin-bottom: 0 !important;
	}
	.partner-register-body .input-group select.form-control {
		flex: 0 0 45% !important;
		max-width: 300px !important;
		border-radius: 4px !important;
		margin-right: 15px !important;
	}
	.partner-register-body .input-group input.form-control {
		flex: 1 !important;
		border-radius: 4px !important;
	}
	.partner-register-body .checkbox-inline,
	.partner-register-body .text-center label {
		font-weight: 400;
		font-size: 13px;
	}
	.partner-register-body .btn-primary {
		width: 100%;
		max-width: 300px;
		height: 45px;
		background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
		border: none;
		font-size: 16px;
		font-weight: 500;
		border-radius: 4px;
		transition: all 0.3s;
		text-transform: uppercase;
		letter-spacing: 1px;
		display: block;
		margin: 0 auto;
	}
	.partner-register-body .btn-primary:hover {
		transform: translateY(-2px);
		box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
	}
	.partner-register-body select.form-control {
		appearance: none;
		-webkit-appearance: none;
		-moz-appearance: none;
		background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23999%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
		background-repeat: no-repeat;
		background-position: right 12px top 50%;
		background-size: 12px auto;
		padding-right: 35px;
	}
	.partner-register-body .row {
		margin-left: -10px;
		margin-right: -10px;
		display: flex;
		flex-wrap: wrap;
		margin-bottom: 10px;
	}
	.partner-register-body .row > [class*="col-"] {
		padding-left: 10px;
		padding-right: 10px;
		box-sizing: border-box;
		margin-bottom: 10px;
	}
	.partner-register-body .col-sm-6 {
		width: 50%;
		float: none;
	}
	.partner-register-body .agreement-section {
		text-align: center;
		width: 100%;
		margin: 25px 0 20px 0;
		clear: both;
	}
	.partner-register-body .agreement-section label {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		cursor: pointer;
		font-weight: 400;
		font-size: 13px;
		margin: 0;
	}
	.partner-register-body .agreement-section input[type="checkbox"] {
		margin-right: 6px;
		width: 14px;
		height: 14px;
		cursor: pointer;
	}
	/* Role Selection Styles */
	.role-selection-group {
		display: flex;
		flex-wrap: wrap;
		gap: 10px;
		margin-bottom: 15px;
		justify-content: center;
	}
	.role-option {
		background: #f8f9fa;
		border: 1px solid #eee;
		border-radius: 6px;
		padding: 10px;
		flex: 1;
		min-width: 220px;
		box-sizing: border-box;
		text-align: center;
		transition: all 0.2s;
	}
	.role-option:hover {
		border-color: #667eea;
		background: #f0f4ff;
	}
	.role-option label {
		display: inline-flex !important;
		align-items: center;
		justify-content: center;
		margin-bottom: 6px !important;
		cursor: pointer;
		font-size: 14px !important;
	}
	.role-option input[type="checkbox"] {
		width: 14px;
		height: 14px;
		margin: 0 6px 0 0 !important;
		cursor: pointer;
		position: relative;
		top: 0;
	}
	.role-desc {
		font-size: 11px;
		color: #555;
		margin: 0;
		line-height: 1.3;
		word-break: keep-all;
	}
	.stipulation-toggle-btn {
		background: none;
		border: 1px solid #ddd;
		padding: 2px 8px;
		font-size: 12px;
		border-radius: 3px;
		margin-left: 10px;
		color: #666;
	}
	.partner-register-body .submit-section {
		text-align: center;
		width: 100%;
		margin: 20px 0;
		clear: both;
	}
	@media (max-width: 768px) {
		.partner-register-body .col-sm-6 {
			width: 100%;
		}
	}
	.sound_only {
		position: absolute;
		left: -9999px;
		width: 0;
		height: 0;
		overflow: hidden;
	}
</style>
<div class="partner-register-wrapper">
	<div class="partner-register-container">
		<div class="partner-register-header">
			<h3>판매자센터 가입 신청</h3>
		</div>
		<form class="form" role="form" name="fregister" id="fregister" action="<?php echo $action_url ?>" onsubmit="return fregister_submit(this);" method="POST" enctype="multipart/form-data" autocomplete="off">
		<div class="partner-register-body">
			<div class="form-group">
				<label>
					판매자센터 가입약관
					<button type="button" class="stipulation-toggle-btn" id="btn_stipulation_toggle" onclick="toggleStipulation()">약관 내용 보기 <i class="fa fa-chevron-down"></i></button>
				</label>
				<div id="stipulation_box" style="display:none; margin-top:10px;">
					<textarea class="form-control" rows="8" readonly><?php echo $partner_stipulation; ?></textarea>
				</div>
			</div>
            <script>
            function toggleStipulation() {
                var btn = document.getElementById('btn_stipulation_toggle');
                if(typeof jQuery !== 'undefined') {
                    jQuery('#stipulation_box').slideToggle(function(){
                        if(jQuery(this).is(':visible')) {
                            btn.innerHTML = '약관 내용 닫기 <i class="fa fa-chevron-up"></i>';
                        } else {
                            btn.innerHTML = '약관 내용 보기 <i class="fa fa-chevron-down"></i>';
                        }
                    });
                } else {
                    var el = document.getElementById('stipulation_box');
                    el.style.display = (el.style.display == 'none') ? 'block' : 'none';
                    if(el.style.display == 'block') {
                        btn.innerHTML = '약관 내용 닫기 <i class="fa fa-chevron-up"></i>';
                    } else {
                         btn.innerHTML = '약관 내용 보기 <i class="fa fa-chevron-down"></i>';
                    }
                }
            }
            </script>

				<?php if($is_seller && $is_marketer) { ?>
					<div class="role-selection-group">
						<div class="role-option">
							<label>
								<input type="checkbox" name="pt_partner" value="1"> 판매자(셀러) 신청
							</label>
							<p class="role-desc">
								직접 보유한 상품이나 서비스를 등록하고 판매하여 수익을 창출합니다.<br>판매 관리와 정산 시스템을 제공받습니다.
							</p>
						</div>
						<div class="role-option">
							<label>
								<input type="checkbox" name="pt_marketer" value="1"> 추천인(마케터) 신청
							</label>
							<p class="role-desc">
								등록된 상품을 홍보하고 추천하여 판매 발생 시 수수료 수익을 얻습니다.<br>전용 홍보 링크와 통계를 제공받습니다.
							</p>
						</div>
					</div>
			<?php } else if($is_seller) { ?>
				<input type="hidden" name="pt_partner" value="1">
				<input type="hidden" name="pt_marketer" value="0">
			<?php } else if($is_marketer) { ?>
				<input type="hidden" name="pt_partner" value="0">
				<input type="hidden" name="pt_marketer" value="1">
			<?php } ?>

			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label for="pt_type"><b>판매자센터 유형</b><strong class="sound_only"> 필수</strong></label>
						<select name="pt_type" id="pt_type" required class="form-control">
							<option value="">판매자센터 유형을 선택해 주세요.</option>
							<?php if($is_company) { ?>
								<option value="1">기업 판매자센터</option>
							<?php } ?>
							<?php if($is_personal) { ?>
								<option value="2">개인 판매자센터</option>
							<?php } ?>
						</select>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group has-feedback">
						<label for="pt_name"><b>담당자 이름</b><strong class="sound_only"> 필수</strong></label>
						<input type="text" name="pt_name" id="pt_name" value="<?php echo get_text($member['mb_name']); ?>" class="form-control" required placeholder="실명입력">
						<span class="fa fa-user form-control-feedback"></span>
					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label for="pt_hp"><b>담당자 연락처</b><strong class="sound_only"> 필수</strong></label>
						<div class="input-group" >
							<select name="pt_hp_nation" id="pt_hp_nation" class="form-control" >
								<option value="">- 국가 선택 -</option>
								<?php
								global $countries, $country_local_names;
								foreach ($countries as $country => $code) {
									$selected = strtolower($member['mb_hp_nation']) == strtolower($country) ? ' selected' : '';
									$display_name = $country;
									if (isset($country_local_names[$country])) {
										$display_name = $country . ' (' . $country_local_names[$country] . ')';
									}
									echo "<option value=\"$country\"$selected>$display_name ($code)</option>";
								}
								?>
							</select>
							<input type="text" name="pt_hp" id="pt_hp" value="<?php echo get_text($member['mb_hp']); ?>" class="form-control" required placeholder="휴대폰 번호입력" >
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group has-feedback">
						<label for="pt_email"><b>담당자 이메일</b><strong class="sound_only"> 필수</strong></label>
						<input type="text" name="pt_email" id="pt_email" value="<?php echo get_text($member['mb_email']); ?>" class="form-control" required placeholder="이메일 주소입력">
						<span class="fa fa-envelope form-control-feedback"></span>
					</div>
				</div>
			</div>

			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label for="pt_sns_id"><b>메신저</b><strong class="sound_only"> 필수</strong></label>
						<div class="input-group">
							<select name="pt_sns_name" id="pt_sns_name" class="form-control" >
								<option value="">- 메신저 선택 -</option>
								<?php
								foreach ($snslist as $key => $val) {
									$selected = strtolower($member['mb_sns_name']) == strtolower($key) ? ' selected' : '';
									echo "<option value=\"$key\"$selected>$val</option>";
								}
								?>
							</select>
							<input type="text" name="pt_sns_id" id="pt_sns_id" placeholder="메신저ID 입력" oninput="this.value=this.value.replace(/\s/g, '');" value="<?php echo get_text($member['mb_sns_id']); ?>" class="form-control" >
					</div>
				</div>
			</div>
		</div>





				<?php
				/*
				<div class="well well-sm" >
					사업자등록증(기업) 또는 신분증(개인) 사본과 입금 통장사본을 스캔하여 반드시 첨부해 주셔야 포인트 출금신청을 할 수 있습니다.
				</div>

				<div class="row">
					<div class="col-sm-6">
						<div class="form-group">
							<label><b>서류사본</b><strong class="sound_only">필수</strong></label>
							<input type="file" name="pf_file[]" class="form-control input-sm" required title="사업자등록증 또는 신분증 사본 : 용량 <?php echo $upload_max_filesize; ?> 이하만 업로드 가능">
						</div>
					</div>
					<div class="col-sm-6">
						<div class="form-group">
							<label><b>통장사본</b><strong class="sound_only">필수</strong></label>
							<input type="file" name="pf_file[]" class="form-control input-sm" required title="입금 통장사본 : 용량 <?php echo $upload_max_filesize; ?> 이하만 업로드 가능">
						</div>
					</div>
				</div>
				*/
				?>

			<div class="agreement-section">
				<label>
					<input type="checkbox" name="agree" value="1" id="agree11">
					<span>판매자센터가입약관과 상기 정보제공에 동의합니다.</span>
				</label>
			</div>

		<div class="submit-section">
				<button type="submit" class="btn btn-primary">판매자센터 신청하기</button>
			</div>
		</div>
		</form>
	</div>
</div>

<script>
    function fregister_submit(f) {
		<?php if($is_seller && $is_marketer) { ?>
        if (!f.pt_partner.checked && !f.pt_marketer.checked) {
            alert("가입하실 판매자(셀러) 또는 추천인(마케터) 항목을 체크 하십시오.");
            f.pt_partner.focus();
            return false;
        }
		<?php } ?>
		if (!f.agree.checked) {
            alert("판매자센터가입약관과 정보제공에 동의하셔야 가입하실 수 있습니다.");
            f.agree.focus();
            return false;
        }
		<?php if($use_company && $use_personal) { ?>
			var type = false;
			for(var i=0;i<f.pt_type.length;i++) {
				if(f.pt_type[i].checked == true) {
					type = true;
					break;
				}
			}
			if (!type) {
	            alert("등록할 판매자센터 유형을 선택해 주세요.");
				return false;
		    }
		<?php } ?>

		//이메일
		var regex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if(regex.test(f.pt_email.value) === false) {
			alert("잘못된 이메일 형식입니다.");
            f.pt_email.focus();
			return false;
		}

		if (confirm("판매자센터 등록을 신청하시겠습니까?")) {
			f.action = "<?php echo $action_url;?>";
			return true;
		}

		return false;
    }
</script>

<!-- JavaScript -->
<script type="text/javascript" src="<?php echo $skin_url;?>/assets/js/bootstrap.min.js"></script>

<!-- Custom Toast -->
<div id="custom-toast"></div>
<style>
#custom-toast {
    visibility: hidden;
    min-width: 320px;
    background-color: rgba(50, 50, 50, 0.95);
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 20px;
    position: fixed;
    z-index: 10000;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    line-height: 1.5;
    box-shadow: 0 4px 25px rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.5s;
}

#custom-toast.show {
    visibility: visible;
    opacity: 1;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
    function getQueryParam(name) {
        var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
        return results ? decodeURIComponent(results[1]) || 0 : null;
    }

    var msg = getQueryParam('msg');
    if (msg === 'unregistered_partner') {
        var x = document.getElementById("custom-toast");
        x.innerHTML = "등록된 판매자센터만 이용할 수 있습니다.<br><span style='font-size:0.9em; opacity:0.9;'>서비스 이용을 위해 먼저 판매자센터 가입 신청을 해주세요.</span>";
        x.className = "show";
        setTimeout(function(){ x.className = x.className.replace("show", ""); }, 6000);

        // Remove query param
        if (history.pushState) {
            var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname;
            window.history.pushState({path:newurl},'',newurl);
        }
    }
});
</script>