/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{defineComponent as t,ref as i,reactive as e,computed as r,unref as n,watch as s,onMounted as m,nextTick as o,createVNode as l}from"vue";import{useEventListener as h}from"@gsc-basic/hooks";import{getSlot as a}from"@gsc-basic/utils";import c from"../../node_modules/lodash-es/isNaN.js";const u="gsc-virtual-scroll";function g(t,i="px"){return null==t||""===t?void 0:c(+t)?String(t):`${Number(t)}${i}`}const d=/* @__PURE__ */t({name:"GscVirtualScroll",props:{height:[Number,String],maxHeight:[Number,String],maxWidth:[Number,String],minHeight:[Number,String],minWidth:[Number,String],width:[Number,String],bench:{type:[Number,String],default:0},itemHeight:{type:[Number,String],required:!0},items:{type:Array,default:()=>[]}},setup(t,{slots:c}){const d=i(null),p=e({first:0,last:0,scrollTop:0}),f=r(()=>Number.parseInt(t.bench,10)),b=r(()=>Number.parseInt(t.itemHeight,10)),N=r(()=>Math.max(0,p.first-n(f))),x=r(()=>Math.min((t.items||[]).length,p.last+n(f))),H=r(()=>({height:g((t.items||[]).length*n(b))})),S=r(()=>{const i={},e=g(t.height),r=g(t.minHeight),n=g(t.minWidth),s=g(t.maxHeight),m=g(t.maxWidth),o=g(t.width);return e&&(i.height=e),r&&(i.minHeight=r),n&&(i.minWidth=n),s&&(i.maxHeight=s),m&&(i.maxWidth=m),o&&(i.width=o),i});function y(i){const e=n(d);if(!e)return 0;const r=Number.parseInt(t.height||0,10)||e.clientHeight;return i+Math.ceil(r/n(b))}function v(){const t=n(d);t&&(p.scrollTop=t.scrollTop,p.first=Math.floor(p.scrollTop/n(b)),p.last=y(p.first))}function W(){const{items:i=[]}=t;return i.slice(n(N),n(x)).map(_)}function _(t,i){const e=g((i+=n(N))*n(b));return l("div",{class:`${u}__item`,style:{top:e},key:i},[a(c,"default",{index:i,item:t})])}return s([()=>t.itemHeight,()=>t.height],()=>{v()}),m(()=>{p.last=y(0),o(()=>{const t=n(d);t&&h({el:t,name:"scroll",listener:v,wait:0})})}),()=>l("div",{class:u,style:n(S),ref:d},[l("div",{class:`${u}__container`,style:n(H)},[W()])])}});export{d as default};