import {
Editable,
isPageBuilderActive
} from '@components/common/page-builder/index.js';
import { ProductList } from '@components/frontStore/catalog/ProductList.js';
import { Package } from 'lucide-react';
import React, { useEffect, useState } from 'react';
/**
* Collection stack — 1–3 stacked collection rows, each with a heading,
* optional "View all" link, and a strip of products. Uses the shared
* ProductList so card visuals match the category grid page.
*/
export interface CollectionStackRow {
id: string;
title: string;
subText?: string | null;
source?: string | null;
viewAllLink?: string | null;
viewAllLabel?: string | null;
products: any[];
}
export interface CollectionStackProps {
collectionStackWidget: {
rows: CollectionStackRow[];
productCount: number;
countPerRow: number;
divider: boolean;
};
}
// Page-builder-only placeholder. Mirrors a single collection row with a
// heading + view-all + N product card outlines so the merchant can see
// the row shape before picking a collection. `count` outlines laid out in
// `columns` columns — matching the storefront grid.
function PlaceholderRow({
count,
columns
}: {
count: number;
columns: number;
}) {
return (
{Array.from({ length: count }, (_, i) => (
))}
);
}
export default function CollectionStack({
collectionStackWidget
}: CollectionStackProps) {
const {
rows = [],
productCount,
countPerRow,
divider
} = collectionStackWidget;
const [inPb, setInPb] = useState(false);
useEffect(() => {
setInPb(isPageBuilderActive());
}, []);
if (!rows.length) {
if (inPb) {
return (
);
}
return null;
}
return (
{rows.map((row, i) => (
{/* Maps to settings.collections.${i}.title — the resolver
filters out rows lacking source/title, but the picker
guarantees both fields, so the rendered index matches
the settings index in practice. */}
{row.title}
{row.viewAllLink && (
{row.viewAllLabel || 'View all →'}
)}
{row.subText && (
{row.subText}
)}
{divider && i < rows.length - 1 && (
)}
))}
);
}
export const query = `
query Query(
$collections: JSON
$productCount: Int
$countPerRow: Int
$divider: Boolean
) {
collectionStackWidget(
collections: $collections
productCount: $productCount
countPerRow: $countPerRow
divider: $divider
) {
rows {
id
title
subText
source
viewAllLink
viewAllLabel
products {
...Product
}
}
productCount
countPerRow
divider
}
}
`;
export const fragments = `
fragment Product on Product {
productId
name
sku
variantGroupId
price {
regular {
value
text
}
special {
value
text
}
}
inventory {
isInStock
}
image {
alt
url
}
url
}
`;
export const variables = `{
collections: getWidgetSetting("collections", []),
productCount: getWidgetSetting("productCount", 4),
countPerRow: getWidgetSetting("countPerRow", 4),
divider: getWidgetSetting("divider", true)
}`;