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

  string public baseURI = "ipfs://";
  string public baseExtension = ".json";
  string public notRevealedUri = "ipfs://QmTreXvsADJkpawjBR8rnzSkXHNstaDfjT5vasYyxJTbnM/hidden.json";
  uint256 public cost = 0.05 ether;
  uint256 public maxSupply = 2019;
  uint256 public maxMintAmount = 5;
  uint256 internal _reserved = 40;
  bool public paused = true;
  bool public revealed = false;
  mapping(address => uint256) public addressMintedBalance;

  constructor() ERC721("LFT NFT", "LFT") {
  }

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

  // public
  function mint(uint256 _mintAmount) public payable {
    require(!paused, "The sale has not yet started");
    uint256 supply = totalSupply();
    require(_mintAmount > 0, "You need to mint at least 1 NFT");
    require(_mintAmount <= maxMintAmount, "You can only mint a maximum of 5 NFTs at a time");
    require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

    if (msg.sender != owner()) {
            require(msg.value >= cost * _mintAmount, "Not enough ETH sent");
    }

    for (uint256 i = 1; i <= _mintAmount; i++) {
      addressMintedBalance[msg.sender]++;
      _safeMint(msg.sender, supply + i);
    }
  }
  
  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"
    );
    
    if(revealed == false) {
        return notRevealedUri;
    }

    string memory currentBaseURI = _baseURI();
    return bytes(currentBaseURI).length > 0
        ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
        : "";
  }

  //only owner
  function reveal() public onlyOwner {
      revealed = true;
  }
  
  function setCost(uint256 _newCost) public onlyOwner {
    cost = _newCost;
  }

  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 getReservedLeft() public view returns (uint256) {
    return _reserved;
    }

  function claimReserved(uint256 _number, address _receiver) external onlyOwner {
        require(_number <= _reserved, "That would exceed the max reserved.");

        uint256 _tokenId = totalSupply() + 1;
        for (uint256 i; i < _number; i++) {
            _safeMint(_receiver, _tokenId + i);
        }

        _reserved = _reserved - _number;
    }

  function pause(bool _state) public onlyOwner {
    paused = _state;
  }
 
   function withdraw() public onlyOwner {
        uint256 _balance = address(this).balance;
        require(payable(msg.sender).send(_balance));
    }

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

// internal