class PembayaranModeService:
    def get_active_mode(self, view):
        if view.radio_tunai.isChecked():
            return "tunai"
        if view.radio_credit.isChecked():
            return "credit"
        return "debit"

    def get_total_widget(self, view, mode):
        mapping = {
            "tunai": getattr(view, "input_total_tunai", None),
            "credit": getattr(view, "input_total_credit", None),
            "debit": getattr(view, "input_total_debit", None),
        }
        return mapping.get(mode)

    def get_ppn_widget(self, view, mode):
        mapping = {
            "tunai": getattr(view, "ppn_tunai", None),
            "credit": getattr(view, "ppn_credit", None),
            "debit": getattr(view, "ppn_debit", None),
        }
        return mapping.get(mode)

    def get_diskon_widget(self, view, mode):
        mapping = {
            "tunai": getattr(view, "diskon_tambahan_tunai", None),
            "credit": getattr(view, "diskon_tambahan_credit", None),
            "debit": getattr(view, "diskon_tambahan_debit", None),
        }
        return mapping.get(mode)

    def get_harus_dibayar_widget(self, view, mode):
        mapping = {
            "tunai": getattr(view, "input_total_harus_dibayar_tunai", None),
            "credit": getattr(view, "input_total_harus_dibayar_credit", None),
            "debit": getattr(view, "input_total_harus_dibayar_debit", None),
        }
        return mapping.get(mode)

    # edited by glg
    def get_diskon_nilai_widget(self, view, mode):
        mapping = {
            "tunai": getattr(view, "diskon_tambahan_rp_tunai", None),
            "credit": getattr(view, "diskon_tambahan_rp_credit", None),
            "debit": getattr(view, "diskon_tambahan_rp_debit", None),
        }
        return mapping.get(mode)

    def get_selected_button_text(self, buttons):
        for btn in list(buttons or []):
            if btn.isChecked():
                return str(btn.text() or "").strip()
        return ""
