#pragma once

#include <functional>
#include "DataFields.h"
#include "PvApp.h"

struct PopLineInfo
{
	string title; // 控件名称标题
	string type; // 控件类型
	int pvid;	// 值的控件ID
	//PopLineInfo(string s, string t, int id) : title(s), type(t), pvid(id) {}
};

class PvPop : public PvObject
{
public:
	PvPop(PARAM* p, int parent, string title, int w = 900, int h = 700);

	void set_data(DataFields& data);
	void set_data(string k, string v);
	string get_data(string k);
	DataFields& get_data();

	void set_line_callback(function<void(shared_ptr<PvLineParam>)> cb);

	void on_show() override;
	void on_hide() override;
	virtual void do_cleanup();

	void foreach_line(std::function<void(string k, string v)>);

	void set_status(string status);
	string status();

	void update(PARAM* p);

	void set_pop_cb(std::function<void(PARAM* p, int status)> cb);

	void set_err(PARAM* p, string err);
	string err();

	void reset(PARAM* p);

	void set_enabled(string title, bool b);
	virtual void on_click_ok();

	void clear();

public:
	static string POP_DEFAULT;

protected:
	shared_ptr<PanelParam> w_param_;

	// 原始数据
	DataFields data_;

	function<void(shared_ptr<PvLineParam>)> cb_line_changed_ = nullptr;

	int w_main_;
	int w_worksace_;
	int lab_title_;
	int id_err_;

	int width_;
	int height_;
	PvRect rt_pop_;

	string title_;
	string status_;
	string err_;

	// 弹出窗口的行控件信息
	unordered_map<string, PopLineInfo> map_w_;

	std::function<void(PARAM* p, int status)> cb_pop_ = nullptr;
};


class PvPopConfirm : public PvPop
{
public:
	PvPopConfirm(PARAM* p, int parent, string title, int w = 900, int h = 700);

	int lab_text_ = PV_INVALID_ID;
};