# Route Configuration Defaults and Helpers
#
# Provides shared default values and helper functions for route creation.
# Reduces duplication by providing common patterns.

let contracts = import "contracts.ncl" in

{
  # Base route with common defaults
  # Use this as foundation via merge operator (&)
  # Note: | default = allows overriding via merge
  base_route = {
    enabled | default = true,
    generate_boilerplate_only | default = false,
    replace_existing_boilerplate | default = false,
    show_in_sitemap | default = true,
    menu_group | default = "main",
    priority | default = 0.8,
    is_external | default = false,
    component_dynamic | default = false,
    content_type_param | default = false,
    keywords | default = [],
    lang_prefixes | default = [],
    menu_order | default = 999,
  },

  # Helper function: Create a route with minimal required fields
  #
  # Usage:
  #   make_route "Home" "/" "en"
  #     & { priority = 1.0, menu_icon = "home", ... }
  #
  # Parameters:
  #   comp_name: Component name (e.g., "Home", "About")
  #   url_path: URL path (e.g., "/", "/about")
  #   lang: Language code (e.g., "en", "es")
  #
  # Returns: Route record with defaults + generated keys
  make_route
    | String -> String -> String -> Dyn
    = fun comp_name url_path lang =>
      base_route & {
        component = comp_name,
        path = url_path,
        language = lang,
        # Auto-generate title/description keys from component name (| default = allows override)
        title_key | default = "%{std.string.lowercase comp_name}-page-title",
        description_key | default = "%{std.string.lowercase comp_name}-page-description",
      },

  # Helper function: Create a content route (blog, portfolio, etc.)
  #
  # Usage:
  #   make_content_route "ContentIndex" "/blog" "en" "blog"
  #     & { menu_icon = "book", ... }
  #
  # Parameters:
  #   comp_name: Component name
  #   url_path: URL path
  #   lang: Language code
  #   ctype: Content type (e.g., "blog", "portfolio")
  #
  # Returns: Route record with content-specific settings
  make_content_route
    | String -> String -> String -> String -> Dyn
    = fun comp_name url_path lang ctype =>
      make_route comp_name url_path lang & {
        component_dynamic = true,
        content_type_param = true,
        props = {
          content_type = ctype,
          use_categories = true,
          use_feature = true,
        },
      },

  # Helper function: Create an admin route (protected)
  #
  # Usage:
  #   make_admin_route "AdminDashboard" "/admin" "en"
  #     & { menu_icon = "shield", ... }
  #
  # Parameters:
  #   comp_name: Component name
  #   url_path: URL path
  #   lang: Language code
  #
  # Returns: Route record with admin-specific settings
  make_admin_route
    | String -> String -> String -> Dyn
    = fun comp_name url_path lang =>
      make_route comp_name url_path lang & {
        menu_group = "admin",
        show_in_sitemap = false,
        priority = 0.3,
      },

  # Helper function: Create an external link route
  #
  # Usage:
  #   make_external_link "GitHub" "https://github.com" "en"
  #     & { menu_icon = "external", ... }
  #
  # Parameters:
  #   lbl: Display label
  #   ext_url: External URL
  #   lang: Language code
  #
  # Returns: Route record for external links
  make_external_link
    | String -> String -> String -> Dyn
    = fun lbl ext_url lang =>
      base_route & {
        component = "ExternalLink",
        path = ext_url,
        language = lang,
        title_key = lbl,
        description_key = lbl,
        is_external = true,
        show_in_sitemap = false,
      },

  # Common menu orders for consistency
  menu_orders = {
    home = 1,
    about = 2,
    services = 3,
    portfolio = 4,
    blog = 5,
    contact = 10,
    admin = 100,
  },

  # Common priorities for SEO
  priorities = {
    critical = 1.0,    # Home page
    high = 0.9,        # Main pages (About, Services)
    normal = 0.8,      # Content pages (Blog posts)
    low = 0.5,         # Archive, Tags
    minimal = 0.3,     # Admin, Login
  },
}
