export interface Category {
  id: string;
  name: string;
  slug: string;
  icon?: string;
  display_order: number;
  is_active: boolean;
  item_count?: number;
}

export interface Listing {
  id: string;
  rank?: number;
  name: string;
  image_url: string;
  url?: string; // Legacy fallback
  facebook_url: string; // Required
  website_url?: string; // Optional
  category_id: string;
  category_name?: string;
  current_bid: number;
  clicks: number;
  hearts: number;
  is_active: boolean;
  created_at: string;
  updated_at: string;
  last_bid_at: string;
}

export interface Bid {
  id: string;
  listing_id: string;
  listing_name: string;
  amount: number;
  previous_bid: number;
  payment_id: string;
  ip_address?: string;
  created_at: string;
  time_period: 'today' | 'all_time';
}

export type PaymentStatus = 'pending' | 'processing' | 'paid' | 'success' | 'failed' | 'cancelled' | 'expired' | 'refunded';

export interface PaymentTransaction {
  id: string;
  transaction_id: string;
  listing_id: string;
  listing_name: string;
  url?: string;
  listing_url?: string;
  facebook_url?: string;
  website_url?: string;
  listing_image: string;
  category_id: string;
  category_name?: string;
  amount: number;
  currency?: string;
  gateway: 'bkash' | 'nagad' | 'rocket' | 'sslcommerz' | 'shurjopay' | 'aamarpay' | 'uddoktapay';
  mode: 'test' | 'live';
  status: PaymentStatus;
  gateway_transaction_id?: string;
  gateway_response?: Record<string, any>;
  ip_address?: string;
  created_at: string;
  updated_at?: string;
  verified_at?: string;
  paid_at?: string;
  failure_reason?: string;
}

export interface MenuItem {
  id: string;
  title: string;
  url: string;
  description?: string;
  location?: 'header' | 'footer' | 'both';
  target?: '_self' | '_blank';
  display_order: number;
  is_active: boolean;
  open_as?: 'link' | 'modal';
}

export type Language = 'en' | 'bn';
export type Theme = 'dark' | 'light';

export interface TranslationItem {
  key: string;
  category?: string;
  en: string;
  bn: string;
}

export type TranslationsMap = Record<string, { en: string; bn: string; category?: string }>;
export type TranslationDictionary = TranslationsMap;

export interface SiteSettings {
  site_name: string;
  site_subtitle: string;
  site_url: string;
  currency_symbol: string;
  minimum_bid_increment: number;
  initial_minimum_bid: number;
  visitor_timeout_seconds: number;
  pagination_size: number;
  maintenance_mode: boolean;
  translation_enabled: boolean;
  default_language: Language;
  default_payment_gateway?: 'bkash' | 'nagad' | 'rocket' | 'sslcommerz' | 'shurjopay' | 'aamarpay';
  seo_title: string;
  seo_description: string;
  seo_og_image: string;
  favicon_url: string;
  show_footer_admin_button?: boolean;
  custom_css?: string;
}

export interface DesignSettings {
  primary_color: string;
  secondary_color: string;
  background_color: string;
  card_color: string;
  text_color: string;
  muted_text_color: string;
  border_color: string;
  accent_color: string;
  button_color: string;
  button_text_color: string;
  rank1_bg: string;
  rank1_border: string;
  rank2_bg: string;
  rank3_bg: string;
  header_bg: string;
  footer_bg: string;
  footer_text_color?: string;
  footer_link_color?: string;
  footer_link_hover_color?: string;
  border_radius: string;
  font_family: string;
  logo_url: string;
  custom_css?: string;
}

export interface FrontendTexts {
  site_logo_text: string;
  live_ranking_badge: string;
  tab_all_time: string;
  tab_today: string;
  visitor_badge_prefix: string;
  claim_hero_title: string;
  claim_hero_desc: string;
  category_all: string;
  category_more: string;
  outbid_btn_text: string;
  current_bid_label: string;
  next_bid_label: string;
  additional_amount_label: string;
  payment_method_label: string;
  modal_target_label: string;
  modal_name_placeholder: string;
  modal_url_placeholder: string;
  total_generated_prefix: string;
  total_generated_suffix: string;
  developer_popup_title: string;
  developer_popup_handle: string;
  developer_popup_bio: string;
  footer_attribution: string;
  footer_brand_tagline: string;
  footer_author_name?: string;
  footer_author_url?: string;
  footer_sponsor_text?: string;
  footer_sponsor_url?: string;
  footer_domain_name?: string;
  footer_domain_rating?: string;
  footer_domain_label?: string;
  footer_domain_url?: string;
  footer_show_rating_badge?: boolean;
}

export interface DeveloperProfile {
  name: string;
  handle: string;
  image_url: string;
  bio: string;
  website_url: string;
  twitter_url: string;
  github_url: string;
  is_enabled: boolean;
}

export interface FloatingScrollPopup {
  is_enabled: boolean;
  scroll_threshold_percent: number;
  prefix_text: string;
  prefix_color: string;
  author_text: string;
  author_color: string;
  bg_color: string;
  border_color: string;
  avatar_image_url: string;
  target_url: string;
  show_close_button: boolean;
}

export interface ContentPage {
  id: 'rules' | 'terms' | 'privacy' | 'stats';
  title: string;
  slug: string;
  content: string;
  updated_at: string;
}

export interface GatewayConfig {
  id: 'bkash' | 'nagad' | 'rocket' | 'sslcommerz' | 'shurjopay' | 'aamarpay' | 'uddoktapay';
  name: string;
  is_enabled: boolean;
  mode: 'test' | 'live';
  merchant_id?: string;
  merchant_mobile?: string;
  store_id?: string;
  store_password?: string;
  signature_key?: string;
  api_key?: string;
  allowed_channels?: string[];
  session_timeout?: number | string;
  username?: string;
  password?: string;
  app_key?: string;
  app_secret?: string;
  public_key?: string;
  private_key?: string;
  terminal_id?: string;
  pin_password?: string;
  order_prefix?: string;
  api_url?: string;
  callback_url?: string;
  success_url?: string;
  fail_url?: string;
  cancel_url?: string;
  ipn_url?: string;
  webhook_url?: string;
}

export interface VisitorSettings {
  is_enabled: boolean;
  show_active_visitors: boolean;
  show_total_visitors: boolean;
  baseline_active: number;
  baseline_total: number;
}

export interface AppState {
  timeFilter: 'all_time' | 'today';
  selectedCategory: string;
  searchQuery: string;
  currentPage: number;
  activeVisitors: number;
  totalVisitors: number;
  liveListingTarget: Listing | null;
  isOutbidModalOpen: boolean;
  isCategoryModalOpen: boolean;
  isDeveloperModalOpen: boolean;
  isStatsModalOpen: boolean;
  activeContentModal: string | null;
  isAdminOpen: boolean;
}
