import{invoke as e}from"./core-gjudXfwa.js";import{TauriEvent as t,emit as n,emitTo as r,listen as i,once as a}from"./event-DPTCP6WO.js";import{PhysicalPosition as o,PhysicalSize as s,Window as c,getCurrentWindow as l,n as u,t as d}from"./window-C9NbB0_c.js";function f(){return new h(l(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}async function p(){return e(`plugin:webview|get_all_webviews`).then(e=>e.map(e=>new h(new c(e.windowLabel,{skip:!0}),e.label,{skip:!0})))}var m=[`tauri://created`,`tauri://error`],h=class{constructor(t,n,r){this.window=t,this.label=n,this.listeners=Object.create(null),r?.skip||e(`plugin:webview|create_webview`,{windowLabel:t.label,options:{...r,label:n}}).then(async()=>this.emit(`tauri://created`)).catch(async e=>this.emit(`tauri://error`,e))}static async getByLabel(e){return(await p()).find(t=>t.label===e)??null}static getCurrent(){return f()}static async getAll(){return p()}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:i(e,t,{target:{kind:`Webview`,label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?()=>{let n=this.listeners[e];n.splice(n.indexOf(t),1)}:a(e,t,{target:{kind:`Webview`,label:this.label}})}async emit(e,t){if(m.includes(e)){for(let n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return}return n(e,t)}async emitTo(e,t,n){if(m.includes(t)){for(let e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return}return r(e,t,n)}_handleTauriEvent(e,t){return m.includes(e)?(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0):!1}async position(){return e(`plugin:webview|webview_position`,{label:this.label}).then(e=>new o(e))}async size(){return e(`plugin:webview|webview_size`,{label:this.label}).then(e=>new s(e))}async close(){return e(`plugin:webview|webview_close`,{label:this.label})}async setSize(t){return e(`plugin:webview|set_webview_size`,{label:this.label,value:t instanceof u?t:new u(t)})}async setPosition(t){return e(`plugin:webview|set_webview_position`,{label:this.label,value:t instanceof d?t:new d(t)})}async setFocus(){return e(`plugin:webview|set_webview_focus`,{label:this.label})}async setAutoResize(t){return e(`plugin:webview|set_webview_auto_resize`,{label:this.label,value:t})}async hide(){return e(`plugin:webview|webview_hide`,{label:this.label})}async show(){return e(`plugin:webview|webview_show`,{label:this.label})}async setZoom(t){return e(`plugin:webview|set_webview_zoom`,{label:this.label,value:t})}async reparent(t){return e(`plugin:webview|reparent`,{label:this.label,window:typeof t==`string`?t:t.label})}async clearAllBrowsingData(){return e(`plugin:webview|clear_all_browsing_data`)}async setBackgroundColor(t){return e(`plugin:webview|set_webview_background_color`,{color:t})}async onDragDropEvent(e){let n=await this.listen(t.DRAG_ENTER,t=>{e({...t,payload:{type:`enter`,paths:t.payload.paths,position:new o(t.payload.position)}})}),r=await this.listen(t.DRAG_OVER,t=>{e({...t,payload:{type:`over`,position:new o(t.payload.position)}})}),i=await this.listen(t.DRAG_DROP,t=>{e({...t,payload:{type:`drop`,paths:t.payload.paths,position:new o(t.payload.position)}})}),a=await this.listen(t.DRAG_LEAVE,t=>{e({...t,payload:{type:`leave`}})});return()=>{n(),i(),r(),a()}}};export{h as Webview,p as getAllWebviews,f as getCurrentWebview};