import{a1 as a,a2 as e,h as l,o as s,X as i,a3 as t,a4 as o,Z as n,c as p,aq as u,ao as c}from"./index.9313841a.js";import{Q as d}from"./QPage.51e20052.js";import{u as m}from"./use-quasar.ca800b49.js";import{F as r}from"./FileUploadS3.c9d78bff.js";import{b as v,c as f}from"./common.356e5c35.js";import{u as g}from"./T3Data.889a220d.js";import{l as y}from"./api.c096d0cb.js";import{k as b}from"./index.d11c4764.js";import"./index.57b723e8.js";import"./_commonjsHelpers.a5007c1f.js";import"./plugin-vue_export-helper.21dcd24c.js";const h={class:"flex flex-col w-full max-w-7xl"},j={class:"flex items-center"},x={class:"image-container relative w-52"},w={class:"flex grid-cols-4 gap-4"},A={__name:"EditApp",setup(A){const _=m(),U=a(),V=e(),F=l({});let k=!1;const I=l(!0),P=l(null),R={}.API_URL+"/file/";function q(a){const e=a.body;F.value.imageId=e.id,E()}function C(){F.value.imageId=null,k=!1}async function D(){var a,e;g.value&&((null==(e=null==(a=P.value)?void 0:a.uppy.getFiles())?void 0:e.length)>0&&!k?P.value.upload():E())}function E(){y.patch("t3Apps/"+V.params.id,{json:F.value}).then((async()=>{U.push({path:"/user/apps"}),_.notify({type:"positive",message:"Application updated"})})).catch((a=>{_.notify({type:"negative",message:"Application not updated! "+a.message})}))}return s((()=>{v.value.title="Edit Application",v.value.back="/apps-library",y.get("t3Apps/"+V.params.id).then((async a=>{var e;const l=await a.json();I.value=!1,f(g.value)||g.value.id===l.userId||(U.push({path:"/apps-library"}),_.notify({type:"negative",message:"Permission denied!"})),F.value={name:l.name,description:l.description},l.image&&(I.value=!0,b.get(R+(null==(e=l.image)?void 0:e.path)).then((async a=>{var e;const s=await a.blob();k=!0,null==(e=P.value)||e.uppy.addFile({id:l.image.id,name:l.image.name,type:s.type,data:s})})).finally((()=>{I.value=!1})))})).catch((a=>{_.notify({type:"negative",message:a.message})}))})),(a,e)=>(i(),t(d,{class:"flex justify-center p-4"},{default:o((()=>[n("div",h,[n("div",j,[n("div",x,[p(r,{ref_key:"fileUploaderRef",ref:P,path:"app-images",types:["image/*"],height:150,onUploaded:q,onFileRemoved:C},null,512)]),p(u,{class:"grow px-4",modelValue:F.value.name,"onUpdate:modelValue":e[0]||(e[0]=a=>F.value.name=a),label:"Name"},null,8,["modelValue"])]),p(u,{class:"py-2",modelValue:F.value.description,"onUpdate:modelValue":e[1]||(e[1]=a=>F.value.description=a),label:"Description",type:"textarea",autogrow:""},null,8,["modelValue"]),n("div",w,[p(c,{label:"Save",color:"primary",icon:"save",onClick:D,disable:I.value},null,8,["disable"]),p(c,{label:"Cancel",icon:"cancel",to:"/apps-library"})])])])),_:1}))}};export{A as default};
