import {
  DollarSign,
  Building2,
  Tag,
  Globe,
} from "lucide-react";

export type ChannelPrice = {
  retail: string;
  compareAt: string;
  wholesale: string;
  cost: string;
  effectiveDateFrom?: string;
  effectiveDateTo?: string;
  min_qty?: string;
  max_qty?: string;
  priority?: string;
};

export type BranchChannelPrices = Record<string, ChannelPrice>;

export type ChannelKey = keyof typeof channelLabels;

export type Branch = {
  id: number;
  name: string;
  code: string;
  isDefault?: boolean;
};

export type ProductOption = {
  id: number;
  name: string;
  values: string[];
  isPredefined?: boolean;
};

export type Variant = {
  id: number;
  title: string;
  sku: string;
};

export type PredefinedOptionValue = {
  id: number;
  value: string;
};

export type PredefinedOption = {
  id: number;
  name: string;
  options: PredefinedOptionValue[];
};

export const predefinedOptions: PredefinedOption[] = [
  {
    id: 1,
    name: "Size",
    options: [
      { id: 1, value: "XS" },
      { id: 2, value: "S" },
      { id: 3, value: "M" },
      { id: 4, value: "L" },
      { id: 5, value: "XL" },
      { id: 6, value: "XXL" },
      { id: 7, value: "XXXL" }
    ]
  },
  {
    id: 2,
    name: "Color",
    options: [
      { id: 1, value: "Black" },
      { id: 2, value: "White" },
      { id: 3, value: "Red" },
      { id: 4, value: "Blue" },
      { id: 5, value: "Green" },
      { id: 6, value: "Yellow" },
      { id: 7, value: "Orange" },
      { id: 8, value: "Purple" },
      { id: 9, value: "Pink" },
      { id: 10, value: "Brown" },
      { id: 11, value: "Gray" }
    ]
  },
  {
    id: 3,
    name: "Material",
    options: [
      { id: 1, value: "Cotton" },
      { id: 2, value: "Polyester" },
      { id: 3, value: "Wool" },
      { id: 4, value: "Silk" },
      { id: 5, value: "Leather" },
      { id: 6, value: "Denim" },
      { id: 7, value: "Linen" }
    ]
  },
  {
    id: 4,
    name: "Style",
    options: [
      { id: 1, value: "Casual" },
      { id: 2, value: "Formal" },
      { id: 3, value: "Sport" },
      { id: 4, value: "Vintage" },
      { id: 5, value: "Modern" },
      { id: 6, value: "Classic" }
    ]
  }
];

export const defaultBranchChannelPrices: BranchChannelPrices = {
  pos: { 
    retail: "", 
    compareAt: "", 
    wholesale: "", 
    cost: "",
    effectiveDateFrom: "",
    effectiveDateTo: "",
    min_qty: "",
    max_qty: "",
    priority: ""
  },
  facebook: { 
    retail: "", 
    compareAt: "", 
    wholesale: "", 
    cost: "",
    effectiveDateFrom: "",
    effectiveDateTo: "",
    min_qty: "",
    max_qty: "",
    priority: ""
  },
  offline: { 
    retail: "", 
    compareAt: "", 
    wholesale: "", 
    cost: "",
    effectiveDateFrom: "",
    effectiveDateTo: "",
    min_qty: "",
    max_qty: "",
    priority: ""
  },
  online: { 
    retail: "", 
    compareAt: "", 
    wholesale: "", 
    cost: "",
    effectiveDateFrom: "",
    effectiveDateTo: "",
    min_qty: "",
    max_qty: "",
    priority: ""
  },
};

export const initialBranches: Branch[] = [
  { id: 1, name: "Main Store", code: "MAIN", isDefault: true },
  { id: 2, name: "Downtown Branch", code: "DT" },
  { id: 3, name: "Airport Branch", code: "AIR" },
  { id: 4, name: "Mall Branch", code: "MALL" },
];

export const channelHints = {
  pos: "In-store point of sale transactions",
  facebook: "Facebook Marketplace and Shop sales",
  offline: "Catalog, phone orders, and direct sales",
  online: "Website and e-commerce platform sales",
};

export const channelLabels = {
  pos: "POS",
  facebook: "Facebook",
  offline: "Offline",
  online: "Online",
};

export const channelIcons = {
  pos: DollarSign,
  facebook: Tag,
  offline: Building2,
  online: Globe,
};

// Form Data Types for React Hook Form
export type PricingFormData = {
  productName: string;
  hasVariants: boolean;
  
  // Universal pricing (when samePriceAllBranches is true)
  universal?: {
    sameChannelPrice: boolean;
    
    // Simple universal pricing (no variants)
    simple?: ChannelPrice;
    
    // Channel-wise universal pricing (dynamic channels by name)
    channels?: Record<string, ChannelPrice>;
    
    // Variant-based universal pricing (dynamic channels by name)
    variants?: Record<number, Record<string, ChannelPrice>>;
  };
  
  // Branch-specific pricing (when samePriceAllBranches is false)
  branches?: {
    // For simple products (dynamic channels by name)
    simple?: Record<number, Record<string, ChannelPrice>>;
    
    // For variants (dynamic channels by name)
    variants?: Record<number, Record<number, Record<string, ChannelPrice>>>;
  };
};
