SAN BERNARDINO (CBSLA) — A 40-year-old man accused of shooting a San Bernardino County Sheriff’s Department deputy earlier this week remained hospitalized and in custody Thursday.

A San Bernardino County Sheriff’s Department deputy was shot and wounded Tuesday and was being treated at a nearby hospital. (CBSLA)

READ MORE: Día De Los Muertos Celebrations and Others Return To LA

According to the department, Deputy Dustin Whitson responded Tuesday to a call of an unwanted person at Bear Valley Storage facility.

When Whitson arrived at the scene, he saw a Ford SUV matching the description provided by the storage facility parked near the AutoZone, just east of the storage facility, and approached the vehicle to speak to the passenger, the department said.

Moments later, the department said a member of the public used Whitson’s radio to report that he had suffered a gunshot wound. Whitson was airlifted to a hospital where he remained hospitalized in critical condition.

The suspected shooter, identified as 40-year-old Robert Elvis Sparks of San Bernardino, then fled the scene in the SUV, the department said, and was spotted by deputies from the Apple Valley Station who then began following the vehicle.

The department said Sparks drove into the open desert and “brandished a gun and fired at the deputies,” before becoming stuck in soft sand. Sparks then exited the vehicle, started walking away and then allegedly began shooting at deputies who subsequently returned fire.

READ MORE: Sigma Nu Fraternity At USC Suspends Member At Center Of Sexual Assault Allegations

The department said Sparks then walked toward a home before allegedly turning to shoot at the sheriff’s department helicopter, prompting deputies to again fire their weapons — striking Sparks.

Sparks was airlifted to a hospital where he remained in critical condition and in custody.

Investigators said two handguns were found in Sparks’ possession, one of which was said to be Whitson’s service weapon.

Detectives said Sparks had a no-bail warrant out for his arrest after he was reported missing from a board and care facility in San Bernardino where he had been living since his release from Patton State Hospital last October. Sheriff John McMahon said Sparks had an “extensive” criminal history.

The investigation was ongoing, and the motive for the shooting remained unclear.

Anyone with information was asked to call Det. Adrian Bustamante at 909-387-3589.

MORE NEWS: USC Places Sigma Nu Fraternity On Interim Suspension After Reports Of 'Possible Drug-Facilitated Sexual Assaults,' Students Protest In Support Of Victims

Detectives with the Specialized Investigations Division responded to conduct the investigation.