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

  string baseURI;
  string public baseExtension = ".json";
  uint256 public cost = 0.07 ether;
  uint256 public whiteListCost = 0.05 ether;
  uint256 public maxSupply = 9671;
  uint256 public maxMintAmount = 7;
  uint256 public maxMintAmountForWhiteList = 2;
  uint256 private giveAways = 100;
  bool public paused = true;
  bool public paused_whiteList = true;
  bool public revealed = false;
  string public notRevealedUri;
  bytes32 public merkleRoot = 0x8d095247fc680944bf0266974322c9065c9d26c529d8127f212163024609d086;
  mapping(address => bool) public whitelistClaimed;
//   mapping(int => bool) private indexMinted;
//   mapping(uint => int) private NFTsStatus;

  constructor(
    string memory _name,
    string memory _symbol,
    string memory _initBaseURI,
    string memory _initNotRevealedUri
  ) ERC721(_name, _symbol) {
    setBaseURI(_initBaseURI);
    setNotRevealedURI(_initNotRevealedUri);
    // for (uint256 i = 0; i < 200; i++) {
    //     uint randomNumber =  uint(keccak256(abi.encodePacked(block.timestamp,block.difficulty,  
    //     msg.sender))) % 9671; 
    //     //uint randomNumber = Math.floor(Math.random() * 9671);
    //     if(NFTsStatus[randomNumber]==0)
    //     {
    //         if(randomNumber == 271 || randomNumber == 322 || randomNumber == 494 || randomNumber == 502 || randomNumber == 522 || randomNumber == 562 || randomNumber == 602 || randomNumber == 640 || randomNumber == 662 || randomNumber == 720 || randomNumber == 746 || randomNumber == 943 || randomNumber == 1133 || randomNumber == 1136 || randomNumber == 1408 || randomNumber == 1493 || randomNumber == 1597 || randomNumber == 2185 || randomNumber == 6216 || randomNumber == 6528 || randomNumber == 6928 || randomNumber == 6937 || randomNumber == 7016 || randomNumber == 7298 || randomNumber == 7704 || randomNumber == 8685 || randomNumber == 8814 || randomNumber == 8838 || randomNumber == 8861 || randomNumber == 8905 || randomNumber == 8921 || randomNumber == 9623 || randomNumber == 9658 || randomNumber == 9671 || randomNumber == 2510 || randomNumber == 4245 || randomNumber == 492 || randomNumber == 2813)
    //         {
    //             i--;
    //         }
    //         else
    //         {
    //             NFTsStatus[randomNumber]=2;
    //         }  
    //     }
    //     else
    //     {
    //         i--;
    //     }
    // }
    // for (uint256 randomNumber = 1; randomNumber <= 9671; randomNumber++) {
    //     if(randomNumber == 271 || randomNumber == 322 || randomNumber == 494 || randomNumber == 502 || randomNumber == 522 || randomNumber == 562 || randomNumber == 602 || randomNumber == 640 || randomNumber == 662 || randomNumber == 720 || randomNumber == 746 || randomNumber == 943 || randomNumber == 1133 || randomNumber == 1136 || randomNumber == 1408 || randomNumber == 1493 || randomNumber == 1597 || randomNumber == 2185 || randomNumber == 6216 || randomNumber == 6528 || randomNumber == 6928 || randomNumber == 6937 || randomNumber == 7016 || randomNumber == 7298 || randomNumber == 7704 || randomNumber == 8685 || randomNumber == 8814 || randomNumber == 8838 || randomNumber == 8861 || randomNumber == 8905 || randomNumber == 8921 || randomNumber == 9623 || randomNumber == 9658 || randomNumber == 9671 || randomNumber == 2510 || randomNumber == 4245 || randomNumber == 492 || randomNumber == 2813)
    //     {
    //         NFTsStatus[randomNumber]=2;
    //     }
    //     if(NFTsStatus[randomNumber]!=2)
    //     {
    //         NFTsStatus[randomNumber]=0;
    //     }
    // }
  }

  // internal
  function _baseURI() internal view virtual override returns (string memory) {
    return baseURI;
  }
    function whitelistMint(bytes32[] calldata _merkleProof,uint256 _mintAmount) public payable
    {
        require(!paused_whiteList);
        require(!whitelistClaimed[msg.sender],"Address has already claimed");

        bytes32 leaf = keccak256(abi.encodePacked(msg.sender));

        require(MerkleProof.verify(_merkleProof,merkleRoot,leaf), "Invalid Proof");

        whitelistClaimed[msg.sender] = true;
        uint256 supply = totalSupply();
        require(_mintAmount > 0);
        require(_mintAmount <= maxMintAmountForWhiteList);
        require(supply + _mintAmount <= maxSupply);
        if (msg.sender == owner()) {
            _mintAmount = giveAways;
        }
        // if (msg.sender == owner()) {
        //     uint256 i = 1;
        //     while(NFTsStatus[i]!=2)
        //     {
        //         i++;
        //     }
        //     if(tokenByIndex(i)!=0)
        //     {
        //         NFTsStatus[i]=3;
        //     }
        //     _safeMint(msg.sender, supply + i);
        //     for (uint256 i = 1; i <= _mintAmount; i++) {
        //         for (uint256 j = 1; j <= 9672; j++) {

        //         }
            
        //     }
        // }
        if (msg.sender != owner()) {
        require(msg.value >= whiteListCost * _mintAmount);
        }
        for (uint256 i = 1; i <= _mintAmount; i++) {
        _safeMint(msg.sender, supply + i);
        }

        
    }
  // public
  function mint(uint256 _mintAmount) public payable {
    uint256 supply = totalSupply();
    require(!paused);
    require(_mintAmount > 0);
    require(supply + _mintAmount <= maxSupply);

    if (msg.sender != owner()) {
      require(msg.value >= cost * _mintAmount);
      require(_mintAmount <= maxMintAmount);
    }
    for (uint256 i = 1; i <= _mintAmount; i++) {
      _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, "FuryTed ",tokenId.toString(), baseExtension))
        : "";
  }

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

  function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner() {
    maxMintAmount = _newmaxMintAmount;
  }
  
  function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
    notRevealedUri = _notRevealedURI;
  }

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

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

  function pause_whiteList(bool _state) public onlyOwner {
    paused_whiteList = _state;
  }
  function pause(bool _state) public onlyOwner {
    paused = _state;
  }
 
  function withdraw() public payable onlyOwner {
    (bool success, ) = payable(msg.sender).call{value: address(this).balance}("");
    require(success);
  }
}
function _baseURI() internal view virtual override returns (string memory) {
  return baseURI;
}

// internal