/**
 * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
 * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
 */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { getType } from '.';
import { ERRORMESSAGE, EVENT } from "../constant";
import { MessageName, DisplayTypeEnum } from "../types";
/**
 * @description context中需要包含app节点，用于插入selector中
 */
export var createIframeNode = function createIframeNode(context, selector, renderDisplayType) {
  return new Promise(function (resolve, reject) {
    var dorpinDom = null;
    if (getType(selector) === 'string') {
      dorpinDom = document.querySelector(selector);
    }
    if (dorpinDom === null) {
      var error = {
        code: ERRORMESSAGE.CREATEPAYMENT_PARAMETER_ERROR.code,
        message: "Failed to execute 'querySelector' on 'Document': ".concat(selector, " is not a valid selector")
      };
      reject(error);
      context._dispatchToSDK({
        name: MessageName.APP_TO_SDK,
        instanceId: context.AMSSDK._instanceId,
        context: {
          event: EVENT.error.name,
          data: error
        }
      });
      return;
    }
    if (renderDisplayType === DisplayTypeEnum.popup) dorpinDom.innerHTML = '';
    if (context.app) {
      dorpinDom.appendChild(context.app);
    }
    resolve();
  });
};
export var createPreloadIframeNode = function createPreloadIframeNode(virtualPreloadIframe) {
  var body = document.body || null;
  if (body) {
    body.appendChild(virtualPreloadIframe);
  }
};