  We present a time-dependent photoionization code that combines
self-consistently metal evolution and dust destruction under an intense X-ray
UV radiation field. Firstly, we extend the mathematical formulation of the
time-dependent evolution of dust grains under an intense radiation flux with
the inclusion of the process of ion field emission (IFE). We determine the
relative importance of IFE with respect to X-ray and UV sublimation as a
function of grain size, intensity and hardness of the incident spectrum. We
then combine the processes of dust destruction with a photoionization code that
follows the evolution of the ionization states of the metals and the relative
radiative transitions. Our code treats, self-consistently, the gradual
recycling of metals into gas as dust is sublimated away; it allows for any
initial dust grain distribution and follows its evolution in space and time. In
this first paper, we use our code to study the time-dependent behaviour of the
X-ray and optical opacities in the nearby environment of a Gamma-ray Burst, and
show how the time variability of the low-energy and high-energy opacities can
yield powerful clues on the characteristics of the medium in which the bursts
occur.
