/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
class n {
  constructor(l) {
    this.hooks = l, this.pendingDeployedSolutionId = null, this._isCancelling = !1, this.handleDeployCancelled = () => {
      this.pendingDeployedSolutionId = null, this.hooks.onDeployCancelled?.();
    }, this.handleDeployFailed = (e) => {
      if (this.pendingDeployedSolutionId = null, this._isCancelling) {
        this.closeDialogs();
        return;
      }
      this.hooks.onDeployFailedReal?.(e.detail?.error), this.closeDialogs(!0);
    }, this.handleDeploySuccess = (e) => {
      this.pendingDeployedSolutionId = e?.detail || null;
      const o = this.hooks.deployingDialogRef.value;
      o && (o.isWaitingForCard = !0, o.deploymentProgress = 100), this.hooks.onDeploySuccess?.(e?.detail || "");
    }, this.deployProgressStart = (e) => {
      const o = this.hooks.deployingDialogRef.value;
      o && (o.card = this.hooks.getCard(), o.abortController = e.detail, o.deploymentProgress = 0, o.isWaitingForCard = !1, o.open = !0), this.hooks.deployDialogRef.value && this.hooks.deployDialogRef.value.classList.add("display-none"), this.hooks.onDeployStarted?.(e.detail);
    }, this.deployProgressUpdated = (e) => {
      const o = this.hooks.deployingDialogRef.value;
      o && (o.deploymentProgress = e.detail.progress);
    }, this.handleDeploymentProcessCancelled = () => {
      this.pendingDeployedSolutionId = null, this._isCancelling = !0, this.hooks.onDeploymentProcessCancelled?.();
    }, this.handleDeployedCardReady = async (e) => {
      !this.pendingDeployedSolutionId || e.detail?.card?.id !== this.pendingDeployedSolutionId || (this.pendingDeployedSolutionId = null, this.closeDialogs(), await new Promise((i) => requestAnimationFrame(() => requestAnimationFrame(i))), this.hooks.onDeployedCardReady?.(e.detail));
    }, this.handleDeploymentFallback = (e) => {
      !this.pendingDeployedSolutionId || e.detail?.solutionId !== this.pendingDeployedSolutionId || (this.pendingDeployedSolutionId = null, this.closeDialogs(), this.hooks.onDeploymentFallback?.(e.detail));
    };
  }
  //--------------------------------------------------------------------------
  // Imperative helpers
  //--------------------------------------------------------------------------
  /**
   * Close the deploying dialog and (optionally) the deploy dialog. Calls
   * the deploy dialog's `close()` so internal alert/form state is reset.
   * Fires `onCloseAfterCancel` exactly once if a cancellation was in flight.
   */
  closeDialogs(l = !1) {
    this._isCancelling && (this.hooks.onCloseAfterCancel?.(), this._isCancelling = !1), this.hooks.deployingDialogRef.value && this.hooks.deployingDialogRef.value.close();
    const e = this.hooks.deployDialogRef.value;
    e && (e.classList.remove("display-none"), l ? e.open = !0 : e.close(!1));
  }
}
export {
  n as D
};
