<template>
    <view class="referral-section">
        <view class="referral-section__inner">
            <view class="referral-section__header">
                <text class="referral-section__title">推荐奖励</text>
                <view
                    class="referral-section__link"
                    hover-class="mi-tap--hover"
                    :hover-stay-time="150"
                    @tap="$emit('view-rules')"
                >
                    <text class="referral-section__records-link">规则说明</text>
                    <image
                        class="referral-section__link-arrow"
                        src="https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/images/chevronright11.png"
                        mode="aspectFit"
                    />
                </view>
            </view>

            <view class="referral-section__code-row">
                <view class="referral-section__code-box">
                    <text class="referral-section__code-label">我的邀请码</text>
                    <text class="referral-section__code-value">{{ data.code }}</text>
                </view>
                <view
                    class="referral-section__copy-btn"
                    hover-class="mi-tap-btn--hover"
                    :hover-stay-time="150"
                    @tap="copyCode"
                >
                    <view class="referral-section__copy-icon">
                        <view class="referral-section__copy-sheet referral-section__copy-sheet--back"></view>
                        <view class="referral-section__copy-sheet referral-section__copy-sheet--front"></view>
                    </view>
                    <text class="referral-section__copy-text">复制</text>
                </view>
            </view>

            <view class="referral-section__stats">
                <view class="referral-section__stat">
                    <text class="referral-section__stat-num referral-section__stat-num--orange">
                        {{ data.invited }}
                    </text>
                    <text class="referral-section__stat-label">已推荐</text>
                </view>
                <view class="referral-section__stat-divider"></view>
                <view class="referral-section__stat">
                    <text class="referral-section__stat-num referral-section__stat-num--green">
                        {{ data.registered }}
                    </text>
                    <text class="referral-section__stat-label">已注册</text>
                </view>
                <view class="referral-section__stat-divider"></view>
                <view class="referral-section__stat">
                    <text class="referral-section__stat-num referral-section__stat-num--amber">
                        {{ data.purchased }}
                    </text>
                    <text class="referral-section__stat-label">已购课</text>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    options: {
        virtualHost: false,
        styleIsolation: 'apply-shared'
    },
    props: {
        data: {
            type: Object,
            default: () => ({
                code: 'FIT-ZXF-2024',
                invited: 5,
                registered: 3,
                purchased: 2
            })
        }
    },
    emits: ['view-rules'],
    methods: {
        copyCode() {
            uni.setClipboardData({
                data: this.data.code,
                success: () => {
                    uni.showToast({ title: '已复制', icon: 'success' })
                }
            })
        }
    }
}
</script>

<style>
@import '@/common/style/memberInfo/member-info-component-reset.css';
@import '@/common/style/memberInfo/member-info-referral.css';
@import '@/common/style/memberInfo/member-info-tap.css';
</style>
