<?php
global $wp_query;
// Current author

$user_id = get_current_user_id();
$user_info = get_userdata($user_id);

$des = !empty($user_info->description) ? $user_info->description : 'TA很懒，什么也没写';
$web = !empty($user_info->user_url) ? $user_info->user_url : '请输入你的网址';
$qq = !empty($user_info->user_qq) ? $user_info->user_qq : '请输入QQ，以方便联系';
$location = !empty($user_info->user_location) ? $user_info->user_location : '未知地带';
$gender = isset($user_info->user_gender) ? $user_info->user_gender : '保密';
$email = !empty($user_info->user_email) ? $user_info->user_email : '暂未绑定';
$phone = !empty($user_info->user_phone) ? encryptTel($user_info->user_phone) : '暂未绑定';

$em_check = check_email_bind($user_id);
$ph_check = get_user_meta($user_id,'user_phone',true);

if($gender == 0){
    $gender_name = '男';
} else if($gender == 1){
    $gender_name = '女';
} else {
    $gender_name = '保密';
}

$has_custom_password = ppo_user_has_custom_password($user_id);

$tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'profile';

?>

<div class="user-edit-page">

<ul class="user-page-tab">
    <li><a href="?tab=profile" class="user-tab-item <?php echo $tab === 'profile' ? 'active' : ''; ?>">个人资料</a></li>
    <li><a href="?tab=security" class="user-tab-item <?php echo $tab === 'security' ? 'active' : ''; ?>">安全设置</a></li>
</ul>

<div class="user-page-body user-edit-body">

<?php if($tab === 'profile' || $tab === '') : ?>
<div class="edit-tab-item">
    <div class="edit-body-inner uk-grid-medium" uk-grid>
        <div class="left uk-width-3-5">

            <div class="eidt-box edit-top">
                <div class="left">
                    <div class="uid_show"><span>UID</span><small><?php echo $user_id; ?></small></div>
                    <div class="regdate_show">
                        <div><span>注册时间：</span><small><?php echo user_show_registered_date($user_id); ?></small></div>
                        <div><span>上次登录：</span><small><?php get_last_login($user_id); ?></small></div>
                    </div>
                </div>
            </div>

            <div class="eidt-box">
                <div class="left">
                    <div class="edit-title"><i class="ri-user-5-line"></i>昵称</div>
                    <div class="edit-info"><?php echo @$user_info->display_name;?></div>
                </div>
                <a class="edit_btn user-info-edit" action="display_name">编辑</a>
            </div>

            <div class="eidt-box">
                <div class="left">
                    <div class="edit-title"><i class="ri-profile-line"></i>个人简介</div>
                    <div class="edit-info"><?php echo $des; ?></div>
                </div>
                <a class="edit_btn user-info-edit" action="description">编辑</a>
            </div>

            <div class="eidt-box">
                <div class="left">
                    <div class="edit-title"><i class="ri-user-smile-line"></i>性别</div>
                    <div class="edit-info"><?php echo $gender_name; ?></div>
                </div>
                <a class="edit_btn user-info-edit" action="user_gender" gender="<?php echo $gender ?>">编辑</a>
            </div>

            <div class="eidt-box">
                <div class="left">
                    <div class="edit-title"><i class="ri-window-line"></i>个人网址</div>
                    <div class="edit-info"><?php echo $web; ?></div>
                </div>
                <a class="edit_btn user-info-edit" action="user_url">编辑</a>
            </div>

            <div class="eidt-box">
                <div class="left">
                    <div class="edit-title"><i class="ri-qq-line"></i>QQ号码</div>
                    <div class="edit-info"><?php echo $qq ; ?></div>
                </div>
                <a class="edit_btn user-info-edit" action="user_qq">编辑</a>
            </div>

            <div class="eidt-box">
                <div class="left">
                    <div class="edit-title"><i class="ri-map-pin-user-line"></i>居住地址</div>
                    <div class="edit-info"><?php echo $location ; ?></div>
                </div>
                <a class="edit_btn user-info-edit" action="user_location">编辑</a>
            </div>

            <div id="user-edit-modal" uk-modal="bg-close:false">
                <div class="uk-modal-dialog uk-modal-body user-edit-modal uk-margin-auto-vertical uk-animation-scale-up uk-animation-fast">
                    <div class="edit-modal-title"></div>
                    
                    <div class="edit-form-box"></div>
                    <div class="user-edit-tool">
                        <button class="uk-modal-close" type="button">取消</button>
                        <button class="user-edit-sure" type="button" uid="<?php echo $user_id ?>">确定</button>
                    </div>
                </div>
            </div>

        </div>

        <div class="right uk-width-2-5">
            <div class="yinsi-edit">
                <h4><i class="ri-chat-private-line"></i>隐私设置</h4>
            </div>
        </div>
    </div>
    </div>
    <?php endif; ?>

    <?php if($tab === 'security') : ?>
    <div class="edit-tab-item">
        <div class="safe-edit-wrap">
        <h4 class="safe-title"><i class="ri-shield-user-line"></i>账户安全</h4>
        <div class="safe-edit-body">

            <div class="safe-eidt-box">
                    <div class="left">
                        <div class="edit-title"><i class="ri-lock-password-line safe-pass"></i>账户密码</div>
                        <div class="edit-info"><?php if($has_custom_password) echo '建议每隔一段时间修改一次密码'; else echo '请设置自定义密码' ?></div>
                    </div>
                    <a class="edit_btn user-pass-edit" action="user_pass"><?php if($has_custom_password) echo '修改'; else echo '设置' ?></a>
                </div>

            <div class="safe-eidt-box">
                    <div class="left">
                        <div class="edit-title"><i class="ri-mail-line safe-email"></i><?php echo $em_check ? '修改邮箱' : '绑定邮箱'; ?></div>
                        <div class="edit-info"><?php echo $email ?></div>
                    </div>
                    <a class="edit_btn user-safe-edit" action="user_email" type="<?php echo $em_check ?>"><?php if($em_check) echo '修改'; else echo '绑定' ?></a>
                </div>   
                
            <div class="safe-eidt-box">
                    <div class="left">
                        <div class="edit-title"><i class="ri-smartphone-line safe-phone"></i><?php echo $ph_check ? '修改手机' : '绑定手机'; ?></div>
                        <div class="edit-info"><?php echo $phone ?></div>
                    </div>
                    <a class="edit_btn user-safe-edit" action="user_phone"><?php if($ph_check) echo '修改'; else echo '绑定' ?></a>
                </div>     

        </div>  
        </div>

        <div class="safe-edit-wrap">
            <h4 class="safe-title"><i class="ri-parent-line"></i>社交账户绑定</h4>
            <div class="safe-edit-body">
                <?php echo  oauth_bind_list($user_id); ?>
            </div>
        </div>
        
        <div id="user-safe-modal" uk-modal="bg-close:false">
                <div class="uk-modal-dialog uk-modal-body user-safe-modal uk-margin-auto-vertical uk-animation-scale-up uk-animation-fast">
                    <div class="safe-modal-title"></div>
                    
                    <div class="safe-form-box"></div>
                    <div class="user-edit-tool">
                        <button class="uk-modal-close" type="button">取消</button>
                        <button class="user-safe-sure" type="button" uid="<?php echo $user_id ?>">确定</button>
                    </div>
                </div>
            </div>

        <div id="user-repass-modal" uk-modal="bg-close:false">
            <div class="uk-modal-dialog uk-modal-body user-repass-modal uk-margin-auto-vertical uk-animation-scale-up uk-animation-fast">
                <div class="safe-modal-title"></div>

                <div class="safe-form-box"></div>
                <div class="user-edit-tool">
                    <button class="uk-modal-close" type="button">取消</button>
                    <button class="user-pass-sure" type="button" uid="<?php echo $user_id ?>">确定</button>
                </div>
            </div>
        </div>

    </div>
    <?php endif; ?>

</div>
