import{D as s}from"./drb-confirm-helpers-15e164fa.js";import{F as a}from"./form-handler-d276c37d.js";import{s as n,f as d}from"./pricing-311df2f8.js";import{a as u}from"./v2-alert-pink-5610c78e.js";const b={form:null,init(e){document.addEventListener("drb-dialog-content-updated",r=>{const i=r.target.closest("drb-dialog#project-brief-dialog"),t=i==null?void 0:i.querySelector("[data-project-brief-form]");t&&(this.form=t,this.budgetField=this.form.querySelector("[data-project-budget]"),this.initForm(e),this.bindBudgetFormatting())})},initForm(e){const r=async t=>{const{redirect:o}=await t.json();window.location.href=o},i=(e==null?void 0:e.onSuccess)||r;this.formHandler=new a(this.form,{defaultServerErrorMsg:"Something went wrong. Please try again later.",transformData:t=>(t.budget=n(t.budget),{project_brief:{...t}}),onError:(t,o)=>{s.open({title:o,iconHtml:u,centered:!0,cancelText:"",confirmText:"Close"})},onSuccess:i}),this.addBudgetValidation()},bindBudgetFormatting(){this.budgetField&&(this.budgetField.value=d(this.budgetField.value,{maximumFractionDigits:0}),this.budgetField.addEventListener("input",()=>{this.budgetField.value=d(this.budgetField.value,{maximumFractionDigits:0})}))},addBudgetValidation(){if(!this.budgetField)return;const e=Number(this.budgetField.getAttribute("data-project-budget-min-cost"))||0;this.formHandler.pristineValidation.addValidator(this.budgetField,r=>this.form.hasAttribute("data-published-brief")?(n(r)||0)>=e:!0,`A minimum budget of $${e} is required to publish your brief.`,1,!0)}};export{b as P}; //# sourceMappingURL=project-brief-dialog-5ede6814.js.map