#!/usr/bin/env -S deno serve -A
import { Context, Env, Hono, Input } from "jsr:@hono/hono@4";
import { getCookie, setCookie } from 'jsr:@hono/hono@4/cookie'

const app = new Hono();

function showCookies(c:Context<Env, string, Input>) {
  let result = "<html>\n<body>\n<h1>Cookies</h1>\n<ul>";
  const cookies = getCookie(c);
  for(const key of Object.keys(cookies)) {
     result += "<li><strong>" + key + ":</strong> " + cookies[key] + "</li>\n";
  }
  result += "</ul>\n</body>\n</html>"
  return result;
  
}

app.get('/cookies', function (c) {
  const result = showCookies(c)
  return c.html(result);
})

app.get('/set/:name/:value', function (c) {
 setCookie(c, c.req.param("name"), c.req.param("value"), { maxAge: 900000 })
return c.html("<h1>ok!</h1>");
})

export default app;