#!/usr/bin/env nu

# Docker Cross-build Image Builder
# Nushell version of build-docker-cross.sh
# Builds Docker image for cross-platform compilation

def main [] {
    # Configuration - following project's configuration-driven approach
    let dockerfile = "Dockerfile.cross"
    let image_tag = "localhost/website-cross:latest"

    print $"(ansi blue)🐳 Building Docker cross-compilation image...(ansi reset)"
    print $"(ansi blue)📄 Dockerfile: ($dockerfile)(ansi reset)"
    print $"(ansi blue)🏷️  Tag: ($image_tag)(ansi reset)"

    # Check if Dockerfile exists
    if not ($dockerfile | path exists) {
        print $"(ansi red)❌ Dockerfile not found: ($dockerfile)(ansi reset)"
        exit 1
    }

    # Check if Docker is available
    try {
        docker --version | ignore
    } catch {
        print $"(ansi red)❌ Docker is not available or not running(ansi reset)"
        exit 1
    }

    # Build the Docker image
    try {
        docker build -f $dockerfile -t $image_tag .
        print $"(ansi green)✅ Docker image built successfully: ($image_tag)(ansi reset)"

        # Show image info
        let image_info = (docker images $image_tag --format "table {{.Repository}}:{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}")
        print $"(ansi blue)📊 Image info:(ansi reset)"
        print $image_info

    } catch {
        print $"(ansi red)❌ Failed to build Docker image(ansi reset)"
        exit 1
    }
}
