import React from 'react';
import { useNavigate } from 'react-router-dom';
import { ADMIN_EVENTS_PATH, ADMIN_WELCOME_PACKAGES_PATH } from '../../constants';

const STORAGE_KEY = 'tenant-admin:onboarding-progress';

export default function WelcomeLandingPage() {
  const navigate = useNavigate();

  React.useEffect(() => {
    try {
      const prev = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '{}');
      const next = { ...prev, welcomeSeen: true, lastStep: 'landing' };
      localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
    } catch (error) {
      console.warn('Failed to persist onboarding progress', error);
    }
  }, []);

  return (
    <div className="flex flex-col gap-4 p-6" data-testid="welcome-landing">
      <div className="flex flex-col gap-3 rounded-2xl border border-slate-200 bg-white p-4 shadow-sm">
        <h1 className="text-lg font-semibold">Tenant Admin Onboarding</h1>
        <p className="text-sm text-slate-600">Starte mit der Einrichtung deines Workspaces.</p>
        <div className="flex flex-wrap gap-2">
          <button
            type="button"
            className="rounded-md bg-slate-900 px-4 py-2 text-white"
            onClick={() => navigate(ADMIN_WELCOME_PACKAGES_PATH)}
          >
            hero.primary.label
          </button>
          <button
            type="button"
            className="rounded-md border border-slate-300 px-4 py-2 text-slate-700"
            onClick={() => navigate(ADMIN_EVENTS_PATH)}
          >
            hero.secondary.label
          </button>
        </div>
      </div>

      <div className="flex justify-end">
        <button
          type="button"
          className="text-sm text-slate-600 underline"
          onClick={() => navigate(ADMIN_EVENTS_PATH)}
        >
          layout.jumpToDashboard
        </button>
      </div>
    </div>
  );
}

