#!/bin/zsh

# ============================================================================
#  CODEBASE COLLECTOR — "Give the AI EVERYTHING"
#  Recursively grabs every code file, config, .env, Docker stuff, scripts,
#  and packs it into one beautiful file with a full file map.
# ============================================================================

setopt NULL_GLOB 2>/dev/null

# ── CONFIG ──────────────────────────────────────────────────────────────────
OUTPUT_FILE="FULL_CODEBASE.txt"
TARGET_DIR="${1:-.}"
MAX_FILE_SIZE_KB=500
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")

# ── COLORS ──────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'

# ── FILE EXTENSIONS TO INCLUDE ──────────────────────────────────────────────
CODE_EXTENSIONS=(
    py js ts jsx tsx go rs rb php java kt kts
    scala c h cpp hpp cc cxx cs swift m mm
    r R pl pm lua zig nim dart ex exs erl hrl
    hs lhs ml mli fs fsx clj cljs cljc v sv
    vhd vhdl sol move cairo
    html htm css scss sass less styl
    vue svelte astro mdx
    sh bash zsh fish ps1 psm1 bat cmd
    json jsonc json5 yaml yml toml ini cfg conf
    xml xsl xslt plist hcl tf tfvars
    md markdown txt rst adoc tex org
    sql prisma graphql gql
    gradle sbt cmake mk
    gemspec podspec
    env editorconfig prettierrc eslintrc babelrc browserslistrc
    stylelintrc commitlintrc
    lock map csv tsv
    proto thrift avsc
    ipynb
    ejs hbs handlebars pug jade njk twig jinja j2
)

# ── EXACT FILENAMES TO ALWAYS INCLUDE ───────────────────────────────────────
EXACT_FILENAMES=(
    Dockerfile Dockerfile.dev Dockerfile.prod Dockerfile.staging
    docker-compose.yml docker-compose.yaml docker-compose.dev.yml
    docker-compose.prod.yml docker-compose.override.yml
    .dockerignore .gitignore .gitattributes .gitmodules
    .editorconfig
    .prettierrc .prettierrc.json .prettierrc.yml .prettierrc.yaml
    .prettierrc.js .prettierrc.cjs .prettierrc.toml .prettier.config.js
    .eslintrc .eslintrc.js .eslintrc.cjs .eslintrc.json .eslintrc.yml .eslintrc.yaml
    .babelrc .babelrc.json .stylelintrc .stylelintrc.json
    .env .env.local .env.development .env.production .env.staging
    .env.test .env.example .env.sample .env.template
    .flake8 .pylintrc .rubocop.yml .ruby-version .node-version .nvmrc
    .python-version .tool-versions
    Makefile makefile GNUmakefile Rakefile Gemfile Gemfile.lock
    Pipfile Pipfile.lock Cargo.toml Cargo.lock go.mod go.sum
    package.json package-lock.json yarn.lock pnpm-lock.yaml bun.lockb
    tsconfig.json tsconfig.base.json tsconfig.build.json jsconfig.json
    webpack.config.js webpack.config.ts vite.config.js vite.config.ts
    rollup.config.js rollup.config.ts esbuild.config.js
    next.config.js next.config.mjs next.config.ts
    nuxt.config.js nuxt.config.ts svelte.config.js astro.config.mjs
    tailwind.config.js tailwind.config.ts postcss.config.js postcss.config.cjs
    jest.config.js jest.config.ts vitest.config.ts vitest.config.js
    pytest.ini setup.py setup.cfg pyproject.toml
    requirements.txt requirements-dev.txt requirements.in constraints.txt
    tox.ini poetry.lock composer.json composer.lock
    build.gradle build.gradle.kts settings.gradle settings.gradle.kts
    pom.xml CMakeLists.txt meson.build
    Justfile justfile Taskfile.yml Taskfile.yaml Earthfile Tiltfile Brewfile
    Procfile Vagrantfile Jenkinsfile
    cloudbuild.yaml serverless.yml serverless.yaml serverless.ts
    fly.toml render.yaml app.yaml app.json vercel.json netlify.toml
    firebase.json .firebaserc angular.json nx.json project.json workspace.json
    lerna.json turbo.json .swcrc biome.json deno.json deno.jsonc import_map.json
    renovate.json .releaserc .releaserc.json .releaserc.yml
    CODEOWNERS LICENSE LICENSE.md LICENSE.txt
    CHANGELOG.md CONTRIBUTING.md README.md README.rst TODO.md
)

# ── DIRECTORIES TO SKIP ─────────────────────────────────────────────────────
SKIP_DIRS=(
    node_modules .git .svn .hg
    __pycache__ .pytest_cache .mypy_cache .ruff_cache .tox .nox
    venv .venv .env_dir virtualenv .virtualenv
    .idea .vscode .vs
    dist build out target bin obj
    .next .nuxt .output .svelte-kit .astro .vercel .netlify .serverless
    .terraform .gradle .maven .cargo
    vendor Pods DerivedData
    .sass-cache .parcel-cache .turbo .cache
    coverage .nyc_output htmlcov
    .eggs .bundle
    tmp temp logs
    __MACOSX
)

# ── CHECK IF PATH IS INSIDE A SKIPPED DIR ──────────────────────────────────
is_in_skip_dir() {
    local filepath="$1"
    for dir in "${SKIP_DIRS[@]}"; do
        if [[ "$filepath" == *"/${dir}/"* ]] || [[ "$filepath" == *"/${dir}" ]]; then
            return 0
        fi
        # Also catch ./dir/ at the start
        if [[ "$filepath" == "${dir}/"* ]] || [[ "$filepath" == "./${dir}/"* ]]; then
            return 0
        fi
    done
    return 1
}

# ── CHECK IF FILE SHOULD BE INCLUDED ───────────────────────────────────────
should_include() {
    local filepath="$1"
    local filename="${filepath:t}"   # zsh way to get basename
    local extension="${filename:e}"  # zsh way to get extension

    # Check exact filename matches
    for exact in "${EXACT_FILENAMES[@]}"; do
        if [[ "$filename" == "$exact" ]]; then
            return 0
        fi
    done

    # Catch .env.anything
    if [[ "$filename" == .env* ]]; then
        return 0
    fi

    # Catch Dockerfile.anything
    if [[ "$filename" == Dockerfile* ]] || [[ "$filename" == dockerfile* ]]; then
        return 0
    fi

    # Catch docker-compose*.anything
    if [[ "$filename" == docker-compose* ]]; then
        return 0
    fi

    # Catch GitHub Actions / CI workflows
    if [[ "$filepath" == *".github/"* ]] && [[ "$extension" == "yml" || "$extension" == "yaml" ]]; then
        return 0
    fi

    # Check extension match
    if [[ -n "$extension" ]]; then
        for ext in "${CODE_EXTENSIONS[@]}"; do
            if [[ "$extension" == "$ext" ]]; then
                return 0
            fi
        done
    fi

    return 1
}

# ── CHECK IF FILE IS BINARY ────────────────────────────────────────────────
is_binary() {
    local filepath="$1"
    local mime
    mime=$(file --mime-encoding "$filepath" 2>/dev/null)
    if [[ "$mime" == *"binary"* ]]; then
        return 0
    fi
    return 1
}

# ── DETECT LANGUAGE FOR SYNTAX HINT ────────────────────────────────────────
get_language_hint() {
    local filename="${1:t}"
    local ext="${filename:e}"

    # Exact name matches first
    case "$filename" in
        Dockerfile*)         echo "dockerfile"; return ;;
        Makefile|makefile|GNUmakefile) echo "makefile"; return ;;
        Jenkinsfile)         echo "groovy"; return ;;
        Vagrantfile|Rakefile|Gemfile) echo "ruby"; return ;;
        *.env*)              echo "dotenv"; return ;;
    esac

    case "$ext" in
        py)         echo "python" ;;
        js)         echo "javascript" ;;
        ts)         echo "typescript" ;;
        jsx)        echo "jsx" ;;
        tsx)        echo "tsx" ;;
        go)         echo "go" ;;
        rs)         echo "rust" ;;
        rb)         echo "ruby" ;;
        php)        echo "php" ;;
        java)       echo "java" ;;
        kt|kts)     echo "kotlin" ;;
        scala)      echo "scala" ;;
        c|h)        echo "c" ;;
        cpp|hpp|cc) echo "cpp" ;;
        cs)         echo "csharp" ;;
        swift)      echo "swift" ;;
        html|htm)   echo "html" ;;
        css)        echo "css" ;;
        scss)       echo "scss" ;;
        json|jsonc) echo "json" ;;
        yaml|yml)   echo "yaml" ;;
        toml)       echo "toml" ;;
        xml)        echo "xml" ;;
        sql)        echo "sql" ;;
        sh|bash)    echo "bash" ;;
        zsh)        echo "zsh" ;;
        md)         echo "markdown" ;;
        graphql|gql) echo "graphql" ;;
        tf|hcl)     echo "hcl" ;;
        lua)        echo "lua" ;;
        dart)       echo "dart" ;;
        ex|exs)     echo "elixir" ;;
        vue)        echo "vue" ;;
        svelte)     echo "svelte" ;;
        prisma)     echo "prisma" ;;
        sol)        echo "solidity" ;;
        ini|cfg|conf) echo "ini" ;;
        proto)      echo "protobuf" ;;
        r|R)        echo "r" ;;
        *)          echo "plaintext" ;;
    esac
}

# ── MAIN ────────────────────────────────────────────────────────────────────

echo ""
echo "${BOLD}${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}"
echo "${BOLD}${CYAN}║          🔥  CODEBASE COLLECTOR — GRAB EVERYTHING  🔥       ║${NC}"
echo "${BOLD}${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""

# Resolve to absolute path
ABS_TARGET=$(cd "$TARGET_DIR" && pwd)

echo "${YELLOW}Target directory:${NC} $ABS_TARGET"
echo "${YELLOW}Output file:${NC}      $OUTPUT_FILE"
echo "${YELLOW}Max file size:${NC}    ${MAX_FILE_SIZE_KB}KB"
echo ""

# ── PHASE 1: COLLECT ALL FILE PATHS ────────────────────────────────────────
echo "${CYAN}[1/4]${NC} 🔍 Scanning for files..."

collected_files=()
skipped_binary=()
skipped_size=()
skipped_self=0
total_scanned=0

# Simple and robust: just find ALL regular files, filter in the loop
while IFS= read -r file; do
    total_scanned=$((total_scanned + 1))

    # Skip our own output file
    local_name="${file:t}"
    if [[ "$local_name" == "$OUTPUT_FILE" ]] || [[ "$local_name" == "CollectCode.sh" ]]; then
        skipped_self=$((skipped_self + 1))
        continue
    fi

    # Make a relative path for checking skip dirs
    relpath="${file#$ABS_TARGET/}"

    # Check if in a skipped directory
    if is_in_skip_dir "$relpath"; then
        continue
    fi

    # Check if we care about this file
    if should_include "$file"; then
        # Check file size
        local_size=$(stat -f%z "$file" 2>/dev/null || wc -c < "$file" 2>/dev/null | tr -d ' ')
        local_size_kb=$((local_size / 1024))

        if [[ $local_size_kb -gt $MAX_FILE_SIZE_KB ]]; then
            skipped_size+=("$relpath (${local_size_kb}KB)")
            continue
        fi

        # Check if binary
        if is_binary "$file"; then
            skipped_binary+=("$relpath")
            continue
        fi

        collected_files+=("$file")
    fi
done < <(find "$ABS_TARGET" -type f 2>/dev/null | sort)

echo "${GREEN}   ✓ Scanned ${total_scanned} total files${NC}"
echo "${GREEN}   ✓ Found ${#collected_files[@]} files to include${NC}"
[[ ${#skipped_binary[@]} -gt 0 ]] && echo "${YELLOW}   ⊘ Skipped ${#skipped_binary[@]} binary files${NC}"
[[ ${#skipped_size[@]} -gt 0 ]] && echo "${YELLOW}   ⊘ Skipped ${#skipped_size[@]} files over ${MAX_FILE_SIZE_KB}KB${NC}"

if [[ ${#collected_files[@]} -eq 0 ]]; then
    echo ""
    echo "${RED}   ✗ No files found!${NC}"
    echo ""
    echo "${YELLOW}   DEBUG: Listing first 20 files found by find:${NC}"
    find "$ABS_TARGET" -type f 2>/dev/null | head -20 | while read f; do
        relp="${f#$ABS_TARGET/}"
        echo "     $relp"
    done
    echo ""
    echo "${YELLOW}   If you see files above, the extension/name filter isn't matching them.${NC}"
    echo "${YELLOW}   Check CODE_EXTENSIONS and EXACT_FILENAMES arrays in the script.${NC}"
    exit 1
fi

# ── PHASE 2: ORGANIZE + STATS ──────────────────────────────────────────────
echo "${CYAN}[2/4]${NC} 📂 Building file map..."

total_lines=0
total_bytes=0
typeset -A ext_count

for file in "${collected_files[@]}"; do
    lines=$(wc -l < "$file" 2>/dev/null | tr -d ' ')
    bytes=$(stat -f%z "$file" 2>/dev/null || wc -c < "$file" 2>/dev/null | tr -d ' ')
    total_lines=$((total_lines + lines))
    total_bytes=$((total_bytes + bytes))

    fname="${file:t}"
    ext="${fname:e}"
    # For dotfiles without extension, use filename
    if [[ -z "$ext" ]]; then
        ext="$fname"
    fi
    ext_count[$ext]=$(( ${ext_count[$ext]:-0} + 1 ))
done

# Human-readable size
if [[ $total_bytes -gt 1048576 ]]; then
    total_size="$(( total_bytes / 1048576 )).$(( (total_bytes % 1048576) * 10 / 1048576 ))MB"
elif [[ $total_bytes -gt 1024 ]]; then
    total_size="$(( total_bytes / 1024 ))KB"
else
    total_size="${total_bytes}B"
fi

echo "${GREEN}   ✓ ${#collected_files[@]} files, ${total_lines} lines, ${total_size}${NC}"

echo "${CYAN}[3/4]${NC} 📊 Sorting file types..."

# Build sorted type breakdown string
type_breakdown=""
for ext in "${(@k)ext_count}"; do
    type_breakdown+="${ext_count[$ext]} .${ext}\n"
done
type_breakdown=$(echo "$type_breakdown" | sort -rn)

echo "${GREEN}   ✓ Found ${#ext_count[@]} different file types${NC}"

# ── PHASE 3: WRITE OUTPUT ──────────────────────────────────────────────────
echo "${CYAN}[4/4]${NC} ✍️  Writing ${OUTPUT_FILE}..."

{
    cat << 'HEADER_ART'
################################################################################
#                                                                              #
#   ██████╗ ██████╗ ██████╗ ███████╗██████╗  █████╗ ███████╗███████╗          #
#  ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔══██╗██╔════╝██╔════╝          #
#  ██║     ██║   ██║██║  ██║█████╗  ██████╔╝███████║███████╗█████╗            #
#  ██║     ██║   ██║██║  ██║██╔══╝  ██╔══██╗██╔══██║╚════██║██╔══╝            #
#  ╚██████╗╚██████╔╝██████╔╝███████╗██████╔╝██║  ██║███████║███████╗          #
#   ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═╝  ╚═╝╚══════╝╚══════╝          #
#                                                                              #
#          COMPLETE CODEBASE DUMP — EVERY FILE, EVERY LINE                     #
#                                                                              #
################################################################################
HEADER_ART

    echo ""
    echo "=============================================================================="
    echo " PROJECT CODEBASE — FULL SOURCE DUMP"
    echo "=============================================================================="
    echo ""
    echo " Generated:       $TIMESTAMP"
    echo " Source Dir:       $ABS_TARGET"
    echo " Total Files:      ${#collected_files[@]}"
    echo " Total Lines:      ${total_lines}"
    echo " Total Size:       ${total_size}"
    echo ""
    echo " THIS FILE CONTAINS THE COMPLETE CODEBASE INCLUDING:"
    echo "   • All source code files (every language found)"
    echo "   • All configuration files (json, yaml, toml, xml, ini, etc.)"
    echo "   • All environment files (.env, .env.local, .env.production, etc.)"
    echo "   • All Docker files (Dockerfile, docker-compose.yml, .dockerignore)"
    echo "   • All CI/CD configs (Jenkinsfile, GitHub Actions, etc.)"
    echo "   • All build configs (webpack, vite, tsconfig, Makefile, etc.)"
    echo "   • All package manifests (package.json, Cargo.toml, go.mod, etc.)"
    echo "   • All lock files (package-lock.json, yarn.lock, etc.)"
    echo "   • All documentation (README, CHANGELOG, LICENSE, etc.)"
    echo "   • All scripts (shell, python, etc.)"
    echo ""
    echo " STRUCTURE OF THIS FILE:"
    echo "   1. DIRECTORY TREE"
    echo "   2. FILE MAP (indexed table of every file)"
    echo "   3. FILE TYPE BREAKDOWN (stats by extension)"
    echo "   4. SKIPPED FILES (binary/oversized — for transparency)"
    echo "   5. COMPLETE FILE CONTENTS (every file printed in full)"
    echo ""
    echo "=============================================================================="
    echo ""
    echo ""

    # ── SECTION 1: DIRECTORY TREE ───────────────────────────────────────────
    echo "╔══════════════════════════════════════════════════════════════════════════════╗"
    echo "║  SECTION 1: DIRECTORY TREE                                                  ║"
    echo "╚══════════════════════════════════════════════════════════════════════════════╝"
    echo ""

    if command -v tree &>/dev/null; then
        tree_ignore=$(printf "%s|" "${SKIP_DIRS[@]}")
        tree_ignore="${tree_ignore%|}"
        tree -a -I "$tree_ignore" --charset=utf-8 "$ABS_TARGET" 2>/dev/null || echo "(tree output failed)"
    else
        echo "(For a visual tree: brew install tree)"
        echo ""
        echo "Collected file paths:"
        for file in "${collected_files[@]}"; do
            relpath="${file#$ABS_TARGET/}"
            echo "  $relpath"
        done
    fi

    echo ""
    echo ""

    # ── SECTION 2: FILE MAP ─────────────────────────────────────────────────
    echo "╔══════════════════════════════════════════════════════════════════════════════╗"
    echo "║  SECTION 2: FILE MAP — INDEXED LIST OF ALL ${#collected_files[@]} FILES"
    echo "╚══════════════════════════════════════════════════════════════════════════════╝"
    echo ""
    echo " Each file below appears in SECTION 5 with full contents."
    echo " Use [###] index to jump to any file."
    echo ""
    printf " %-6s  %-7s  %-8s  %s\n" "INDEX" "LINES" "SIZE" "FILE PATH"
    printf " %-6s  %-7s  %-8s  %s\n" "-----" "-----" "------" "----------------------------------------------"

    idx=1
    for file in "${collected_files[@]}"; do
        relpath="${file#$ABS_TARGET/}"
        lines=$(wc -l < "$file" 2>/dev/null | tr -d ' ')
        bytes=$(stat -f%z "$file" 2>/dev/null || wc -c < "$file" 2>/dev/null | tr -d ' ')

        if [[ $bytes -gt 1024 ]]; then
            size="$(( bytes / 1024 ))KB"
        else
            size="${bytes}B"
        fi

        printf " [%03d]  %-7s  %-8s  %s\n" "$idx" "$lines" "$size" "$relpath"
        idx=$((idx + 1))
    done

    echo ""
    echo ""

    # ── SECTION 3: FILE TYPE BREAKDOWN ──────────────────────────────────────
    echo "╔══════════════════════════════════════════════════════════════════════════════╗"
    echo "║  SECTION 3: FILE TYPE BREAKDOWN                                             ║"
    echo "╚══════════════════════════════════════════════════════════════════════════════╝"
    echo ""
    printf " %-25s  %s\n" "EXTENSION/TYPE" "COUNT"
    printf " %-25s  %s\n" "───────────────────────" "─────"

    echo "$type_breakdown" | while read count ext; do
        [[ -z "$count" ]] && continue
        printf " %-25s  %s\n" "$ext" "$count"
    done

    echo ""
    echo ""

    # ── SECTION 4: SKIPPED FILES ────────────────────────────────────────────
    if [[ ${#skipped_binary[@]} -gt 0 || ${#skipped_size[@]} -gt 0 ]]; then
        echo "╔══════════════════════════════════════════════════════════════════════════════╗"
        echo "║  SECTION 4: SKIPPED FILES (listed for completeness)                         ║"
        echo "╚══════════════════════════════════════════════════════════════════════════════╝"
        echo ""

        if [[ ${#skipped_binary[@]} -gt 0 ]]; then
            echo " Binary files (not text):"
            for f in "${skipped_binary[@]}"; do
                echo "   ⊘ $f"
            done
            echo ""
        fi

        if [[ ${#skipped_size[@]} -gt 0 ]]; then
            echo " Oversized files (>${MAX_FILE_SIZE_KB}KB):"
            for f in "${skipped_size[@]}"; do
                echo "   ⊘ $f"
            done
            echo ""
        fi
        echo ""
    fi

    # ── SECTION 5: FILE CONTENTS ────────────────────────────────────────────
    echo "╔══════════════════════════════════════════════════════════════════════════════╗"
    echo "║  SECTION 5: COMPLETE FILE CONTENTS                                          ║"
    echo "║                                                                              ║"
    echo "║  Every file printed in full with:                                            ║"
    echo "║    • Clear start/end markers                                                 ║"
    echo "║    • File path, size, line count in the header                               ║"
    echo "║    • Language hint for syntax context                                        ║"
    echo "╚══════════════════════════════════════════════════════════════════════════════╝"
    echo ""
    echo ""

    idx=1
    for file in "${collected_files[@]}"; do
        relpath="${file#$ABS_TARGET/}"
        lines=$(wc -l < "$file" 2>/dev/null | tr -d ' ')
        bytes=$(stat -f%z "$file" 2>/dev/null || wc -c < "$file" 2>/dev/null | tr -d ' ')
        lang=$(get_language_hint "$file")

        echo "┌──────────────────────────────────────────────────────────────────────────────"
        echo "│ 📄 FILE [$(printf '%03d' $idx)/${#collected_files[@]}]: $relpath"
        echo "│ LANGUAGE: $lang | LINES: $lines | SIZE: ${bytes} bytes"
        echo "├──────────────────────────────────────────────────────────────────────────────"
        echo "│"

        if [[ -s "$file" ]]; then
            cat -n "$file" 2>/dev/null || echo "│ [ERROR: Could not read file]"
        else
            echo "│ [EMPTY FILE]"
        fi

        echo "│"
        echo "└──────────────────────────────────────────────────────────────────────────────"
        echo "   ✅ END OF [$(printf '%03d' $idx)]: $relpath"
        echo ""
        echo ""

        # Progress to stderr
        if (( idx % 25 == 0 )); then
            echo "   ... ${idx}/${#collected_files[@]} files written ..." >&2
        fi

        idx=$((idx + 1))
    done

    # ── FOOTER ──────────────────────────────────────────────────────────────
    echo ""
    echo "################################################################################"
    echo "#                                                                              #"
    echo "#                     ✅ END OF COMPLETE CODEBASE DUMP                         #"
    echo "#                                                                              #"
    printf "#  Total Files:  %-58s #\n" "${#collected_files[@]}"
    printf "#  Total Lines:  %-58s #\n" "${total_lines}"
    printf "#  Total Size:   %-58s #\n" "${total_size}"
    printf "#  Generated:    %-58s #\n" "${TIMESTAMP}"
    echo "#                                                                              #"
    echo "#  This file contains EVERYTHING: source code, configs, env vars, Docker,      #"
    echo "#  CI/CD, build tools, package manifests, docs — the complete picture.          #"
    echo "#                                                                              #"
    echo "################################################################################"

} > "$OUTPUT_FILE"

# ── DONE ────────────────────────────────────────────────────────────────────
output_bytes=$(stat -f%z "$OUTPUT_FILE" 2>/dev/null || wc -c < "$OUTPUT_FILE" | tr -d ' ')
if [[ $output_bytes -gt 1048576 ]]; then
    output_human="$(( output_bytes / 1048576 ))MB"
elif [[ $output_bytes -gt 1024 ]]; then
    output_human="$(( output_bytes / 1024 ))KB"
else
    output_human="${output_bytes}B"
fi

echo ""
echo "${BOLD}${GREEN}╔══════════════════════════════════════════════════════════════╗${NC}"
echo "${BOLD}${GREEN}║                    ✅  DONE — ALL COLLECTED                  ║${NC}"
echo "${BOLD}${GREEN}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo "  ${BOLD}Output:${NC}       $OUTPUT_FILE"
echo "  ${BOLD}Output size:${NC}  $output_human"
echo "  ${BOLD}Files:${NC}        ${#collected_files[@]}"
echo "  ${BOLD}Total lines:${NC}  ${total_lines}"
echo ""
echo "  ${YELLOW}Feed this to any AI and it'll know your ENTIRE codebase.${NC}"
echo ""