import{r as e}from"./sellerArchiveCaptureHudPayload-D6BfEDB0.js";var t=`xyxp-seller-datacompass-capture-hud`,n=`xyxp-seller-archive-capture-hud-embed`,r=`xyxp-seller-capture-hud-root`,i=`xyxp-cap-rows-host`,a=`xyxp-cap-drag`,o=`xyxp-cap-collapse-btn`,s=`xyxp-cap-embedded-head`,c=`xyxp-cap-open-analysis`,l=`xyxp-cap-actions`,u=`xyxp-cap-auto-status`,d=`xyxp-cap-auto-start`,f=`xyxp-cap-auto-stop`,p=`xyxp_seller_capture_hud_pos`,m=14,h=52,g=`#ffda00`,_=`#ffc400`;function v(e,t){return t===null||t<=0?0:Math.min(100,100*e/t)}function y(e){return e.expected===null?`unknown`:e.collected<=0?`empty`:e.collected<e.expected?`partial`:`full`}function b(e){if(e.length<10)return e;let t=Number.parseInt(e.slice(5,7),10),n=Number.parseInt(e.slice(8,10),10);return!Number.isFinite(t)||!Number.isFinite(n)?e.slice(5):`${t}/${n}`}function x(e){let t=e.date,n=e.expected===null?`列表基准未记录（请在该日打开一次完整商品列表）`:`${e.expected} 件`;return`${t} · 已存档 ${e.collected} 条 · 基准 ${n}`}function S(e,t,n){let r=n.offsetWidth||200,i=n.offsetHeight||48,a=Math.max(8,window.innerWidth-r-8),o=Math.max(8,window.innerHeight-i-8);return{left:Math.min(a,Math.max(8,e)),top:Math.min(o,Math.max(8,t))}}function C(e){e.style.left=`auto`,e.style.top=`auto`,e.style.right=`${m}px`,e.style.bottom=`${h}px`}async function w(e){let t=(await chrome.storage.local.get(p))[p];if(t&&typeof t.left==`number`&&Number.isFinite(t.left)&&typeof t.top==`number`&&Number.isFinite(t.top)){let n=S(t.left,t.top,e);e.style.left=`${n.left}px`,e.style.top=`${n.top}px`,e.style.right=`auto`,e.style.bottom=`auto`}else C(e)}function T(e){if(e.dataset.xyxpCapDrag===`1`)return;e.dataset.xyxpCapDrag=`1`;let t=!1,n=0,r=0,i=0,s=0,c=a=>{if(!t)return;let o=a.clientX-n,c=a.clientY-r,l=S(i+o,s+c,e);e.style.left=`${l.left}px`,e.style.top=`${l.top}px`,e.style.right=`auto`,e.style.bottom=`auto`},l=()=>{if(!t)return;t=!1,document.body.style.userSelect=``;let n=e.getBoundingClientRect(),r=S(n.left,n.top,e);e.style.left=`${r.left}px`,e.style.top=`${r.top}px`,chrome.storage.local.set({[p]:{left:r.left,top:r.top}}),window.removeEventListener(`mousemove`,c,!0),window.removeEventListener(`mouseup`,u,!0)},u=()=>{l()};e.addEventListener(`mousedown`,l=>{let d=l.target;if(d.closest(`.${o}`)||!d.closest(`.${a}`))return;l.preventDefault();let f=e.getBoundingClientRect();(e.style.left===`auto`||e.style.top===`auto`)&&(e.style.left=`${f.left}px`,e.style.top=`${f.top}px`,e.style.right=`auto`,e.style.bottom=`auto`),t=!0,n=l.clientX,r=l.clientY,i=e.getBoundingClientRect().left,s=e.getBoundingClientRect().top,document.body.style.userSelect=`none`,window.addEventListener(`mousemove`,c,!0),window.addEventListener(`mouseup`,u,!0)},!0)}function E(e){let t=e.querySelector(`.${i}`);return t||(t=document.createElement(`div`),t.className=i,e.append(t)),t}function D(e){let t=e.querySelector(`.xyxp-cap-cal-wrap`);return t||(t=document.createElement(`div`),t.className=`xyxp-cap-cal-wrap`,E(e).after(t)),t}var O=!1;function k(){if(O)return;O=!0;let e=document.createElement(`style`);e.setAttribute(`data-xyxp-seller-cap-hud`,`1`);let p=`.${r}`;e.textContent=`
#${t}${p} {
  position: fixed;
  z-index: 2147483000;
  min-width: 200px;
  max-width: min(94vw, 400px);
  padding: 0 12px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", sans-serif;
  font-size: 12px;
  line-height: 1.35;
  color: #222;
  pointer-events: auto;
}
#${n}${p} {
  position: relative;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0 0 8px;
  padding: 8px 10px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", sans-serif;
  font-size: 11px;
  line-height: 1.35;
  color: #222;
}
#${t} .${a} {
  cursor: grab;
  box-sizing: border-box;
  margin: 0 -12px 4px;
  min-height: 10px;
  padding: 6px 12px;
  border-radius: 10px 10px 0 0;
  user-select: none;
  touch-action: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.04) 0%, transparent 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#${t} .${a} .xyxp-cap-drag-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  color: #333;
}
#${t} .${o},
#${n} .${o} {
  flex-shrink: 0;
  padding: 2px 8px;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  color: #374151;
  background: rgba(0, 0, 0, 0.06);
}
#${t} .${o}:hover,
#${n} .${o}:hover {
  background: rgba(0, 0, 0, 0.1);
}
#${n} .${s} {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: #333;
}
${p}.xyxp-cap-root--collapsed .${i},
${p}.xyxp-cap-root--collapsed .xyxp-cap-cal-wrap,
${p}.xyxp-cap-root--collapsed .${u},
${p}.xyxp-cap-root--collapsed .${l} {
  display: none !important;
}
${p}.xyxp-cap-root--collapsed {
  padding-bottom: 4px;
}
#${n}${p}.xyxp-cap-root--collapsed {
  padding-bottom: 6px;
}
#${t} .${a}:active {
  cursor: grabbing;
}
${p} .${l} {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 10px;
}
${p} .${l} button {
  box-sizing: border-box;
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
${p} .${d} {
  color: #1a1a1a;
  background: linear-gradient(180deg, ${g} 0%, ${_} 100%);
}
${p} .${f} {
  color: #fff;
  background: linear-gradient(180deg, #f87171 0%, #ef4444 100%);
}
${p} .${f}:disabled,
${p} .${d}:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
${p} .${c} {
  color: #1a1a1a;
  background: linear-gradient(180deg, #f3f4f6 0%, #e5e7eb 100%);
}
${p} .${l} button:hover:not(:disabled) {
  filter: brightness(1.03);
}
${p} .${l} button:active:not(:disabled) {
  filter: brightness(0.97);
}
#${n}${p} .${l} {
  margin-top: 6px;
  gap: 4px;
}
#${n}${p} .${l} button {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 6px;
}
${p} .${u} {
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.45;
  color: #374151;
  background: rgba(255, 218, 0, 0.18);
  border: 1px solid rgba(252, 211, 77, 0.65);
}
${p} .${u}[hidden] {
  display: none !important;
}
${p} .${i} .xyxp-cap-row + .xyxp-cap-row {
  margin-top: 10px;
}
${p} .xyxp-cap-cal-wrap {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}
${p} .xyxp-cap-cal-wrap[hidden] {
  display: none !important;
}
${p} .xyxp-cap-cal-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: #444;
  line-height: 1.45;
}
${p} .xyxp-cap-cal-days-input {
  box-sizing: border-box;
  width: 3.4em;
  margin: 0 2px;
  padding: 1px 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  font-size: inherit;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: inherit;
  background: #fff;
}
${p} .xyxp-cap-cal-days-input:focus {
  outline: 2px solid rgba(255, 218, 0, 0.55);
  outline-offset: 0;
}
${p} .xyxp-cap-cal-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px 8px;
  align-items: stretch;
  padding: 2px 0 4px;
}
/* 数据分析页内嵌：小格 + 自动换行向下铺，不占横向滚动条 */
#${n}${p} .xyxp-cap-cal-wrap {
  margin-top: 8px;
  padding-top: 8px;
}
#${n}${p} .xyxp-cap-cal-title {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 600;
  color: #555;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#${n}${p} .xyxp-cap-cal-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 4px 5px;
  align-items: stretch;
  padding: 2px 0 4px;
}
#${n}${p} .xyxp-cap-cal-cell {
  min-width: 0;
  min-height: 22px;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 10px;
}
${p} .xyxp-cap-cal-cell {
  box-sizing: border-box;
  min-width: 0;
  min-height: 30px;
  padding: 6px 4px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #1a1a1a;
  border: 1px solid rgba(0, 0, 0, 0.12);
  cursor: default;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
${p} .xyxp-cap-cal-cell--unknown {
  background: #e5e7eb;
  color: #4b5563;
}
${p} .xyxp-cap-cal-cell--empty {
  background: #fff;
  color: #6b7280;
}
${p} .xyxp-cap-cal-cell--partial {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}
${p} .xyxp-cap-cal-cell--full {
  background: #d1fae5;
  border-color: #6ee7b7;
  color: #065f46;
}
${p} .xyxp-cap-line {
  margin-bottom: 6px;
  font-weight: 500;
}
${p} .xyxp-cap-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  overflow: hidden;
}
${p} .xyxp-cap-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, ${g} 0%, ${_} 100%);
  transition: width 0.25s ease;
  min-width: 0;
}
`,document.documentElement.appendChild(e)}function A(){let e=document.getElementById(t);return e||(e=document.createElement(`div`),e.id=t,e.classList.add(r),e.setAttribute(`role`,`status`),e.setAttribute(`aria-live`,`polite`),E(e),document.body.append(e),T(e),w(e),e)}function j(e){let t=e.querySelector(`#${n}`);return t||(t=document.createElement(`div`),t.id=n,t.classList.add(r),t.setAttribute(`role`,`region`),t.setAttribute(`aria-label`,`数据整理进度与存档日历`),E(t),e.appendChild(t),t)}function M(e){let t=e.querySelector(`.${s}`);return t||(t=document.createElement(`div`),t.className=s,e.insertBefore(t,e.firstChild)),t}function N(e,t,n){e.setAttribute(`aria-expanded`,t?`false`:`true`),e.textContent=t?`展开`:`收起`,e.title=t?`展开数据整理进度`:`收起数据整理进度`,e.onclick=e=>{e.preventDefault(),e.stopPropagation(),n?.()}}function P(e,n,r){if(e.id!==t)return;let i=e.querySelector(`.${a}`);if(!i){i=document.createElement(`div`),i.className=a,i.setAttribute(`aria-label`,`拖动移动数据整理进度`),i.title=`按住顶部区域可拖动位置`;let t=document.createElement(`span`);t.className=`xyxp-cap-drag-title`,t.textContent=`数据整理进度`,i.append(t),e.insertBefore(i,e.firstChild)}let s=i.querySelector(`.${o}`);s||(s=document.createElement(`button`),s.type=`button`,s.className=o,i.append(s)),N(s,n,r)}function F(e,t,r){if(e.id!==n)return;let i=M(e),a=i.querySelector(`.xyxp-cap-embedded-title`);a||(a=document.createElement(`span`),a.className=`xyxp-cap-embedded-title`,a.textContent=`数据整理进度`,i.prepend(a));let s=i.querySelector(`.${o}`);s||(s=document.createElement(`button`),s.type=`button`,s.className=o,i.append(s)),N(s,t,r)}function I(e,t){e.classList.toggle(`xyxp-cap-root--collapsed`,t)}function L(e){if(e.message===`正在停止…`)return e.message;if(e.running&&e.date){let t=e.expected===null?`—`:String(e.expected);return`自动整理中：${e.date} · 第 ${e.page} 页 · ${e.collected}/${t} · 队列 ${e.queueIndex}/${e.queueTotal}`}return e.running&&e.message,e.message}function R(e,t,n){e.querySelector(`.${l}`)?.remove(),e.querySelector(`.${u}`)?.remove();let r=n.autoCapture?L(n.autoCapture):``;if(r&&(n.autoCapture?.running===!0||n.autoCapture?.message)&&n.autoCapture){let e=document.createElement(`div`);e.className=u,e.textContent=r,e.setAttribute(`role`,`status`),t.after(e)}let i=document.createElement(`div`);if(i.className=l,n.placement===`fixed`&&n.onStartAutoCapture&&n.onStopAutoCapture){let e=document.createElement(`button`);e.type=`button`,e.className=d,e.textContent=`自动整理`;let t=n.calendarStripDays??14;e.setAttribute(`aria-label`,`按近 ${t} 天未整理完日期自动翻页整理`),e.disabled=n.autoCapture?.running===!0,e.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),n.onStartAutoCapture?.()});let r=document.createElement(`button`);r.type=`button`,r.className=f,r.textContent=`停止`,r.setAttribute(`aria-label`,`停止自动整理`),r.disabled=n.autoCapture?.running!==!0,r.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),n.onStopAutoCapture?.()}),i.append(e,r)}let a=document.createElement(`button`);a.type=`button`,a.className=c,a.textContent=n.ctaLabel,a.setAttribute(`aria-label`,n.ctaAria),a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),n.ctaFn()}),i.append(a);let o=e.querySelector(`.${u}`);o?o.after(i):t.after(i)}function z(){chrome.runtime.sendMessage({type:`OPEN_SELLER_ARCHIVE_TAB`}).then(e=>{e&&typeof e==`object`&&`ok`in e&&e.ok===!1&&console.warn(`[xyxp] 打开数据分析页失败`,e.error??e)}).catch(e=>{console.warn(`[xyxp] 打开数据分析页 sendMessage 异常`,e)})}function B(){document.getElementById(t)?.remove()}function V(e){e.querySelector(`#${n}`)?.remove()}function H(t,n){let r=document.createElement(`div`);r.className=`xyxp-cap-cal-title`;let i=t.length;if(n.showCalendarDaySelector===!0&&typeof n.calendarStripDays==`number`&&n.onCalendarStripDaysChange){r.append(`近 `);let t=document.createElement(`input`);t.type=`number`,t.min=`1`,t.max=`90`,t.step=`1`,t.className=`xyxp-cap-cal-days-input`,t.value=String(n.calendarStripDays),t.title=`展示天数（1～90）`,t.setAttribute(`aria-label`,`存档日历展示天数`);let i=()=>{let r=e(Number(t.value));t.value=String(r),r!==n.calendarStripDays&&n.onCalendarStripDaysChange?.(r)};t.addEventListener(`change`,i),t.addEventListener(`blur`,i),t.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),i(),t.blur())}),t.addEventListener(`click`,e=>{e.stopPropagation()}),t.addEventListener(`mousedown`,e=>{e.stopPropagation()}),r.append(t,` 天存档（灰=未整理，黄=整理中，绿=全部整理）`)}else r.textContent=n.calendarTitle??`近${i}天存档（灰=未整理，黄=整理中，绿=全部整理）`;return r}function U(e,t,n){let r=n?.placement??`fixed`,i=n?.mount;if(r===`embedded`&&!i)return;let a=r===`embedded`?j(i):A();k();let o=n?.hudCollapsed===!0,s=()=>{n?.onHudCollapsedChange?.(!o)};r===`fixed`?P(a,o,s):F(a,o,s),I(a,o);let c=E(a),l=D(a);R(a,l,{placement:r,ctaLabel:n?.ctaLabel??`数据分析`,ctaAria:n?.ctaAriaLabel??`在新标签页打开插件卖家数据分析`,ctaFn:n?.onCtaClick??z,calendarStripDays:n?.calendarStripDays,autoCapture:n?.autoCapture,onStartAutoCapture:n?.onStartAutoCapture,onStopAutoCapture:n?.onStopAutoCapture});let u=document.createDocumentFragment();for(let t of e){let e=t.expected===null?`—`:String(t.expected),n=document.createElement(`div`);n.className=`xyxp-cap-line`,n.textContent=`${t.title}：${t.collected} / ${e}`;let r=document.createElement(`div`);r.className=`xyxp-cap-track`;let i=document.createElement(`div`);i.className=`xyxp-cap-fill`,i.style.width=`${v(t.collected,t.expected)}%`,r.append(i);let a=document.createElement(`div`);a.className=`xyxp-cap-row`,a.append(n,r),u.append(a)}if(c.replaceChildren(u),!t||t.length===0)l.hidden=!0,l.replaceChildren();else{l.hidden=!1;let e=H(t,{calendarTitle:n?.calendarTitle,calendarStripDays:n?.calendarStripDays,showCalendarDaySelector:n?.showCalendarDaySelector,onCalendarStripDaysChange:n?.onCalendarStripDaysChange}),r=document.createElement(`div`);r.className=`xyxp-cap-cal-strip`,r.setAttribute(`role`,`img`);let i=t.length;r.setAttribute(`aria-label`,n?.calendarTitle??`最近 ${i} 个自然日各日存档条数与列表基准对比`);for(let e of t){let t=document.createElement(`div`);t.className=`xyxp-cap-cal-cell xyxp-cap-cal-cell--${y(e)}`,t.textContent=b(e.date),t.title=x(e),r.append(t)}l.replaceChildren(e,r)}r===`fixed`&&requestAnimationFrame(()=>{w(a)})}export{V as n,U as r,B as t};