export const STEP_LABELS = ['Modèle', 'Étapes', 'Items / Devis', 'Sommaire', 'Publier']

// Types de job — SOURCE UNIQUE dans config/job-types (ré-exporté ici pour compat des imports existants).
export { JOB_TYPE_OPTIONS } from 'src/config/job-types'

export const PRIORITY_OPTIONS = [
  { label: 'Urgent', value: 'high' },
  { label: 'Moyenne', value: 'medium' },
  { label: 'Basse', value: 'low' },
]

export const ORDER_MODE_OPTIONS = [
  { label: 'Devis', value: 'quotation' },
  { label: 'Commande directe', value: 'direct' },
  { label: 'Pré-payée', value: 'prepaid' },
]

export const ACCEPTANCE_METHOD_OPTIONS = [
  { label: 'Lien simple (JWT)', value: 'jwt' },
  { label: 'Signature DocuSeal', value: 'docuseal' },
]

export const BILLING_INTERVAL_OPTIONS = [
  { label: 'Mensuel', value: 'Month' },
  { label: 'Annuel', value: 'Year' },
]

export const CATALOG_CATEGORIES = ['Tous', 'Internet', 'Téléphonie', 'Bundle', 'Équipement', 'Frais']

// Internet hero tiers — single-select, swappable. The wizard shows the
// currently-selected tier as the primary tile, with the rest revealed on
// hover. Clicking another tier REPLACES the selection (doesn't stack).
// Megafibre 80 is the anchor "à partir de 39.95$" promo (base 79.95 - RAB-LOYAUTE
// -40). Higher tiers have no loyalty rebate — shown at base.
// Combo rebates (RAB2X/RAB3X/RAB4X) are added manually from the catalog.
export const INTERNET_HERO_TIERS = [
  // Prix EFFECTIFS après promo 24 mois (rabais récurrent RAB-LOYAUTE, rate overridé). Stratégie marketing :
  // 500 et 1 Gbps au MÊME prix (49.95) → le 1 Gbps devient le choix évident (« no brainer »). 80 = entrée de gamme.
  {
    id: 'tier_m80',
    code: 'FTTH80I',
    label: 'Megafibre 80',
    speed: '80 / 80 Mbps',
    badge: 'Économique',
    price_effective: 39.95,
    price_base: 79.95,
    desc: 'Fibre symétrique · promo −40$/mois (24 mois)',
    icon: 'wifi',
    items: [
      { item_code: 'FTTH80I', item_name: 'Internet Megafibre 80 Mbps', rate: 79.95, billing: 'recurring', billing_interval: 'Month', contract_months: 24, project_template_id: 'fiber_install' },
      { item_code: 'RAB-LOYAUTE', item_name: 'Rabais promotionnel (24 mois)', rate: -40.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24, is_rebate: true, applies_to_item: 'FTTH80I' },
    ],
  },
  {
    id: 'tier_500',
    code: 'INT-500',
    label: 'Fibre 500',
    speed: '500 / 500 Mbps',
    price_effective: 49.95,
    price_base: 89.95,
    desc: 'Fibre symétrique · streaming 4K, télétravail',
    icon: 'wifi',
    items: [
      { item_code: 'INT-500', item_name: 'Internet 500 Mbps', rate: 89.95, billing: 'recurring', billing_interval: 'Month', contract_months: 24, project_template_id: 'fiber_install' },
      { item_code: 'RAB-LOYAUTE', item_name: 'Rabais promotionnel (24 mois)', rate: -40.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24, is_rebate: true, applies_to_item: 'INT-500' },
    ],
  },
  {
    id: 'tier_1g',
    code: 'INT-1G',
    label: 'Gigafibre 1 Gbps',
    speed: '1000 / 1000 Mbps',
    badge: 'Populaire',
    price_effective: 49.95,
    price_base: 109.95,
    desc: 'Même prix que le 500 — le choix évident',
    icon: 'speed',
    default: true,
    items: [
      { item_code: 'INT-1G', item_name: 'Internet 1 Gbps', rate: 109.95, billing: 'recurring', billing_interval: 'Month', contract_months: 24, project_template_id: 'fiber_install' },
      { item_code: 'RAB-LOYAUTE', item_name: 'Rabais promotionnel (24 mois)', rate: -60.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24, is_rebate: true, applies_to_item: 'INT-1G' },
    ],
  },
]

// Stable set of all hero SKUs — used by selectHeroTier() to clean previous
// hero lines (including the -40 loyalty rebate) before applying a new tier.
export const INTERNET_HERO_CODES = new Set(
  INTERNET_HERO_TIERS.flatMap(t => t.items.map(i => i.item_code))
)

// TV hero tiers — mirrors INTERNET_HERO_TIERS pattern. Base (25$) adds the
// TV-BASE item directly. Mix 5 (+10$) and Mix 10 (+15$) will open the channel
// picker once the channel list is finalized. À la carte opens the unit-priced
// channel picker (no base tier, no combo). For now the non-base tiers are
// placeholder: they add their item but display "Configuration à venir" hint.
export const TV_HERO_TIERS = [
  {
    id: 'tv_base',
    code: 'TV-BASE',
    label: 'Télé Base',
    desc: 'Environ 50 chaînes généralistes, infos, communauté',
    price_effective: 25.00,
    price_base: 25.00,
    icon: 'live_tv',
    default: true,
    ready: true,
    items: [
      { item_code: 'TV-BASE', item_name: 'Forfait IPTV Base', rate: 25.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
    ],
  },
  {
    id: 'tv_mix5',
    code: 'TV-MIX5',
    label: 'Mix 5 chaînes',
    badge: 'Populaire',
    desc: 'Base + 5 chaînes thématiques au choix',
    price_effective: 35.00,
    price_base: 35.00,
    picks_allowed: 5,
    pick_unit_cost: 2.00,
    icon: 'playlist_add_check',
    ready: true,
    items: [
      { item_code: 'TV-BASE', item_name: 'Forfait IPTV Base', rate: 25.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
      { item_code: 'TV-MIX5', item_name: 'Bonus Mix 5 chaînes', rate: 10.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
    ],
  },
  {
    id: 'tv_mix10',
    code: 'TV-MIX10',
    label: 'Mix 10 chaînes',
    desc: 'Base + 10 chaînes thématiques au choix',
    price_effective: 42.50,
    price_base: 42.50,
    picks_allowed: 10,
    pick_unit_cost: 1.75,
    icon: 'playlist_add_check',
    ready: true,
    items: [
      { item_code: 'TV-BASE', item_name: 'Forfait IPTV Base', rate: 25.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
      { item_code: 'TV-MIX10', item_name: 'Bonus Mix 10 chaînes', rate: 17.50, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
    ],
  },
  {
    id: 'tv_a_la_carte',
    code: 'TELE_CARTE',
    label: 'À la carte',
    desc: 'Pas de base — prix unitaire par chaîne',
    price_effective: 0,
    price_base: 0,
    icon: 'tune',
    ready: false,
    items: [
      // Legacy reuse: gestionclient.product.sku = TELE_CARTE ("Télévision à la carte")
      { item_code: 'TELE_CARTE', item_name: 'Télévision à la carte', rate: 0, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
    ],
  },
]

export const TV_HERO_CODES = new Set(
  TV_HERO_TIERS.flatMap(t => t.items.map(i => i.item_code))
)

// Upsell/addon presets — chip-style toggles that stack on top of the hero.
// `tier` controls styling: upsell (+mo$ chip), addon. Rebates (is_rebate +
// applies_to_item) are netted into the parent line on customer-facing
// invoices but kept explicit in internal editing. Combo rebates are added
// manually by the sales rep (see combo rebate note below).
export const RESIDENTIAL_PRESETS = [
  {
    id: 'preset_phone',
    tier: 'upsell',
    label: 'Téléphonie',
    price_delta: 28.95,
    icon: 'phone',
    desc: '28.95$/mois · illimitée CA/US',
    service_type: 'phone',
    combo_eligible: true,
    items: [
      // Legacy reuse: gestionclient.product.sku = TELEPMENS
      // "Téléphonie IP, options toutes incluses, Canada et É-U illimité".
      // Bundle discount (to reach ~10$/mo) is applied manually by the sales
      // rep, not auto-generated. See docs/reference/erpnext-item-diff.md.
      { item_code: 'TELEPMENS', item_name: 'Téléphonie IP illimitée CA/US', rate: 28.95, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
    ],
  },
  {
    id: 'preset_wifi_boost',
    tier: 'addon',
    label: 'Booster WiFi',
    price_delta: 5.00,
    icon: 'router',
    desc: '+5$/mois · maillage mesh',
    service_type: 'wifi_boost',
    combo_eligible: false,
    items: [
      { item_code: 'EQ-WIFI-BOOST', item_name: 'Booster WiFi (maillage)', rate: 5.00, billing: 'recurring', billing_interval: 'Month', contract_months: 24 },
    ],
  },
]

// Premium sports channels — each carries a +surcharge and counts as pick_cost
// picks inside a Mix selection. `group_channels` is a soft grouping (e.g. RDS
// group includes RDS + RDS2) so picking the parent also brings the satellite
// channels. Using the channel *name* as the identifier for now; if names
// change we'll migrate to an internal id.
// NOTE: surcharge applies once per parent pick regardless of group size; the
// group_channels count is purely informational for the picker UI.
export const PREMIUM_SPORTS_CHANNELS = [
  { id: 'ch_rds',           name: 'RDS',           group_count: 2, surcharge: 3.00, pick_cost: 2 },
  { id: 'ch_tsn',           name: 'TSN',           group_count: 5, surcharge: 3.00, pick_cost: 2 },
  { id: 'ch_sportsnet',     name: 'SPORTSNET',     group_count: 2, surcharge: 3.00, pick_cost: 2 },
  { id: 'ch_sportsnet_one', name: 'SPORTSNET ONE', group_count: 1, surcharge: 3.00, pick_cost: 2 },
  { id: 'ch_tva_sports',    name: 'TVA SPORTS',    group_count: 2, surcharge: 3.00, pick_cost: 2 },
]

// All selectable Mix 5 / Mix 10 channels. Premium parents are flagged via
// `premium_group` — they consume `pick_cost` picks (2) AND add a $3/mo
// surcharge. Aliases in `sub` are shown in the tooltip ("RDS includes RDS INFO").
// Regular channels count for 1 pick and no surcharge.
// Picker UX: fuzzy match against name + sub[]. Selecting a premium parent
// automatically locks its sub-channels (they ride together).
export const TV_CHANNELS = [
  { name: 'A&E' },
  { name: 'ADDIK' },
  { name: 'ADULT SWIM' },
  { name: 'AMC' },
  { name: 'BBC NEWS' },
  { name: 'BNN' },
  { name: 'C&I' },
  { name: 'CARTOON NETWORK', sub: ['Boomerang'] },
  { name: 'CANAL D' },
  { name: 'CANAL VIE' },
  { name: 'CASA' },
  { name: 'CINEPOP' },
  { name: 'CNN' },
  { name: 'CTV COMEDY' },
  { name: 'CTV DRAMA' },
  { name: 'CTV NATURE', sub: ['formerly Disc Science'] },
  { name: 'CTV SCI-FI' },
  { name: 'DEJA VIEW' },
  { name: 'DTOUR' },
  { name: 'E!' },
  { name: 'ELLE FICTION' },
  { name: 'EVASION' },
  { name: 'FLAVOUR NETWORK', sub: ['formerly Food Network'] },
  { name: 'FOX NEWS' },
  { name: 'FX' },
  { name: 'FXX' },
  { name: 'GOLF CHANNEL' },
  { name: 'H2' },
  { name: 'HISTORIA' },
  { name: 'HLN' },
  { name: 'HOME NETWORK', sub: ['formerly HGTV'] },
  { name: 'ICI ARTV' },
  { name: 'ICI EXPLORA' },
  { name: 'INVESTIGATION', sub: ['Bell Media'] },
  { name: 'LCN' },
  { name: 'LIFETIME' },
  { name: 'MOVIETIME' },
  { name: 'MUCH' },
  { name: 'MAX' },
  { name: 'NAT GEO WILD' },
  { name: 'NATIONAL GEOGRAPHIC' },
  { name: 'OXYGEN TRUE CRIME', sub: ['formerly Investigation Disc'] },
  { name: 'PRISE 2' },
  { name: 'QUB', sub: ['YOOPA'] },
  { name: 'RDS', premium_group: 'ch_rds', sub: ['RDS INFO'] },
  { name: 'SHOWCASE' },
  { name: 'SLICE' },
  { name: 'SERIES+' },
  { name: 'SPORTSNET 360' },
  { name: 'SPORTSNET', premium_group: 'ch_sportsnet', sub: ['SPORTSNET 2'] },
  { name: 'SPORTSNET ONE', premium_group: 'ch_sportsnet_one' },
  { name: 'TELETOON', sub: ['Cartoon Network'] },
  { name: 'TELETOON FR' },
  { name: 'TEMOIN' },
  { name: 'TLC' },
  { name: 'TREEHOUSE' },
  { name: 'TSN', premium_group: 'ch_tsn', sub: ['TSN2', 'TSN3', 'TSN4', 'TSN5'] },
  { name: 'TVA SPORTS', premium_group: 'ch_tva_sports', sub: ['TVA SPORTS 2'] },
  { name: 'USA NETWORK', sub: ['formerly Disc Channel'] },
  { name: 'W NETWORK' },
  { name: 'YTV' },
  { name: 'Z TELE' },
  { name: 'ZESTE' },
]

// Cart item codes for picker output.
export const TV_PREMIUM_SURCHARGE_CODE = 'TV-PREMIUM-SUR'
export const TV_ALC_OVERAGE_CODE = 'TV-ALC-OVER'

// Autocomplete presets for the per-step "extra fee" field. When a preset is
// picked, both label (step.extra_label) and amount (step.extra_fee) auto-fill.
// User can still type a free-form label or enter a custom amount; presets are
// just a fast path for recurring situational fees on field-tech visits.
export const EXTRA_FEE_PRESETS = [
  { id: 'fee_emondage',    label: 'Émondage',                  amount: 75.00 },
  { id: 'fee_conduit',     label: 'Fourreau souterrain',       amount: 125.00 },
  { id: 'fee_dig',         label: 'Creusage supplémentaire',   amount: 100.00 },
  { id: 'fee_travel',      label: 'Déplacement longue distance', amount: 50.00 },
  { id: 'fee_height',      label: 'Installation en hauteur',   amount: 40.00 },
  { id: 'fee_drill',       label: 'Perçage mur extérieur',     amount: 35.00 },
  { id: 'fee_wiring',      label: 'Passage de fil additionnel', amount: 30.00 },
  { id: 'fee_wifi_config', label: 'Configuration WiFi avancée', amount: 40.00 },
  { id: 'fee_rush',        label: 'Dépannage urgent',          amount: 50.00 },
  { id: 'fee_custom_eq',   label: 'Équipement spécifique',     amount: 25.00 },
]

// Referral credit — one-time line appended when a valid referral code is
// entered. 50$ credit to the new subscriber; once the service is delivered a
// matching credit applies on the next invoice of the referrer (handled in the
// Referral Credit doctype on the backend).
export const REFERRAL_ITEM_CODE = 'REF-CREDIT-50'
export const REFERRAL_CREDIT_AMOUNT = 50.00

// Combo rebates are applied MANUALLY by the sales rep from the catalog
// (legacy RAB2X / RAB3X / RAB4X SKUs, -5 / -10 / -15 $). We intentionally
// do NOT auto-insert a combo rebate line — the rep picks the right SKU
// based on the actual bundle. See docs/reference/erpnext-item-diff.md.

const CAT_ICON_MAP = { Internet: 'wifi', Téléphonie: 'phone', Bundle: 'inventory_2', Équipement: 'router', Frais: 'receipt', Autre: 'category' }
export function catIcon (cat) {
  return CAT_ICON_MAP[cat] || 'category'
}

export { HUB_URL } from 'src/config/hub'
