function mockChooseImage(){let e=wx.getFileSystemManager();if(!global.__minium_mock_choose_image){let t=!1;global.__minium_mock_choose_image=function(...s){const i=s.map((t=>{const{imageData:s,imageName:i,size:a}=t,r=`${wx.env.USER_DATA_PATH}/.MINIUM_TMP/${i}`;return s&&0!==s.length?new Promise(((t,a)=>{e.writeFile({filePath:r,data:s,encoding:"base64",success:()=>{e.stat({path:r,success:({stats:e})=>{t({imageName:i,filePath:r,size:e.size})}})},fail:({errMsg:e})=>{a("writeFile:fail the maximum size of the file storage limit is exceeded"===e?new Error("小程序文件空间不足"):"writeFile:fail sdcard not mounted"===e?new Error("sdcard未挂载"):new Error(`Mock失败: ${e}`))}})})):Promise.resolve({imageName:i,filePath:r,size:a})}));return Promise.all(i).then((e=>(function(e,s){if(t)return!1;t=!0;const i={},a={},r={chooseImage(e){o();const t={errMsg:"chooseImage:ok",tempFilePaths:s.map((e=>e.filePath)),tempFiles:s.map((e=>({path:e.filePath,size:e.size})))};if(!e.success&&!e.fail&&!e.complete)return Promise.resolve(t);e.success&&e.success(t),e.complete&&e.complete(t)},chooseMedia(e){o();const t={errMsg:"chooseMedia:ok",tempFiles:s.map((e=>({tempFilePath:e.filePath,size:e.size,fileType:"image"}))),type:"image"};if(!e.success&&!e.fail&&!e.complete)return Promise.resolve(t);e.success&&e.success(t),e.complete&&e.complete(t)},createCameraContext(){const e=i.createCameraContext(),a=e.takePhoto;return Object.defineProperty(e,"takePhoto",{configurable:!0,get:()=>function(e){if(!t)return a.call(this,e);o();const i={tempImagePath:s[0].filePath,errMsg:"takePhoto:ok"};e.success&&e.success(i),e.complete&&e.complete(i)}}),e}},c=Object.keys(r);function o(){t&&(t=!1,c.forEach((t=>{a[t]?a[t].get?Object.defineProperty(e,t,{configurable:!0,get:()=>i[t]}):Object.defineProperty(e,t,{writable:!0,value:i[t]}):e[t]=i[t]})))}c.forEach((t=>{i[t]=e[t],a[t]=Object.getOwnPropertyDescriptor(e,t)})),c.forEach((t=>{a[t]?a[t].get?Object.defineProperty(e,t,{configurable:!0,get:()=>r[t]}):Object.defineProperty(e,t,{writable:!0,value:r[t]}):e[t]=r[t]}))}(wx,e),e.map((e=>({name:e.imageName,size:e.size}))))))};let s=!1;e.mkdir({dirPath:`${wx.env.USER_DATA_PATH}/.MINIUM_STORE`,recursive:!1,success(){s=!0},fail:({errMsg:e})=>{e.indexOf("file already exists")>=0&&(s=!0)}});const i=e.saveFile,a=e.saveFileSync,r=e.getSavedFileList;Object.defineProperty(e,"saveFile",{configurable:!0,get:()=>function({tempFilePath:t,filePath:s,success:a,fail:r,complete:c}){if(t.startsWith(`${wx.env.USER_DATA_PATH}/.MINIUM_TMP`)){const i={srcPath:t,destPath:s||`${wx.env.USER_DATA_PATH}/.MINIUM_STORE/${t.split("/").pop()}`};return a&&(i.success=e=>{e.errMsg=e.errMsg.replace("copyFile","saveFile"),e.savedFilePath=i.destPath,a(e)}),r&&(i.fail=e=>{e.errMsg=e.errMsg.replace("copyFile","saveFile"),r(e)}),c&&(i.complete=e=>{e.errMsg=e.errMsg.replace("copyFile","saveFile"),0===e.errMsg.indexOf("saveFile:ok")&&(e.savedFilePath=i.destPath),c(e)}),e.copyFile(i)}return i({tempFilePath:t,filePath:s,success:a,fail:r,complete:c})}}),Object.defineProperty(e,"saveFileSync",{configurable:!0,get:()=>function(t,s){if(t.startsWith(`${wx.env.USER_DATA_PATH}/.MINIUM_TMP`)){const i=t,a=s||`${wx.env.USER_DATA_PATH}/.MINIUM_STORE/${t.split("/").pop()}`;try{return e.copyFileSync(i,a),a}catch(e){throw e.message.replace("copyFileSync","saveFileSync")}}return a(t,s)}}),Object.defineProperty(e,"getSavedFileList",{configurable:!0,get:()=>function({success:t,complete:s}){Promise.all([new Promise((t=>{e.stat({path:`${wx.env.USER_DATA_PATH}/.MINIUM_STORE/`,recursive:!0,complete:e=>{t((e.stats||[]).filter((e=>"/"!==e.path)).map((e=>({filePath:`${wx.env.USER_DATA_PATH}/.MINIUM_STORE/${e.path.startsWith("/")?e.path.slice(1):e.path}`,size:e.stats.size,createTime:e.stats.lastModifiedTime}))))}})})),new Promise((e=>{r({complete:t=>{e(t.fileList||[])}})}))]).then((([e,i])=>{const a={fileList:e.concat(i),errMsg:"getSavedFileList:ok"};t&&t(a),s&&s(a)}))}})}return new Promise(((t,s)=>{e.mkdir({dirPath:`${wx.env.USER_DATA_PATH}/.MINIUM_TMP`,recursive:!1,success(){t([])},fail:({errMsg:i})=>{i.indexOf("file already exists")>=0?e.stat({path:`${wx.env.USER_DATA_PATH}/.MINIUM_TMP/`,recursive:!0,success:e=>{if(console.warn("[debug]fs.stat success"),!e.stats.length)return t([]);t(e.stats.map((e=>({name:e.path.replace(/^\//,""),size:e.stats.size}))).filter((e=>e.name)))},fail:s}):s({errMsg:i})}})}))}
