import {
  Settings,
  DollarSign,
  Shield,
  LayoutDashboard,
  Eye,
} from "lucide-react";
import { FieldDefinition, TabDefinition, TabColors } from "@/components/admin/settings";
import MinimumTradeAmountsField from "./components/MinimumTradeAmounts";

// Tab definitions for P2P settings
export const P2P_TABS: TabDefinition[] = [
  {
    id: "trading",
    label: "Trading",
    icon: Settings,
    description: "Configure trading parameters and limits",
  },
  {
    id: "fees",
    label: "Fees & Limits",
    icon: DollarSign,
    description: "Configure fees and transaction limits",
  },
  {
    id: "platform",
    label: "Platform",
    icon: LayoutDashboard,
    description: "Platform-wide settings and controls",
  },
  {
    id: "security",
    label: "Security",
    icon: Shield,
    description: "Security and verification settings",
  },
  {
    id: "ui",
    label: "UI & Display",
    icon: Eye,
    description: "User interface display options",
  },
];

// Tab colors for P2P settings
export const P2P_TAB_COLORS: Record<string, TabColors> = {
  trading: {
    bg: "bg-green-500/10",
    text: "text-green-500",
    border: "border-green-500/20",
    gradient: "from-green-500/20 via-green-400/10 to-transparent",
    glow: "shadow-green-500/20",
    iconBg: "bg-gradient-to-br from-green-500 to-green-600",
  },
  fees: {
    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",
  },
  platform: {
    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",
  },
  security: {
    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",
  },
  ui: {
    bg: "bg-purple-500/10",
    text: "text-purple-500",
    border: "border-purple-500/20",
    gradient: "from-purple-500/20 via-purple-400/10 to-transparent",
    glow: "shadow-purple-500/20",
    iconBg: "bg-gradient-to-br from-purple-500 to-purple-600",
  },
};

// Field definitions for P2P settings
export const P2P_FIELD_DEFINITIONS: FieldDefinition[] = [
  // Trading Settings
  {
    key: "p2pDefaultEscrowTime",
    label: "Default Escrow Time (minutes)",
    type: "number",
    description: "The default time a trade will be held in escrow",
    category: "trading",
    subcategory: "Time Settings",
    min: 1,
    max: 1440,
  },
  {
    key: "p2pDefaultPaymentWindow",
    label: "Default Payment Window (minutes)",
    type: "number",
    description: "The time buyers have to complete payment before the trade is automatically cancelled",
    category: "trading",
    subcategory: "Time Settings",
    min: 1,
    max: 1440,
  },
  {
    key: "p2pMinimumTradeAmount",
    label: "Minimum Trade Amount ($)",
    type: "number",
    description: "The minimum amount allowed for a P2P trade",
    category: "trading",
    subcategory: "Amount Limits",
    min: 0,
    step: 0.01,
  },
  {
    key: "p2pMaximumTradeAmount",
    label: "Maximum Trade Amount ($)",
    type: "number",
    description: "The maximum amount allowed for a P2P trade",
    category: "trading",
    subcategory: "Amount Limits",
    min: 0,
    step: 0.01,
  },
  {
    key: "p2pAutoCancelUnpaidTrades",
    label: "Auto-Cancel Unpaid Trades",
    type: "switch",
    description: "Automatically cancel trades that are not paid within the payment window",
    category: "trading",
    subcategory: "Automation",
  },

  // Fees Settings
  {
    key: "p2pMakerFee",
    label: "Maker Fee",
    type: "range",
    description: "Fee percentage charged to offer creators",
    category: "fees",
    subcategory: "Transaction Fees",
    min: 0,
    max: 5,
    step: 0.01,
    suffix: "%",
  },
  {
    key: "p2pTakerFee",
    label: "Taker Fee",
    type: "range",
    description: "Fee percentage charged to offer takers",
    category: "fees",
    subcategory: "Transaction Fees",
    min: 0,
    max: 5,
    step: 0.01,
    suffix: "%",
  },
  {
    key: "p2pDisputeFeePercent",
    label: "Dispute Fee",
    type: "range",
    description: "Fee percentage charged for dispute resolution",
    category: "fees",
    subcategory: "Transaction Fees",
    min: 0,
    max: 10,
    step: 0.1,
    suffix: "%",
  },
  {
    key: "p2pEscrowReleaseTime",
    label: "Escrow Release Time",
    type: "text",
    description: "Time when escrow funds are automatically released (HH:MM format)",
    category: "fees",
    subcategory: "Escrow",
  },
  {
    key: "p2pAutoReleaseEscrow",
    label: "Automatic Escrow Release",
    type: "switch",
    description: "Automatically release escrow funds after the payment window expires",
    category: "fees",
    subcategory: "Escrow",
  },
  {
    key: "p2pMinimumTradeAmounts",
    label: "Minimum Trade Amounts",
    type: "custom",
    description: "Configure minimum trade amounts per currency",
    category: "fees",
    subcategory: "Currency Minimums",
    fullWidth: true,
    customRender: MinimumTradeAmountsField,
  },

  // Platform Settings
  {
    key: "p2pEnabled",
    label: "P2P Trading Enabled",
    type: "switch",
    description: "Enable or disable P2P trading platform-wide",
    category: "platform",
    subcategory: "Status",
  },
  {
    key: "p2pMaintenanceMode",
    label: "Maintenance Mode",
    type: "switch",
    description: "Put P2P trading in maintenance mode",
    category: "platform",
    subcategory: "Status",
  },
  {
    key: "p2pAllowNewOffers",
    label: "Allow New Offers",
    type: "switch",
    description: "Allow users to create new P2P offers",
    category: "platform",
    subcategory: "Offers",
  },
  {
    key: "p2pAllowGuestBrowsing",
    label: "Allow Guest Browsing",
    type: "switch",
    description: "Allow non-logged-in users to browse P2P offers",
    category: "platform",
    subcategory: "Access",
  },
  {
    key: "p2pAllowCustomPaymentMethods",
    label: "Allow Custom Payment Methods",
    type: "switch",
    description: "Allow users to add custom payment methods",
    category: "platform",
    subcategory: "Payment Methods",
  },
  {
    key: "p2pAutoApproveOffers",
    label: "Auto Approve Offers",
    type: "switch",
    description: "Automatically approve new and edited offers. When disabled, offers require admin moderation.",
    category: "platform",
    subcategory: "Offers",
  },
  {
    key: "p2pMaxActiveOffersPerUser",
    label: "Max Active Offers Per User",
    type: "number",
    description: "Maximum number of active offers a user can have",
    category: "platform",
    subcategory: "Limits",
    min: 1,
    max: 100,
    step: 1,
  },
  {
    key: "p2pMaxActiveTrades",
    label: "Max Active Trades",
    type: "number",
    description: "Maximum number of concurrent active trades per user",
    category: "platform",
    subcategory: "Limits",
    min: 1,
    max: 100,
    step: 1,
  },

  // Security Settings
  {
    key: "p2pEnableDisputeSystem",
    label: "Enable Dispute System",
    type: "switch",
    description: "Allow users to open disputes on trades",
    category: "security",
    subcategory: "Disputes",
  },
  {
    key: "p2pEnableRatingSystem",
    label: "Enable Rating System",
    type: "switch",
    description: "Allow users to rate each other after trades",
    category: "security",
    subcategory: "Trust & Safety",
  },
  {
    key: "p2pEnableChatSystem",
    label: "Enable Chat System",
    type: "switch",
    description: "Allow users to chat during trades",
    category: "security",
    subcategory: "Communication",
  },

  // UI Settings
  {
    key: "p2pShowRecentTrades",
    label: "Show Recent Trades",
    type: "switch",
    description: "Display recent trades on the P2P homepage",
    category: "ui",
    subcategory: "Display",
  },
  {
    key: "p2pShowMarketTrends",
    label: "Show Market Trends",
    type: "switch",
    description: "Display market trends and statistics",
    category: "ui",
    subcategory: "Display",
  },
];

// Default settings values
export const P2P_DEFAULT_SETTINGS: Record<string, any> = {
  p2pDefaultEscrowTime: 30,
  p2pDefaultPaymentWindow: 15,
  p2pAutoCancelUnpaidTrades: true,
  p2pMaximumTradeAmount: 100000,
  p2pMinimumTradeAmount: 10,
  p2pMakerFee: 0.1,
  p2pTakerFee: 0.2,
  p2pDisputeFeePercent: 1,
  p2pEscrowReleaseTime: "00:00",
  p2pEnabled: true,
  p2pMaintenanceMode: false,
  p2pAllowNewOffers: true,
  p2pAllowGuestBrowsing: true,
  p2pAllowCustomPaymentMethods: false,
  p2pAutoApproveOffers: false,
  p2pMaxActiveOffersPerUser: 5,
  p2pMaxActiveTrades: 10,
  p2pEnableDisputeSystem: true,
  p2pEnableRatingSystem: true,
  p2pEnableChatSystem: true,
  p2pShowRecentTrades: true,
  p2pShowMarketTrends: true,
};
