{"version":3,"file":"CartCost.mjs","names":[],"sources":["../../src/CartCost.tsx"],"sourcesContent":["import {Money, type MoneyPropsBase} from './Money.js';\nimport {useCart} from './CartProvider.js';\n\ninterface CartCostPropsBase {\n  /** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */\n  amountType?: 'total' | 'subtotal' | 'tax' | 'duty';\n  /** Any `ReactNode` elements. */\n  children?: React.ReactNode;\n}\n\ntype CartCostProps = Omit<React.ComponentProps<typeof Money>, 'data'> &\n  CartCostPropsBase;\n\n/**\n * The `CartCost` component renders a `Money` component with the cost associated with the `amountType` prop.\n * If no `amountType` prop is specified, then it defaults to `totalAmount`.\n * Depends on `useCart()` and must be a child of `<CartProvider/>`\n * @publicDocs\n */\nexport function CartCost(props: CartCostProps): JSX.Element | null {\n  const {cost} = useCart();\n  const {amountType = 'total', children, ...passthroughProps} = props;\n  let amount;\n\n  if (amountType == 'total') {\n    amount = cost?.totalAmount;\n  } else if (amountType == 'subtotal') {\n    amount = cost?.subtotalAmount;\n  } else if (amountType == 'tax') {\n    amount = cost?.totalTaxAmount;\n  } else if (amountType == 'duty') {\n    amount = cost?.totalDutyAmount;\n  }\n\n  if (amount == null) {\n    return null;\n  }\n\n  return (\n    <Money {...passthroughProps} data={amount}>\n      {children}\n    </Money>\n  );\n}\n\n// This is only for documentation purposes, and it is not used in the code.\n/** @publicDocs */\nexport interface CartCostPropsForDocs<AsType extends React.ElementType = 'div'>\n  extends Omit<MoneyPropsBase<AsType>, 'data'>, CartCostPropsBase {}\n"],"mappings":";;;;;;;;;;AAmBA,SAAgB,SAAS,OAA0C;CACjE,MAAM,EAAC,SAAQ,SAAS;CACxB,MAAM,EAAC,aAAa,SAAS,UAAU,GAAG,qBAAoB;CAC9D,IAAI;AAEJ,KAAI,cAAc,QAChB,UAAS,MAAM;UACN,cAAc,WACvB,UAAS,MAAM;UACN,cAAc,MACvB,UAAS,MAAM;UACN,cAAc,OACvB,UAAS,MAAM;AAGjB,KAAI,UAAU,KACZ,QAAO;AAGT,QACE,oBAAC,OAAD;EAAO,GAAI;EAAkB,MAAM;EAChC;EACK,CAAA"}