import { useMemo, memo } from 'react' import { Link } from '../link' import { AccessibilityBox, LoadTimeBox, LighthouseBox, OnlineBox, IssuesBox, WarningsBox, } from './blocks' import { Issue } from '@app/types' import { MoreOptionsBase } from './menu' import { Lighthouse } from '../lighthouse' import { usePageSpeed } from '@app/data/external/pagespeed/results' const styles = { title: 'text-base md:text-lg truncate', spacing: 'py-1', row: 'flex flex-1', metaBlock: 'px-2 py-1 border', } // TODO: add types export function WebsiteCellPagesComponent({ url, handleClickOpen, pages, issues, issuesInfo, crawlWebsite, pageLoadTime, pageHeaders, index, online, insight, pageInsights, lighthouseVisible, }: any) { const { accessScore } = issuesInfo ?? {} const { loading, getPageSpeed } = usePageSpeed(url, (eventData) => { handleClickOpen(eventData, 'Lighthouse', url) }) const lhExists = insight && Object.keys(insight)?.length const handleMainClick = (eventData?: any, title?: string, _mini?: boolean, url?: string) => () => { if (!lhExists) { getPageSpeed() } else if (handleClickOpen) { handleClickOpen(eventData, title, url) } } const linkUrl = useMemo( () => `/website-details?url=${encodeURIComponent(url)}`, [url] ) // real time issue tracking [TODO: combine with website analytic data] const { errorCount, warningCount } = useMemo(() => { let errors = 0 let warnings = 0 let notices = 0 if (issues?.length) { issues.forEach((iss: any) => { const pageIssues = iss?.issues pageIssues?.forEach((page: Issue) => { if (page?.type === 'error') { errors++ } if (page?.type === 'warning') { warnings++ } if (page?.type === 'notice') { notices++ } }) }) } else { errors = issuesInfo?.errorCount warnings = issuesInfo?.warningCount notices = issuesInfo?.noticesCount } return { errorCount: errors, warningCount: warnings, noticeCount: notices, totalIssues: errors + warnings + notices, } }, [issues, issuesInfo]) const lhQuerable = pageInsights || (insight && !!lhExists) return (