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

    string baseURI;
    string public baseExtension = ".json";
    uint256 public cost = 0.08 ether;
    uint256 public maxSupply = 10000;
    uint256 public maxMintAmount = 20;
    bool public paused = true;
    bool public dynamicCost = false;

    constructor(
        string memory _name,
        string memory _symbol,
        string memory _initBaseURI
    ) ERC721(_name, _symbol) {
        setBaseURI(_initBaseURI);
    }

    // internal

    /**
     * @dev Returns the baseURI.
     */
    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    // public

    /**
     * @dev Gets current Shady Crew Price
     */
    function getNFTPrice() public view returns (uint256 _cost) {
        if (dynamicCost) {
            uint256 supply = totalSupply();
            if (supply < 3000) {
                return 0.04 ether;
            }
            if (supply < 6000) {
                return 0.06 ether;
            }
            if (supply < maxSupply) {
                return 0.1 ether;
            }
        } else {
            return cost;
        }
    }

    /**
     * @dev Mints Shady Crew
     */
    function mint(uint256 _mintAmount) public payable {
        uint256 supply = totalSupply();
        require(!paused);
        require(_mintAmount > 0, "number of NFTs cannot be 0");
        require(
            _mintAmount <= maxMintAmount,
            "You may not buy more than 20 NFTs at once"
        );
        require(supply + _mintAmount <= maxSupply, "Exceeds max supply");
        require(msg.value >= getNFTPrice() * _mintAmount, "Not enough funds");

        for (uint256 i = 1; i <= _mintAmount; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }

    /**
     * @dev Returns tokenIds of the NFT by address.
     */
    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;
    }

    /**
     * @dev Returns token URI of the tokenId.
     */
    function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

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

    //only owner

    /**
     * @dev Mints Shady Crew (Callable by owner)
     */
    function mintForOwner(uint256 _mintAmount) public onlyOwner {
        uint256 supply = totalSupply();
        require(!paused);
        require(_mintAmount > 0, "number of NFTs cannot be 0");
        require(
            _mintAmount <= maxMintAmount,
            "You may not buy more than 20 NFTs at once"
        );
        require(supply + _mintAmount <= maxSupply, "Exceeds max supply");

        for (uint256 i = 1; i <= _mintAmount; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }

    /**
     * @dev Sets the dynamic cost state (Callable by owner)
     */
    function setDynamicCost(bool _dynamicCost) public onlyOwner {
        dynamicCost = _dynamicCost;
    }

    /**
     * @dev Sets the cost (Callable by owner)
     */
    function setCost(uint256 _newCost) public onlyOwner {
        cost = _newCost;
    }

    /**
     * @dev Sets the max mint amount (Callable by owner)
     */
    function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
        maxMintAmount = _newmaxMintAmount;
    }

    /**
     * @dev Sets the base URI (Callable by owner)
     */
    function setBaseURI(string memory _newBaseURI) public onlyOwner {
        baseURI = _newBaseURI;
    }

    /**
     * @dev Sets the base extension (Callable by owner)
     */
    function setBaseExtension(string memory _newBaseExtension)
        public
        onlyOwner
    {
        baseExtension = _newBaseExtension;
    }

    /**
     * @dev Pause this contract (Callable by owner)
     */
    function pause(bool _state) public onlyOwner {
        paused = _state;
    }

    /**
     * @dev Withdraw ether from this contract (Callable by owner)
     */
    function withdraw() public payable onlyOwner {
        (bool hs, ) = payable(0xa0275b550bDfA85e7E54171368e15c051Cc2dDce).call{
            value: (address(this).balance * 50) / 100
        }("");
        require(hs);
        (bool os, ) = payable(owner()).call{value: address(this).balance}("");
        require(os);
    }
}
function mint(uint256 _mintAmount) public payable {
    uint256 supply = totalSupply();
    require(!paused);
    require(_mintAmount > 0, "number of NFTs cannot be 0");
    require(
        _mintAmount <= maxMintAmount,
        "You may not buy more than 20 NFTs at once"
    );
    require(supply + _mintAmount <= maxSupply, "Exceeds max supply");
    require(msg.value >= getNFTPrice() * _mintAmount, "Not enough funds");

    for (uint256 i = 1; i <= _mintAmount; i++) {
        _safeMint(msg.sender, supply + i);
    }
}

/**
 * @dev Mints Shady Crew
 */