from pypos.core.utils.ui_scale_runtime import scale_ui_px


def set_fixed_dialog_size(dialog, width=700, height=400):
    # edited by glg
    # Backward-compatible helper:
    # - tetap dipanggil oleh modul lama
    # - tapi perilaku dibuat responsif (minimum + resize) agar dialog bisa menyesuaikan layout.
    target_w = max(1, int(scale_ui_px(width)))
    target_h = max(1, int(scale_ui_px(height)))
    dialog.setMinimumSize(target_w, target_h)
    dialog.resize(target_w, target_h)
    if hasattr(dialog, "setSizeGripEnabled"):
        try:
            dialog.setSizeGripEnabled(True)
        except (TypeError, ValueError, KeyError, AttributeError, RuntimeError, OSError):
            pass
