contract Popheads is ERC721, Ownable {
  constructor() ERC721("Popheads", "POP") {}

  string private uri = "https://assets.bossdrops.io/popheads/metadata/";
  bool public lockedSupply = false;
  uint public numMinted = 0;
  uint public startIndex;
  uint MAX_SUPPLY = 69;
  /**
   * Airdrop can only be called once and should be called with an array of MAX_SUPPLY addresses.
   */
  function airdrop(address[] memory addresses) public onlyOwner {
    require(!lockedSupply, "Supply is locked");
    require(addresses.length == MAX_SUPPLY, "addresses length must be MAX_SUPPLY");
    setRandomStartIndex();
    for (uint i = startIndex; i < MAX_SUPPLY; i++) {
      _mint(addresses[i], numMinted);
      numMinted++;
    }
    for (uint i = 0; i < startIndex; i++) {
      _mint(addresses[i], numMinted);
      numMinted++;
    }
    lockedSupply = true;
  }

  function setRandomStartIndex() private {
    startIndex = uint(uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp))) % MAX_SUPPLY);
  }
  
  function setBaseURI(string memory baseURI) public onlyOwner {
    uri = baseURI;
  }

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

  function isApprovedForAll(address owner, address operator)
    public
    view
    override
    returns (bool)
  {
    return
        OpenSeaGasFreeListing.isApprovedForAll(owner, operator) ||
        super.isApprovedForAll(owner, operator);
  }
}
function airdrop(address[] memory addresses) public onlyOwner {
  require(!lockedSupply, "Supply is locked");
  require(addresses.length == MAX_SUPPLY, "addresses length must be MAX_SUPPLY");
  setRandomStartIndex();
  for (uint i = startIndex; i < MAX_SUPPLY; i++) {
    _mint(addresses[i], numMinted);
    numMinted++;
  }
  for (uint i = 0; i < startIndex; i++) {
    _mint(addresses[i], numMinted);
    numMinted++;
  }
  lockedSupply = true;
}

/**
 * Airdrop can only be called once and should be called with an array of MAX_SUPPLY addresses.
 */