|
| 1 | +import { Card } from "@/components/ui/Card" |
| 2 | +import { HapticButtonLink } from "@/components/ui/HapticButtonLink" |
| 3 | +import { Section } from "@/components/ui/Section" |
| 4 | +import type { CompareApplicationLayoutBlock } from "@/lib/cms" |
| 5 | +import { getMediaUrl } from "@/lib/media" |
| 6 | +import { cn } from "@/lib/utils" |
| 7 | +import type { Media } from "@/payload-types" |
| 8 | +import { IconCheck, IconX } from "@tabler/icons-react" |
| 9 | +import Image from "next/image" |
| 10 | + |
| 11 | +interface CompareApplicationSectionProps { |
| 12 | + content?: CompareApplicationLayoutBlock | null |
| 13 | +} |
| 14 | + |
| 15 | +export function CompareApplicationSection({ content }: CompareApplicationSectionProps) { |
| 16 | + const apps = content?.apps?.filter((app) => Boolean(app.name)) ?? [] |
| 17 | + const buttons = content?.buttons?.filter((button) => Boolean(button.label && button.url)) ?? [] |
| 18 | + const button = buttons[0] |
| 19 | + const showIcon = content?.showIcon !== false |
| 20 | + |
| 21 | + if (!content || apps.length === 0) return null |
| 22 | + |
| 23 | + return ( |
| 24 | + <Section |
| 25 | + heading={content.sectionHeading} |
| 26 | + description={content.sectionDescription} |
| 27 | + linkButton={content.sectionLinkButton} |
| 28 | + funnelType={content.sectionLayout ?? "center"} |
| 29 | + animation={{ preset: "none" }} |
| 30 | + > |
| 31 | + <Card size="lg" variant="light" radialGradient={content.gradient} gradientDirection={content.gradientDirection} className="w-full p-0!"> |
| 32 | + <div className="relative z-10 overflow-x-auto rounded-[inherit]"> |
| 33 | + <table className="w-full table-fixed border-separate border-spacing-0" style={{ minWidth: `${Math.max(apps.length, 2) * 15}rem` }}> |
| 34 | + <thead> |
| 35 | + <tr> |
| 36 | + {apps.map((app, index) => { |
| 37 | + const logo = typeof app.logo === "object" ? (app.logo as Media) : null |
| 38 | + const logoUrl = getMediaUrl(logo?.url) |
| 39 | + |
| 40 | + return ( |
| 41 | + <th |
| 42 | + scope="col" |
| 43 | + className={cn("border-b border-white/10 p-5 text-left align-top", index > 0 && "border-l")} |
| 44 | + key={app.id ?? `${app.name}-${index}`} |
| 45 | + > |
| 46 | + <div className="flex items-center gap-3"> |
| 47 | + <div className="relative flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-xl border border-white/10 bg-white/5 p-2"> |
| 48 | + {logoUrl && ( |
| 49 | + <Image |
| 50 | + src={logoUrl} |
| 51 | + alt={logo?.alt || app.name} |
| 52 | + fill |
| 53 | + sizes="44px" |
| 54 | + className="object-contain p-2" |
| 55 | + /> |
| 56 | + )} |
| 57 | + </div> |
| 58 | + <span className="text-lg font-semibold text-white">{app.name}</span> |
| 59 | + </div> |
| 60 | + </th> |
| 61 | + ) |
| 62 | + })} |
| 63 | + </tr> |
| 64 | + </thead> |
| 65 | + <tbody> |
| 66 | + <tr> |
| 67 | + {apps.map((app, index) => { |
| 68 | + const features = app.features?.filter((feature) => Boolean(feature.title)) ?? [] |
| 69 | + |
| 70 | + return ( |
| 71 | + <td className={cn("p-5 align-top", index > 0 && "border-l border-white/10")} key={app.id ?? `${app.name}-${index}`}> |
| 72 | + <div className="flex h-full flex-col"> |
| 73 | + <ul className="flex flex-col gap-2"> |
| 74 | + {features.map((feature, featureIndex) => ( |
| 75 | + <li |
| 76 | + className={cn("flex items-start text-sm", showIcon && "gap-2", feature.exists === false ? "text-tertiary" : "text-white")} |
| 77 | + key={feature.id ?? `feature-${featureIndex}`} |
| 78 | + > |
| 79 | + {showIcon && |
| 80 | + (feature.exists === false ? ( |
| 81 | + <IconX size={16} className="mt-0.5 shrink-0" aria-hidden="true" /> |
| 82 | + ) : ( |
| 83 | + <IconCheck size={16} className="mt-0.5 shrink-0 text-brand" aria-hidden="true" /> |
| 84 | + ))} |
| 85 | + <span>{feature.title}</span> |
| 86 | + </li> |
| 87 | + ))} |
| 88 | + </ul> |
| 89 | + |
| 90 | + {index === 0 && button && ( |
| 91 | + <div className="mt-auto pt-6"> |
| 92 | + <HapticButtonLink |
| 93 | + href={button.url} |
| 94 | + variant={button.variant ?? "normal"} |
| 95 | + className={cn("w-full!", button.variant === "filled" && "bg-white/80! text-primary! hover:bg-white!")} |
| 96 | + > |
| 97 | + {button.label} |
| 98 | + </HapticButtonLink> |
| 99 | + </div> |
| 100 | + )} |
| 101 | + </div> |
| 102 | + </td> |
| 103 | + ) |
| 104 | + })} |
| 105 | + </tr> |
| 106 | + </tbody> |
| 107 | + </table> |
| 108 | + </div> |
| 109 | + </Card> |
| 110 | + </Section> |
| 111 | + ) |
| 112 | +} |
0 commit comments