/*
HelloDom — the minimum DOM-mode example. Build with:
    crafter-build --local --target=wasm32-wasip1

Output lands in bin/HelloDom-wasm32-wasip1-native-native-<hash>/. The
runtime expects a co-located dom-env.js (provided by Crafter.Graphics
itself) plus a runtime.js / index.html pair that wires the env into the
WebAssembly imports — see EnableWasiBrowserRuntime in Crafter.Build.
*/
import std;
import Crafter.Build;
namespace fs = std::filesystem;
using namespace Crafter;

extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
    std::vector<std::string> depArgs(args.begin(), args.end());
    depArgs.push_back("--target=wasm32-wasip1");
    Configuration* graphics = LocalProject({
        .projectFile = "../../project.cpp",
        .args = depArgs,
    });

    Configuration cfg;
    cfg.path = "./";
    cfg.name = "HelloDom";
    cfg.outputName = "HelloDom";
    cfg.type = ConfigurationType::Executable;
    cfg.target = "wasm32-wasip1";
    ApplyStandardArgs(cfg, args);
    cfg.dependencies = { graphics };

    std::array<fs::path, 0> ifaces = {};
    std::array<fs::path, 1> impls = { "main" };
    cfg.GetInterfacesAndImplementations(ifaces, impls);

    // Generates index.html + runtime.js in the bin dir so the .wasm can
    // be loaded directly in a browser via a static file server.
    EnableWasiBrowserRuntime(cfg);

    return cfg;
}
