weightElement.ts 1.04 KB
export type WeightInputMode = 'net' | 'tare'

export function readWeightInputMode(cfg: Record<string, unknown> | undefined | null): WeightInputMode {
  const v = String(cfg?.weightInputMode ?? cfg?.WeightInputMode ?? 'net')
    .trim()
    .toLowerCase()
  return v === 'tare' ? 'tare' : 'net'
}

/** Label display: numeric value + template unit (e.g. 500 + g → 500g). */
export function formatWeightDisplay(rawValue: string, unit: string): string {
  const raw = String(rawValue ?? '').trim()
  const u = String(unit ?? '').trim()
  if (!raw) return ''
  if (u && !raw.endsWith(u)) return `${raw}${u}`
  return raw
}

export function weightInputPlaceholder(mode: WeightInputMode): string {
  return mode === 'tare' ? 'Enter weight or read from scale' : 'Net weight'
}

export const WEIGHT_INPUT_MODE_OPTIONS: Array<{
  value: WeightInputMode;
  label: string;
  /** Template editor: temporarily disable until tare flow is ready. */
  disabled?: boolean;
}> = [
  { value: 'net', label: 'Net weight' },
  { value: 'tare', label: 'Tare weight', disabled: true },
]