import{A as u}from"./Translator.js?ver=1.5.0";import{C as _}from"./CurrencyFormatter.js?ver=1.5.0";function f(a,n){var o;let s=[],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;let l=i.detail.default_variation_id==e.id;if(!l&&i.detail.variation_type==="simple"&&(l=!0),l&&(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.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),s.push(t)}}return s}const c=a=>!(a.stockStatus==="in-stock"&&(Array.isArray(a.children)&&a.children.length===0||!a.children)),y=(a,n,s=!1)=>!a&&s?"":(a||(a="0.00"),u.get("shop.currency_sign")+" "+a),v=(a,n,s=!1)=>_.formatNumber(a,n,s),b=a=>{if(!a.item_price||!a.item_cost)return"--";const n=Number(String(a.item_price).replace(",",".")),s=Number(String(a.item_cost).replace(",","."));return isNaN(n)||isNaN(s)||n===0?"--":((n-s)/n*100).toFixed(2)+"% "},h=a=>{if(!a.item_price||!a.item_cost)return"--";const n=Number(String(a.item_price).replace(",",".")),s=Number(String(a.item_cost).replace(",","."));if(isNaN(n)||isNaN(s))return"--";const t=n-s;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(s=>{(Number(s.object_id)!==0||s.object_id===null)&&n.add(s.object_id)}),n.size};export{g as a,y as b,h as c,b as d,v as f,k as g,f as p};
