import * as React from "react";
import { jsxLF } from "../util";
import { Badge } from "./Badge";
export interface BadgeInfoProps {
badge: pxt.auth.Badge;
}
export const BadgeInfo = (props: BadgeInfoProps) => {
const { badge } = props;
const date = new Date(badge.timestamp)
return
{lf("Awarded For:")}
{badgeDescription(badge)}
{ badge.timestamp ?
{lf("Awarded On:")}
{date.toLocaleDateString(pxt.U.userLanguage())}
: undefined }
}
export const badgeDescription = (badge: pxt.auth.Badge) => {
switch (badge.type) {
case "skillmap-completion":
return {jsxLF(
lf("Completing {0}"),
{pxt.U.rlf(badge.title)}
)}
}
}
function sourceURLToSkillmapURL(sourceURL: string) {
if (sourceURL.indexOf("/api/md/") !== -1) {
// docs url: https://www.makecode.com/api/md/arcade/skillmap/forest
const path = sourceURL.split("/api/md/")[1];
// remove the target from the url
const docsPath = path.split("/").slice(1).join("/");
return pxt.webConfig?.skillmapUrl + "#docs:" + docsPath;
}
else {
// github url: /user/repo#filename
const parts = sourceURL.split("#");
if (parts.length == 2) {
return pxt.webConfig.skillmapUrl + "#github:https://github.com/" + parts[0] + "/" + parts[1];
}
}
if (pxt.BrowserUtils.isLocalHostDev()) {
// local url: skillmap/forest
return "http://localhost:3000#local:" + sourceURL
}
return sourceURL;
}