Lightbox not closing properly

I have a bit of code, which passes info to the a lightbox. Then there are a couple of datasets and a repeater within the lightbox. On the closure of the lightbox, “closed” is supposed to be printed out to the console. However, I do not see this getting printed when i try it out on the live site. Also, when I try to open the lightbox again, I get an error “lightbox already open”. On opening the lightbox the second time, the parameters passed to it is ignored and the previous parameter passed is used again.

I am triggering the lightbox on a click of a button in a repeater, based on the item that is clicked. Before opening the lightbox, I am also print out the parameter to the console to check whether there is any error in getting the parameter using context. however, there is no error in this.

Can someone help as to why this error is coming. I am attaching the relevant code as well as the errors screenshot

If you see the screenshot of the part of the console. You will see “going in C0004” being printed the first time. and C0004 getting printed, This is being called from inside the lightbox. There is no “closed” getting printed out to the console.

Then you would see the "going in C000 3" this is the attempt to open the lightbox again. Then the error in red. Later "C000 4 " gets printed. This is not what is passed to the lightbox the second time. It is the parameter passed the first time.

There are warning messages also getting printed. However there are no repeater4 inside the lightbox. I am also attaching the code of the lightbox as well below.