const externalLinksConfig = [
	{
		name: "Lemmy",
		id: "lemmy",
		generateLink: (link) => {
			if (link.startsWith("@")) {
				return "https://" + link + "/";
			} else if (link.startsWith("!") && link.indexOf("@") !== -1) {
				let community = link.substring(1).split("@")[0];
				let host = link.split("@")[1];
				return "https://" + host + "/c/" + community;
			} else {
				return link;
			}
		},
		listingClass: "bi-envelope", //TODO: canvas adaptation: actually put a lemmy icon
		generateListingName: (link) => link,
		placeholder: "!community@example.org",
		configureInputField: (inputField) => {
			inputField.placeholder = "!community@example.com";
			inputField.title =
				"Lemmy link using the !community@example.com format, a Lemmy domain using the @example.com format or a post with it’s url";
		},
	},
	{
		name: "Matrix",
		id: "matrix",
		generateLink: (link) => "https://matrix.to/#/" + link,
		listingClass: "bi-chat-dots", //TODO: canvas adaptation: actually put a Matrix, if any exist
		generateListingName: (link) => link,
		placeholder: "#example:example.com",
		configureInputField: (inputField) => {
			inputField.placeholder = "#example:example.com";
			inputField.title =
				"Link to a Matrix room or space, in the form of #example:example.com";
			inputField.pattern = "#.*:.*";
		},
	},
	{
		name: "Website",
		id: "website",
		generateLink: (link) => link,
		listingClass: "bi-globe",
		generateListingName: (link) => {
			try {
				const urlObject = new URL(link);
				return urlObject.hostname.replace(/^www./, "");
			} catch (e) {
				return "Website";
			}
		},
		placeholder: "https://example.org",
		configureInputField: (inputField) => {
			inputField.type = "url";
			inputField.placeholder = "https://example.com";
			inputField.pattern = "https?://.*";
			inputField.title = "Website URL using the http:// or https:// protocol";
		},
	},
	{
		name: "Discord",
		id: "discord",
		generateLink: (link) => "https://discord.gg/" + link,
		generateListingName: (link) => link,
		listingClass: "bi-discord",
		editorPrefix: "discord.gg/",
		placeholder: "r/example",
		configureInputField: (inputField) => {
			inputField.placeholder = "pJkm23b2nA";
		},
		extractId: (content) => {
			const discordPattern =
				/^(?:(?:https?:\/\/)?(?:www\.)?(?:(?:discord)?\.?gg|discord(?:app)?\.com\/invite)\/)?([^\s/]+?)(?=\b)$/;
			id = content.trim().match(discordPattern)?.[1];
			if (id) {
				return id;
			}
			return content;
		},
	},
	{
		name: "Subreddit",
		id: "subreddit",
		generateLink: (link) => "https://reddit.com/r/" + link,
		listingClass: "bi-reddit",
		generateListingName: (link) => "r/" + link,
		editorPrefix: "reddit.com/",
		placeholder: "pJkm23b2nA",
		configureInputField: (inputField) => {
			inputField.placeholder = "r/example";
			inputField.pattern = "^r/[A-Za-z0-9][A-Za-z0-9_]{1,50}$";
			inputField.title = "Subreddit in format of r/example";
			inputField.minLength = "4";
			inputField.maxLength = "50";
		},
		extractId: (content) => {
			const subredditPattern =
				/^(?:(?:(?:(?:(?:https?:\/\/)?(?:(?:www|old|new|np)\.)?)?reddit\.com)?\/)?[rR]\/)?([A-Za-z0-9][A-Za-z0-9_]{1,20})(?:\/[^" ]*)*$/;
			id = content.trim().match(subredditPattern)?.[1];
			if (id) {
				return id;
			}
			return content;
		},
		formatIdInEditor: (content) => {
			if (content != "") {
				return "r/" + content;
			}
			return "";
		},
	},
];

console.info(
	`%cThe Fediverse Canvas Atlas
%cCopyright (c) 2017 Roland Rytz <roland@draemm.li>
Copyright (c) 2023 Place Atlas Initiative and contributors
Copyright (c) 2025 Fediverse Canvas Atlas contributors
Licensed under AGPL-3.0 (https://2023.place-atlas.stefanocoding.me/license.txt)

https://sc07.dev/fediverse.events/canvas-atlas

To get the image of the canvas, use downloadCanvas().
`,
	"font-size: 150%; line-height: 150%",
	""
);
