import React, { ReactNode, ElementType, ComponentPropsWithoutRef } from 'react';
import { Box, BoxProps } from './Box';

interface SurfaceProps<T extends ElementType = 'div'> extends Omit<BoxProps<T>, 'children' | 'className' | 'display'> {
  as?: T;
  children: ReactNode;
  variant?: 'default' | 'muted' | 'dark' | 'glass' | 'gradient-blue' | 'gradient-gold' | 'gradient-purple' | 'gradient-green' | 'discord' | 'discord-inner';
  rounded?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full';
  border?: boolean;
  padding?: number;
  className?: string;
  display?: 'block' | 'inline-block' | 'flex' | 'inline-flex' | 'grid' | 'none';
  shadow?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'discord' | string;
}

export function Surface<T extends ElementType = 'div'>({ 
  as,
  children, 
  variant = 'default',
  rounded = 'lg',
  border = false,
  padding = 0,
  className = '',
  display,
  shadow = 'none',
  ...props 
}: SurfaceProps<T> & ComponentPropsWithoutRef<T>) {
  const variantClasses: Record<string, string> = {
    default: 'bg-iron-gray',
    muted: 'bg-iron-gray/50',
    dark: 'bg-deep-graphite',
    glass: 'bg-deep-graphite/60 backdrop-blur-md',
    'gradient-blue': 'bg-gradient-to-br from-primary-blue/20 via-iron-gray/80 to-deep-graphite',
    'gradient-gold': 'bg-gradient-to-br from-yellow-600/20 via-iron-gray/80 to-deep-graphite',
    'gradient-purple': 'bg-gradient-to-br from-purple-600/20 via-iron-gray/80 to-deep-graphite',
    'gradient-green': 'bg-gradient-to-br from-green-600/20 via-iron-gray/80 to-deep-graphite',
    'discord': 'bg-gradient-to-b from-deep-graphite to-iron-gray',
    'discord-inner': 'bg-gradient-to-br from-iron-gray via-deep-graphite to-iron-gray'
  };

  const shadowClasses: Record<string, string> = {
    none: '',
    sm: 'shadow-sm',
    md: 'shadow-md',
    lg: 'shadow-lg',
    xl: 'shadow-xl',
    discord: 'shadow-[0_0_80px_rgba(88,101,242,0.15)]'
  };

  const roundedClasses: Record<string, string> = {
    none: 'rounded-none',
    sm: 'rounded-sm',
    md: 'rounded-md',
    lg: 'rounded-lg',
    xl: 'rounded-xl',
    '2xl': 'rounded-2xl',
    full: 'rounded-full'
  };

  const paddingClasses: Record<number, string> = {
    0: 'p-0',
    1: 'p-1',
    2: 'p-2',
    3: 'p-3',
    4: 'p-4',
    6: 'p-6',
    8: 'p-8',
    10: 'p-10',
    12: 'p-12'
  };

  const classes = [
    variantClasses[variant],
    roundedClasses[rounded],
    border ? 'border border-charcoal-outline' : '',
    paddingClasses[padding] || 'p-0',
    shadowClasses[shadow],
    display ? display : '',
    className
  ].filter(Boolean).join(' ');

  return (
    <Box className={classes} {...props}>
      {children}
    </Box>
  );
}
