#include "confirm.h"
#include "ui.h"

#include <stdio.h>
#include <string.h>

void confirm_set_message(ConfirmDialog *cd, const char *fmt, ...) {
    va_list args;
    va_start(args, fmt);
    vsnprintf(cd->message, sizeof(cd->message), fmt, args);
    va_end(args);
}

void confirm_draw(const ConfirmDialog *cd, Display *dpy, Window win, GC gc, int win_w, int win_h) {
    int box_w = CONFIRM_BOX_W, box_h = CONFIRM_BOX_H;
    int x = (win_w - box_w) / 2;
    int y = (win_h - box_h) / 2;

    ui_draw_bevel(dpy, win, gc, x, y, box_w, box_h, 0);

    XSetForeground(dpy, gc, 0x000000);
    XDrawString(dpy, win, gc, x + 12, y + 24, cd->message, (int)strlen(cd->message));

    ui_draw_button(dpy, win, gc, x + CONFIRM_YES_BTN_X, y + CONFIRM_BTN_Y,
                   CONFIRM_BTN_W, CONFIRM_BTN_H, "Yes", 0);
    ui_draw_button(dpy, win, gc, x + CONFIRM_NO_BTN_X, y + CONFIRM_BTN_Y,
                   CONFIRM_BTN_W, CONFIRM_BTN_H, "No", 0);
}
