/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
const n="popup",e="manual";function o(n){const{popupElement:e,popup:o}=n||{};return e??o??null}function i(n){return null!=n&&"open"in n&&"declaredClass"in n}function p(n){return!!n&&"arcgis-popup"===n.tagName.toLowerCase()&&"open"in n}function t(o,t,l){const[u,a,s]=t;if(l){const[e,o,t]=l;e&&i(o)&&(o.view=null,e.remove(o,n),o!==a&&a&&o.destroy()),e&&t&&p(t)&&(t.view=null,e.remove(t,n),t!==s&&s&&t.remove())}u&&i(a)&&(a.view=o,u.add(a,{key:n,position:e,internal:!0})),u&&s&&p(s)&&(s.view=o,u.add(s,{key:n,position:e,internal:!0}))}async function l(n,e){const{popup:o,popupElement:t}=n;i(o)?await s(o,null,e):t&&p(t)?await s(null,t,e):e?.defer(async()=>{await n.setupPopup();const{popup:o,popupElement:t}=n;i(o)&&!n.destroyed&&n.ready&&n.popupEnabled?await s(o,null,e):t&&p(t)&&await s(null,t,e)})}function u(n,e){const{popup:o,popupElement:t}=n;if(i(o))return o.open(e);t&&p(t)&&t.open(e)}function a(n,e){i(n)&&n.close(),e&&p(e)&&(e.visible=!1)}async function s(n,e,o){if(i(n)){const e=await n.viewModel.handleViewClick(o);return void(e?.promises?.length?n.open(e):n.visible&&n.close())}if(e&&p(e)){const n=await e.handleViewClick(o);n?.promises?.length?e.open(n):e.visible&&(e.visible=!1)}}export{t as addPopup,a as closePopup,i as isPopup,p as isPopupElement,u as openPopupWithOptions,l as openPopupWithViewClick,o as popupFromView};
