package components;

import data.BetStrategyMysql.BetStrategyMysql;
import data.DTO.FibonacciDTO.FibonacciDTO;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class AjaxButtonPanel extends Panel {
    public AjaxButtonPanel(String id, IModel<FibonacciDTO> rowModel) {
        super(id, rowModel);
        setOutputMarkupId(true);

        // Add an AjaxButton with an event
        add(new AjaxButton("button", Model.of("Close Sequence")) {
            @Override
            protected void onSubmit(AjaxRequestTarget target) {
                // Handle the button click here
                FibonacciDTO rowObject = rowModel.getObject();

                // Your button logic for the row here
                // TODO kanse en bekräfta dialog?
                BetStrategyMysql.getInstance().closeFibonacciSequence(rowObject.getSequenceNumber());

                target.getPage().renderPage();
            }

            @Override
            protected void onError(AjaxRequestTarget target) {
                // Handle errors here if needed
            }
        });
    }
}
