import { useDeferredValue } from 'react';
import { useTranslation } from 'react-i18next';
import { useSearchParams } from 'react-router-dom';
import SEOHead from '@/components/seo/SEOHead';
import { generateOrganization, generateWebSite, getSiteOrigin } from '@/utils/seo';
import {
FileText,
FileOutput,
Minimize2,
ImageIcon,
Film,
Hash,
Eraser,
Layers,
Scissors,
RotateCw,
Image,
FileImage,
Droplets,
Lock,
Unlock,
ListOrdered,
PenLine,
GitBranch,
Scaling,
ScanText,
Sheet,
ArrowUpDown,
QrCode,
Code,
MessageSquare,
Languages,
Table,
Search,
X,
} from 'lucide-react';
import ToolCard from '@/components/shared/ToolCard';
import HeroUploadZone from '@/components/shared/HeroUploadZone';
import AdSlot from '@/components/layout/AdSlot';
import SocialProofStrip from '@/components/shared/SocialProofStrip';
interface ToolInfo {
key: string;
path: string;
icon: React.ReactNode;
bgColor: string;
}
const pdfTools: ToolInfo[] = [
{ key: 'pdfEditor', path: '/tools/pdf-editor', icon: , bgColor: 'bg-rose-50' },
{ key: 'pdfToWord', path: '/tools/pdf-to-word', icon: , bgColor: 'bg-red-50' },
{ key: 'wordToPdf', path: '/tools/word-to-pdf', icon: , bgColor: 'bg-blue-50' },
{ key: 'compressPdf', path: '/tools/compress-pdf', icon: , bgColor: 'bg-orange-50' },
{ key: 'mergePdf', path: '/tools/merge-pdf', icon: , bgColor: 'bg-violet-50' },
{ key: 'splitPdf', path: '/tools/split-pdf', icon: , bgColor: 'bg-pink-50' },
{ key: 'rotatePdf', path: '/tools/rotate-pdf', icon: , bgColor: 'bg-teal-50' },
{ key: 'pdfToImages', path: '/tools/pdf-to-images', icon: , bgColor: 'bg-amber-50' },
{ key: 'imagesToPdf', path: '/tools/images-to-pdf', icon: , bgColor: 'bg-lime-50' },
{ key: 'watermarkPdf', path: '/tools/watermark-pdf', icon: , bgColor: 'bg-cyan-50' },
{ key: 'protectPdf', path: '/tools/protect-pdf', icon: , bgColor: 'bg-red-50' },
{ key: 'unlockPdf', path: '/tools/unlock-pdf', icon: , bgColor: 'bg-green-50' },
{ key: 'pageNumbers', path: '/tools/page-numbers', icon: , bgColor: 'bg-sky-50' },
{ key: 'pdfFlowchart', path: '/tools/pdf-flowchart', icon: , bgColor: 'bg-indigo-50' },
{ key: 'pdfToExcel', path: '/tools/pdf-to-excel', icon: , bgColor: 'bg-green-50' },
{ key: 'removeWatermark', path: '/tools/remove-watermark-pdf', icon: , bgColor: 'bg-rose-50' },
{ key: 'reorderPdf', path: '/tools/reorder-pdf', icon: , bgColor: 'bg-violet-50' },
{ key: 'extractPages', path: '/tools/extract-pages', icon: , bgColor: 'bg-amber-50' },
{ key: 'chatPdf', path: '/tools/chat-pdf', icon: , bgColor: 'bg-blue-50' },
{ key: 'summarizePdf', path: '/tools/summarize-pdf', icon: , bgColor: 'bg-emerald-50' },
{ key: 'translatePdf', path: '/tools/translate-pdf', icon: , bgColor: 'bg-purple-50' },
{ key: 'tableExtractor', path: '/tools/extract-tables', icon:
, bgColor: 'bg-teal-50' },
];
const otherTools: ToolInfo[] = [
{ key: 'imageConvert', path: '/tools/image-converter', icon: , bgColor: 'bg-purple-50' },
{ key: 'imageResize', path: '/tools/image-resize', icon: , bgColor: 'bg-teal-50' },
{ key: 'compressImage', path: '/tools/compress-image', icon: , bgColor: 'bg-orange-50' },
{ key: 'ocr', path: '/tools/ocr', icon: , bgColor: 'bg-amber-50' },
{ key: 'removeBg', path: '/tools/remove-background', icon: , bgColor: 'bg-fuchsia-50' },
{ key: 'imageToSvg', path: '/tools/image-to-svg', icon: , bgColor: 'bg-indigo-50' },
{ key: 'videoToGif', path: '/tools/video-to-gif', icon: , bgColor: 'bg-emerald-50' },
{ key: 'qrCode', path: '/tools/qr-code', icon: , bgColor: 'bg-indigo-50' },
{ key: 'htmlToPdf', path: '/tools/html-to-pdf', icon: , bgColor: 'bg-sky-50' },
{ key: 'wordCounter', path: '/tools/word-counter', icon: , bgColor: 'bg-blue-50' },
{ key: 'textCleaner', path: '/tools/text-cleaner', icon: , bgColor: 'bg-indigo-50' },
];
export default function HomePage() {
const { t } = useTranslation();
const siteOrigin = getSiteOrigin(typeof window !== 'undefined' ? window.location.origin : '');
const [searchParams, setSearchParams] = useSearchParams();
const query = searchParams.get('q') || '';
const deferredQuery = useDeferredValue(query.trim().toLowerCase());
const matchesTool = (tool: ToolInfo) => {
if (!deferredQuery) {
return true;
}
const haystack = `${t(`tools.${tool.key}.title`)} ${t(`tools.${tool.key}.shortDesc`)}`.toLowerCase();
return haystack.includes(deferredQuery);
};
const filteredPdfTools = pdfTools.filter(matchesTool);
const filteredOtherTools = otherTools.filter(matchesTool);
const updateQuery = (value: string) => {
const nextParams = new URLSearchParams(searchParams);
if (value.trim()) {
nextParams.set('q', value);
} else {
nextParams.delete('q');
}
setSearchParams(nextParams, { replace: true });
};
return (
<>
{/* Hero Section */}
{t('home.hero')}
{t('home.heroSub')}
{/* Smart Upload Zone */}
{/* Ad Slot */}
{t('common.developers')}
{t('pages.developers.ctaTitle')}
{t('pages.developers.ctaSubtitle')}
{/* Tools Grid */}
{t('home.pdfTools')}
{filteredPdfTools.map((tool) => (
))}
{t('home.otherTools', 'Other Tools')}
{filteredOtherTools.map((tool) => (
))}
{filteredPdfTools.length + filteredOtherTools.length === 0 && (
{t('home.noSearchResults')}
)}
{/* Features / Why Choose Us */}
{t('home.featuresTitle', 'A smarter way to convert and edit online')}
{t('home.feature1Title', 'One complete workspace')}
{t('home.feature1Desc', 'Edit, convert, compress, merge, split without switching tabs.')}
100%
{t('home.feature2Title', 'Accuracy you can trust')}
{t('home.feature2Desc', 'Get pixel-perfect, editable files in seconds with zero quality loss.')}
{t('home.feature3Title', 'Built-in security')}
{t('home.feature3Desc', 'Access files securely, protected by automatic encryption.')}
{/* Ad Slot - Bottom */}
>
);
}