import { View, Text, Image } from '@tarojs/components';
import { useState } from 'react';
import Taro from '@tarojs/taro';
import NavBar from '@/components/NavBar';

export default function SharePage() {
  const [shareLink, setShareLink] = useState('https://paopao.com/ref/abc123');
  const [qrCodeUrl, setQrCodeUrl] = useState('');

  const handleCopyLink = () => {
    Taro.setClipboardData({ data: shareLink })
  };

  const handleGeneratePoster = () => {
    Taro.showToast({ title: '海报生成功能开发中', icon: 'none' })
  };

  const handleShare = (platform: string) => {
    // TODO: 接入分享 API
  };

  return (
    <View className="min-h-screen bg-gray-100">
      <NavBar title="分享赚佣金" />

      {/* 佣金概览 */}
      <View className="p-6 text-white" style={{ background: 'linear-gradient(to right, #ef4444, #f97316)' }}>
        <Text className="text-sm opacity-90">累计佣金(元)</Text>
        <View className="flex items-baseline mt-2 mb-4">
          <Text className="text-3xl font-bold">1,258</Text>
          <Text className="text-lg ml-1">.50</Text>
        </View>
        <View className="flex justify-between">
          <View className="text-center">
            <Text className="text-xl font-bold block">36</Text>
            <Text className="text-xs opacity-75">邀请人数</Text>
          </View>
          <View className="text-center">
            <Text className="text-xl font-bold block">89</Text>
            <Text className="text-xs opacity-75">订单数</Text>
          </View>
          <View className="text-center">
            <Text className="text-xl font-bold block">¥528</Text>
            <Text className="text-xs opacity-75">待结算</Text>
          </View>
        </View>
      </View>

      {/* 分享方式 */}
      <View className="p-4">
        <View className="bg-white rounded-lg p-4 mb-4">
          <Text className="text-base font-medium mb-4 block">分享链接</Text>
          <View className="flex items-center bg-gray-100 rounded-lg p-3 mb-3">
            <Text className="flex-1 text-sm text-gray-600 truncate">{shareLink}</Text>
            <Text className="text-sm text-blue-500 ml-2" onClick={handleCopyLink}>复制</Text>
          </View>
          <View className="flex" style={{ gap: '16px' }}>
            <View
              className="flex-1 bg-green-500 text-white rounded-lg py-3 text-center"
              onClick={() => handleShare('wechat')}
            >
              <Text className="text-white">微信分享</Text>
            </View>
            <View
              className="flex-1 bg-blue-500 text-white rounded-lg py-3 text-center"
              onClick={() => handleShare('moments')}
            >
              <Text className="text-white">朋友圈</Text>
            </View>
          </View>
        </View>

        {/* 分享海报 */}
        <View className="bg-white rounded-lg p-4 mb-4">
          <Text className="text-base font-medium mb-4 block">分享海报</Text>
          <View className="bg-gray-100 rounded-lg p-8 text-center mb-3">
            {qrCodeUrl ? (
              <Image src={qrCodeUrl} className="w-32 h-32 mx-auto" />
            ) : (
              <View>
                <Text className="text-4xl mb-2">📱</Text>
                <Text className="text-sm text-gray-500">点击下方按钮生成专属海报</Text>
              </View>
            )}
          </View>
          <View
            className="bg-red-500 text-white rounded-lg py-3 text-center"
            onClick={handleGeneratePoster}
          >
            <Text className="text-white">生成海报</Text>
          </View>
        </View>

        {/* 分享规则 */}
        <View className="bg-white rounded-lg p-4">
          <Text className="text-base font-medium mb-3 block">分享规则</Text>
          <View className="text-sm text-gray-600 flex flex-col" style={{ gap: '8px' }}>
            <View className="flex">
              <Text className="text-red-500 mr-2">•</Text>
              <Text>每邀请一位新用户注册，获得 ¥10 奖励</Text>
            </View>
            <View className="flex">
              <Text className="text-red-500 mr-2">•</Text>
              <Text>被邀请人完成首单，您可获得订单金额 5% 佣金</Text>
            </View>
            <View className="flex">
              <Text className="text-red-500 mr-2">•</Text>
              <Text>佣金满 ¥100 可申请提现</Text>
            </View>
            <View className="flex">
              <Text className="text-red-500 mr-2">•</Text>
              <Text>提现将在 1-3 个工作日内到账</Text>
            </View>
          </View>
        </View>
      </View>
    </View>
  );
}
