// ── ElevationWizard ──────────────────────────────────────────────────────────
#include "ElevationWizard.h"
#include <wx/statline.h>

ElevationWizard::ElevationWizard(wxWindow* parent)
    : wxDialog(parent, wxID_ANY, "Elevation Wizard",
               wxDefaultPosition, wxDefaultSize,
               wxDEFAULT_DIALOG_STYLE)
{
    SetMinSize(wxSize(420, -1));

    wxBoxSizer* top = new wxBoxSizer(wxVERTICAL);

    // ── Title ────────────────────────────────────────────────────────────────
    wxStaticText* title = new wxStaticText(this, wxID_ANY,
                                           "Welcome to the Elevation Wizard");
    wxFont tf = title->GetFont();
    tf.SetWeight(wxFONTWEIGHT_BOLD);
    tf.SetPointSize(tf.GetPointSize() + 3);
    title->SetFont(tf);
    top->Add(title, 0, wxALL, 12);

    // ── Description ──────────────────────────────────────────────────────────
    wxStaticText* desc = new wxStaticText(this, wxID_ANY,
        "I'll walk you through setting up track elevation.\n\n"
        "First, choose how you'd like to work:");
    top->Add(desc, 0, wxLEFT | wxRIGHT | wxBOTTOM, 12);

    top->Add(new wxStaticLine(this), 0, wxEXPAND | wxLEFT | wxRIGHT, 12);

    // ── Method choice ────────────────────────────────────────────────────────
    m_rbGrade = new wxRadioButton(this, wxID_ANY,
        "Set Grade - choose a gradient angle and direction",
        wxDefaultPosition, wxDefaultSize, wxRB_GROUP);

    wxStaticText* gradeDesc = new wxStaticText(this, wxID_ANY,
        "Pick a starting piece, set the grade, and build track.\n"
        "New pieces automatically inherit the elevation.\n"
        "Right-click any graded piece to end the run.\n\n"
        "To continue, click Next and then click the track\n"
        "piece which will start the grade.");
    wxFont smallFont = gradeDesc->GetFont();
    smallFont.SetPointSize(smallFont.GetPointSize() - 1);
    gradeDesc->SetFont(smallFont);

    m_rbTarget = new wxRadioButton(this, wxID_ANY,
        "Set Target Height - say where you want to end up");

    wxStaticText* targetDesc = new wxStaticText(this, wxID_ANY,
        "Pick a starting piece, click its connector dot and\n"
        "draw out the dotted line to your target location.\n"
        "Once reached, enter desired height into a dialog.\n"
        "The app works out the grade and places the track\n"
        "for you automatically.");
    targetDesc->SetFont(smallFont);

    m_rbGrade->SetValue(true);

    top->AddSpacer(8);
    top->Add(m_rbGrade,   0, wxLEFT | wxRIGHT, 16);
    top->Add(gradeDesc,   0, wxLEFT | wxRIGHT | wxBOTTOM, 30);
    top->Add(m_rbTarget,  0, wxLEFT | wxRIGHT, 16);
    top->Add(targetDesc,  0, wxLEFT | wxRIGHT | wxBOTTOM, 30);

    top->Add(new wxStaticLine(this), 0, wxEXPAND | wxLEFT | wxRIGHT, 12);

    // ── Buttons ──────────────────────────────────────────────────────────────
    wxBoxSizer* btnRow = new wxBoxSizer(wxHORIZONTAL);
    btnRow->AddStretchSpacer();
    wxButton* btnNext   = new wxButton(this, wxID_OK,     "Next");
    wxButton* btnCancel = new wxButton(this, wxID_CANCEL, "Cancel");
    btnRow->Add(btnNext,   0, wxRIGHT, 6);
    btnRow->Add(btnCancel, 0);
    top->Add(btnRow, 0, wxEXPAND | wxALL, 12);

    btnNext->Bind(wxEVT_BUTTON,   &ElevationWizard::OnNext,   this);
    btnCancel->Bind(wxEVT_BUTTON, &ElevationWizard::OnCancel, this);

    SetSizerAndFit(top);
    SetDefaultItem(btnNext);
    Centre();
}

void ElevationWizard::OnNext(wxCommandEvent&) {
    m_method = m_rbGrade->GetValue() ? kSetGrade : kSetTarget;
    EndModal(wxID_OK);
}

void ElevationWizard::OnCancel(wxCommandEvent&) {
    m_method = kNone;
    EndModal(wxID_CANCEL);
}
