import type { HostKind, PathKind } from './api'; /** Guess a path kind from the literal user input. The dashboard pre-fills * the kind selector but the user can override (the backend trusts the * selection — selecting `exact` for `/greet/:name` matches it literally). */ export function guessPathKind(raw: string): PathKind { if (raw.endsWith('/*')) return 'prefix'; if (/(^|\/):[a-zA-Z_]/.test(raw)) return 'param'; return 'exact'; } /** Guess a host kind. Empty → any, leading "*." → wildcard, else strict. */ export function guessHostKind(raw: string): HostKind { if (!raw.trim()) return 'any'; if (raw.startsWith('*.')) return 'wildcard'; return 'strict'; } /** Warn-not-block: does the user's selection match what we'd guess * from the input? Used by the routing form for the soft mismatch * hint. Returns null when no warning is needed. */ export function pathKindMismatchWarning(raw: string, kind: PathKind): string | null { const guessed = guessPathKind(raw); if (guessed === kind) return null; const hint = guessed === 'param' ? 'this looks like a param pattern (contains `:name`)' : guessed === 'prefix' ? 'this looks like a prefix pattern (ends with `/*`)' : 'this looks like a literal path'; return `Selected kind is "${kind}", but ${hint}. Routing will use the selected kind.`; }