import"./rolldown-runtime-BM3Ffeng.js";import{at as e,it as t,nt as n,ot as r,w as ee}from"./element-plus-vendor-BF9PNysW.js";import{A as i,D as a,E as o,G as s,I as c,J as l,N as u,O as d,P as f,Pt as p,Tt as m,Xt as te,Z as h,_ as g,bt as _,et as v,gt as y,ht as b,k as ne,nt as x,v as S,x as C}from"./vue-vendor-DMUmTARL.js";import{Xa as re}from"./icons-vendor-Buq6V-Ga.js";import{y as w}from"./index-y6crcKNt.js";import{t as T}from"./sortable.esm-BBo_Uzmk.js";var E={class:`w-full`},D=[`aria-label`],O={class:`inline-flex items-center gap-1`},k={key:0,class:`text-xs opacity-70`},A={class:`mt-3 flex flex-wrap items-center gap-2`},j=c({__name:`ExpireOptionEditor`,props:{modelValue:{},valueMode:{default:`seconds`},allowForever:{type:Boolean,default:!0},allowCustomDate:{type:Boolean,default:!1},ariaLabel:{default:`有效期可选项`}},emits:[`update:modelValue`],setup(c,{emit:j}){let M=[{label:`秒`,value:`s`},{label:`分钟`,value:`m`},{label:`小时`,value:`h`},{label:`天`,value:`d`},{label:`周`,value:`w`},{label:`月`,value:`M`},{label:`年`,value:`y`}],ie=[{label:`分钟`,value:`m`},{label:`小时`,value:`h`},{label:`天`,value:`d`}],N={s:1,m:60,h:3600,d:86400,w:604800,M:2592e3,y:31536e3},ae={s:1/60,m:1,h:60,d:1440,w:10080,M:43200,y:525600},oe={s:59,m:59,h:23,d:31,w:52,M:12,y:100},P=c,se=j,F=w(),I=m(!1),L=m(1),R=m(`d`),z=m(),B=o(()=>Array.isArray(P.modelValue)?P.modelValue:[]),V=o(()=>P.valueMode===`minutes`?ie:M),H=o(()=>Object.fromEntries(V.value.map(e=>[e.value,e.label]))),U=(e,t)=>e*N[t],W=e=>!!e&&Object.prototype.hasOwnProperty.call(N,e),G=e=>{if(typeof e==`number`)return e;if(e.unit===`forever`)return-1;let t=Number(e.seconds);return Number.isFinite(t)?t:typeof e.value!=`number`||!W(e.unit)?0:U(e.value,e.unit)},K=o(()=>B.value.some(e=>G(e)===-1)),q=o(()=>B.value.some(e=>typeof e==`number`&&e===-2)),ce=o(()=>P.valueMode===`minutes`?99999999:oe[R.value]),le=e=>e===-1?`永久`:e===-2?`自定义日期`:e%1440==0?`${e/1440}天`:e%60==0?`${e/60}小时`:`${e}分钟`,ue=e=>typeof e==`number`?le(e):G(e)===-1?`永久`:`${e.value??``}${H.value[e.unit||``]||e.unit||``}`,de=(e,t)=>`${typeof e}-${G(e)}-${t}`,J=e=>se(`update:modelValue`,e),Y=m(),X=null,Z=()=>{!Y.value||X||(X=T.create(Y.value,{animation:150,draggable:`.expire-option-editor__item`,onEnd:({oldIndex:e,newIndex:t})=>{if(e==null||t==null||e===t)return;let n=[...B.value],r=n.splice(e,1)[0];r!==void 0&&(n.splice(t,0,r),J(n))}}))};h(()=>{s(Z)}),l(()=>{X?.destroy(),X=null});let fe=()=>{I.value=!0,L.value=1,R.value=`d`,s(()=>z.value?.focus?.())},Q=()=>{I.value=!1},pe=e=>P.valueMode===`minutes`?e*ae[R.value]:{value:e,unit:R.value,seconds:U(e,R.value)},$=()=>{let e=Number(L.value);if(!Number.isInteger(e)||e<1){F.error(`请输入有效的时长（正整数）`);return}let t=pe(e),n=G(t);if(B.value.some(e=>G(e)===n)){F.warning(`该有效期已存在`);return}J([...B.value,t]),Q()},me=()=>{if(K.value)return;let e=P.valueMode===`minutes`?-1:{value:1,unit:`forever`,seconds:-1};J([...B.value,e])},he=()=>{q.value||J([...B.value,-2])},ge=e=>{B.value.length<=1||J(B.value.filter((t,n)=>n!==e))};return(o,s)=>{let l=re,m=e,h=ee,w=n,T=t,j=r;return v(),i(`div`,E,[a(`div`,{ref_key:`optionContainerRef`,ref:Y,class:`flex min-h-10 flex-wrap`,"aria-label":c.ariaLabel},[(v(!0),i(C,null,x(p(B),(e,t)=>(v(),d(m,{key:de(e,t),closable:p(B).length>1,"disable-transitions":!1,size:`large`,class:`expire-option-editor__item mb-2 mr-2 cursor-grab active:cursor-grabbing`,onClose:e=>ge(t)},{default:b(()=>[a(`span`,O,[f(l,{class:`h-4 w-4 text-placeholder`}),a(`span`,null,te(ue(e)),1),t===0?(v(),i(`span`,k,`（默认）`)):ne(``,!0)])]),_:2},1032,[`closable`,`onClose`]))),128))],8,D),a(`div`,A,[p(I)?(v(),i(C,{key:0},[f(h,{ref_key:`inputRef`,ref:z,modelValue:p(L),"onUpdate:modelValue":s[0]||=e=>_(L)?L.value=e:null,min:1,max:p(ce),controls:!1,class:`!w-28`,onKeyup:S($,[`enter`])},null,8,[`modelValue`,`max`]),f(T,{modelValue:p(R),"onUpdate:modelValue":s[1]||=e=>_(R)?R.value=e:null,class:`!w-28`},{default:b(()=>[(v(!0),i(C,null,x(p(V),e=>(v(),d(w,{key:e.value,label:e.label,value:e.value},null,8,[`label`,`value`]))),128))]),_:1},8,[`modelValue`]),f(j,{type:`primary`,onClick:$},{default:b(()=>[...s[2]||=[u(`确定`,-1)]]),_:1}),f(j,{onClick:Q},{default:b(()=>[...s[3]||=[u(`取消`,-1)]]),_:1})],64)):(v(),i(C,{key:1},[f(j,{onClick:fe},{default:b(()=>[...s[4]||=[u(`+ 添加`,-1)]]),_:1}),y(f(j,{onClick:me},{default:b(()=>[...s[5]||=[u(` + 永久 `,-1)]]),_:1},512),[[g,c.allowForever&&!p(K)]]),y(f(j,{onClick:he},{default:b(()=>[...s[6]||=[u(` + 自定义日期 `,-1)]]),_:1},512),[[g,c.allowCustomDate&&!p(q)]])],64))])])}}});export{j as t};