When a court intends to commit an offender with a serious and persistent mental illness, as defined in section 245.462, subdivision 20, paragraph (c), to the custody of the commissioner of corrections for imprisonment at a state correctional facility, either when initially pronouncing a sentence or when revoking an offender’s probation, the court, when consistent with public safety, may instead place the offender on probation or continue the offender’s probation and require as a condition of the probation that the offender successfully complete an appropriate supervised alternative living program having a mental health treatment component. This section applies only to offenders who would have a remaining term of imprisonment after adjusting for credit for prior imprisonment, if any, of one year or more.