import type { StateInfoSection, StateProvisions } from '@/lib/domain/state-info'

/**
 * Sample state provisions in the structured shape (2026-09-25).
 *
 * West Virginia is the real thing, transcribed from the permit provider's own
 * state sheet, so the layout is reviewed against content that actually exists
 * rather than invented filler. Every other state falls back to GENERIC until
 * the provider's API is connected — `getStateProvisions` is the single seam
 * that swaps sample content for live content.
 */

const GENERIC: StateProvisions = {
  travel: [
    {
      items: [
        { term: 'Oversize', detail: 'Half an hour before sunrise to half an hour after sunset, Monday through Saturday.' },
        { term: 'Night travel', detail: 'Not permitted for oversize loads unless the permit says otherwise.' },
        { term: 'Speed limit', detail: 'Posted speed limit.' },
      ],
    },
    {
      heading: 'Restricted travel',
      items: [
        { detail: 'Metro-area curfews apply during weekday peak hours.' },
        { detail: 'Over-dimensional travel is usually not allowed on major holidays and holiday weekends.' },
        { detail: 'Always confirm against the permit and the provisions issued for this load.' },
      ],
    },
  ],
  escort: [
    {
      note: 'Escort counts scale with dimensions and road type.',
      items: [
        { term: 'Width over the threshold', detail: '1 escort on divided highways; front and rear on two-lane roads.' },
        { term: 'Height over the threshold', detail: '1 height pole escort, in addition to any other escort.' },
        { term: 'Overhang', detail: 'Front or rear overhang past the limit needs 1 escort.' },
      ],
    },
    { items: [{ detail: 'Local districts may impose additional escort requirements.' }] },
  ],
  permit_limits: [
    {
      note: 'What a routine permit covers. Past these, the load is a superload.',
      items: [
        { term: 'Length', detail: 'No limit if the route can accommodate it.' },
        { term: 'Width', detail: 'Routine to the state maximum; wider needs route review.' },
        { term: 'Height', detail: 'Routine to the state maximum; higher needs engineer approval.' },
        { term: 'Weight', detail: 'Routine to the state gross maximum.' },
      ],
    },
  ],
  legal_limits: [
    {
      note: 'Above any of these, the load needs an oversize or overweight permit before it moves.',
      items: [
        { term: 'Width', detail: '8′6″ on the Interstate and designated roads.' },
        { term: 'Height', detail: '13′6″.' },
        { term: 'Length', detail: '53′ trailer on designated highways.' },
        { term: 'Weight', detail: '80,000 lbs gross.' },
      ],
    },
  ],
  signs: [
    {
      heading: 'Signs',
      items: [
        { term: 'Required', detail: '"Oversize Load" signs front and rear on all oversize loads.' },
        { term: 'Overweight only', detail: 'No sign or flag requirement for overweight-only loads.' },
      ],
    },
    {
      heading: 'Flags and lights',
      items: [
        { detail: 'Red flags on every extremity of the load.' },
        { detail: 'Overhang past 4 feet needs a flag or a flashing amber light.' },
        { detail: 'Amber beacons functioning while operating under permit.' },
      ],
    },
  ],
  superloads: [
    {
      items: [
        { term: 'Review', detail: 'Extended review, often a route survey, sometimes a police escort.' },
        { term: 'Lead time', detail: 'Processing takes significantly longer than a routine permit. Plan ahead.' },
      ],
    },
  ],
}

/**
 * West Virginia — the provider's published state sheet, 2026-09-25.
 * Kept verbatim in substance: the numbers are the reason anyone opens this.
 */
const WV: StateProvisions = {
  travel: [
    {
      items: [
        { term: 'Night travel', detail: 'Allowed for overweight only, up to 110,000 lbs gross.' },
        { term: 'Permit validity', detail: '5 days.' },
        { term: 'Speed limit', detail: 'Posted speed limit.' },
      ],
    },
    {
      heading: 'Overweight only',
      items: [
        { term: 'Under 110,000 lbs gross', detail: 'Movement allowed 24/7.' },
        { term: 'Over 110,000 lbs gross', detail: 'Sunrise to sunset, Monday through Friday only.' },
      ],
    },
    {
      heading: 'Oversize operating hours',
      items: [{ detail: 'Sunrise to sunset, Monday through Friday.' }],
    },
    {
      heading: 'Weekend movement',
      note: 'Sunrise to sunset, and allowed by route type when the load stays within these:',
      items: [
        { term: 'Interstate and divided', detail: 'Up to 14′6″ high, 14′ wide, 95′ long, 15′ total overhang.' },
        { term: 'US and selected WV routes', detail: 'Up to 14′ high, 12′ wide, 75′ long, 10′ total overhang.' },
        { term: 'All other routes', detail: 'Up to 13′6″ high, 12′ wide, 75′ long, 10′ total overhang.' },
      ],
    },
    {
      heading: 'Holidays',
      items: [{ detail: 'Over-dimensional travel is usually not allowed on major holidays and holiday weekends.' }],
    },
    {
      heading: 'West Virginia Parkway',
      items: [
        { term: 'Night', detail: 'No night running and no overnight parking on the Parkway, so the entry cutoff moves with the season.' },
        { term: 'Over 14′ wide', detail: 'Monday through Thursday only. No Friday movement.' },
        { term: 'Everything else', detail: 'Same as the West Virginia Interstates.' },
      ],
    },
  ],
  escort: [
    {
      heading: 'On 4 or more lane divided highways',
      items: [
        { term: 'Over 95′ long', detail: '1 escort.' },
        { term: 'Over 100′ long', detail: '2 escorts.' },
        { term: 'Over 10′ front or rear overhang', detail: '1 escort.' },
        { term: 'Over 12′ wide', detail: '1 escort.' },
        { term: 'Over 14′ wide', detail: '2 escorts.' },
        { term: 'Over 15′ wide', detail: '3 escorts.' },
        { term: 'Over 16′ wide', detail: 'As required by the route.' },
        { term: 'Over 15′ high', detail: '1 height pole escort, in addition to any other escort.' },
      ],
    },
    {
      heading: 'On 2-lane highways',
      items: [
        { term: 'At 75′ long', detail: '1 rear escort.' },
        { term: 'Over 95′ long', detail: '2 escorts.' },
        { term: 'Over 10′ front or rear overhang', detail: '1 escort.' },
        { term: '10′6″ to 12′ wide', detail: '1 front escort.' },
        { term: 'Over 12′ wide', detail: '2 escorts.' },
        { term: 'Over 15′ wide', detail: '3 escorts.' },
        { term: 'Over 16′ wide', detail: 'As required by the route.' },
        { term: 'Over 15′ high', detail: '1 height pole escort, in addition to any other escort.' },
      ],
    },
    { items: [{ detail: 'Local districts may impose additional escort requirements.' }] },
  ],
  permit_limits: [
    {
      items: [
        { term: 'Length', detail: 'No limit if the route can accommodate it.' },
        { term: 'Width', detail: '16′ on 4-lanes, 15′ on 2-lanes.' },
        { term: 'Height', detail: '16′ if the route can accommodate it. Over 15′ needs engineer approval.' },
        { term: 'Weight', detail: '120,000 lbs gross. Single 28,000, tandem 45,000.' },
      ],
    },
    {
      items: [
        { detail: 'A superload permit can go higher and is usually a routine issue.' },
        { detail: 'Loads past these dimensions are treated as superloads.' },
      ],
    },
  ],
  legal_limits: [
    {
      items: [
        { term: 'Length', detail: '53′ trailer or load on the Interstate and designated highways, rear tractor axle to trailer first axle not over 37′. 48′ trailer and 60′ overall on non-designated roads.' },
        { term: 'Overhang', detail: '3′ front, 6′ rear, on all roads.' },
        { term: 'Width', detail: '8′6″ on the Interstate and designated roads, 8′ on non-designated.' },
        { term: 'Height', detail: '13′6″.' },
        { term: 'Weight', detail: '80,000 lbs gross on designated routes, 65,000 on non-designated. Single 20,000, tandem 34,000, tridem 42,500 at 8′ spacing.' },
      ],
    },
  ],
  signs: [
    {
      heading: 'Signs',
      items: [
        { term: 'Required', detail: '"Oversize Load" signs front and rear on all oversize loads.' },
        { term: 'Overweight only', detail: 'No sign or flag requirement.' },
      ],
    },
    {
      heading: 'Flags',
      note: 'Six flags on every oversize load.',
      items: [
        { detail: 'One on each side of the front bumper of the power unit.' },
        { detail: 'One on each top corner of the load.' },
        { detail: 'The remaining two go on the load’s corners or widest points; the state does not say exactly where.' },
        { detail: 'Overhang past 4 feet needs a flag or a flashing amber light.' },
      ],
    },
    {
      heading: 'Lighting',
      items: [{ detail: 'Overhang past 4 feet needs a flashing amber light, as an alternative to a flag.' }],
    },
  ],
  superloads: [
    {
      items: [
        { term: 'Threshold', detail: 'Anything past the routine permit limits: over 16′ wide, over 16′ high, or over 120,000 lbs gross.' },
        { term: 'Review', detail: 'Usually a routine issue in West Virginia, but expect a route survey and a longer lead time.' },
      ],
    },
  ],
}

const PER_STATE: Record<string, StateProvisions> = { WV }

export function getStateProvisions(code: string): StateProvisions {
  return PER_STATE[code.trim().toUpperCase()] ?? GENERIC
}

/** True when the state's own sheet is loaded, rather than the generic fallback. */
export function hasStateSheet(code: string): boolean {
  return !!PER_STATE[code.trim().toUpperCase()]
}

export type { StateInfoSection }
