import{i as e,r as t}from"./collectionSkuImages-BDnlQcTj.js";function n(e){let n=e.trim();return n?t(n)||n:``}function r(e){return e.slice(0,9)}function i(e){let t=new Set,i=[],a=e=>{if(typeof e!=`string`)return;let r=n(e);!r||t.has(r)||(t.add(r),i.push(e.trim()))};for(let t of e.images)a(t.url);for(let t of e.skus)a(t.imageUrl);return r(i)}function a(e){let t=e.images.filter(e=>e.role===`main`).map(e=>e.url),a=e.images.filter(e=>e.role===`detail`).map(e=>e.url);if(!a.length)return i(e);let o=new Set,s=[],c=e=>{if(typeof e!=`string`)return;let t=n(e);!t||o.has(t)||(o.add(t),s.push(e.trim()))};c(t[0]);for(let e of a)c(e);return r(s)}function o(t){let r=a(t);if(!r.length)throw Error(`NO_IMAGES_FOR_AUTO_SAVE`);let i=new Map;for(let e of t.images){let t=n(e.url);if(t&&!i.has(t)&&i.set(t,e),e.posterUrl?.trim()){let t=n(e.posterUrl);t&&!i.has(t)&&i.set(t,e)}}let o=r.map(e=>{let t=n(e),r=i.get(t);return r?{...r,url:e}:{url:e,role:`other`}});return e({...t,images:o,skus:[...t.skus],updatedAt:new Date().toISOString()})}function s(e){return a({id:`_`,platform:`unknown`,externalId:`_`,url:``,title:``,description:``,price:{currentText:``,currency:`CNY`},images:[...e.mainImages.map(e=>({url:e,role:`main`})),...e.detailImages.map(e=>({url:e,role:`detail`})),...(e.skuImages??[]).map(e=>({url:e,role:`sku`})),...(e.commentImages??[]).map(e=>({url:e,role:`comment`}))],tags:[],skus:[],collectedAt:``,updatedAt:``})}export{s as n,o as t};