---
import { Icon } from 'astro-icon/components';
import { readItems } from '@directus/sdk';

import type { Project } from '@lib/directusTypes';

import directus from '@lib/directus';

const projects = await directus.request(
  readItems('site_projects', {
    fields: ['*'],
    sort: ['-isActive'],
  })
);

const baseClasses = 'smooth-reveal-cards rounded-xl flex flex-col';
const borderClasses = 'border border-neutral-100 dark:border-stone-500/20';
const bgColorClasses =
  'bg-neutral-100/80 hover:bg-neutral-100 dark:bg-neutral-800/60 dark:hover:bg-neutral-800/90';
const shadowClasses = 'shadow-xs hover:shadow-md dark:shadow-md dark:hover:shadow-lg';
---

<section class:list={['flex flex-col gap-4', Astro.props.className]}>
  <h3
    class="relative flex w-full items-center gap-3 pb-10 text-5xl text-neutral-800 dark:text-neutral-200"
  >
    Projects
  </h3>
  <div class="ml-8 grid grid-cols-1 gap-3 md:grid-cols-2 print:flex print:flex-col">
    {
      projects.map((project: Project) => {
        return (
          <div class={`${baseClasses}`}>
            <div
              class={`rounded-xl transition-all duration-300 ${borderClasses} ${bgColorClasses} ${shadowClasses}`}
            >
              <div class="p-4 md:p-10">
                <h3 class="text-lg font-bold text-gray-800 dark:text-white">{project.name}</h3>
                <p class="mt-2 text-gray-500 dark:text-neutral-400">{project.description}</p>
                <ul class="mt-1 flex list-disc flex-col gap-2 text-sm text-gray-500 dark:text-neutral-400 [&>li]:ml-4">
                  {project.highlights.map((highlight) => {
                    return <li class="marker:text-yellow-500">{highlight}</li>;
                  })}
                </ul>
                <div class="flex">
                  <a
                    class="group group-hover relative inline-block gap-x-1 rounded-lg border border-transparent disabled:pointer-events-none disabled:opacity-50"
                    href={project.url}
                  >
                    <div class="group-hover:text-steel dark:group-hover:text-bermuda transition-text text-md relative z-10 mx-auto flex min-h-[44px] items-center font-semibold text-neutral-600 decoration-2 duration-300 sm:mx-0 sm:mt-4 dark:text-neutral-300">
                      <span class="relative inline-block overflow-hidden"> Visit Page </span>
                      <Icon
                        name="mdi:keyboard-arrow-right"
                        class="translate-y-0.5 transition duration-300 group-hover:translate-x-1"
                      />
                    </div>
                  </a>
                  <a
                    class="group group-hover relative ml-auto inline-block gap-x-1 rounded-lg border border-transparent disabled:pointer-events-none disabled:opacity-50"
                    href={project.source}
                  >
                    <div class="group-hover:text-gitea-primary dark:group-hover:text-gitea-primary transition-text text-md relative z-10 mx-auto flex min-h-[44px] items-center font-semibold text-neutral-600 decoration-2 duration-300 sm:mx-0 sm:mt-4 dark:text-neutral-300">
                      <span class="relative inline-block overflow-hidden"> Source </span>
                      <Icon name="pajamas:gitea" class="ml-2 translate-y-0.5" />
                    </div>
                  </a>
                </div>
              </div>
            </div>
          </div>
        );
      })
    }
  </div>
</section>
