import Link from "next/link";
import bcrypt from "bcryptjs";
import { logoutStaff } from "@/lib/actions";
import { requireStaff } from "@/lib/auth";

export async function StaffShell({ children }: { children: React.ReactNode }) {
  const user = await requireStaff();
  const defaultPassword = bcrypt.compareSync("IranHealth-1405", user.password_hash);
  return (
    <div className="app" lang="fa" dir="rtl">
      <header className="top">
        <div className="brand">
          <strong>ایران هلث</strong>
          <span>پنل پرونده</span>
        </div>
        <nav>
          <Link href="/staff/cases">پرونده‌ها</Link>
          <Link href="/staff/cases/new">پرونده جدید</Link>
          <Link href="/staff/password">گذرواژه</Link>
          <form action={logoutStaff}>
            <button className="secondary" type="submit">خروج</button>
          </form>
        </nav>
      </header>
      <main className="wrap stack">
        {defaultPassword ? (
          <aside className="banner">
            <strong>گذرواژه هنوز همان گذرواژه اولیه است.</strong>
            <p>از بخش گذرواژه آن را عوض کنید. این حساب را روی سرور واقعی با همین رمز رها نکنید.</p>
          </aside>
        ) : null}
        {children}
      </main>
    </div>
  );
}
