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AC;SAC1C,GAAG,CAAC,IAAI;;QACP,OAAO;YACL,IAAI,CAAC,EAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,EAAE,CAAA,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC;YACtC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,EAAE;SAC7B,CAAC;KACH,CAAC,CAAC;AACP,EAAE;AAiCF;;;;;AAKO,MAAM,mBAAmB,GAAG,CAAC,UAAuC;IACzE,OAAO,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,KAAI,EAAE,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC;MAUW,oBAAoB,GAAG,CAAC,UAAuC,EAAE,OAAe;IAC3F,OAAO,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,KAAI,EAAE,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;AAC1E,EAAE;AAWF;;;MAGa,cAAc,GAAG,CAAC,KAA8B,EAAE,KAAe;IAC5E,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,CAAC,CAAC;IACxD,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,EAAE,MAAK,EAAE,CAAC,CAAC;AACjD;;;;","names":[],"sources":["src/functions/line-items/index.ts"],"sourcesContent":["import { getQueryArg } from '@wordpress/url';\n\nimport { Bump, BundleComponentRow, BundleItem, Checkout, ChoiceType, LineItem, LineItemData, lineItems, Price, PriceChoice, Product, RecursivePartial } from '../../types';\n\n// Order bundle items by their `position` (the order set in the bundle).\nconst byPosition = <T extends { position?: number }>(items: T[] = []): T[] => [...items].sort((a, b) => (a?.position ?? 0) - (b?.position ?? 0));\n\n/**\n * A bundle component's line item `quantity` is the total across the whole\n * purchase (per-bundle count × bundle quantity). Divide it back out by the\n * parent quantity to get the per-bundle count the bundle actually defines.\n */\nexport const getPerBundleQuantity = (component: LineItem, parentQuantity = 1): number => {\n const parentQty = Math.max(Number(parentQuantity) || 1, 1);\n const total = Math.max(Number(component?.quantity) || 1, 1);\n return Math.max(Math.round(total / parentQty), 1);\n};\n\n/**\n * Build display rows from bundle component line items.\n *\n * By default every component is shown (variant items render `Name - Variant`,\n * plain items render just `Name`). Pass `showAll = false` for variants-only\n * mode, which lists only the components that have a variant selection.\n */\nexport const getBundleComponentRowsFromLineItems = (components: LineItem[] = [], parentQuantity = 1, showAll = true, separator = '·'): BundleComponentRow[] => {\n const sep = (separator || '·').trim() || '·';\n return (components || [])\n .map(component => {\n // Prefer the raw options array so we can join with the separator; fall back to the pre-joined display string when it's absent.\n const options = (component?.variant_options || []).filter(Boolean);\n const variants = options.length ? options.join(` ${sep} `) : (component?.variant_display_options || '').trim();\n // Variants-only mode: drop components without a selection.\n if (!showAll && !variants) return null;\n const componentProduct = (component?.price as Price)?.product as Product;\n const name = componentProduct?.name || '';\n if (!name) return null;\n const qty = getPerBundleQuantity(component, parentQuantity);\n return { id: component?.id, name, variants, qty };\n })\n .filter(Boolean) as BundleComponentRow[];\n};\n\n/**\n * Build a list of display rows from BundleItems attached to a Product\n * (subscription detail panel — no LineItems exist for components there,\n * only the bundle definition).\n */\nexport const getBundleComponentRowsFromBundleItems = (items: BundleItem[] = []): BundleComponentRow[] => {\n return byPosition(items)\n .map(item => {\n const componentProduct = item?.component_product as Product;\n const name = componentProduct?.name || '';\n const qty = Math.max(Number(item?.quantity) || 1, 1);\n if (!name) return null;\n // Bundle definitions carry no variant selection.\n return { id: item?.id, name, variants: '', qty };\n })\n .filter(Boolean) as BundleComponentRow[];\n};\n\n/**\n * Group line items into bundle parents (with components nested) and regulars.\n */\nexport const groupBundleLineItems = (items: LineItem[] = []) => {\n const regular: LineItem[] = [];\n const bundleParents: LineItem[] = [];\n const componentsByParent: Record<string, LineItem[]> = {};\n\n (items || []).forEach(item => {\n // Skip components surfaced at the top level — they're rendered nested.\n if (item?.component_line_item) {\n return;\n }\n\n const product = (item?.price as Price)?.product as Product | undefined;\n if (product?.bundle) {\n bundleParents.push(item);\n componentsByParent[item.id] = byPosition(item?.component_line_items?.data || []);\n return;\n }\n\n regular.push(item);\n });\n\n return { regular, bundleParents, componentsByParent };\n};\n\n// Get only enabled price choices.\nexport const getEnabledPriceChoices = (choices: Array<PriceChoice>): Array<PriceChoice> => {\n return (choices || []).filter(choice => choice?.enabled !== false);\n};\n\n// convert price choice to line item data.\nexport const convertPriceChoiceToLineItemData = (choice: PriceChoice): LineItemData => {\n return {\n price_id: choice.id,\n quantity: choice.quantity,\n };\n};\n\nexport const convertLineItemsToLineItemData = (\n lineItems: RecursivePartial<lineItems>,\n): Array<{\n price_id: string;\n quantity: number;\n variant_id?: string;\n}> => {\n return (lineItems?.data || [])\n .filter(item => !item?.component_line_item)\n .map(item => {\n return {\n ...(!!item?.id ? { id: item.id } : {}),\n price_id: item.price.id,\n quantity: item.quantity,\n variant_id: item.variant?.id,\n };\n });\n};\n\nexport const addLineItem = (lineItems: RecursivePartial<lineItems>, data: { price_id: string; quantity: number }) => {\n const lineItemData = convertLineItemsToLineItemData(lineItems);\n const index = lineItemData.findIndex(item => item.price_id === data.price_id);\n lineItemData[index] = data;\n return lineItemData;\n};\n/**\n * Calculates the initial line items for the session.\n */\nexport const calculateInitialLineItems = (choices: Array<PriceChoice>, choiceType: ChoiceType) => {\n // check the url query first.\n const prices = getQueryArg(window.location.href, 'prices') as unknown as Array<PriceChoice>;\n if (prices) {\n return prices.map(convertPriceChoiceToLineItemData);\n }\n\n // get prices from choices.\n return getInitialChoiceLineItems(choices, choiceType);\n};\n\n/**\n * Get the initial choice line items.\n */\nexport const getInitialChoiceLineItems = (choices: Array<PriceChoice>, choiceType: ChoiceType) => {\n if (choiceType === 'all') {\n return getEnabledPriceChoices(choices).map(convertPriceChoiceToLineItemData);\n } else {\n return [getEnabledPriceChoices(choices).map(convertPriceChoiceToLineItemData)?.[0]];\n }\n};\n\n/**\n * Get price ids from line items\n * @param order\n * @returns\n */\nexport const getLineItemPriceIds = (line_items: RecursivePartial<lineItems>) => {\n return (line_items?.data || []).map(item => item.price.id);\n};\n\nexport const getLineItemBumpIds = (line_items: RecursivePartial<lineItems>) => {\n return (line_items?.data || []).map(item => (item?.bump as Bump)?.id || (item?.bump as string));\n};\n\nexport const getLineItemPrices = (line_items: RecursivePartial<lineItems>) => {\n return (line_items?.data || []).map(item => item.price);\n};\n\nexport const getLineItemByPriceId = (line_items: RecursivePartial<lineItems>, priceId: string) => {\n return (line_items?.data || []).find(item => item.price.id === priceId);\n};\n\n/**\n * Is this product in the checkout session?\n */\nexport const isProductInOrder = (product: RecursivePartial<Product>, order: Checkout) => {\n const prices = getLineItemPrices(order?.line_items);\n if (!prices?.length) return false;\n return !!prices.find(price => (price?.product as Product)?.id === product.id);\n};\n\n/**\n * Is the price in a checkout session\n */\nexport const isPriceInOrder = (price: RecursivePartial<Price>, order: Checkout) => {\n const priceIds = getLineItemPriceIds(order?.line_items);\n return !!priceIds.find(id => price?.id === id);\n};\n\n/**\n * Is the price in a checkout session\n */\nexport const isBumpInOrder = (bump: RecursivePartial<Bump>, order: Checkout) => {\n const bumpIds = getLineItemBumpIds(order?.line_items);\n return !!bumpIds.find(id => bump?.id === id);\n};\n\n/**\n * Attempt to get the session id\n *\n * @param formId The form id.\n * @param order The order\n * @param refresh Should we refresh?\n *\n * @returns string\n */\nexport const getSessionId = (formId, order, refresh = false) => {\n // if we want to get a fresh session, skip\n if (refresh === true) {\n return false;\n }\n\n // if we already have an ID set, return that:\n if (order?.id) {\n return order.id;\n }\n\n // check the url query first\n const urlId = getQueryArg(window.location.href, 'order');\n if (urlId) {\n return urlId;\n }\n\n // check id in localstorage\n return window.localStorage.getItem(formId);\n};\n\n/** Check if the order has a subscription */\nexport const hasSubscription = (order: Checkout) => {\n // no line items.\n if (!order?.line_items?.data?.length) return false;\n // has subscription product.\n return order?.line_items.data?.some(item => item?.price?.recurring_interval_count);\n};\n\nexport const hasTrial = (order: Checkout) => {\n return order?.trial_amount;\n};\n\n/** Check if the order has a payment plan. */\nexport const hasPaymentPlan = (order: Checkout) => {\n return hasSubscription(order) && order?.line_items.data?.some(item => item?.price?.recurring_period_count);\n};\n"],"version":3}