var L=Object.defineProperty;var W=(e,t,r)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var n=(e,t,r)=>W(e,typeof t!="symbol"?t+"":t,r);import{V as K,f as z,e as X,C as Z,_,g as b,h as g,i as f,j as s,l as F,t as v,m,s as C,o as G,p as Y,w as ee,k as Q,F as te,x as h}from"./index-BLqts8WY.js";import{Q as re}from"./QuickNav-DgCyvgDx.js";import{T as ie}from"./TopMessage-BE0GBIgW.js";import{l as oe,e as se,h as ne,ap as ae,aK as de,aL as le,aM as pe,at as ue}from"./index-MyY_xqVN.js";import"./index-CsfPLOYu.js";var ce=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,he=(e,t,r,i)=>{for(var a=i>1?void 0:i?fe(t,r):t,l=e.length-1,d;l>=0;l--)(d=e[l])&&(a=(i?d(t,r,a):d(a))||a);return i&&a&&ce(t,r,a),a};let T=class extends K{constructor(){super(...arguments);n(this,"$notify");n(this,"activeDid","");n(this,"apiServer","");n(this,"amountInput","0");n(this,"descriptionOfCondition","");n(this,"descriptionOfItem","");n(this,"destinationPathAfter","");n(this,"hideBackButton",!1);n(this,"message","");n(this,"offeredToProject",!1);n(this,"offeredToRecipient",!1);n(this,"offererDid");n(this,"offerId","");n(this,"prevCredToEdit");n(this,"projectId","");n(this,"projectName","a project");n(this,"recipientDid","");n(this,"recipientName","");n(this,"showGeneralAdvanced",!1);n(this,"unitCode","HUR");n(this,"validThroughDateInput","");n(this,"libsUtil",oe)}async mounted(){var a,l,d,p,c,y,o,I,w,O,x,D,$,j,E,k,N,P,S,A,U,q,R,V,M,B;try{this.prevCredToEdit=this.$route.query.prevCredToEdit?JSON.parse(this.$route.query.prevCredToEdit):void 0}catch{this.$notify({group:"alert",type:"danger",title:"Retrieval Error",text:"The previous record isn't available for editing. If you submit, you'll create a new record."},6e3)}const r=(d=(l=(a=this.prevCredToEdit)==null?void 0:a.claim)==null?void 0:l.includesObject)==null?void 0:d.amountOfThisGood;this.amountInput=this.$route.query.amountInput||(r?String(r):"")||this.amountInput,this.unitCode=this.$route.query.unitCode||((y=(c=(p=this.prevCredToEdit)==null?void 0:p.claim)==null?void 0:c.includesObject)==null?void 0:y.unitCode)||this.unitCode,this.descriptionOfCondition=((I=(o=this.prevCredToEdit)==null?void 0:o.claim)==null?void 0:I.description)||this.descriptionOfCondition,this.descriptionOfItem=this.$route.query.description||((x=(O=(w=this.prevCredToEdit)==null?void 0:w.claim)==null?void 0:O.itemOffered)==null?void 0:x.description)||this.descriptionOfItem,this.destinationPathAfter=this.$route.query.destinationPathAfter,this.offererDid=this.$route.query.offererDid||((j=($=(D=this.prevCredToEdit)==null?void 0:D.claim)==null?void 0:$.agent)==null?void 0:j.identifier)||this.offererDid,this.hideBackButton=this.$route.query.hideBackButton==="true",this.message=this.$route.query.message||"";let i;((P=(N=(k=(E=this.prevCredToEdit)==null?void 0:E.claim)==null?void 0:k.itemOffered)==null?void 0:N.isPartOf)==null?void 0:P["@type"])==="PlanAction"&&(i=(U=(A=(S=this.prevCredToEdit)==null?void 0:S.claim)==null?void 0:A.itemOffered)==null?void 0:U.isPartOf),this.projectId=this.$route.query.projectId||(i==null?void 0:i.identifier)||this.projectId,this.projectName=this.$route.query.projectName||(i==null?void 0:i.name)||this.projectName,this.recipientDid=this.$route.query.recipientDid||((V=(R=(q=this.prevCredToEdit)==null?void 0:q.claim)==null?void 0:R.recipient)==null?void 0:V.identifier),this.recipientName=this.$route.query.recipientName||"",this.validThroughDateInput=((B=(M=this.prevCredToEdit)==null?void 0:M.claim)==null?void 0:B.validThrough)||this.validThroughDateInput;try{const u=await z();if(this.apiServer=u.apiServer??"",this.activeDid=u.activeDid??"",this.showGeneralAdvanced=u.showGeneralAdvanced??!1,this.recipientDid&&!this.recipientName){const H=await X.contacts.toArray(),J=await se();this.recipientName=ne(this.recipientDid,this.activeDid,J,H)}this.offeredToProject=!!this.projectId,this.offeredToRecipient=!this.offeredToProject&&!!this.recipientDid}catch(u){console.error("Error retrieving settings from database:",u),this.$notify({group:"alert",type:"danger",title:"Error",text:u.message||"There was an error retrieving your settings."},-1)}if(this.projectId&&!this.projectName){const u=await ae(this.projectId,this.axios,this.apiServer,this.activeDid);this.projectName=u!=null&&u.name?"the project: "+u.name:"a project"}}changeUnitCode(){const r=Object.keys(this.libsUtil.UNIT_SHORT),i=r.indexOf(this.unitCode);this.unitCode=r[(i+1)%r.length]}increment(){this.amountInput=`${(parseFloat(this.amountInput)||0)+1}`}decrement(){this.amountInput=`${Math.max(0,(parseFloat(this.amountInput)||1)-1)}`}cancel(){this.destinationPathAfter?this.$router.push({path:this.destinationPathAfter}):this.$router.back()}cancelBack(){this.$router.back()}async confirm(){if(!this.activeDid){this.$notify({group:"alert",type:"danger",title:"Error",text:"You must select an identifier before you can record a offer."},2e3);return}if(parseFloat(this.amountInput)<0){this.$notify({group:"alert",type:"danger",text:"You may not send a negative number.",title:""},2e3);return}if(!this.descriptionOfItem&&!parseFloat(this.amountInput)){this.$notify({group:"alert",type:"danger",title:"Error",text:`You must enter a description or some number of ${this.libsUtil.UNIT_LONG[this.unitCode]}.`},2e3);return}this.$notify({group:"alert",type:"toast",text:"Recording the offer...",title:""},1e3),await this.recordOffer()}notifyUserOfProject(){this.projectId?this.$notify({group:"alert",type:"warning",title:"Error",text:"You cannot assign both to a project and to a recipient."},3e3):this.$notify({group:"alert",type:"warning",title:"Error",text:"To assign to a project, you must open this page through a project."},3e3)}notifyUserOfRecipient(){this.recipientDid?this.$notify({group:"alert",type:"warning",title:"Error",text:"You cannot assign both to a recipient and to a project."},3e3):this.$notify({group:"alert",type:"warning",title:"Error",text:"To assign to a recipient, you must open this page from a contact."},3e3)}async recordOffer(){var r,i,a;try{const l=this.offeredToRecipient?this.recipientDid:void 0,d=this.offeredToProject?this.projectId:void 0;let p;if(this.prevCredToEdit?p=await de(this.axios,this.apiServer,this.prevCredToEdit,this.activeDid,this.descriptionOfItem,parseFloat(this.amountInput),this.unitCode,this.descriptionOfCondition,this.validThroughDateInput,l,d):p=await le(this.axios,this.apiServer,this.activeDid,this.descriptionOfItem,parseFloat(this.amountInput),this.unitCode,this.descriptionOfCondition,this.validThroughDateInput,l,d),p.type==="error"||this.isCreationError(p.response)){const c=this.getCreationErrorMessage(p);console.error("Error with offer creation result:",p),this.$notify({group:"alert",type:"danger",title:"Error",text:c||"There was an error creating the offer."},-1)}else this.$notify({group:"alert",type:"success",title:"Success",text:"That offer was recorded."},5e3),localStorage.removeItem("imageUrl"),this.destinationPathAfter?this.$router.push({path:this.destinationPathAfter}):this.$router.back()}catch(l){console.error("Error with offer recordation caught:",l);const d=l.userMessage||((a=(i=(r=l.response)==null?void 0:r.data)==null?void 0:i.error)==null?void 0:a.message)||"There was an error recording the offer.";this.$notify({group:"alert",type:"danger",title:"Error",text:d},-1)}}constructOfferParam(){var d,p;const r=this.offeredToRecipient?this.recipientDid:void 0,i=this.offeredToProject?this.projectId:void 0,a=pe((d=this.prevCredToEdit)==null?void 0:d.claim,this.activeDid,r,this.descriptionOfItem,parseFloat(this.amountInput),this.unitCode,this.descriptionOfCondition,i,this.validThroughDateInput,(p=this.prevCredToEdit)==null?void 0:p.id);return JSON.stringify(a)}isCreationError(r){var i;return r.status!==201||((i=r.data)==null?void 0:i.error)}getCreationErrorMessage(r){var i,a,l,d,p;return((i=r.error)==null?void 0:i.userMessage)||((a=r.error)==null?void 0:a.error)||((p=(d=(l=r.response)==null?void 0:l.data)==null?void 0:d.error)==null?void 0:p.message)}explainData(){this.$notify({group:"alert",type:"success",title:"Data Sharing",text:ue},-1)}};T=he([Z({components:{QuickNav:re,TopMessage:ie}})],T);const me={id:"Content",class:"p-6 pb-24 max-w-3xl mx-auto"},ge={key:0,class:"text-lg text-center font-light relative px-7"},ve={class:"text-xl font-bold text-center mb-4"},ye={class:"flex flex-row justify-center"},be={class:"flex flex-row mt-2"},Ce={class:"flex flex-row mt-2"},Te={class:"rounded-l border border-r-0 border-slate-400 bg-slate-200 text-center px-2 py-2"},Ie={class:"h-7 mt-4 flex"},we={class:"text-sm mt-1"},Oe={class:"h-7 mt-4 flex"},xe={class:"text-sm mt-1"},De={key:1,class:"mt-4 flex"},$e={class:"text-center mb-2 mt-6 italic"},je={class:"grid grid-cols-1 sm:grid-cols-2 gap-2"};function Ee(e,t,r,i,a,l){const d=b("QuickNav"),p=b("TopMessage"),c=b("fa"),y=b("router-link");return h(),g(te,null,[f(d),f(p),s("section",me,[e.hideBackButton?F("",!0):(h(),g("div",ge,[s("h1",{class:"text-lg text-center px-2 py-1 absolute -left-2 -top-1",onClick:t[0]||(t[0]=o=>e.cancelBack())},[f(c,{icon:"chevron-left",class:"fa-fw"})])])),t[18]||(t[18]=s("h1",{class:"text-4xl text-center font-light px-4 mb-4"},"What Is Offered",-1)),s("h1",ve,[s("span",null," Offer to "+v(e.offeredToProject?e.projectName:e.offeredToRecipient?e.recipientName:"someone not named"),1)]),m(s("textarea",{class:"block w-full rounded border border-slate-400 mb-2 px-3 py-2",placeholder:"What is offered","onUpdate:modelValue":t[1]||(t[1]=o=>e.descriptionOfItem=o),"data-testId":"itemDescription"},null,512),[[C,e.descriptionOfItem]]),s("div",ye,[s("span",{class:"rounded-l border border-r-0 border-slate-400 bg-slate-200 text-center text-blue-500 px-2 py-2 w-20",onClick:t[2]||(t[2]=o=>e.changeUnitCode())},v(e.libsUtil.UNIT_SHORT[e.unitCode]||e.unitCode),1),s("div",{class:"border border-r-0 border-slate-400 bg-slate-200 px-4 py-2",onClick:t[3]||(t[3]=o=>e.amountInput==="0"?null:e.decrement())},[f(c,{icon:"chevron-left"})]),m(s("input",{type:"number",class:"border border-r-0 border-slate-400 px-2 py-2 text-center w-20","onUpdate:modelValue":t[4]||(t[4]=o=>e.amountInput=o),"data-testId":"inputOfferAmount"},null,512),[[C,e.amountInput]]),s("div",{class:"rounded-r border border-slate-400 bg-slate-200 px-4 py-2",onClick:t[5]||(t[5]=o=>e.increment())},[f(c,{icon:"chevron-right"})])]),s("div",be,[t[15]||(t[15]=s("span",{class:"rounded-l border border-r-0 border-slate-400 bg-slate-200 text-center px-2 py-2"}," Conditions ",-1)),m(s("textarea",{class:"w-full border border-slate-400 px-3 py-2 rounded-r",placeholder:"Prerequisites, other people to include, etc.","onUpdate:modelValue":t[6]||(t[6]=o=>e.descriptionOfCondition=o)},null,512),[[C,e.descriptionOfCondition]])]),s("div",Ce,[s("span",Te,v(e.validThroughDateInput?"":"No")+" Expiration ",1),m(s("input",{"onUpdate:modelValue":t[7]||(t[7]=o=>e.validThroughDateInput=o),type:"date",class:"w-full rounded border border-slate-400 px-3 py-2 rounded-r"},null,512),[[C,e.validThroughDateInput]])]),s("div",Ie,[e.projectId&&!e.offeredToRecipient?m((h(),g("input",{key:0,type:"checkbox",class:"h-6 w-6 mr-2","onUpdate:modelValue":t[8]||(t[8]=o=>e.offeredToProject=o)},null,512)),[[G,e.offeredToProject]]):(h(),Y(c,{key:1,icon:"square",class:"bg-slate-500 text-slate-500 h-5 w-5 px-0.5 py-0.5 mr-2 rounded",onClick:t[9]||(t[9]=o=>e.notifyUserOfProject())})),s("label",we,v(e.projectId?"This is offered to "+e.projectName:"No project was chosen"),1)]),s("div",Oe,[e.recipientDid&&!e.offeredToProject?m((h(),g("input",{key:0,type:"checkbox",class:"h-6 w-6 mr-2","onUpdate:modelValue":t[10]||(t[10]=o=>e.offeredToRecipient=o)},null,512)),[[G,e.offeredToRecipient]]):(h(),Y(c,{key:1,icon:"square",class:"bg-slate-500 text-slate-500 h-5 w-5 px-0.5 py-0.5 mr-2 rounded",onClick:t[11]||(t[11]=o=>e.notifyUserOfRecipient())})),s("label",xe,v(e.recipientDid?"This is offered to "+e.recipientName:"No recipient was chosen."),1)]),e.showGeneralAdvanced?(h(),g("div",De,[f(y,{to:{name:"claim-add-raw",query:{claim:e.constructOfferParam()}},class:"text-blue-500"},{default:ee(()=>t[16]||(t[16]=[Q(" Edit & Submit Raw ")])),_:1},8,["to"])])):F("",!0),s("p",$e,[t[17]||(t[17]=Q(" Sign & Send to publish to the world ")),f(c,{icon:"circle-info",class:"pl-2 text-blue-500 cursor-pointer",onClick:t[12]||(t[12]=o=>e.explainData())})]),s("div",je,[s("button",{class:"block w-full text-center text-lg font-bold uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-2 py-3 rounded-md",onClick:t[13]||(t[13]=(...o)=>e.confirm&&e.confirm(...o))}," Sign & Send "),s("button",{class:"block w-full text-center text-md uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-1.5 py-2 rounded-md",onClick:t[14]||(t[14]=(...o)=>e.cancel&&e.cancel(...o))}," Cancel ")])])],64)}const Re=_(T,[["render",Ee]]);export{Re as default};