import{r as e}from"./p-5ab6b26f.js";import{g as t}from"./p-b01cb482.js";class r{constructor(t){e(this,t),this.defaultOptions={type:"point",multiple:!1,combine:!1,delete:!1,mode:"draw"}}async create(e,r){let l=t(r.mapId);if(!l)throw"Draw action map not found";let o=document.querySelector("gl-draw-toolbar");return o&&r.toolbarLabel&&(o.label=r.toolbarLabel),l.drawOptions=this.getControlOptions(r),l.drawing=!0,e&&l.draw.set(e),await new Promise(e=>{let t=()=>{l.drawing=!1,e(),o.removeEventListener("glDrawCancel",t),o.removeEventListener("glDrawConfirm",r)},r=()=>{let t=l.draw.getAll();l.drawing=!1,e(t),o.removeEventListener("glDrawConfirm",r),o.removeEventListener("glDrawConfirm",r)};o.addEventListener("glDrawCancel",t),o.addEventListener("glDrawConfirm",r)})}getControlOptions(e){let t=Object.assign({},this.defaultOptions,e||{}),r="simple_select";"direct"===t.mode&&(r="direct_select"),"draw"===t.mode&&("point"===t.type&&(r="draw_point"),"line"===t.type&&(r="draw_line_string"),"polygon"===t.type&&(r="draw_polygon"));let l={controls:{point:t.multiple&&"point"===t.type,line_string:t.multiple&&"line"===t.type,polygon:t.multiple&&"polygon"===t.type,trash:t.delete,combine_features:t.multiple&&t.combine,uncombine_features:t.multiple&&t.combine},defaultMode:r};return t.styles&&(l.styles=t.styles),l}}export{r as gl_draw_controller};