package com.unibuy.smartdevice.ui.dialog;

import android.content.Context;

import com.unibuy.smartdevice.DialogAbstract;
import com.unibuy.smartdevice.MyApp;
import com.unibuy.smartdevice.databinding.DialogCreditCardReceiptBinding;
import com.unibuy.smartdevice.exception.LogsIOException;
import com.unibuy.smartdevice.tools.HandlerMain;

public class CreditCardReceiptDialog extends DialogAbstract {
    public CreditCardReceiptDialog(Context context, HandlerMain srcHandlerMain) {
        super(context, srcHandlerMain);
    }

    @Override
    protected Context setCtx() {
        return getContext();
    }

    @Override
    protected Class<? extends DialogAbstract> setCls() {
        return getClass();
    }

    @Override
    protected HandlerMain setHandlerMain() {
        return null;
    }

    private DialogCreditCardReceiptBinding binding;

    @Override
    protected void onCreate(Context context) {
        binding = DialogCreditCardReceiptBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.tvMerchantNo.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getMarchantNo());
        binding.tvTerminalNo.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getTerminalNo());
        binding.tvCardType.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getCardType());
        binding.tvCardNo.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getCardNo());
        binding.tvTransType.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getTransType());
        binding.tvBatchNo.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getBatchNo());
        binding.tvAuthCode.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getAuthCode());
        binding.tvDateTime.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getDateTime());
        binding.tvInvNo.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getInvNo());
        binding.tvAmount.setText(MyApp.getInstance().getCreditCardReceiptInfoData().getCCRAmount());


        // 禁止使用者在7秒內關閉dialog
        setCancelable(false);

        // 7秒後自動關閉
        new android.os.Handler().postDelayed(() -> {
            if (isShowing()) {
                dismiss();
            }
        }, 7000); // 7000毫秒 = 7秒

        // 「確認」按鈕點擊事件，立即關閉
        binding.confirmButton.setOnClickListener(v -> {
            if (isShowing()) {
                dismiss();
            }
        });
    }
}
