---
import { Image } from "astro:assets";
import Social from "./Social.astro";
import pb from "../lib/pb";
import c from "../lib/config";



const avatarRec = await pb
  .collection("images")
  .getFirstListItem("useAsAvatar=true").catch(() => null);
const icon = avatarRec ? await pb.files.getUrl(avatarRec, avatarRec.file) : null;
const socials = await pb.collection("socials").getFullList();

const config = {
  icon,
  socials,
  title: c.TITLE,
  description: c.DESCRIPTION,
};
---

<aside>
  <div class="p-4">
    <a href="/">
      {
        config.icon && (
          <Image
            class={"icon"}
            src={config.icon}
            alt={"Icon"}
            width={50}
            height={50}
          />
        )
      }
      <h1 class="font-bold text-2xl pt-4">{config.title}</h1></a
    >
    <p class="pt-4">{config.description}</p>
    {
      config.socials &&
        config.socials.map((s) => (
          <Social href={s.url} text={s.name} image={s.icon} alt={s.name} />
        ))
    }
  </div>
</aside>

<style>
  img.icon {
    width: 10rem;
      height: 10rem;
      margin: 0 auto;
      object-fit: cover;
      object-position: center;
      border-radius: 50%;
  }
</style>
