import{r as e,g as i}from"./p-823ca21f.js";import{TargetProgramLoader as t}from"../gc-target-program-loader/lib/TargetProgramLoader";import{c as r}from"./p-ab62068b.js";import{ServicesRegistry as a}from"../gc-core-services/lib/ServicesRegistry";import{targetConfigServiceType as o}from"../gc-service-target-config/lib/TargetConfigService";import{createPropertyAutoFill as s}from"../gc-core-assets/lib/GcDesigner";import{ActionRegistry as n}from"../gc-widget-menu/lib/ActionRegistry";import{GcMessageDialog as c}from"../gc-widget-message-dialog/lib/GcMessageDialog";import{connectionManager as g}from"../gc-target-connection-manager/lib/ConnectionManager";import{GcUtils as m}from"../gc-core-assets/lib/GcUtils";const d=a.getService(o);let l=class{constructor(i){e(this,i);this.impl=undefined;this.propertyAutoFill=undefined;this.autoProgram=false;this.optional=false;this.sram=false}async loadProgram(){const e=this.programOrBinPath;if(!e){return await c.error(`gc-target-program-loader id=${this.el.id} is missing a program or binary path property`)}const i=document.querySelector(`gc-widget-menuaction[action-id="open_program_loader_dialog_${this.el.id}"]`)??document.querySelector('gc-widget-menuaction[action-id="cmd_open_program_loader_dialog"]');const t=i?.label.split("...")[0].trim()??"Load Program";let r=t.split(" ")[0];if(r.endsWith("e")){r=r.substring(0,r.length-1)}const a=e?.lastIndexOf("/")??-1;const o=`${r}ing ${e.substring(a+1)} for ${this.impl.toString()}`;if(await c.prompt(t,`${o}?`,"image:flash_on")==="confirm"){const{progress:e,result:i}=await c.progress(t,o,"image:flash_on",true,0,100,true);let r=false;const a=new class i{assertStillConnecting(){if(r){throw Error("Operation aborted by user")}}addProgressMessage(e,i,t=0){g.addProgressMessage(e,i,t)}addErrorMessage(e){g.addProgressMessage(e)}addWarningMessage(e){g.addProgressMessage(e)}addDebugMessage(i){g.addProgressMessage(i);e.setMessage(i)}};i.then((e=>{r=e==="dismiss"}));try{await g.loadProgram(this.impl,a,e.setValue);e.setValue(100)}catch(i){e.cancel();if(!r){await c.error(`${t} Failed: ${i.message||i.toString()}`)}}}}connectedCallback(){const e=r(this.el);this.impl=new t(e);if(this.el.id){n.registerAction(`open_program_loader_dialog_${this.el.id}`,{run:()=>{this.loadProgram()},isEnabled(){return!m.isInDesigner}})}this.propertyAutoFill=s(this.el);this.propertyAutoFill.register("deviceName",(async()=>(await d.getBoardsAndDevices()).map((e=>e.id)))).register("connectionName",(async()=>(await d.getConnections(e["deviceName"])).map((e=>e.id))))}disconnectedCallback(){this.propertyAutoFill.unregister("deviceName").unregister("connectionName")}get el(){return i(this)}};export{l as gc_target_program_loader};
//# sourceMappingURL=p-8c52051d.entry.js.map