import { __require as requireIsPrimitive } from "./helpers/isPrimitive.js";
import { __require as requireIsCallable } from "../is-callable/index.js";
import { __require as requireIsDateObject } from "../is-date-object/index.js";
import { __require as requireIsSymbol } from "../is-symbol/index.js";
var es2015;
var hasRequiredEs2015;
function requireEs2015() {
  if (hasRequiredEs2015) return es2015;
  hasRequiredEs2015 = 1;
  var hasSymbols = typeof Symbol === "function" && typeof Symbol.iterator === "symbol";
  var isPrimitive = requireIsPrimitive();
  var isCallable = requireIsCallable();
  var isDate = requireIsDateObject();
  var isSymbol = requireIsSymbol();
  var ordinaryToPrimitive = function OrdinaryToPrimitive(O, hint) {
    if (typeof O === "undefined" || O === null) {
      throw new TypeError("Cannot call method on " + O);
    }
    if (typeof hint !== "string" || hint !== "number" && hint !== "string") {
      throw new TypeError('hint must be "string" or "number"');
    }
    var methodNames = hint === "string" ? ["toString", "valueOf"] : ["valueOf", "toString"];
    var method, result, i;
    for (i = 0; i < methodNames.length; ++i) {
      method = O[methodNames[i]];
      if (isCallable(method)) {
        result = method.call(O);
        if (isPrimitive(result)) {
          return result;
        }
      }
    }
    throw new TypeError("No default value");
  };
  var GetMethod = function GetMethod2(O, P) {
    var func = O[P];
    if (func !== null && typeof func !== "undefined") {
      if (!isCallable(func)) {
        throw new TypeError(func + " returned for property " + String(P) + " of object " + O + " is not a function");
      }
      return func;
    }
    return void 0;
  };
  es2015 = function ToPrimitive(input) {
    if (isPrimitive(input)) {
      return input;
    }
    var hint = "default";
    if (arguments.length > 1) {
      if (arguments[1] === String) {
        hint = "string";
      } else if (arguments[1] === Number) {
        hint = "number";
      }
    }
    var exoticToPrim;
    if (hasSymbols) {
      if (Symbol.toPrimitive) {
        exoticToPrim = GetMethod(
          /** @type {Record<PropertyKey, unknown>} */
          input,
          Symbol.toPrimitive
        );
      } else if (isSymbol(input)) {
        exoticToPrim = Symbol.prototype.valueOf;
      }
    }
    if (typeof exoticToPrim !== "undefined") {
      var result = exoticToPrim.call(input, hint);
      if (isPrimitive(result)) {
        return result;
      }
      throw new TypeError("unable to convert exotic object to primitive");
    }
    if (hint === "default" && (isDate(input) || isSymbol(input))) {
      hint = "string";
    }
    return ordinaryToPrimitive(
      /** @type {object} */
      input,
      hint === "default" ? "number" : hint
    );
  };
  return es2015;
}
export {
  requireEs2015 as __require
};
