import{r as e}from"./authSession-CrP9lMPq.js";import{r as t}from"./norm-CeclA1Tu.js";var n=`https://api2.bysjob.com`,r=()=>{try{return`https://api2.bysjob.com`.replace(/\/+$/g,``)}catch{}try{let e=String(globalThis?.location?.protocol||``);if(e!==`chrome-extension:`&&e!==`moz-extension:`){let e=String(globalThis?.location?.origin||``).replace(/\/+$/g,``);if(e&&(e.includes(`localhost`)||e.includes(`127.0.0.1`)))return e}}catch{}return n},i=async n=>{let r=await e(),i=t(r?.accessToken||r?.token);if(!i){if(n)throw Error(`请先登录`);return{}}return{"x-auth-token":i,Authorization:`Bearer `+i}},a=async(e,t,n)=>{let a=n?.auth??`required`,o=typeof t?.body==`string`,s=a===`none`?{}:await i(a===`required`),c={...o?{"Content-Type":`application/json`}:{},...s,...t?.headers||{}},l=await fetch(r()+e,{...t,headers:c}),u=await l.text(),d=null;try{d=JSON.parse(u)}catch{d=u}if(!l.ok){let e=d&&typeof d==`object`&&(d.message||d.error)||`请求失败 (`+l.status+`)`,t=Error(String(e));throw t.code=d?.code||d?.error,t.statusCode=l.status,t}return d},o={getTemplates:async()=>(await a(`/api/forms/templates`)).templates||[],list:async()=>(await a(`/api/forms`)).forms||[],get:async e=>(await a(`/api/forms/`+e)).form,create:async e=>a(`/api/forms`,{method:`POST`,body:JSON.stringify(e)}),update:async(e,t)=>a(`/api/forms/`+e,{method:`PUT`,body:JSON.stringify(t)}),remove:async e=>a(`/api/forms/`+e,{method:`DELETE`}),publish:async e=>a(`/api/forms/`+e+`/publish`,{method:`POST`}),close:async e=>a(`/api/forms/`+e+`/close`,{method:`POST`}),getBySlug:async e=>(await a(`/api/forms/f/`+e,void 0,{auth:`optional`})).form,submit:async(e,t)=>a(`/api/forms/f/`+e+`/submissions`,{method:`POST`,body:JSON.stringify(t)},{auth:`optional`}),listSubmissions:async(e,t=100,n=0)=>await a(`/api/forms/`+e+`/submissions?limit=`+t+`&offset=`+n),exportCsv:async e=>{let t=await fetch(r()+`/api/forms/`+e+`/submissions/export`,{headers:await i(!0)});if(!t.ok)throw Error(`导出失败`);return t.blob()},quoteAnalysis:async e=>a(`/api/forms/`+e+`/analyze/quote`),analyze:async e=>a(`/api/forms/`+e+`/analyze`,{method:`POST`}),listAnalyses:async e=>(await a(`/api/forms/`+e+`/analyses`)).analyses||[]};export{o as t};