import { RenderFunc } from "https://esm.town/v/pomdtr/invoice_schema";
import clsx from "npm:clsx";
import { render as preactRender } from "npm:preact-render-to-string";
export const render: RenderFunc = ({ title, table, to, from, details }) => {
return preactRender(
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{title}</title>
<link rel="icon" href="https://fav.farm/📃" />
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-white">
<header>
<section>
<div class="px-8 py-24 flex flex-col mx-auto justify-center sm:px-12 lg:px-24 max-w-6xl">
<div class="flex justify-between items-start">
<div class="text-left text-sm space-y-1 text-gray-500">
{from.map((value) => <p>{value}</p>)}
</div>
<div class="text-right text-sm space-y-1 text-gray-500">
{to.map((value) => <p>{value}</p>)}
</div>
</div>
<div class="sm:flex sm:items-center mt-12">
<div class="sm:flex-auto">
<h1 class="text-xl">{title}</h1>
</div>
</div>
<div class="-mx-4 mt-24 flow-root sm:mx-0">
<table class="min-w-full">
<thead class="border-b border-gray-300 text-gray-900">
<tr>
{table.columns.map((column, idx) => (
<th
scope="col"
class={`px-3 py-3.5 text-left ${
clsx({
"text-left": idx == 0,
"text-right": idx > 0,
})
}`}
>
{column}
</th>
))}
</tr>
</thead>
<tbody>
{table.rows.map((row) => (
<tr class="border-b border-gray-200">
{row.map((item, idx) => (
<td
class={`hidden px-3 py-5 text-sm text-gray-500 sm:table-cell ${
clsx({
"text-left": idx == 0,
"text-right": idx > 0,
})
}`}
>
{item}
</td>
))}
</tr>
))}
</tbody>
<tfoot>
{table.summary.map(([key, value]) => (
<tr class="text-right">
<th
scope="row"
colspan={table.columns.length - 1}
class="hidden pl-4 pr-3 pt-6 sm:table-cell sm:pl-0"
>
{key}
</th>
<td class="pl-3 pr-4 pt-6 sm:pr-0 text-gray-500">{value}</td>
</tr>
))}
</tfoot>
</table>
</div>
<div class="flex justify-between mt-12 items-start">
<div class="text-left text-sm space-y-1 text-gray-500">
{details.map(([title, value]) => (
<p>
<strong>{title}:</strong> {value}
</p>
))}
</div>
</div>
</div>
</section>
</header>
</body>