contract FeelGangPixel is ERC721A, Ownable {

  using Strings for uint256;



  string public baseURI;

  string public baseExtension = ".json";

  string public notRevealedUri;

  uint256 public cost = 0.01 ether;

  uint256 public maxSupply = 2500;

  uint256 public maxsize = 30 ; // max mint per tx

  bool public paused = true;

  bool public revealed = true;

  bool public publicSale = true;

  address public feelgang;



  constructor(

    string memory _initBaseURI,

    string memory _initNotRevealedUri

  ) ERC721A("Feel Gang Pixel", "FGP", maxsize) {

    setBaseURI(_initBaseURI);

    setNotRevealedURI(_initNotRevealedUri);

    setfeelgangaddress(0x3Fd0e935effB3505BdF19262D974ce819bd631B4); // set your collection address here

  }



  // internal

  function _baseURI() internal view virtual override returns (string memory) {

    return baseURI;

  }



  // public

  function mint(uint256 tokens) public payable {

    require(!paused, "FGP: oops contract is paused");

    require(publicSale, "FGP: Sale Hasn't started yet");

    IERC721 NFT = IERC721(feelgang);

    uint256 ownerfeelgang = NFT.balanceOf(_msgSender());

    uint256 supply = totalSupply();

    uint256 ownercount = balanceOf(_msgSender());

    require(ownerfeelgang > 0, "You dont own a FeelGang NFT");

    require(tokens > 0, "FGP: need to mint at least 1 NFT");

    require(tokens <= ownerfeelgang, "FGP: max nft exceeded");

    require(supply + tokens <= maxSupply, "FGP: Supply Exceeded");

    require(ownercount + tokens <= ownerfeelgang, "FGP: Max NFT Per Wallet exceeded");

    require(tokens <= maxsize, "FGP: MAX MINT PER TX Exceeded");

    require(msg.value >= cost * tokens, "FGP: insufficient funds");



      _safeMint(_msgSender(), tokens);

    

  }





  





  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),

      "ERC721AMetadata: 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 gift(uint256 _mintAmount, address destination) public onlyOwner {

    require(_mintAmount > 0, "need to mint at least 1 NFT");

    uint256 supply = totalSupply();

    require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");



      _safeMint(destination, _mintAmount);



  }

  function reveal(bool _state) public onlyOwner {

      revealed = _state;

  }





  function setmaxsize(uint256 _maxsize) public onlyOwner {

    maxsize = _maxsize;

  }





    function setMaxsupply(uint256 _newsupply) public onlyOwner {

    maxSupply = _newsupply;

  }





  function setBaseURI(string memory _newBaseURI) public onlyOwner {

    baseURI = _newBaseURI;

  }



  function setBaseExtension(string memory _newBaseExtension) public onlyOwner {

    baseExtension = _newBaseExtension;

  }

  

  function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {

    notRevealedUri = _notRevealedURI;

  }



  function pause(bool _state) public onlyOwner {

    paused = _state;

  }





    function togglepublicSale(bool _state) external onlyOwner {

        publicSale = _state;

    }



        function setfeelgangaddress(address _newaddress) public onlyOwner {

        feelgang = _newaddress;

    }



    function setCost(uint256 _newCost) public onlyOwner {

    cost = _newCost;

  }

  

 

  function withdraw() public payable onlyOwner {

    (bool success, ) = payable(msg.sender).call{value: address(this).balance}("");

    require(success);

  }

}
function mint(uint256 tokens) public payable {

  require(!paused, "FGP: oops contract is paused");

  require(publicSale, "FGP: Sale Hasn't started yet");

  IERC721 NFT = IERC721(feelgang);

  uint256 ownerfeelgang = NFT.balanceOf(_msgSender());

  uint256 supply = totalSupply();

  uint256 ownercount = balanceOf(_msgSender());

  require(ownerfeelgang > 0, "You dont own a FeelGang NFT");

  require(tokens > 0, "FGP: need to mint at least 1 NFT");

  require(tokens <= ownerfeelgang, "FGP: max nft exceeded");

  require(supply + tokens <= maxSupply, "FGP: Supply Exceeded");

  require(ownercount + tokens <= ownerfeelgang, "FGP: Max NFT Per Wallet exceeded");

  require(tokens <= maxsize, "FGP: MAX MINT PER TX Exceeded");

  require(msg.value >= cost * tokens, "FGP: insufficient funds");



    _safeMint(_msgSender(), tokens);

    

}

// public