import { formatCredits } from '../../lib/credit-costs'; /** What the Force scan button prints, the longer title it carries, and where it leads. */ export interface ScanButtonCopy { label: string; title: string; /** The brand is not set up yet: the button opens the settings instead of scanning. */ opensSettings: boolean; } /** * The Force scan button's words: the price of the scan when the agent has * said it, so the merchant reads what a press costs before pressing. * * @param {boolean} requiresSetup - The brand still lacks its language and country. * @param {number | null} scanCostCredits - Credits one scan debits; null when unknown. * @returns {ScanButtonCopy} The label and the title. */ export const scanButtonCopy = ( requiresSetup: boolean, scanCostCredits: number | null ): ScanButtonCopy => { if (requiresSetup) { return { label: 'Set language & country', title: 'Set brand language and country before scanning', opensSettings: true, }; } if (scanCostCredits === null || scanCostCredits <= 0) { return { label: 'Force scan now', title: 'Force scan now', opensSettings: false, }; } const price = formatCredits(scanCostCredits); return { label: `Force scan now ยท ${price}`, title: `Force scan now. Costs ${price}, debited when the scan runs.`, opensSettings: false, }; };