'use strict';

var index = require('./index-23d51a41.cjs.dev.js');
var zod = require('zod');
var fetchCurrencyValue = require('./fetchCurrencyValue-b917a4d6.cjs.dev.js');

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n["default"] = e;
  return Object.freeze(n);
}

const PropertiesInput = /* @__PURE__ */(() => zod.z.object({}).catchall(zod.z.union([index.BigNumberTransformSchema$1, zod.z.unknown()])))();

/**
 * @internal
 */
const OptionalPropertiesInput = /* @__PURE__ */(() => zod.z.union([zod.z.array(zod.z.array(PropertiesInput)).transform(i => i.flat()), zod.z.array(PropertiesInput), PropertiesInput]).optional().nullable())();

/**
 * @internal
 */
const BasicNFTInput = /* @__PURE__ */(() => zod.z.object({
  name: zod.z.union([zod.z.string(), zod.z.number()]).optional().nullable(),
  description: zod.z.string().nullable().optional().nullable(),
  image: index.FileOrBufferOrStringSchema.nullable().optional(),
  animation_url: index.FileOrBufferOrStringSchema.optional().nullable()
}))();

/**
 * @internal
 */
const CommonNFTInput = /* @__PURE__ */(() => BasicNFTInput.extend({
  external_url: index.FileOrBufferOrStringSchema.nullable().optional(),
  background_color: index.HexColor.optional().nullable(),
  properties: OptionalPropertiesInput,
  attributes: OptionalPropertiesInput
}).catchall(zod.z.union([index.BigNumberTransformSchema$1, zod.z.unknown()])))();

/**
 * @internal
 */
const NFTInputOrUriSchema = /* @__PURE__ */(() => zod.z.union([CommonNFTInput, zod.z.string()]))();

/**
 * @internal
 */
const CommonNFTOutput = /* @__PURE__ */(() => CommonNFTInput.extend({
  id: zod.z.string(),
  uri: zod.z.string(),
  image: zod.z.string().nullable().optional(),
  external_url: zod.z.string().nullable().optional(),
  animation_url: zod.z.string().nullable().optional()
}))();

/**
 * @public
 */

/**
 * @public
 */

/**
 * @public
 */

/**
 * @public
 */

/**
 * @public
 */

/**
 * @internal
 */
async function setErc20Allowance(contractToApprove, value, currencyAddress, overrides) {
  if (fetchCurrencyValue.isNativeToken(currencyAddress)) {
    overrides["value"] = value;
  } else {
    const ERC20Abi = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@thirdweb-dev/contracts-js/dist/abis/IERC20.json')); })).default;
    const signer = contractToApprove.getSigner();
    const provider = contractToApprove.getProvider();
    const erc20 = new index.ContractWrapper(signer || provider, currencyAddress, ERC20Abi, contractToApprove.options, contractToApprove.storage);
    const owner = await contractToApprove.getSignerAddress();
    const spender = contractToApprove.address;
    const allowance = await erc20.read("allowance", [owner, spender]);
    if (allowance.lt(value)) {
      // approve overrides the previous allowance, set it to the minimum required for this tx
      await erc20.sendTransaction("approve", [spender, value]);
    }
    return overrides;
  }
}

exports.BasicNFTInput = BasicNFTInput;
exports.CommonNFTInput = CommonNFTInput;
exports.CommonNFTOutput = CommonNFTOutput;
exports.NFTInputOrUriSchema = NFTInputOrUriSchema;
exports.setErc20Allowance = setErc20Allowance;
