import { useScopedFormContext } from '@components/common/page-builder/WidgetSettingsScope.js';
import { _ } from '@evershop/evershop/lib/locale/translate/_';
import React from 'react';
/**
* Shared settingComponent for both recommendation widget types
* (specifications/05 § 9.1). Scalars only — deliberately no list-typed
* settings (the legacy /admin/widgets/edit surface seeds those as JSON
* strings). `limit` registers with valueAsNumber: the widget-save AJV has no
* coerceTypes, so a string from a number input would fail the integer schema.
*/
function Field({
label,
hint,
children
}: {
label?: string;
hint?: string;
children: React.ReactNode;
}) {
return (
{label && (
{label}
)}
{children}
{hint &&
{hint}
}
);
}
interface RecommendationWidgetSettingProps {
recommendationWidget?: {
heading?: string | null;
limit?: number | null;
};
}
function RecommendationWidgetSetting({
recommendationWidget
}: RecommendationWidgetSettingProps) {
const { heading = '', limit = undefined } = recommendationWidget ?? {};
const { register } = useScopedFormContext();
return (
);
}
export default RecommendationWidgetSetting;
export const query = `
query Query($heading: String, $limit: Int) {
recommendationWidget(heading: $heading, limit: $limit) {
heading
limit
}
}
`;
export const variables = `{
heading: getWidgetSetting("heading"),
limit: getWidgetSetting("limit")
}`;