"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CANONICAL_TEMPLATE_ROOT = void 0;
exports.resolveTemplateSourceAbsolutePath = resolveTemplateSourceAbsolutePath;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const paths_1 = require("../../../lib/paths");
const path_resolution_1 = require("../../../lib/templates/path-resolution");
Object.defineProperty(exports, "CANONICAL_TEMPLATE_ROOT", { enumerable: true, get: function () { return path_resolution_1.CANONICAL_TEMPLATE_ROOT; } });
const default_assets_1 = require("../../../lib/workspace-init/default-assets");
function resolveTemplateSourceAbsolutePath(options) {
    const workspaceAbsolutePath = (0, path_resolution_1.resolveWorkspaceTemplateAbsolutePath)(options);
    if (node_fs_1.default.existsSync(workspaceAbsolutePath)) {
        return {
            source: "workspace",
            absolutePath: workspaceAbsolutePath
        };
    }
    const packageRoot = (0, default_assets_1.resolvePackageRootFromWorkspaceInitModuleDirectory)(node_path_1.default.resolve(__dirname, "../../../lib/workspace-init"));
    const packageAbsolutePath = (0, paths_1.resolveRepositoryRelativePath)(packageRoot, options.templatePath);
    if (node_fs_1.default.existsSync(packageAbsolutePath)) {
        return {
            source: "package",
            absolutePath: packageAbsolutePath
        };
    }
    return null;
}
