Your lease payments already include tax. The Purchase Option Price (POP) does not. Because you have not paid tax on the POP you do not get the same tax credit as you would on a vehicle you had purchased (and paid all the tax on). Typically, leased vehicles are not shown as trades on the new contract. Equity or negative equity will be determined based on the current buyout before tax. Any equity will be shown as downpayment and any negative equity will be added to the selling price. By doing this, the dealer is purchasing the car from the leasing company independently of the new transaction.
Alternatively, depending on the terms of the original lease, it may be better for the dealer to just pay the remaining payments to the leasing company and send the car back to them. If, say, the lease payment is $200 then the remaining payments would be $200 x 18 = $3600. If the negative equity is $4000, it would make more sense for the dealer to just build the $3600 into the new deal, send $3600 to the leasing company along with the car. Of course, this assumes the car is within the mileage limit and does not have any damage.