import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
/* eslint-disable complexity */
/* eslint-disable max-lines */
import asyncArt from "../../styles/assets/logo/AsyncArt_logo.jpg";
import cryptopunks from "../../styles/assets/logo/cryptopunks.png";
import dataverse from "../../styles/assets/logo/dataverse logo.png";
import foundation from "../../styles/assets/logo/foundation logo.png";
import hashmasks from "../../styles/assets/logo/Hashmasks logo.jpg";
import knownOrigin from "../../styles/assets/logo/KnownOrigin logo.png";
import loot from "../../styles/assets/logo/loot.ico";
import makersplace from "../../styles/assets/logo/MakersPlace logo.png";
import nifty from "../../styles/assets/logo/nifty logo.png";
import opensea from "../../styles/assets/logo/opensea logo.png";
import rarible from "../../styles/assets/logo/rarible-logo.jpeg";
import superrare from "../../styles/assets/logo/superrare logo.jpeg";
import tryshowtime from "../../styles/assets/logo/tryshowtime logo.png";
import twitter from "../../styles/assets/logo/twitter logo.png";
import zora from "../../styles/assets/logo/zora logo.png";
import magiceden from "../../styles/assets/logo/magiceden logo.png";
import objkt from "../../styles/assets/logo/objkt logo.png";
import kalamint from "../../styles/assets/logo/kalamint logo.png";
import viv3 from "../../styles/assets/logo/viv3 logo.png";
import looksrare from "../../styles/assets/logo/looksrare logo.png";
import treasureland from "../../styles/assets/logo/treasureland logo.svg";
import nftscan from "../../styles/assets/logo/nftscan logo.png";
import nftgo from "../../styles/assets/logo/nftgo logo.ico";
import azuki from "../../styles/assets/logo/azuki logo.ico";
import gem from "../../styles/assets/logo/gem logo.png";
import solanart from "../../styles/assets/logo/solanart logo.webp";
import ipfs from "../../styles/assets/logo/ipfs logo.ico";
import coinbase from "../../styles/assets/logo/coinbase logo.png";
import binance from "../../styles/assets/logo/binance logo.ico";
import tofunft from "../../styles/assets/logo/tofunft logo.ico";
import ethereum from "../../styles/assets/logo/ethereum_logo.png";
import flow from "../../styles/assets/logo/flow_logo.png";
import polygon from "../../styles/assets/logo/polygon_logo.png";
import tezos from "../../styles/assets/logo/tezos_logo.png";
import BSC from "../../styles/assets/logo/BSC_logo.png";
import solana from "../../styles/assets/logo/solana_logo.png";
import arbitrum from "../../styles/assets/logo/arbitrum_logo.svg";
import astar from "../../styles/assets/logo/astar_logo.png";
import aurora from "../../styles/assets/logo/aurora_logo.svg";
import avalanche from "../../styles/assets/logo/avalanche_logo.svg";
import Boba from "../../styles/assets/logo/boba_logo.svg";
import celo from "../../styles/assets/logo/celo_logo.svg";
import cronos from "../../styles/assets/logo/cronos_logo.svg";
import evmos from "../../styles/assets/logo/evmos_logo.svg";
import fantom from "../../styles/assets/logo/fantom_logo.svg";
import fuse from "../../styles/assets/logo/fuse_logo.svg";
import harmony from "../../styles/assets/logo/harmony_logo.svg";
import heco from "../../styles/assets/logo/heco_logo.svg";
import klaytn from "../../styles/assets/logo/klaytn_logo.svg";
import meter from "../../styles/assets/logo/meter_logo.svg";
import metis from "../../styles/assets/logo/metis_logo.svg";
import moonbeam from "../../styles/assets/logo/moonbeam_logo.svg";
import moonriver from "../../styles/assets/logo/moonriver_logo.svg";
import oasis from "../../styles/assets/logo/oasis_logo.svg";
import OEC from "../../styles/assets/logo/OEC_logo.svg";
import optimism from "../../styles/assets/logo/optimism_logo.svg";
import shiden from "../../styles/assets/logo/shiden_logo.svg";
import telos from "../../styles/assets/logo/telos_logo.svg";
import IoTeX from "../../styles/assets/logo/IoTeX_logo.png";
import KCC from "../../styles/assets/logo/KCC_logo.png";
import mirror from "../../styles/assets/logo/mirror logo.png";
import bilibili from "../../styles/assets/logo/bilibili logo.ico";
import youtube from "../../styles/assets/logo/youtube logo.png";
import artBlock from "../../styles/assets/logo/artblocks logo.ico";
export var NftChain;
(function (NftChain) {
  NftChain["Ethereum"] = "Ethereum";
  NftChain["Tezos"] = "Tezos";
  NftChain["Solana"] = "Solana";
  NftChain["BSC"] = "BSC";
  NftChain["Polygon"] = "Polygon";
  NftChain["Arbitrum"] = "Arbitrum";
  NftChain["Optimism"] = "Optimism";
  NftChain["Moonbeam"] = "Moonbeam";
  NftChain["PlatON"] = "PlatON";
  NftChain["Flow"] = "Flow";
  NftChain["FTM"] = "FTM";
  NftChain["OEC"] = "OEC";
  NftChain["IoTeX"] = "IoTeX";
  NftChain["Moonriver"] = "Moonriver";
  NftChain["KCC"] = "KCC";
})(NftChain || (NftChain = {}));
export var NftPlatform;
(function (NftPlatform) {
  NftPlatform["Unknown"] = "Unknown";
  NftPlatform["Opensea"] = "OpenSea";
  NftPlatform["Superrare"] = "SuperRare";
  NftPlatform["Zora"] = "Zora";
  NftPlatform["Foundation"] = "Foundation";
  NftPlatform["Twitter"] = "Twitter";
  NftPlatform["Rarible"] = "Rarible";
  NftPlatform["NiftyGateway"] = "NiftyGateway";
  NftPlatform["AsyncArt"] = "AsyncArt";
  NftPlatform["KnownOrigin"] = "KnownOrigin";
  NftPlatform["MakerSplace"] = "Makersplace";
  NftPlatform["Kalamint"] = "Kalamint";
  NftPlatform["Objkt"] = "Objkt";
  NftPlatform["Magiceden"] = "MagicEden";
  NftPlatform["Tofunft"] = "Tofunft";
  NftPlatform["Viv3"] = "VIV3";
  NftPlatform["Looksrare"] = "Looksrare";
  NftPlatform["Treasureland"] = "Treasureland";
  NftPlatform["Nftscan"] = "Nftscan";
  NftPlatform["Artblocks"] = "Artblocks";
  NftPlatform["NftGo"] = "Nftgo";
  NftPlatform["Azuki"] = "Azuki";
  NftPlatform["Gem"] = "Gem";
  NftPlatform["Solanart"] = "Solannart";
  NftPlatform["Coinbase"] = "Coinbase";
  NftPlatform["Binance"] = "Binance";
  NftPlatform["Tryshowtime"] = "Tryshowtime";
  NftPlatform["Bilibili"] = "Bilibili";
  NftPlatform["Mirror"] = "Mirror";
  NftPlatform["Youtube"] = "Youtube";
  NftPlatform["IPFS"] = "IPFS";
})(NftPlatform || (NftPlatform = {}));
export var extractHex = function extractHex(str) {
  var _str$match;
  return (_str$match = str.match(/0x[\dA-Za-z]+/)) === null || _str$match === void 0 ? void 0 : _str$match[0];
};
export var platformMapInExplore = {
  // Opensea: { logo: opensea, alias: '' },
  Marketplace: {
    logo: dataverse,
    alias: 'all'
  },
  Rarible: {
    logo: rarible,
    alias: 'rarible'
  },
  AsyncArt: {
    logo: asyncArt,
    alias: 'async-art'
  },
  Foundation: {
    logo: foundation,
    alias: 'fnd'
  },
  // NiftyGateway: { logo: nifty, alias: 'nifty-gateway' },
  Superrare: {
    logo: superrare,
    alias: 'superrare'
  },
  Zora: {
    logo: zora,
    alias: 'zora'
  },
  KnownOrigin: {
    logo: knownOrigin,
    alias: 'known-origin'
  },
  Makersplace: {
    logo: makersplace,
    alias: 'makersplace'
  },
  ArtBlock: {
    logo: artBlock,
    alias: 'art-blocks-factory'
  },
  // art-blocks
  CryptoPunk: {
    logo: cryptopunks,
    alias: 'cryptopunks'
  },
  Hashmasks: {
    logo: hashmasks,
    alias: 'hashmasks'
  },
  Loot: {
    logo: loot,
    alias: 'lootproject'
  }
  // Tryshowtime: { logo: tryshowtime, alias: 'tryshowtime' },
};

var nftPlatformMap = [{
  platformUrl: ['opensea'],
  logo: opensea,
  name: NftPlatform.Opensea
}, {
  platformUrl: ['superrare'],
  logo: superrare,
  name: NftPlatform.Superrare
}, {
  platformUrl: ['zora'],
  logo: zora,
  name: NftPlatform.Zora
}, {
  platformUrl: ['foundation'],
  logo: foundation,
  name: NftPlatform.Foundation
}, {
  platformUrl: ['twitter'],
  logo: twitter,
  name: NftPlatform.Twitter
}, {
  platformUrl: ['rarible.com'],
  logo: rarible,
  name: NftPlatform.Rarible
}, {
  platformUrl: ['niftygateway'],
  logo: nifty,
  name: NftPlatform.NiftyGateway
}, {
  platformUrl: ['async.art'],
  logo: asyncArt,
  name: NftPlatform.AsyncArt
}, {
  platformUrl: ['knownorigin'],
  logo: knownOrigin,
  name: NftPlatform.KnownOrigin
}, {
  platformUrl: ['makersplace'],
  logo: makersplace,
  name: NftPlatform.MakerSplace
}, {
  platformUrl: ['tryshowtime'],
  logo: tryshowtime,
  name: NftPlatform.Tryshowtime
}, {
  platformUrl: ['magiceden'],
  logo: magiceden,
  name: NftPlatform.Magiceden
}, {
  platformUrl: ['objkt'],
  logo: objkt,
  name: NftPlatform.Objkt
}, {
  platformUrl: ['kalamint'],
  logo: kalamint,
  name: NftPlatform.Kalamint
}, {
  platformUrl: ['viv3'],
  logo: viv3,
  name: NftPlatform.Viv3
}, {
  platformUrl: ['mirror'],
  logo: mirror,
  name: NftPlatform.Mirror
}, {
  platformUrl: ['bilibili'],
  logo: bilibili,
  name: NftPlatform.Bilibili
}, {
  platformUrl: ['youtube'],
  logo: youtube,
  name: NftPlatform.Youtube
}, {
  platformUrl: ['tofunft'],
  logo: tofunft,
  name: NftPlatform.Tofunft
}, {
  platformUrl: ['looksrare'],
  logo: looksrare,
  name: NftPlatform.Looksrare
}, {
  platformUrl: ['treasureland'],
  logo: treasureland,
  name: NftPlatform.Treasureland
}, {
  platformUrl: ['nftscan'],
  logo: nftscan,
  name: NftPlatform.Nftscan
}, {
  platformUrl: ['artblocks'],
  logo: artBlock,
  name: NftPlatform.Artblocks
}, {
  platformUrl: ['nftgo'],
  logo: nftgo,
  name: NftPlatform.NftGo
}, {
  platformUrl: ['azuki.com'],
  logo: azuki,
  name: NftPlatform.Azuki
}, {
  platformUrl: ['gem.xyz'],
  logo: gem,
  name: NftPlatform.Gem
}, {
  platformUrl: ['solanart.io'],
  logo: solanart,
  name: NftPlatform.Solanart
}, {
  platformUrl: ['dweb.link', 'ipfs.io', 'ipfs.infura.io', 'ipfs.pixura.io', 'ipfs.daonomic.com', 'ipfs.fleek.co'],
  logo: ipfs,
  name: NftPlatform.IPFS
}, {
  platformUrl: ['nft.coinbase'],
  logo: coinbase,
  name: NftPlatform.Coinbase
}, {
  platformUrl: ['binance.com'],
  logo: binance,
  name: NftPlatform.Binance
}];
var getContentIdByUrl = function getContentIdByUrl(url) {
  var platformType = getPlatformType(url);
  var chain;
  var contract;
  var tokenId;
  var contractToken = getContractTokenByUrl(url);
  if (contractToken !== false) {
    contract = contractToken.contract;
    tokenId = contractToken.tokenId;
  }
  switch (platformType) {
    case NftPlatform.Unknown:
      return url;
    case NftPlatform.Artblocks:
      chain = NftChain.Ethereum;
      break;
    case NftPlatform.AsyncArt:
      {
        chain = NftChain.Ethereum;
        contract = extractHex(url);
        var tmp = url.split('/');
        tokenId = tmp[tmp.length - 1].split('-')[1];
        break;
      }
    case NftPlatform.Azuki:
      {
        var _url$match;
        var idx = (_url$match = url.match(/id=.+/)) === null || _url$match === void 0 ? void 0 : _url$match.index;
        if (idx) {
          contract = '0xed5af388653567af2f388e6224dc7c4b3241c544';
          tokenId = url.slice(idx + 3);
        }
        chain = NftChain.Ethereum;
        break;
      }
    case NftPlatform.Coinbase:
      chain = NftChain.Ethereum;
      break;
    case NftPlatform.Foundation:
      {
        var s = url.split('/');
        chain = NftChain.Ethereum;
        tokenId = s[s.length - 1];
        break;
      }
    case NftPlatform.Gem:
      chain = NftChain.Ethereum;
      break;
    case NftPlatform.Kalamint:
      {
        contract = 'KT1EpGgjQs73QfFJs9z7m1Mxm5MTnpC2tqse';
        var _s = url.split('/');
        tokenId = _s[_s.length - 1];
        chain = NftChain.Tezos;
        break;
      }
    case NftPlatform.Looksrare:
      chain = NftChain.Ethereum;
      break;
    case NftPlatform.Magiceden:
      if (url.includes('item-details')) {
        chain = NftChain.Solana;
        var _handleSolana = handleSolana(url);
        contract = _handleSolana.contract;
        tokenId = _handleSolana.tokenId;
      }
      break;
    case NftPlatform.MakerSplace:
      chain = NftChain.Ethereum;
      break;
    case NftPlatform.NftGo:
      chain = NftChain.Ethereum;
      break;
    case NftPlatform.Nftscan:
      {
        if (url.includes('bnb')) {
          chain = NftChain.BSC;
        } else if (url.includes('polygon')) {
          chain = NftChain.Polygon;
        } else if (url.includes('solana')) {
          chain = NftChain.Solana;
          var _handleSolana2 = handleSolana(url);
          contract = _handleSolana2.contract;
          tokenId = _handleSolana2.tokenId;
        } else if (url.includes('arbitrum')) {
          chain = NftChain.Arbitrum;
        } else if (url.includes('optimism')) {
          chain = NftChain.Optimism;
        } else if (url.includes('moonbeam')) {
          chain = NftChain.Moonbeam;
        } else if (url.includes('platon')) {
          chain = NftChain.PlatON;
        }
        break;
      }
    case NftPlatform.NiftyGateway:
      chain = NftChain.Ethereum;
      break;
    case NftPlatform.Objkt:
      chain = NftChain.Tezos;
      break;
    case NftPlatform.Opensea:
      if (url.includes('matic')) {
        chain = NftChain.Polygon;
      } else if (url.includes('solana')) {
        chain = NftChain.Solana;
      } else {
        chain = NftChain.Ethereum;
      }
      break;
    case NftPlatform.Rarible:
      if (url.includes('solana')) {
        var _url$match$, _url$match2;
        chain = NftChain.Solana;
        contract = (_url$match$ = (_url$match2 = url.match('/solana/(.+)\\?')) === null || _url$match2 === void 0 ? void 0 : _url$match2[1]) !== null && _url$match$ !== void 0 ? _url$match$ : undefined;
        tokenId = '-';
      } else if (url.includes('polygon')) {
        chain = NftChain.Solana;
        contract = extractHex(url);
        var tmpSplitArr = url.split('?')[0].split(':');
        tokenId = tmpSplitArr[2];
      } else if (url.includes('tezos')) {
        chain = NftChain.Tezos;
        var res = url.match('/tezos/(.+):(.+)\\?');
        if (res) {
          contract = res[1];
          tokenId = res[2];
        }
      } else if (url.includes('flow')) {
        chain = NftChain.Flow;
        var _res = url.match('/flow/(.+):(.+)\\?');
        if (_res) {
          contract = _res[1];
          tokenId = _res[2];
        }
      }
      break;
    case NftPlatform.Solanart:
      {
        var _tmp = url.split('/');
        contract = _tmp[_tmp.length - 1];
        tokenId = '-';
        chain = NftChain.Solana;
        break;
      }
    case NftPlatform.Superrare:
      {
        var _tmp2 = url.split('/');
        var tmpSplit = _tmp2[_tmp2.length - 1].split('-');
        tokenId = tmpSplit[tmpSplit.length - 1];
        chain = NftChain.Ethereum;
        if (url.includes('artwork-v2')) {
          contract = '0xb932a70a57673d89f4acffbe830e8ed7f75fb9e0';
        }
        break;
      }
    case NftPlatform.Tofunft:
      {
        var _tmp3 = url.match(/https:\/\/tofunft.com\/nft\/(.+?)\/(.+?)\/(\d+)\??/);
        if (_tmp3) {
          var chainMatch = _tmp3[1];
          contract = _tmp3[2];
          tokenId = _tmp3[3];
          switch (chainMatch) {
            case 'bsc':
              {
                chain = NftChain.BSC;
                break;
              }
            case 'eth':
              {
                chain = NftChain.Ethereum;
                break;
              }
            case 'ftm':
              {
                chain = NftChain.FTM;
                break;
              }
            case 'oec':
              {
                chain = NftChain.OEC;
                break;
              }
            default:
              {
                break;
              }
          }
        }
        break;
      }
    case NftPlatform.Treasureland:
      {
        var _res2 = url.match(/https:\/\/(www\.)?treasureland.market\/assets\/(.+?\/)(\d+)(\/\d*)?\?chain_id=(\d+)/);
        if (_res2) {
          contract = _res2[2].replace('/', '');
          tokenId = _res2[3];
          var _chainMatch = _res2.slice(-1)[0];
          switch (_chainMatch) {
            case '56':
              chain = NftChain.BSC;
              break;
            case '1':
              chain = NftChain.Ethereum;
              break;
            case '137':
              chain = NftChain.Polygon;
              break;
            case '1285':
              chain = NftChain.Moonriver;
              break;
            case '4689':
              chain = NftChain.IoTeX;
              break;
            case '1284':
              chain = NftChain.Moonbeam;
              break;
            case '321':
              chain = NftChain.KCC;
              break;
            default:
              break;
          }
        }
        break;
      }
    case NftPlatform.Tryshowtime:
      chain = NftChain.Polygon;
      break;
    case NftPlatform.Viv3:
      chain = NftChain.Flow;
      break;
    case NftPlatform.Zora:
      chain = NftChain.Ethereum;
      break;
    default:
      break;
  }
  if (chain && contract && tokenId) {
    return makeUpContentId(chain, contract, tokenId);
  } else {
    return url;
  }
};
var contractTokenReg = new RegExp('0x.+/.+');
var handleSolana = function handleSolana(url) {
  var _tmpSplitArr$match$, _tmpSplitArr$match;
  var tmpSplitArr = url.split('/');
  return {
    contract: (_tmpSplitArr$match$ = (_tmpSplitArr$match = tmpSplitArr[tmpSplitArr.length - 1].match(/[\d+A-Za-z]*/)) === null || _tmpSplitArr$match === void 0 ? void 0 : _tmpSplitArr$match[0]) !== null && _tmpSplitArr$match$ !== void 0 ? _tmpSplitArr$match$ : tmpSplitArr[tmpSplitArr.length - 1],
    tokenId: '-'
  };
};
var getContractTokenByUrl = function getContractTokenByUrl(url) {
  if (getPlatformType(url) !== NftPlatform.Unknown) {
    var _url$match3;
    var result = (_url$match3 = url.match(contractTokenReg)) === null || _url$match3 === void 0 ? void 0 : _url$match3[0].split('/');
    if (result) {
      return {
        contract: result[0],
        tokenId: result[1]
      };
    }
  }
  return false;
};
var makeUpContentId = function makeUpContentId(chain, contract, tokenId) {
  return "".concat(chain, ":").concat(contract, ":").concat(tokenId);
};
export var getPlatformLogo = function getPlatformLogo(platformUrl) {
  if (!platformUrl) {
    return NftPlatform.Unknown;
  }
  var url = platformUrl.toLowerCase();
  var _iterator = _createForOfIteratorHelper(nftPlatformMap),
    _step;
  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var platform = _step.value;
      var varify = true;
      platform.platformUrl.map(function (linkUrl) {
        if (url.includes(linkUrl)) {
          varify = false;
        }
        return null;
      });
      if (varify) {
        return platform.logo;
      }
    }
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  return NftPlatform.Unknown;
};
export function getPlatformType(platformUrl) {
  if (!platformUrl) {
    return NftPlatform.Unknown;
  }
  var url = platformUrl.toLowerCase();
  var _iterator2 = _createForOfIteratorHelper(nftPlatformMap),
    _step2;
  try {
    for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
      var platform = _step2.value;
      var varify = false;
      platform.platformUrl.map(function (linkUrl) {
        if (url.includes(linkUrl)) {
          varify = true;
        }
        return null;
      });
      if (varify) {
        return platform.name;
      }
    }
  } catch (err) {
    _iterator2.e(err);
  } finally {
    _iterator2.f();
  }
  return NftPlatform.Unknown;
}

// eslint-disable-next-line complexity
export function getChainLogo(chain) {
  switch (chain) {
    case '':
    case 'Ethereum':
    case 'ERC1155':
    case 'ERC721':
      return ethereum;
    case 'BSC':
      return BSC;
    case 'Polygon':
      return polygon;
    case 'Flow':
      return flow;
    case 'Tezos':
      return tezos;
    case 'Solana':
      return solana;
    case 'Arbi':
      return arbitrum;
    case 'Astar':
      return astar;
    case 'Aurora':
      return aurora;
    case 'Avax':
      return avalanche;
    case 'Boba':
      return Boba;
    case 'Celo':
      return celo;
    case 'Cronos':
      return cronos;
    case 'Evmos':
      return evmos;
    case 'FTM':
      return fantom;
    case 'Fuse':
      return fuse;
    case 'Harmony':
      return harmony;
    case 'Heco':
      return heco;
    case 'Klaytn':
      return klaytn;
    case 'Meter':
      return meter;
    case 'Metis':
      return metis;
    case 'Moonbeam':
      return moonbeam;
    case 'Moonriver':
      return moonriver;
    case 'Oasis':
      return oasis;
    case 'OEC':
      return OEC;
    case 'Optimism':
      return optimism;
    case 'Shiden':
      return shiden;
    case 'Telos':
      return telos;
    case 'IoTeX':
      return IoTeX;
    case 'KCC':
      return KCC;
    default:
      return '';
  }
}