<template>
    <view class="container">
        <!-- 自定义头部 -->
        <view class="custom-header">
            <view class="header-left" @click="navBack">
                <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
            </view>
            <text class="header-title">修改真实姓名</text>
            <view class="header-right" @click="saveName">
                <text class="save-btn">保存</text>
            </view>
        </view>
        <view class="header-placeholder"></view>

        <view class="input-card">
            <input class="name-input" type="text" v-model="name" placeholder="请输入真实姓名" />
            <view class="clear-icon" v-if="name.length > 0" @click="clearName">
                <text class="clear-text">×</text>
            </view>
        </view>
        <text class="input-tip">请确保填写真实有效的信息，方便管理员审核。</text>
    </view>
</template>

<script>
export default {
    data() {
        return {
            name: '张*哥'
        }
    },
    onLoad(option) {
        if(option.name) {
            this.name = option.name;
        }
    },
    methods: {
        navBack() {
             uni.navigateBack({
                delta: 1
            });
        },
        clearName() {
            this.name = '';
        },
        saveName() {
            if(!this.name.trim()) {
                uni.showToast({ title: '姓名不能为空', icon: 'none' });
                return;
            }
            // 模拟保存并通知上一个页面更新
            uni.$emit('updateName', this.name);
            uni.navigateBack();
        }
    }
}
</script>

<style>
page {
    background-color: #F8F8F8;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
.custom-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 88rpx;
    padding-top: var(--status-bar-height);
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 30rpx;
    padding-right: 30rpx;
    box-sizing: border-box;
    z-index: 100;
}
.header-placeholder {
    height: calc(88rpx + var(--status-bar-height));
}
.back-icon {
    width: 40rpx;
    height: 40rpx;
}
.header-title {
    font-size: 32rpx; /* 16pt based on design req */
    font-weight: bold;
    color: #333;
}
.header-right {
    /* width: 40rpx; removed fixed width to fit text */
}
.save-btn {
    font-size: 28rpx;
    color: #FF5722;
    font-weight: bold;
}

.container {
    padding: 30rpx;
}
.input-card {
    background-color: #fff;
    border-radius: 12rpx;
    padding: 20rpx 30rpx;
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
}
.name-input {
    flex: 1;
    font-size: 32rpx;
    color: #333;
    height: 60rpx;
}
.clear-icon {
    width: 36rpx;
    height: 36rpx;
    background-color: #CCCCCC;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.clear-text {
    color: #fff;
    font-size: 28rpx;
    line-height: 28rpx;
    margin-top: -2rpx; /* Visual adjustment */
}
.input-tip {
    font-size: 24rpx;
    color: #999;
}
</style>
