import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core'; export interface AiSuggestionsProps { /** * The name of the item with AI Suggestions */ itemName: string; /** * Texts used in various places in the UI */ texts: AiSuggestionsTexts; /** * AI suggestions sections */ sections: AiSuggestionsSections; /** * Optional Intro related properties */ intro?: Intro | undefined; /** * Determines whether to display suggestions or not */ isOpen?: boolean; } export type AiSuggestionsSections = { /** * Tags section */ tags?: TagsSection; /** * ABV section */ abv?: AbvSection; /** * Allergens section */ allergens?: AllergensSection; /** * GTIN section * */ gtin?: GtinSection; }; /** * Allergens related selected suggestions */ export type AllergenSelection = { /** * Selected allergens */ allergens?: Allergen[]; /** * Determines whether Contains No allergens was checked */ containsNoAllergens: boolean; /** * Determines whether Allergens were confirmed */ confirmed: boolean; } /** * Describes selected suggestions */ export type SuggestionsSelected = { /** * Selected tags */ tags?: Tag[]; /** * Selected abv */ abv?: number; /** * Selected allergens data */ allergens?: AllergenSelection; /** * Selected gtin data */ gtin?: string; } /** * Describes AI suggestion section */ export type AiSuggestionsSection = { /** * Title of section to be displayed */ title: string; /** * Determines whether section is selected */ selected: boolean; }; /** * Describes AI suggestions intro */ export interface Intro { /** * Determines whether intro should be displayed (ignored in Desktop mode) */ display: boolean; /** * Texts used in various places in the UI */ texts: IntroTexts; } /** * Texts used in Intro */ export type IntroTexts = { /** * Title of the intro */ title: string; /** * Description */ description: string; /** * Support banner title */ supportInfoTitle: string; /** * Support banner description */ supportInfoDescription: string; /** * Text for the "Don't again" checkbox */ dontShow: string; /** * Text for "ViewSuggestions" button */ viewSuggestionsButton: string; /** * Text for "MaybeLater" button */ cancelButton: string; } /** * Tags section of AI suggestions */ export interface TagsSection extends AiSuggestionsSection { /** * Suggested tags */ suggestedTags: Tag[]; /** * Available tags */ availableTags: Tag[]; /** * Texts for section */ texts: TagsSectionTexts; } /** * Tags section texts */ export type TagsSectionTexts = { /** * Text for suggested tags label */ aiSuggests: string; /** * Text for other tags label */ otherOptions: string; } /** * TagsSection Tag */ export type Tag = { /** * Key of the tag */ key: string; /** * Name of the tag */ name: string; /** * Determines whether the tag is selected */ selected: boolean; /** * Tag icon name */ icon?: string; } /** * Abv section of AI suggestions */ export interface AbvSection extends AiSuggestionsSection { /** * Suggested ABV value */ suggestedValue: number; /** * Current ABV value */ currentValue?: number; /** * Texts for section */ texts: AbvSectionTexts; } /** * Abv section texts */ export type AbvSectionTexts = { /** * Validation message displayed when value is outside of accepted range */ valueOutsideOfAcceptedRangeError: string; /** * Text for suggested abv label */ aiSuggests: string; /** * Text for previous input label */ previousInput: string; /** * Text for input trailing text */ abvTrailingText: string; } /** * Allergens section of AI suggestions */ export interface AllergensSection extends AiSuggestionsSection { /** * Suggested allergens */ suggestedAllergens: Allergen[]; /** * Other available allergens */ availableAllergens: Allergen[]; /** * Texts for section */ texts: AllergensSectionTexts; } /** * Individual allergen */ export type Allergen = { /** * Key of the allergen */ key: string; /** * Determines whether allergen is selected */ selected: boolean; /** * Level of the allergen 'contains' or 'header' */ level: 'contains' | 'header'; /** * Type of allergen eg. glutenCereal, glutenCerealWheat */ type: string; } /** * Texts for allergens section */ export type AllergensSectionTexts = { /** * Text for suggested allergens label */ aiSuggests: string; /** * Text for other allergens label */ otherAllergens: string; /** * Text for Contains no allergens checkbox */ containsNoAllergens: string; /** * Text for show more button */ showMore: string; /** * Text for show less button */ showLess: string; /** * Confirmation modal texts */ confirmModal: { /** * Modal title */ title: string; /** * Modal description */ description: string; /** * Text for "Maybe later" button */ maybeLater: string; /** * Text for "Confirm" button */ confirmButton: string; }, /** * Names for allergens */ allergenNames: Record; } /** * GTIN section of AI suggestions */ export interface GtinSection extends AiSuggestionsSection { /** * Suggested GTIN items from AI matching */ suggestedGtins: GtinValue[]; /** * Texts for section */ texts: GtinSectionTexts; } /** * Individual GTIN value suggestion */ export type GtinValue = { /** * The GTIN barcode value */ gtin: string; /** * Customer-facing product name */ customerName: string; /** * AI confidence match score (0-100) */ matchScore: number; /** * Determines whether this item is selected */ selected: boolean; /** * Optional product image URL */ imageUrl?: string; }; /** * Texts for GTIN section */ export type GtinSectionTexts = { /** * Header text (e.g., "Menu made easy") */ header: string; /** * Description text shown under the header */ description: string; /** * Label for GTIN/Barcode */ gtinLabel: string; /** * Suffix for percentage match */ matchSuffix: string; /** * Accessible label prefix for selecting a GTIN option (e.g., "Select") */ selectGtinLabel?: string; }; /** * Texts for AI Suggestions component */ export type AiSuggestionsTexts = { /** * Title */ title: string; /** * Header for subsection */ sectionsSubheader: string; /** * Description for subsection */ subsectionsDescription: string; /** * Text for "RejectAll" button */ rejectButton: string; /** * Text for "Apply&Save" button */ submitButton: string; /** * Text for "Cancel" button */ cancelButton: string; /** * Error message displayed when something goes wrong */ errorMessage: string; } /** * Event object for when suggestions are submitted */ export interface SuggestionsSubmitEvent { dontShowIntroSelected: boolean, selected: SuggestionsSelected, initialState: AiSuggestionsSections, type: 'approve' | 'reject', } /** * Event object for when suggestions are closed */ export interface SuggestionsCloseEvent { dontShowIntroSelected: boolean, source: string } /** * Event object for when an error occurs */ export interface SuggestionsErrorEvent { errorMessage: string, errorStack?: string } /** * Event name for when suggestions are closed * * @constant */ export const ON_AI_SUGGESTIONS_CLOSE = 'pie-ai-suggestions-close'; /** * Event name for when suggestions are submitted * * @constant */ export const ON_AI_SUGGESTIONS_SUBMIT = 'pie-ai-suggestions-submit'; /** * Event name for when an error occurs * * @constant */ export const ON_AI_SUGGESTIONS_ERROR = 'pie-ai-suggestions-error'; const defaultSuggestionsTexts: AiSuggestionsTexts = { title: 'AI suggestions for', sectionsSubheader: 'Sections to review', subsectionsDescription: 'Use section checkboxes to accept or decline suggestions. You can edit AI suggestions on this page.', rejectButton: 'Decline all', submitButton: 'Apply and save', cancelButton: 'Maybe later', errorMessage: 'Sorry! Something went wrong. Please try again later.', }; const defaultIntroText: IntroTexts = { title: 'AI suggestions', description: 'This AI suggestion feature saves you time when adding new items to your menu. Review and approve the suggestions to add extra information to your items.', supportInfoTitle: 'Getting the best AI support', supportInfoDescription: 'Our AI suggestions require an item name and a category. For the best results, please include a description about each item.', dontShow: 'Don\'t show me this again', viewSuggestionsButton: 'View suggestions', cancelButton: 'Maybe later', }; export type DefaultProps = ComponentDefaultProps; export const defaultProps: DefaultProps = { itemName: '', texts: defaultSuggestionsTexts, sections: {}, intro: { display: false, texts: defaultIntroText, }, isOpen: false, };