import { defineTemplate } from "../metadata-types.js";
import { firstOf, hasDependencyWithId, isAuthoredBy, isOnGithubAccountOf, toBasicLicenses, toLocalUrl, toStatusLegacy, usesPnpm } from "../utilities/template-helpers.js";
import { codemetaJson } from "./codemeta-json.js";
//#region src/lib/templates/project.ts
/**
* Legacy structure used in AllWork desktop app
*/
const project = defineTemplate((context, templateData) => {
	const codemeta = codemetaJson(context, templateData);
	const dependencyUpdates = firstOf(context.dependencyUpdates);
	const github = firstOf(context.github)?.data;
	const gitStats = firstOf(context.gitStats)?.data;
	const metascope = context.metascope?.data;
	const nodeNpmRegistry = firstOf(context.nodeNpmRegistry)?.data;
	const nodePackageJson = firstOf(context.nodePackageJson);
	return {
		description: codemeta.description,
		firstCommitDate: gitStats?.commitDateFirst,
		gitHubLink: github?.url,
		gitHubStarCount: github?.stargazerCount,
		gitIsClean: gitStats?.isClean,
		gitIsDirty: gitStats?.isDirty,
		gitRemoteCount: gitStats?.remoteCount,
		homepage: github?.homepageUrl ?? codemeta.url ?? github?.url,
		isAuthoredByMe: isAuthoredBy(codemeta.author, templateData.authorName),
		isOnMyGitHub: isOnGithubAccountOf(codemeta.codeRepository, templateData.githubAccount),
		isOnNpm: nodeNpmRegistry?.url !== void 0,
		isPublic: !(github?.isPrivate ?? false),
		isRemoteAhead: gitStats?.isRemoteAhead,
		issueCount: github?.issueCountOpen,
		lastCommitDate: gitStats?.commitDateLast,
		license: toBasicLicenses(codemeta.license ?? github?.licenseSpdxId)?.at(0),
		majorUpdateCount: dependencyUpdates?.data.major?.length ?? 0,
		majorUpdateList: dependencyUpdates?.data.major?.map((value) => value.name),
		npmDownloadCount: nodeNpmRegistry?.downloadsTotal,
		readmePath: toLocalUrl(codemeta.readme, metascope?.options.path),
		repositoryPath: metascope?.options.path === void 0 ? void 0 : `file://${metascope.options.path}`,
		semverUpdateCount: void 0,
		semverUpdateList: void 0,
		tags: codemeta.keywords,
		title: codemeta.name,
		type: toStatusLegacy(codemeta.codeRepository, codemeta.author, templateData.authorName, templateData.githubAccount),
		usesPnpm: usesPnpm(nodePackageJson),
		usesSharedConfig: hasDependencyWithId("@kitschpatrol/shared-config", codemeta),
		version: codemeta.version
	};
});
//#endregion
export { project };
