var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellToast/squareToast/methods.tsx
var methods_exports = {};
__export(methods_exports, {
  clear: () => clear,
  fail: () => fail,
  hide: () => hide,
  info: () => info,
  loading: () => loading,
  show: () => show,
  success: () => success
});
module.exports = __toCommonJS(methods_exports);
var import_react = __toESM(require("react"));
var import_toast = __toESM(require("./toast"));
var import_renderImperatively = require("./renderImperatively");
var currentHandler = null;
var currentTimeout = null;
var defaultProps = {
  duration: 2e3,
  mask: false,
  icon: "info"
};
function mergeProps(a, b) {
  const filteredB = Object.keys(b).reduce((acc, key) => {
    if (b[key] !== void 0) {
      acc[key] = b[key];
    }
    return acc;
  }, {});
  return {
    ...a,
    ...filteredB
  };
}
var show = (configOrContent, duration, afterClose) => {
  var _a;
  let props;
  if (typeof configOrContent === "string" || import_react.default.isValidElement(configOrContent)) {
    props = mergeProps(defaultProps, {
      content: configOrContent,
      ...duration !== void 0 && { duration },
      ...afterClose !== void 0 && { afterClose }
    });
  } else {
    props = mergeProps(defaultProps, configOrContent || {});
  }
  const element = /* @__PURE__ */ import_react.default.createElement(
    import_toast.default,
    {
      ...props,
      onCancel: () => {
        currentHandler = null;
      }
    }
  );
  if (currentHandler) {
    if ((_a = currentHandler.isRendered) == null ? void 0 : _a.call(currentHandler)) {
      currentHandler.replace(element);
    } else {
      currentHandler.close();
      currentHandler = (0, import_renderImperatively.renderImperatively)(element);
    }
  } else {
    currentHandler = (0, import_renderImperatively.renderImperatively)(element);
  }
  if (currentTimeout) {
    window.clearTimeout(currentTimeout);
  }
  if (props.duration !== 0) {
    currentTimeout = window.setTimeout(() => {
      clear();
    }, props.duration);
  }
  const instance = {
    close: () => {
      if (currentHandler) {
        currentHandler.close();
        currentHandler = null;
      }
      if (currentTimeout) {
        window.clearTimeout(currentTimeout);
        currentTimeout = null;
      }
    }
  };
  return instance;
};
var clear = () => {
  if (currentHandler) {
    currentHandler.close();
    currentHandler = null;
  }
  if (currentTimeout) {
    window.clearTimeout(currentTimeout);
    currentTimeout = null;
  }
};
var success = (content, duration, afterClose) => {
  return show({ content, icon: "success", duration, afterClose });
};
var info = (content, duration, afterClose) => {
  return show({ content, icon: "info", duration, afterClose });
};
var loading = (content, duration, afterClose) => {
  return show({ content, icon: "loading", duration, afterClose });
};
var fail = (content, duration, afterClose) => {
  return show({ content, icon: "error", duration, afterClose });
};
var hide = () => {
  clear();
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  clear,
  fail,
  hide,
  info,
  loading,
  show,
  success
});
