import React from "react";
import { useNow } from "@/hooks/useNow";

const formatDate = (date) =>
  date.toLocaleDateString("en-US", {
    weekday: "long",
    month: "long",
    day: "numeric",
  });

const greeting = (date) => {
  const hour = date.getHours();
  if (hour < 12) return "Good morning";
  if (hour < 17) return "Good afternoon";
  return "Good evening";
};

const Header = ({ right = null }) => {
  const now = useNow();
  return (
    <header className="px-3 pt-5 sm:px-4 lg:px-5">
      <div className="flex items-center justify-between gap-4 pb-1">
        <div className="min-w-0">
          <h1 className="text-lg font-bold tracking-tight text-[#2b2925]">
            {greeting(now)}
          </h1>
          <p className="hidden text-xs text-[#7c7870] sm:block">
            Here's how the shop is doing
          </p>
        </div>
        <div className="flex shrink-0 items-center gap-3">
          {right}
          <span className="text-xs text-[#7c7870]">{formatDate(now)}</span>
        </div>
      </div>
    </header>
  );
};

export default Header;
