import{a2 as a,a3 as e,h as l,o as s,Y as i,a4 as t,a5 as o,$ as p,c as n,ar as u,ap as c}from"./index.3938ccd1.js";import{Q as d}from"./QPage.62812de7.js";import{u as r}from"./use-quasar.63a27b45.js";import{F as m}from"./FileUploadS3.c8d8f3ba.js";import{globalNav as v,isAdmin as f}from"./common.0a9f0488.js";import{u as g}from"./T3Data.cbe80363.js";import{l as y}from"./api.bf47c78e.js";import{k as b}from"./index.d11c4764.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 _=r(),U=a(),V=e(),F=l({});let k=!1;const I=l(!0),P=l(null),R={}.API_URL+"/file/";function C(a){const e=a.body;F.value.imageId=e.id,Q()}function D(){F.value.imageId=null,k=!1}async function E(){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():Q())}function Q(){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((()=>[p("div",h,[p("div",j,[p("div",x,[n(m,{ref_key:"fileUploaderRef",ref:P,path:"app-images",types:["image/*"],height:150,onUploaded:C,onFileRemoved:D},null,512)]),n(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"])]),n(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"]),p("div",w,[n(c,{label:"Save",color:"primary",icon:"save",onClick:E,disable:I.value},null,8,["disable"]),n(c,{label:"Cancel",icon:"cancel",to:"/apps-library"})])])])),_:1}))}};export{A as default};
