import{i as e}from"./collectionSkuImages-BDnlQcTj.js";import{t}from"./collectionId-8ALNfTtA.js";import{a as n,i as r,n as i,o as a,r as o,t as s}from"./adapterSooxie-LI96NX5W.js";import{r as c}from"./imagePickBroadcast-ZJib9Pjm.js";import{t as l}from"./mountPageCollectActions-Di2YARbR.js";function u(e){let t=e.trim();return t?t.startsWith(`//`)?`https:${t}`:t:``}function d(e,t,n,r){let i=u(n);!i||t.has(i)||(t.add(i),e.push({url:i,role:r}))}function f(e){let t=e.replace(/[^\d.]/g,``),n=Number(t);return Number.isFinite(n)?n:void 0}function p(e,t,n,r){if(!e.length||!t.length)return[];let i=n.replace(/^¥/,``).trim(),a=f(i),o=[];for(let n of e){let e=r.get(n);for(let r of t)o.push({skuId:`${n}-${r}`,priceText:i?`¥${i}`:void 0,price:a,imageUrl:e,properties:[{name:`颜色`,value:n},{name:`尺码`,value:r}]})}return o}function m(e){let t=[];for(let n of e.specs){let e=n.indexOf(`:`);e>0?t.push({kind:`property`,name:n.slice(0,e),text:n.slice(e+1)}):n.trim()&&t.push({kind:`property`,text:n})}return t}function h(e,t){let n=[],r=new Set;for(let t of e.mainImages)d(n,r,t,`main`);for(let t of e.detailImages)d(n,r,t,`detail`);for(let e of t)e.imageUrl&&d(n,r,e.imageUrl,`sku`);return n}function g(){return a(window.location.href)||null}async function _(){try{let e=new URL(window.location.href);return n(e)?s.extractProduct(document,e):null}catch{return null}}async function v(n,a,s=document){if(!n)return{ok:!1,errorMessage:`搜鞋商品页面数据未就绪`};let c=n.id.trim()||a?.trim()||``;if(!c)return{ok:!1,errorMessage:`无法解析搜鞋商品 ID`};let{colors:l,sizes:u}=i(s);if(!l.length||!u.length)return{ok:!1,errorMessage:`未读取到颜色或尺码，请等待页面加载完成后重试`};let d=await o(s),f=r(s,l,d),g=new Date().toISOString(),_=p(l,u,n.priceText,f);return{ok:!0,item:e({id:t(`sooxie`,c),platform:`sooxie`,externalId:c,url:n.url,title:n.title,description:n.description,price:{currentText:n.priceText?.trim()??``,currency:`CNY`},images:h(n,_),tags:m(n),skus:_,collectedAt:g,updatedAt:g,sourceApi:d.length?`sooxie-stock-api`:`sooxie-dom`})}}if(console.log(`[xyxp-sooxie] isolated script loaded`,{href:location.href,top:window.self===window.top}),window.self===window.top){function e(e){let{colors:t,sizes:n}=i(e);return t.length>0&&n.length>0}async function t(t=8e3){if(e(document))return;let n=Date.now()+t;for(;Date.now()<n;)if(await new Promise(e=>{window.setTimeout(e,200)}),e(document))return}async function n(){await t();let e=g(),n=await v(await _(),e,document),{colors:r,sizes:a}=i(document),o=n.item?.skus.filter(e=>e.imageUrl).length??0;return console.log(`[xyxp-sooxie] buildCollectedItem`,{ok:n.ok,skuCount:n.item?.skus.length??0,skuWithImageCount:o,imageCount:n.item?.images.length??0,colorCount:r.length,sizeCount:a.length}),n}function r(){l({hostId:`xyxp-sooxie-manual-add-sidebar`,storageKey:c,platform:`sooxie`,theme:`goofish`,buildCollectedItem:()=>n(),resolveExternalId:()=>g()||null})}chrome.runtime.onMessage.addListener((e,t,r)=>e?.type===`GET_SOOXIE_COLLECTED_ITEM`?(n().then(e=>{r(e.ok&&e.item?{ok:!0,item:e.item}:{ok:!1,error:e.errorMessage??`搜鞋商品数据未就绪`})}).catch(e=>{r({ok:!1,error:e instanceof Error?e.message:`搜鞋整理失败`})}),!0):!1),document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,r,{once:!0}):r()}