#ifndef WXFZFTPUSERSEDITOR_HPP
#define WXFZFTPUSERSEDITOR_HPP

#include <wx/panel.h>

#include "../filezilla/authentication/file_based_authenticator.hpp"

#include "userslist.hpp"
#include "credentialseditor.hpp"

class MountTableEditor;
class wxButton;
class wxTextCtrl;
class wxCheckBox;
class RearrangedItemsPickerCtrl;
class wxSimplebook;
class FiltersEditor;
class CredentialsEditor;
class LimitsEditor;
class RealmsEditor;

class UsersEditor: public wxPanel
{
public:
	using GetIdpUserInfoFunc = std::function<fz::expected<fz::authentication::identity_provider::user_info, wxString> (const std::string &login, const std::string &idp, const fz::authentication::identity_provider::parameters &params)>;

	UsersEditor() = default;

	bool Create(wxWindow *parent);

	void SetGroups(const fz::authentication::file_based_authenticator::groups &groups);
	void SetUsers(fz::authentication::file_based_authenticator::users &users, std::string server_name);
	void SetServerPathFormat(fz::util::fs::path_format server_path_format);
	void SetGetIdpUserInfoFunc(GetIdpUserInfoFunc func);
	void SetGetIdpPropertiesFunc(CredentialsEditor::GetIdpPropertiesFunc func);

private:
	bool TransferDataFromWindow() override;
	bool TransferDataToWindow() override;

	wxCheckBox *enabled_check_{};
	bool no_auth_{};
	wxWindow *mount_table_label_{};
	MountTableEditor *mount_table_editor_{};
	UsersList *users_list_{};
	wxSimplebook *book_{};
	CredentialsEditor *credentials_editor_{};
	wxSimplebook *groups_book_{};
	RearrangedItemsPickerCtrl *groups_chooser_{};
	FiltersEditor *filters_editor_{};
	LimitsEditor *limits_editor_{};
	RealmsEditor *realms_editor_{};
	wxTextCtrl *description_editor_{};

	fz::authentication::file_based_authenticator::users *users_{};
	std::string server_name_;

	fz::authentication::file_based_authenticator::users::value_type *current_user_{};

	GetIdpUserInfoFunc get_idp_user_info_func_;

	std::map<std::string /*idp*/, std::map<std::string /*uid*/, const fz::authentication::file_based_authenticator::users::value_type*>> uidmap_;
};

#endif // WXFZFTPUSERSEDITOR_HPP
