let popupInstance = null;

export function registerImageCompressPopup(instance) {
  popupInstance = instance;
}

export function openImageCompressModal({ path, size }) {
  if (!popupInstance || typeof popupInstance.open !== 'function') {
    console.warn('image-compress-popup 未注册，将直接使用原图');
    return Promise.resolve({
      path,
      size,
      usedCompress: false,
    });
  }

  return popupInstance.open({ path, size }).then((result) => {
    if (!result) {
      return null;
    }
    return result;
  });
}
