#pragma once
#include <wx/wx.h>
#include <wx/spinctrl.h>
#include <vector>
#include "geometry/Vec2.h"

namespace MC { struct CanvasState; }

class LayoutShapeDialog : public wxDialog {
public:
    // Pass a pointer to the state so the dialog can seed itself from the
    // last-used shape/dimensions and remember the new choice on OK. Pass
    // nullptr to fall back to in-polygon inference / defaults.
    LayoutShapeDialog(wxWindow* parent,
                      const std::vector<MC::Vec2>& current,
                      int units = 0,           // 0=mm, 1=cm, 2=inch
                      MC::CanvasState* state = nullptr);

    std::vector<MC::Vec2> GetPolygon() const { return m_poly; }

    // True when the user picked "Free-form (draw on canvas)" and pressed
    // OK. The caller (MainFrame) should then switch the canvas into
    // baseboard-draw mode rather than apply m_poly directly.
    bool DrawAfterClose() const { return m_drawAfterClose; }

private:
    void OnShapeChoice(wxCommandEvent&);
    void OnOK(wxCommandEvent&);
    std::vector<MC::Vec2> BuildFromFields() const;

    wxChoice*        m_shapeChoice = nullptr;
    wxPanel*         m_fieldsPanel = nullptr;
    wxSizer*         m_fieldsSizer = nullptr;
    wxTextCtrl*      m_customText  = nullptr;

    wxSpinCtrl*      m_spW  = nullptr;
    wxSpinCtrl*      m_spH  = nullptr;
    wxSpinCtrl*      m_spW2 = nullptr;
    wxSpinCtrl*      m_spH2 = nullptr;

    std::vector<MC::Vec2> m_poly;
    int m_units = 0;
    MC::CanvasState* m_state = nullptr;   // for last-shape memory
    bool m_drawAfterClose = false;

    enum ShapeId { SH_RECT=0, SH_L, SH_U, SH_T, SH_CUSTOM, SH_FREEFORM, SH_CLEAR };
};
