"use client";
import Image from "next/image";
import Link from "next/link";
import { useState } from "react";
import type { BusinessDetail, BusinessTabId } from "@/data/business";
import { businessTabs } from "@/data/business";
import styles from "./BusinessDetail.module.css";
function Stars({ rating }: { rating: string }) {
return (
{Array.from({ length: 5 }, (_, i) => (
★
))}
{rating}
);
}
function CategoryPills({
items,
active,
onChange,
}: {
items: string[];
active: string;
onChange: (value: string) => void;
}) {
return (
{items.map((item) => (
onChange(item)}
>
{item}
))}
);
}
function FiltersBar({
fields,
tags,
}: {
fields: { label: string; value: string }[];
tags: { label: string; value: string }[];
}) {
return (
<>
Filters
A better focus
{tags.length ? (
{tags.map((tag) => (
{tag.label}: {tag.value}
×
))}
) : null}
>
);
}
export default function BusinessDetailView({
business,
}: {
business: BusinessDetail;
}) {
const [tab, setTab] = useState("products");
const [productCategory, setProductCategory] = useState("All");
const [blogCategory, setBlogCategory] = useState("All");
const [portfolioCategory, setPortfolioCategory] = useState("All");
const [hoveredPortfolio, setHoveredPortfolio] = useState(
business.portfolios[2]?.id ?? null,
);
const products =
productCategory === "All"
? business.products
: business.products.filter((p) => p.category === productCategory);
return (
{business.name}
{business.breadcrumbs.map((crumb, index) => (
{index > 0 ? (
) : null}
{crumb}
))}
{business.name}
{business.tagline}
since
{business.since}
province
{business.province}
{business.activeProducts}
active
product
Telephone
{business.telephone}
{business.description}
{businessTabs.map((item) => (
setTab(item.id)}
>
{item.label}
))}
{tab === "products" ? (
<>
{products.map((product) => (
{product.title}
{product.minOrder}
pcs, min
order
{product.shipsIn}
days
to ship
))}
>
) : null}
{tab === "contact" ? (
⌖
Address
{business.contact.address}
☎
land line
{business.contact.landlines.join(" , ")}
) : null}
{tab === "blog" ? (
<>
{business.posts.map((post) => (
{post.title}
{post.excerpt}
{post.date}
{post.author}
))}
>
) : null}
{tab === "gallery" ? (
{business.gallery.map((item) => (
))}
) : null}
{tab === "portfolios" ? (
<>
{business.portfolios.map((item) => {
const showOverlay =
hoveredPortfolio === item.id ||
(hoveredPortfolio === null &&
item.id === business.portfolios[2]?.id);
return (
setHoveredPortfolio(item.id)}
onMouseLeave={() => setHoveredPortfolio(null)}
>
{item.title}
{item.description}
);
})}
>
) : null}
);
}