require 'redcarpet'
require 'fileutils'
require 'find_and_replace'

set :markdown_engine, :redcarpet
set :markdown, {
  fenced_code_blocks: true,
  strikethrough: true,
  highlight: true,
  tables: true
}

set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
set :fonts_dir, 'fonts'

# Build configuration
configure :build do
  # Minify CSS on build
  activate :minify_css
  # Minify Javascript on build
  activate :minify_javascript
  # Enable cache busting
  activate :asset_hash
end

# Pretty URLs
activate :directory_indexes
set :trailing_slash, false

# Syntax highlighting
activate :syntax, line_numbers: false

# Autoprefixer for CSS compatibility
activate :autoprefixer do |prefix|
  prefix.browsers = "last 2 versions"
end

# LiveReload for development
configure :development do
  activate :livereload
end

# Proxy pages for multi-version docs (optional)
# page "/v2/*", :proxy => "/index.html" do |p|
#   p.proxy_path = "/index.html"
# end

# Build-specific configuration
configure :build do
  # Disable LiveReload in production
  # activate :minify_javascript
end

# Ignore unnecessary files
ignore 'stylesheets/normalize.css'
ignore 'stylesheets/variables.css'
ignore 'stylesheets/icon-font.css'

# Set custom URL prefix if deploying to a subdirectory
# set :http_prefix, '/nexopos-api-docs/'

# Redirects for moved pages (optional)
# redirect 'old-path.html', '/new-path/'

# Custom helpers
helpers do
  def api_base_url
    "https://your-domain.com/api/"
  end

  def code_sample(language, code)
    raw("<pre><code class=\"language-#{language}\">#{code}</code></pre>")
  end
end
