1import{_ as se}from"./XdQcLsRC.js";import{_ as ne}from"./C-vYKife.js";import{_ as oe}from"./YEX3nUlY.js";import{_ as ie}from"./OvnCmZXh.js";import{_ as le}from"./C_tOVlJn.js";import{_ as pe}from"./CEBoj5YC.js";import{u as ue,U as ce,I as de}from"./BD7lD83O.js";import{d as me,i as _e,ak as fe,ag as ve,b as ye,e as ge,J as be,r as C,D as P,j as we,F as Se,c as b,o as d,k as o,l as I,a as s,w as p,p as n,n as r,K as he,m as R,t as E,x as q,aF as Ce,v as Ie,aQ as Re,I as M,A as D,z as Ee,d3 as xe}from"#entry";import{c as j,a as c,e as Ae}from"./KicvpY4j.js";import{I as Te}from"./KV1Is6Jo.js";import{E as k}from"./CTFp1cbv.js";import{u as Ne,c as De}from"./CKlly8d8.js";import{S as ke}from"./CPUGX1I6.js";import{b as Ue}from"./Bm98vdUD.js";import"./BP884Eyd.js";import"./B0Oh4ACn.js";import"./DGFVZ24Q.js";import"./ClXSojo5.js";import"./C4yIh9pK.js";import"./r3HTJ--m.js";import"./DlAUqK2U.js";import"./B2XHbdkR.js";import"./BokSiL_i.js";import"./Cq10Vz2B.js";import"./DZLetHU9.js";import"./DHVAymi1.js";import"./Cu83VI4E.js";import"./Nir8YzLO.js";import"./5Xo_zsgb.js";import"./bT1Ke13T.js";import"./FOfDmaQu.js";import"./CsYeexZd.js";import"./BSOr8_U9.js";import"./-2fOlCHx.js";import"./D_L0mbao.js";import"./D8jYTSnK.js";import"./C42HGVQM.js";import"./0F463cqY.js";import"./CtC-zX1T.js";import"./yDYyMNmM.js";import"./BKYlOKsV.js";import"./BzLCLO6P.js";const Le={class:"content-wrapper"},Ve={class:"flex items-center justify-between mb-8"},Oe={class:"space-x-4"},Fe={key:0,class:"absolute inset-0 bg-gray-200 bg-opacity-75 flex flex-col items-center justify-center z-50 rounded-md"},Be={class:"mt-4 text-lg font-semibold text-gray-700"},Pe={class:"grid grid-cols-6 gap-4"},qe={class:"col-span-6 p-12 rounded bg-gray-50"},Me={key:0},je={key:0,class:"mt-2 text-sm text-gray-600"},$e={class:"font-medium"},ze=!1,Lt=me({__name:"create-asset",async setup(Ze){let U,L;const V=_e(),{user:v,isCommercial:$}=fe(V),{fetchUserDetails:z}=V;try{[U,L]=ve(()=>z()),await U,L()}catch(t){console.error("Failed to fetch user details before component setup:",t)}ye({title:"Create Energy Asset"});const{t:Z}=ge(),{logActivity:w}=be(),O=C(null),y=C(null),{isSubmitting:x,loadingStepMessage:W,startLoadingCycle:Y,advanceLoadingStep:J,startInfoMessageSequence:H,stopInfoMessageSequence:F,resetLoadingState:A}=ue(),{data:B}=Ne(D.REWARD_PLATFORM.INVERTERS),K=P(()=>B.value?B.value.results.length>0:null),g=C({device_identifier:"",plant_identifier:"",external_api_key:"",username:"",password:""}),T=P(()=>{const e=(v.value?.inuse_inverter_brands||[]).map(a=>a.toLowerCase());return Te.slice().filter(a=>a.is_supported).filter(a=>!e.includes(a.name.toLowerCase())).sort((a,i)=>(a.order||0)-(i.order||0)).map(a=>({label:a.name,value:a.name}))}),Q=C(),{values:f,validate:X}=we({initialValues:{name:"",description:"",cover:null,location:{latitude:null,longitude:null,city:"",state:"",country:"US",zipcode:""},asset_type:"Solar",inverter_brand:(()=>{const t=v.value?.default_inverter_brand,e=v.value?.inuse_inverter_brands||[];if(t){const a=t.toLowerCase();if(!e.map(u=>u.toLowerCase()).includes(a)&&T.value.some(u=>u.value.toLowerCase()===a))return T.value.find(u=>u.value.toLowerCase()===a)?.value||""}return""})()},validationSchema:j().shape({name:c().required().label("Name"),description:c().required().label("Description"),cover:Ae().nullable().test("is-img","Invalid image type",t=>{if(!t||!t[0])return!0;const e=t[0];if(!e.type)return!1;const[a,i]=e.type.split("/");return a!=="image"||!i?!1:["png","jpg","jpeg"].includes(i.toLowerCase())}).label("Cover Image"),location:j().shape({latitude:c().nullable().label("Latitude"),longitude:c().nullable().label("Longitude"),country:c().required().label("Country"),city:c().required().label("City"),state:c().required().label("State").test("is-valid-state","Must be a valid US state code",function(t){return t?ce.includes(t.toUpperCase()):!1}),zipcode:c().required().label("ZIP").matches(/^\d{5}$/,"Must be a 5 digit number")}),asset_type:c().label("Asset Type"),inverter_brand:c().required().label("Inverter Type")})});Se(()=>f.inverter_brand,()=>{g.value={device_identifier:"",plant_identifier:"",external_api_key:"",username:"",password:""}});async function G(){return!0}function ee(){const t=new FormData,e=f;e.cover&&e.cover[0]&&t.append("cover",e.cover[0].originFileObj),Object.entries(e).forEach(([l,_])=>{l!=="location"&&l!=="cover"&&t.append(l,_)});const{city:a,state:i,country:u,zipcode:m,latitude:S,longitude:h}=e.location;t.append("city",a.split(" ").map(l=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ")),t.append("state",i.toUpperCase()),t.append("country",u),t.append("zipcode",m),S!==null&&t.append("latitude",String(S)),h!==null&&t.append("longitude",String(h));
1const N=[a,i.toUpperCase(),m].filter(Boolean).join(", ");return t.append("address",N.toUpperCase()),t.append("is_new_inverter","true"),t.append("asset_type",e.asset_type),Object.entries(g.value).forEach(([l,_])=>{_!=null&&t.append(l,_)}),t}async function te(t){H();try{await Ee(`${D.REWARD_PLATFORM.INVERTERS}/`,{method:"post",body:t,timeout:6e4}),F(),J("â
Asset created successfully!!!"),Ue.success({message:"Asset created successfully",placement:"bottomRight"}),w("asset_creation_succeeded",{timestamp:new Date().toISOString()}),await xe(1e3),De(D.REWARD_PLATFORM.INVERTERS),M({name:"MyEnergyAssetsPage"})}catch(e){throw w("asset_creation_failed",{timestamp:new Date().toISOString(),error:JSON.stringify(e)}),F(),e._data&&e._data.message&&typeof e._data.message=="string"&&e._data.message.trim()!==""?y.value=e._data.message:y.value=Z("error.messages.support"),document?.querySelector("form")?.scrollIntoView({behavior:"auto",block:"start"}),e}}async function ae(){y.value=null,Y("Validating your information...");try{const{valid:t,errors:e}=await X();if(w("submit_button_clicked",{timestamp:new Date().toISOString(),button_name:"Submit",button_action:"submit_create_asset_form",is_valid:t,errors:JSON.stringify(e)}),!t){Re(O.value?.querySelector(".form-control__helper--error")),A();return}if(!await G()){A();return}const a=ee();await te(a)}catch(t){console.error("Submission failed:",t)}finally{x.value&&A()}}function re(){w("cancel_button_clicked",{timestamp:new Date().toISOString(),button_name:"Cancel",button_action:"canceled_form_and_navigate_to_my_energy_assets"}),M({name:"MyEnergyAssetsPage"})}return(t,e)=>{const a=se,i=ne,u=oe,m=ie,S=le,h=pe,N=de,l=Ie;return d(),b("div",Le,[o("div",Ve,[e[4]||(e[4]=o("h1",{class:"page-title mb-4"},"Configure New Energy Asset",-1)),o("div",Oe,[s(a,{class:"no-underline text-primary-500",href:r(k).FD_SUBMIT_TICKET,target:"_blank"},{default:p(()=>[...e[2]||(e[2]=[n("Contact Us",-1)])]),_:1},8,["href"]),s(a,{class:"no-underline text-primary-500",href:r(k).FD_CONNECT_INVERTER,target:"_blank"},{default:p(()=>[...e[3]||(e[3]=[n("Need Help? See Our Tip Sheet",-1)])]),_:1},8,["href"])])]),r($)?(d(),I(u,{key:0,class:"p-4"},{default:p(()=>[s(i,{"show-icon":!1,closable:!1,type:"info"},{default:p(()=>[...e[5]||(e[5]=[n(" Inverter setup for commercial accounts is managed by the Brytr team. Please email ",-1),o("a",{href:"mailto:[email protected]",class:"underline"},"[email protected]",-1),n(" to add or change inverters on your account. ",-1)])]),_:1})]),_:1})):(d(),b(he,{key:1},[r(K)?R("",!0):(d(),I(i,{key:0,"show-icon":!1,closable:!1,type:"info",class:"mb-4"},{default:p(()=>[e[8]||(e[8]=n(" Youâre almost there. Once we connect to your solar power system, weâll be generating and verifying one Solar Renewable Energy Certificate (sREC) for every megawatt-hour (MWh) of clean energy you produce. Please ",-1)),s(a,{href:r(k).FD_CONNECT_INVERTER,target:"_blank",class:"underline"},{default:p(()=>[...e[6]||(e[6]=[n("see our tip sheet",-1)])]),_:1},8,["href"]),e[9]||(e[9]=n(" if you need help, or ",-1)),s(a,{href:"mailto:[email protected]",class:"underline"},{default:p(()=>[...e[7]||(e[7]=[n("email us",-1)])]),_:1}),e[10]||(e[10]=n(" with any questions. ",-1))]),_:1})),s(u,{class:"relative"},{default:p(()=>[r(x)?(d(),b("div",Fe,[s(r(ke),{size:"large"}),o("p",Be,E(r(W)),1)])):R("",!0),o("form",{ref_key:"formRef",ref:O,class:"space-y-8",novalidate:"",onSubmit:q(ae,["prevent"])},[r(y)?(d(),I(i,{key:0},{default:p(()=>[n(E(r(y)),1)]),_:1})):R("",!0),o("div",Pe,[s(m,{"wrapper-attrs":{class:"col-span-2"},name:"name",label:"Name This Asset"}),s(m,{name:"description",label:"Description","wrapper-attrs":{class:"col-span-2"},"label-attrs":{tooltipProps:{content:"Tell us about the kind of dwelling, if any, this system is serving (e.g., primary home, vacation house, townhouse, etc.)."}}}),s(S,{"wrapper-attrs":{class:"col-span-2"},name:"cover",label:"Cover Image (Optional)"}),s(m,{"wrapper-attrs":{class:"col-span-2"},name:"location.city",label:"City"}),s(m,{"wrapper-attrs":{class:"col-span-2"},name:"location.state",label:"State"}),s(m,{"wrapper-attrs":{class:"col-span-2"},name:"location.zipcode",label:"ZIP"}),s(h,{"wrapper-attrs":{class:"col-span-2"},name:"inverter_brand",label:"Inverter Brand",options:r(T),"label-attrs":{tooltipProps:{content:"TIP: Your inverter most likely will be in the garage, next to a sub board or main switch board. Or it may be along the side of the house near the meter box."}}},null,8,["options"]),o("div",qe,[n(E(r(f).inverter_brand)+" ",1),r(f).inverter_brand?(d(),I(N,{ref_key:"validationFormRef",ref:Q,
1key:r(f).inverter_brand,modelValue:r(g),"onUpdate:modelValue":e[0]||(e[0]=_=>Ce(g)?g.value=_:null),inverter_brand:r(f).inverter_brand,inverter_name:r(f).name,is_new_inverter:!0,is_pre_validation:ze,onAuthCodeChanged:e[1]||(e[1]=_=>y.value=null)},null,8,["modelValue","inverter_brand","inverter_name"])):(d(),b("div",Me,[e[12]||(e[12]=o("p",null," To get started, please select one inverter type from the list above. ",-1)),r(v)?.inuse_inverter_brands&&r(v).inuse_inverter_brands.length>0?(d(),b("p",je,[e[11]||(e[11]=n(" You have already registered the following inverter brand(s): ",-1)),o("span",$e,E(r(v).inuse_inverter_brands.join(", ")),1)])):R("",!0),e[13]||(e[13]=o("p",{class:"mt-2 text-sm text-gray-600"},[o("b",null,"â ï¸ You can only register one inverter of each type.")],-1))]))])]),o("div",null,[s(l,{"html-type":"submit",loading:r(x)},{default:p(()=>[...e[14]||(e[14]=[n(" Submit ",-1)])]),_:1},8,["loading"]),s(l,{class:"ml-4",ghost:"",onClick:q(re,["stop"])},{default:p(()=>[...e[15]||(e[15]=[n(" Cancel ",-1)])]),_:1})])],544)]),_:1})],64))])}}});export{Lt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.