; and (II) at the time the alien was taken into custody by the State or a political subdivision of the State— (aa) failed to maintain the nonimmigrant status in which the alien was admitted or to which it was changed under section 248; or (bb) failed to comply with the conditions of any such status. (2) In general If the governor of a State (or, if appropriate, the chief executive officer of a political subdivision of the State), exercising authority with respect to the incarceration or detention of an undocumented criminal alien, submits a written request to the Attorney General, the Attorney General may— (A) enter into a contractual arrangement providing for compensation to the State or a political subdivision of the State, as may be appropriate, with respect to the incarceration or detention of the undocumented criminal alien; or (B) take the undocumented criminal alien into the custody of the Federal Government and incarcerate or detain the alien. (3) Detention security In carrying out paragraph (2), the Attorney General shall— (A) give priority to the Federal incarceration of undocumented criminal aliens who have committed aggravated felonies; and (B) ensure that undocumented criminal aliens incarcerated or detained in Federal facilities pursuant to this subsection are held in facilities that provide a level of security appropriate to the crimes for which they were charged or convicted. (4) Amount of compensation (A) In general Compensation provided for each day an undocumented criminal alien is detained by a State or a political subdivision of a State pursuant to a contract under paragraph (2)(A) shall be equal to the average daily cost of incarceration or detention of a prisoner in the relevant State, as determined by the Attorney General. (B) Certification requirement (i) In general The Secretary of Homeland Security shall— (I) promulgate regulations establishing detainer compliance criteria