import { formatDate } from '../../utils/date';

export default function Header({ title, user, lastUpdate, onMenuClick }) {
  return (
    <header className="flex flex-wrap items-center justify-between gap-4 mb-6">
      <div className="flex items-center gap-4">
        <button
          onClick={onMenuClick}
          className="lg:hidden p-2 rounded-xl bg-navy-800 border border-navy-700"
          aria-label="منو"
        >
          ☰
        </button>
        <div>
          <h2 className="text-xl font-bold">{title}</h2>
          {lastUpdate && (
            <p className="text-sm text-gray-500 mt-1">
              آخرین بروزرسانی: {new Date(lastUpdate).toLocaleTimeString('fa-IR', { hour: '2-digit', minute: '2-digit' })}
            </p>
          )}
        </div>
      </div>
      {user && (
        <div className="flex items-center gap-4 text-sm">
          <div className="text-left">
            <p className="font-medium">{user.fullName}</p>
            <p className="text-accent text-xs">عضو ویژه</p>
          </div>
          {user.subscriptionExpiresAt && (
            <div className="card py-2 px-4 text-xs">
              <span className="text-gray-500">انقضای اشتراک</span>
              <p className="font-medium text-amber-400">{formatDate(user.subscriptionExpiresAt)}</p>
            </div>
          )}
          <div className="w-10 h-10 rounded-full bg-accent/30 border border-accent flex items-center justify-center">
            {user.fullName?.[0]}
          </div>
        </div>
      )}
    </header>
  );
}
