contract mfersdrive is ERC721A, Ownable {
  using Strings for uint256;

  string public baseURI;
  string public baseExtension = ".json";
  uint256 public cost = 0.0077 ether;
  uint256 public maxSupply = 7777;
  uint256 public maxsize = 20 ; // max mint per tx
  bool public paused = false;

  constructor() ERC721A("mfers drive", "MFERSDRIVE", maxsize) {
    setBaseURI("ipfs://QmQ6FQb7FHZazCrbQ6yZQ4AwChqhM3KgVhS7ZUzkMdWhMF/");
  }

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

  // public
  function mint(uint256 tokens) public payable {
    require(!paused, "Contract is paused");
    uint256 supply = totalSupply();
    require(tokens > 0, "Need to mint at least 1 NFT");
    require(tokens <= maxsize, "Max mint amount per tx exceeded");
    require(supply + tokens <= maxSupply, "MFER DRIVE! WE SOLD OUT!");
    if (supply < 777) {
      require(msg.value >= 0 * tokens, "It's Free Mint");
    } else {

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

      _safeMint(_msgSender(), tokens);
    
  }



  /// @dev use it for giveaway and mint for yourself
     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 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"
    );
    

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

  //only owner

  function setCost(uint256 _newCost) public onlyOwner {
    cost = _newCost;
  }

    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 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 mint(uint256 tokens) public payable {
    require(!paused, "Contract is paused");
    uint256 supply = totalSupply();
    require(tokens > 0, "Need to mint at least 1 NFT");
    require(tokens <= maxsize, "Max mint amount per tx exceeded");
    require(supply + tokens <= maxSupply, "MFER DRIVE! WE SOLD OUT!");
    if (supply < 777) {
      require(msg.value >= 0 * tokens, "It's Free Mint");
    } else {

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

      _safeMint(_msgSender(), tokens);
    
  }
// public