# Selective imports (ADR-025 Phase 3 Layer 2).
use lib_provisioning/config/accessor/functions.nu [get-provisioning-url]

# Display QR code for URL using qr_maker plugin or fallback
def show_qr [url: string]: nothing -> nothing {
    let has_qr_plugin = ((version).installed_plugins | str contains "qr_maker")

    if $has_qr_plugin {
        print ($url | to qr)
    } else {
        let qr_path = ((get-provisioning-resources) | path join "qrs" | path join ($url | path basename))
        if ($qr_path | path exists) {
            print (open -r $qr_path)
        } else {
            print $"(ansi blue_reverse)($url)(ansi reset)"
            print $"(ansi purple)($url)(ansi reset)"
        }
    }
}

export def "make_qr"  [
  url?: string
] {
  show_qr ($url | default (get-provisioning-url))
}
