import {
  Settings,
  Users,
  UserCheck,
  TrendingUp,
  Shield,
} from "lucide-react";
import { FieldDefinition, TabDefinition, TabColors } from "@/components/admin/settings";

// Tab definitions for copy trading settings
export const COPY_TRADING_TABS: TabDefinition[] = [
  {
    id: "platform",
    label: "Platform",
    icon: Settings,
    description: "Core platform configuration",
  },
  {
    id: "leader",
    label: "Leaders",
    icon: UserCheck,
    description: "Leader requirements and limits",
  },
  {
    id: "follower",
    label: "Followers",
    icon: Users,
    description: "Follower settings and allocation",
  },
  {
    id: "trading",
    label: "Trading",
    icon: TrendingUp,
    description: "Trading fees and order types",
  },
  {
    id: "risk",
    label: "Risk",
    icon: Shield,
    description: "Risk management defaults",
  },
];

// Tab colors for copy trading settings
export const COPY_TRADING_TAB_COLORS: Record<string, TabColors> = {
  platform: {
    bg: "bg-indigo-500/10",
    text: "text-indigo-500",
    border: "border-indigo-500/20",
    gradient: "from-indigo-500/20 via-indigo-400/10 to-transparent",
    glow: "shadow-indigo-500/20",
    iconBg: "bg-gradient-to-br from-indigo-500 to-indigo-600",
  },
  leader: {
    bg: "bg-emerald-500/10",
    text: "text-emerald-500",
    border: "border-emerald-500/20",
    gradient: "from-emerald-500/20 via-emerald-400/10 to-transparent",
    glow: "shadow-emerald-500/20",
    iconBg: "bg-gradient-to-br from-emerald-500 to-emerald-600",
  },
  follower: {
    bg: "bg-blue-500/10",
    text: "text-blue-500",
    border: "border-blue-500/20",
    gradient: "from-blue-500/20 via-blue-400/10 to-transparent",
    glow: "shadow-blue-500/20",
    iconBg: "bg-gradient-to-br from-blue-500 to-blue-600",
  },
  trading: {
    bg: "bg-amber-500/10",
    text: "text-amber-500",
    border: "border-amber-500/20",
    gradient: "from-amber-500/20 via-amber-400/10 to-transparent",
    glow: "shadow-amber-500/20",
    iconBg: "bg-gradient-to-br from-amber-500 to-amber-600",
  },
  risk: {
    bg: "bg-red-500/10",
    text: "text-red-500",
    border: "border-red-500/20",
    gradient: "from-red-500/20 via-red-400/10 to-transparent",
    glow: "shadow-red-500/20",
    iconBg: "bg-gradient-to-br from-red-500 to-red-600",
  },
};

// Field definitions for copy trading settings
export const COPY_TRADING_FIELD_DEFINITIONS: FieldDefinition[] = [
  // Platform Settings
  {
    key: "copyTradingEnabled",
    label: "Enable Copy Trading",
    type: "switch",
    description: "Enable or disable the copy trading platform",
    category: "platform",
    subcategory: "Status",
  },
  {
    key: "copyTradingMaintenanceMode",
    label: "Maintenance Mode",
    type: "switch",
    description: "Enable maintenance mode for copy trading",
    category: "platform",
    subcategory: "Status",
  },
  {
    key: "copyTradingRequireKYC",
    label: "Require KYC",
    type: "switch",
    description: "Require KYC verification for copy trading",
    category: "platform",
    subcategory: "Requirements",
  },

  // Leader Settings
  {
    key: "copyTradingMinLeaderTrades",
    label: "Minimum Leader Trades",
    type: "number",
    description: "Minimum number of trades required to become a leader",
    category: "leader",
    subcategory: "Requirements",
    min: 0,
    step: 1,
  },
  {
    key: "copyTradingMinLeaderWinRate",
    label: "Minimum Win Rate",
    type: "range",
    description: "Minimum win rate percentage required to become a leader",
    category: "leader",
    subcategory: "Requirements",
    min: 0,
    max: 100,
    step: 5,
    suffix: "%",
  },
  {
    key: "copyTradingMinLeaderAccountAge",
    label: "Minimum Account Age (days)",
    type: "number",
    description: "Minimum account age in days to become a leader",
    category: "leader",
    subcategory: "Requirements",
    min: 0,
    step: 1,
  },
  {
    key: "copyTradingMaxFollowersPerLeader",
    label: "Max Followers per Leader",
    type: "number",
    description: "Maximum number of followers a leader can have",
    category: "leader",
    subcategory: "Limits",
    min: 1,
    step: 1,
  },
  {
    key: "copyTradingEnableProfitShare",
    label: "Enable Profit Share",
    type: "switch",
    description: "Allow leaders to earn profit share from followers",
    category: "leader",
    subcategory: "Profit Share",
  },
  {
    key: "copyTradingMaxProfitSharePercent",
    label: "Max Profit Share",
    type: "range",
    description: "Maximum profit share percentage leaders can set",
    category: "leader",
    subcategory: "Profit Share",
    min: 0,
    max: 50,
    step: 5,
    suffix: "%",
  },
  {
    key: "copyTradingAutoApproveLeaders",
    label: "Auto Approve Leaders",
    type: "switch",
    description: "Automatically approve leaders who meet requirements",
    category: "leader",
    subcategory: "Approval",
  },
  {
    key: "copyTradingLeaderApplicationRateLimit",
    label: "Application Rate Limit",
    type: "number",
    description: "Maximum leader applications per user per day",
    category: "leader",
    subcategory: "Limits",
    min: 1,
    step: 1,
  },

  // Follower Settings
  {
    key: "copyTradingMaxLeadersPerFollower",
    label: "Max Leaders per Follower",
    type: "number",
    description: "Maximum number of leaders a follower can follow",
    category: "follower",
    subcategory: "Limits",
    min: 1,
    step: 1,
  },
  {
    key: "copyTradingMinAllocationAmount",
    label: "Minimum Allocation",
    type: "number",
    description: "Minimum allocation amount for following a leader",
    category: "follower",
    subcategory: "Allocation",
    min: 0,
    step: 0.01,
  },
  {
    key: "copyTradingMaxAllocationPercent",
    label: "Max Allocation",
    type: "range",
    description: "Maximum allocation percentage per leader",
    category: "follower",
    subcategory: "Allocation",
    min: 0,
    max: 100,
    step: 5,
    suffix: "%",
  },

  // Trading Settings
  {
    key: "copyTradingPlatformFeePercent",
    label: "Platform Fee",
    type: "range",
    description: "Platform fee percentage on profit share",
    category: "trading",
    subcategory: "Fees",
    min: 0,
    max: 20,
    step: 0.5,
    suffix: "%",
  },
  {
    key: "copyTradingMaxCopyLatencyMs",
    label: "Max Copy Latency (ms)",
    type: "number",
    description: "Maximum latency for copying trades in milliseconds",
    category: "trading",
    subcategory: "Execution",
    min: 100,
    step: 100,
  },
  {
    key: "copyTradingEnableMarketOrders",
    label: "Enable Market Orders",
    type: "switch",
    description: "Allow copying market orders",
    category: "trading",
    subcategory: "Order Types",
  },
  {
    key: "copyTradingEnableLimitOrders",
    label: "Enable Limit Orders",
    type: "switch",
    description: "Allow copying limit orders",
    category: "trading",
    subcategory: "Order Types",
  },
  {
    key: "copyTradingEnableAutoRetry",
    label: "Enable Auto Retry",
    type: "switch",
    description: "Automatically retry failed copy trades",
    category: "trading",
    subcategory: "Execution",
  },
  {
    key: "copyTradingMaxRetryAttempts",
    label: "Max Retry Attempts",
    type: "number",
    description: "Maximum number of retry attempts for failed trades",
    category: "trading",
    subcategory: "Execution",
    min: 0,
    max: 10,
    step: 1,
  },

  // Risk Settings
  {
    key: "copyTradingMaxDailyLossDefault",
    label: "Default Max Daily Loss",
    type: "range",
    description: "Default maximum daily loss percentage for followers",
    category: "risk",
    subcategory: "Loss Limits",
    min: 0,
    max: 50,
    step: 5,
    suffix: "%",
  },
  {
    key: "copyTradingMaxPositionDefault",
    label: "Default Max Position",
    type: "range",
    description: "Default maximum position size percentage",
    category: "risk",
    subcategory: "Position Limits",
    min: 0,
    max: 100,
    step: 5,
    suffix: "%",
  },
];

// Default settings values
export const COPY_TRADING_DEFAULT_SETTINGS: Record<string, any> = {
  copyTradingEnabled: true,
  copyTradingMaintenanceMode: false,
  copyTradingRequireKYC: false,
  copyTradingMinLeaderTrades: 10,
  copyTradingMinLeaderWinRate: 50,
  copyTradingMinLeaderAccountAge: 30,
  copyTradingMaxFollowersPerLeader: 1000,
  copyTradingMaxProfitSharePercent: 50,
  copyTradingEnableProfitShare: true,
  copyTradingAutoApproveLeaders: false,
  copyTradingLeaderApplicationRateLimit: 10,
  copyTradingMaxLeadersPerFollower: 10,
  copyTradingMinAllocationAmount: 50,
  copyTradingMaxAllocationPercent: 50,
  copyTradingPlatformFeePercent: 2,
  copyTradingMaxCopyLatencyMs: 5000,
  copyTradingEnableMarketOrders: true,
  copyTradingEnableLimitOrders: true,
  copyTradingEnableAutoRetry: true,
  copyTradingMaxRetryAttempts: 3,
  copyTradingMaxDailyLossDefault: 20,
  copyTradingMaxPositionDefault: 20,
};
