import{as as l,at as o,ao as u,au as i,av as d,O as w}from"./CPIh6jMJ.js";import{m as I,n as _}from"./Ccuc0Xox.js";const P=[{key:"all",value:null,label:"全部"},...Object.entries(l).map(([t,n])=>({key:t,value:t,label:n}))],y=["code","type","title","desc","imgs","date"],f=Object.fromEntries(y.map(t=>[t,o[t]])),N=Object.values(f),O=["code","type","title","desc","content","imgs","noshowImgs","date","isEnable"],m=Object.fromEntries(O.map(t=>[t,o[t]])),h=Object.values(m),E={controlId:o.isEnable,dataType:2,spliceType:1,filterType:2,values:["1"]};function D(t){if(t==null||t==="")return null;const n=l[t]??String(t);return{controlId:o.type,dataType:11,spliceType:1,filterType:2,values:[n]}}function L(t){if(t==null||t==="")return"";if(/^\d+$/.test(String(t))){const e=Number(t),a=String(t).length<=10?e*1e3:e,r=new Date(a);if(!isNaN(r.getTime()))return r.toISOString().slice(0,10)}const n=new Date(t);return isNaN(n.getTime())?"":n.toISOString().slice(0,10)}function v(t){return t===!0||t===1||t==="1"||t==="true"}const S={imgs:t=>_(t)[0]??null,noshowImgs:v,date:L};async function j({type:t="recent",pageSize:n=5,pageIndex:e=1}={}){const a=[E],r=D(t);r&&a.push(r);const{rows:p,total:g}=await u({worksheetId:i,viewId:d,pageIndex:e,pageSize:n,controls:N,filters:a,getSystemControl:!0});return{items:p.map(T=>{const s=I(T,f,S);return{id:s.id,code:s.code,date:s.date,type:s.type,title:s.title,desc:s.desc,cover:s.imgs}}),total:g}}const b=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function c(t){if(String(t?.[o.isEnable]??"")!=="1")throw new Error("新闻不存在或已下线");return t}async function R(t){if(b.test(t)){const e=await w({worksheetId:i,rowId:t,getSystemControl:!0});return c(e)}const{rows:n}=await u({worksheetId:i,viewId:d,pageIndex:1,pageSize:1,controls:h,filters:[E,{controlId:o.code,dataType:2,spliceType:1,filterType:2,values:[String(t)]}],getSystemControl:!0});if(!n.length)throw new Error("新闻不存在或已下线");return c(n[0])}async function C(t){const n=await R(t),e=I(n,m,S);return{id:e.id,code:e.code,date:e.date,type:e.type,title:e.title,desc:e.desc,content:e.content,cover:e.imgs,noshowImgs:e.noshowImgs}}export{P as N,C as a,j as f};
