contract NFT is ERC721Enumerable, Ownable {
    using Strings for uint256;

    string public baseURI;
    string public baseExtension = ".json";
    uint256 public cost = 0.06 ether;
    uint256 public whitelistCost = 0.05 ether;
    uint256 public maxSupply = 5000;
    uint256 public maxMintAmount = 20;
    bool public paused = true;
    address[] public whitelistedAddresses;

    constructor(
        string memory _name,
        string memory _symbol,
        string memory _initBaseURI
    ) ERC721(_name, _symbol) {
        setBaseURI(_initBaseURI);
    }

    // internal
    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    // public
    function mint(uint256 _mintAmount) public payable {
        require(!paused, "the contract is paused");
        uint256 supply = totalSupply();
        require(_mintAmount > 0, "need to mint at least 1 NFT");
        require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
        require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

        if (msg.sender != owner()) {
            if(isWhitelisted(msg.sender)) {
                require(msg.value >= whitelistCost * _mintAmount, "insufficient funds");
            } else {
                require(msg.value >= cost * _mintAmount, "insufficient funds");
            }
        }

        for (uint256 i = 1; i <= _mintAmount; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }
    
    function isWhitelisted(address _user) public view returns (bool) {
        for (uint i = 0; i < whitelistedAddresses.length; i++) {
            if (whitelistedAddresses[i] == _user) {
                return true;
            }
        }
        return false;
    }

    function walletOfOwner(address _owner) public view returns (uint256[] memory) {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory tokenIds = new uint256[](ownerTokenCount);
        for (uint256 i; i < ownerTokenCount; i++) {
            tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokenIds;
    }

    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory currentBaseURI = _baseURI();
        return bytes(currentBaseURI).length > 0
            ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
            : "";
    }
    
    function setCost(uint256 _newCost, uint256 _newWhitelistCost) public onlyOwner {
        cost = _newCost;
        whitelistCost = _newWhitelistCost;
    }

    function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
        maxMintAmount = _newmaxMintAmount;
    }

    function setBaseURI(string memory _newBaseURI) public onlyOwner {
        baseURI = _newBaseURI;
    }

    function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
        baseExtension = _newBaseExtension;
    }

    function pause(bool _state) public onlyOwner {
        paused = _state;
    }
    
    function whitelistUsers(address[] calldata _users) public onlyOwner {
        delete whitelistedAddresses;
        whitelistedAddresses = _users;
    }
    
    function withdraw() public payable onlyOwner {
        uint256 bps850 = address(this).balance / 10000 * 850;
        uint256 bps2100 = address(this).balance / 10000 * 2100;
        uint256 bps4800 = address(this).balance / 10000 * 4800;

        // Artists' allocation
        (bool graphic, ) = payable(0x57E768f8Bd36a8b7c1092064F49f7dd89726B98C).call{value: bps850}("");
        require(graphic);
        (bool ralphy, ) = payable(0x07FA4193047f41f27AE7c310F6aC0B3915E47323).call{value: bps850}("");
        require(ralphy);

        // Steph's allocation
        (bool steph, ) = payable(0xAd7f0Ec037354ccCE4A4e512333E820ACC0D5ddF).call{value: bps4800}("");
        require(steph);

        // Dev allocation
        (bool darren, ) = payable(0x08cb2589ad79EEd4790ef6C22f9b019431b9792F).call{value: bps2100}("");
        require(darren);
        (bool maco, ) = payable(owner()).call{value: address(this).balance}("");
        require(maco);
    }
}
function mint(uint256 _mintAmount) public payable {
    require(!paused, "the contract is paused");
    uint256 supply = totalSupply();
    require(_mintAmount > 0, "need to mint at least 1 NFT");
    require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
    require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

    if (msg.sender != owner()) {
        if(isWhitelisted(msg.sender)) {
            require(msg.value >= whitelistCost * _mintAmount, "insufficient funds");
        } else {
            require(msg.value >= cost * _mintAmount, "insufficient funds");
        }
    }

    for (uint256 i = 1; i <= _mintAmount; i++) {
        _safeMint(msg.sender, supply + i);
    }
}

// public