import{A as p}from"./Translator.js?ver=1.6.0";import{C as _}from"./CurrencyFormatter.js?ver=1.6.0";function f(a,n){var o;let l=[],t,e;if(a){for(const i of a)if(i!=null&&i.detail){if(t={},t.id=i.detail.id,t.order_id=n,t.post_id=i.ID,t.object_id=i.detail.default_variation_id,t.featured_media=(o=i.detail.featured_media)==null?void 0:o.url,t.price=i.detail.item_price,t.unit_price=i.detail.item_price,t.title=i.post_title,t.post_title=i.post_title,t.quantity=1,t.fulfillment_type=i.detail.fulfillment_type,t.manage_stock=i.detail.manage_stock,t.stockStatus=i.detail.manage_stock==1?i.detail.stock_availability:"in-stock",t.soldIndividually=i.detail.sold_individually,t.settings=i.detail.settings,t.checked=!1,t.min_price=i.detail.min_price,t.max_price=i.detail.max_price,i.detail.variants&&i.detail.variants.length){t.children=[];for(const d in i.detail.variants){e=i.detail.variants[d],t.title=e.variation_title,t.variation_display_title=e.variation_display_title||e.variation_title;let s=i.detail.default_variation_id==e.id;if(!s&&i.detail.variation_type==="simple"&&(s=!0),s&&(t.available=e.manage_stock.toString()==="1"?e.available:1/0,t.price=e.item_price,t.unit_price=e.item_price,t.object_id=e.id,t.cost=e.item_cost,t.other_info=e.other_info,t.payment_type=e.other_info.payment_type,t.bundle_items=e.bundle_children),i.detail.variants&&(i.detail.variation_type==="simple_variations"||i.detail.variation_type==="advanced_variations")){let r={};e=i.detail.variants[d],r.id=e.id,r.order_id=n,r.post_id=e.post_id,r.object_id=e.id,r.price=e.item_price,r.unit_price=e.item_price,r.item_cost=e.item_cost,r.featured_media=e.media&&e.media.meta_value&&e.media.meta_value[0]?e.media.meta_value[0].url:t.featured_media,r.quantity=1,r.post_title=i.post_title,r.title=e.variation_title,r.variation_display_title=e.variation_display_title||e.variation_title,r.fulfillment_type=i.detail.fulfillment_type,r.manage_stock=e.manage_stock,r.stockStatus=e.manage_stock==1?e.stock_status:"in-stock",r.available=e.manage_stock==1?e.available:1/0,r.soldIndividually=e.sold_individually,r.settings=e.settings,r.checked=!1,r.disable=c(r),r.other_info=e.other_info,r.payment_type=e.other_info.payment_type,r.bundle_items=e.bundle_children,t.children.push(r)}}}t.disable=c(t),l.push(t)}}return l}const c=a=>!(a.stockStatus==="in-stock"&&(Array.isArray(a.children)&&a.children.length===0||!a.children)),v=(a,n,l=!1)=>!a&&l?"":(a||(a="0.00"),p.get("shop.currency_sign")+" "+a),y=(a,n,l=!1)=>_.formatNumber(a,n,l),b=a=>{if(!a.item_price||!a.item_cost)return"--";const n=Number(String(a.item_price).replace(",",".")),l=Number(String(a.item_cost).replace(",","."));return isNaN(n)||isNaN(l)||n===0?"--":((n-l)/n*100).toFixed(2)+"% "},h=a=>{if(!a.item_price||!a.item_cost)return"--";const n=Number(String(a.item_price).replace(",",".")),l=Number(String(a.item_cost).replace(",","."));if(isNaN(n)||isNaN(l))return"--";const t=n-l;return _.formatNumber(t*100,!0)},g=a=>a.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "),k=a=>{const n=new Set;return a.order_items.forEach(l=>{(Number(l.object_id)!==0||l.object_id===null)&&n.add(l.object_id)}),n.size};export{g as a,v as b,h as c,b as d,y as f,k as g,f as p};
