import { cookies } from 'next/headers';
import Image from 'next/image';
import { format } from 'date-fns';
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
import { NodeHiveConfig } from '@/config/nodehive.config';
import { createServerClient } from '@/lib/nodehive';
export default async function ArticleList() {
const client = createServerClient();
// Add filters and limit
const apiParams = new DrupalJsonApiParams();
apiParams.addSort('created', 'DESC');
//apiParams.addFields('node--article', ['field_image']);
apiParams.addPageLimit(5);
//apiParams.addFilter('field_tags.name', 'ai','=')
const articles = await client.getNodes('article', '', apiParams);
//console.log(articles);
return (
<div>
<section data-paragraph-type="ArticleList">
<h2 className="mb-4 text-4xl font-bold tracking-tight text-zinc-800 sm:text-5xl">
{title && title}
</h2>
<div className="bg-white text-black">
<ul className="divide-y divide-gray-300">
{articles.data.map((article, index) => (
<li key={index} className="flex justify-between gap-4 py-3">
<a
href={`/node/${article.drupal_internal__nid}`}
className="truncate font-medium text-red-600 hover:text-red-700"
>
{!article.status && (
<span
className="mb mr-5 border-l-4 border-yellow-500 bg-yellow-100 p-4 text-yellow-700"
role="alert"
>
<span className="font-bold">Unpublished.</span>
</span>
)}
{article.title}
</a>
</li>
))}
</ul>
</div>
{/*
<details>
<summary>JSON Output</summary>
<pre className="rounded-md bg-black p-8 text-xs text-slate-50">
{JSON.stringify(articles, null, 2)}
</pre>
</details>
*/}
</section>
</div>
);
}