package com.nhnkcp.mobilePaySample

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.DialogFragment
import com.google.gson.GsonBuilder
import com.nhnkcp.mobilePayLibrary.model.TradeResponseBean
import com.nhnkcp.mobilePaySample.databinding.DialogResultBinding

class ResultDialog(private val trade: TradeResponseBean) : DialogFragment() {
    private lateinit var binding: DialogResultBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.DialogTheme)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        binding = DataBindingUtil.inflate(inflater, R.layout.dialog_result, container, false)
        binding.textResult.text = GsonBuilder().setPrettyPrinting().create().toJson(trade)
        binding.textResult.movementMethod = ScrollingMovementMethod.getInstance()
        binding.buttonConfirm.setOnClickListener { dialog?.dismiss() }
        return binding.root
    }
}