/**
 * EmptyState 空状态组件 - 美化版
 * 显示空数据时的占位界面，采用现代插图风格设计
 */

import React from 'react';
import { View, StyleSheet, ViewStyle, Dimensions } from 'react-native';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { colors, spacing, fontSizes, borderRadius } from '../../theme';
import Text from './Text';
import Button from './Button';

interface EmptyStateProps {
  icon?: string;
  title: string;
  description?: string;
  actionLabel?: string;
  onAction?: () => void;
  style?: ViewStyle;
  variant?: 'default' | 'modern' | 'compact';
}

const EmptyState: React.FC<EmptyStateProps> = ({
  icon = 'folder-open-outline',
  title,
  description,
  actionLabel,
  onAction,
  style,
  variant = 'modern',
}) => {
  // 现代风格空状态
  if (variant === 'modern') {
    return (
      <View style={[styles.modernContainer, style]}>
        <View style={styles.illustrationContainer}>
          <View style={styles.iconBackground}>
            <MaterialCommunityIcons
              name={icon as any}
              size={48}
              color={colors.primary.main}
              style={styles.modernIcon}
            />
          </View>
          <View style={styles.decorativeCircle1} />
          <View style={styles.decorativeCircle2} />
        </View>
        <Text
          variant="h3"
          color={colors.text.primary}
          style={styles.modernTitle}
        >
          {title}
        </Text>
        {description && (
          <Text
            variant="body"
            color={colors.text.secondary}
            style={styles.modernDescription}
          >
            {description}
          </Text>
        )}
        {actionLabel && onAction && (
          <Button
            title={actionLabel}
            onPress={onAction}
            variant="primary"
            size="md"
            style={styles.modernButton}
          />
        )}
      </View>
    );
  }

  // 紧凑风格
  if (variant === 'compact') {
    return (
      <View style={[styles.compactContainer, style]}>
        <MaterialCommunityIcons
          name={icon as any}
          size={40}
          color={colors.text.disabled}
          style={styles.compactIcon}
        />
        <Text
          variant="body"
          color={colors.text.secondary}
          style={styles.compactTitle}
        >
          {title}
        </Text>
      </View>
    );
  }

  // 默认风格
  return (
    <View style={[styles.container, style]}>
      <MaterialCommunityIcons
        name={icon as any}
        size={64}
        color={colors.text.disabled}
        style={styles.icon}
      />
      <Text
        variant="h3"
        color={colors.text.secondary}
        style={styles.title}
      >
        {title}
      </Text>
      {description && (
        <Text
          variant="body"
          color={colors.text.secondary}
          style={styles.description}
        >
          {description}
        </Text>
      )}
      {actionLabel && onAction && (
        <Button
          title={actionLabel}
          onPress={onAction}
          variant="outline"
          size="md"
          style={styles.button}
        />
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  // 默认风格
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    padding: spacing.xl,
  },
  icon: {
    marginBottom: spacing.lg,
  },
  title: {
    textAlign: 'center',
    marginBottom: spacing.sm,
  },
  description: {
    textAlign: 'center',
    marginBottom: spacing.lg,
  },
  button: {
    minWidth: 120,
  },

  // 现代风格
  modernContainer: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    padding: spacing.xl,
    minHeight: 280,
  },
  illustrationContainer: {
    position: 'relative',
    alignItems: 'center',
    justifyContent: 'center',
    marginBottom: spacing.xl,
    width: 120,
    height: 120,
  },
  iconBackground: {
    width: 100,
    height: 100,
    borderRadius: borderRadius['2xl'],
    backgroundColor: colors.primary.main + '15',
    alignItems: 'center',
    justifyContent: 'center',
    shadowColor: colors.primary.main,
    shadowOffset: { width: 0, height: 4 },
    shadowOpacity: 0.2,
    shadowRadius: 12,
    elevation: 4,
  },
  modernIcon: {
    opacity: 0.9,
  },
  decorativeCircle1: {
    position: 'absolute',
    width: 24,
    height: 24,
    borderRadius: borderRadius.full,
    backgroundColor: colors.primary.light + '30',
    top: 5,
    right: 10,
  },
  decorativeCircle2: {
    position: 'absolute',
    width: 16,
    height: 16,
    borderRadius: borderRadius.full,
    backgroundColor: colors.primary.main + '20',
    bottom: 15,
    left: 5,
  },
  modernTitle: {
    textAlign: 'center',
    marginBottom: spacing.sm,
    fontWeight: '700',
    fontSize: fontSizes.xl,
  },
  modernDescription: {
    textAlign: 'center',
    marginBottom: spacing.lg,
    fontSize: fontSizes.md,
    lineHeight: 22,
    maxWidth: 280,
  },
  modernButton: {
    minWidth: 140,
    borderRadius: borderRadius.lg,
  },

  // 紧凑风格
  compactContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    padding: spacing.lg,
  },
  compactIcon: {
    marginRight: spacing.sm,
  },
  compactTitle: {
    fontSize: fontSizes.md,
  },
});

export default EmptyState;
