'use client';

import * as React from 'react';
import { usePathname } from 'next/navigation';
import { cn } from '@/lib/utils';
import { getToolByHref } from '@/lib/tools';

interface AppPageProps {
  title: string;
  description?: string;
  children: React.ReactNode;
  className?: string;
}

export function AppPage({ title, description, children, className }: AppPageProps) {
  const pathname = usePathname();
  const firstSegment = pathname.split('/').filter(Boolean)[0];
  const tool = getToolByHref(`/${firstSegment ?? ''}`);
  const Icon = tool?.icon;

  return (
    <div className={cn("min-h-screen py-8", className)}>
      <div className="max-w-7xl mx-auto px-8 space-y-6 animate-fade-in">
        <div>
          <div className="flex items-center gap-3 mb-1">
            {Icon && <Icon className="h-6 w-6 text-primary shrink-0" />}
            <h1 className="text-2xl font-bold">{title}</h1>
          </div>
          {description && (
            <p className="text-sm text-muted-foreground">
              {description}
            </p>
          )}
        </div>
        {children}
      </div>
    </div>
  );
}
