---
import { ShowcaseText } from "starlight-showcases";

import { getResourcesByType, type ResourceType } from "../libs/resources";

export type ResourceProps = Props;

interface Props {
  type: ResourceType;
  resourcesUrl?: string | undefined;
  githubOrg?: string | undefined;
}

const { type, resourcesUrl, githubOrg = "trueberryless-org" } = Astro.props;

const resources = await getResourcesByType(type, resourcesUrl);
---

{
  resources && resources.length > 0 ? (
    <ShowcaseText
      entries={resources.map((resource) => ({
        href:
          resource.url ?? `https://github.com/${githubOrg}/${resource.name}`,
        title: resource.name,
        description: resource.description,
      }))}
    />
  ) : (
    <p>
      {githubOrg} has not yet published any {type}.
    </p>
  )
}
