#pragma once
#include <View.h>
#include <Slider.h>
#include <Button.h>
#include <TextControl.h>
#include <Message.h>
#include <Control.h>
#include <Button.h>
#include <GroupLayout.h>
#include <StringView.h>
#include <GroupView.h>
class LooperLogScaler;
class HaikuLooperSlider : public BControl {
	inline BMessage *make_self_msg(int32 what) {
		auto output = new BMessage(what);
		output->AddPointer("catmeow:target", this);
		return output;
	}
	BSlider *slider = NULL;
	BButton *btn;
	BStringView *text_label;
	BStringView *min_label_view;
	BStringView *max_label_view;
	BGroupView *limits_view;
	bool limits_visible = false;
	BTextControl *text;
	BBitmap *text_mode_bitmap = nullptr;
	BBitmap *slider_mode_bitmap = nullptr;
	double value;
	BGroupView *text_layout_view;
	bool pressed = false;
	BGroupLayout *text_layout;
	LooperLogScaler *scaler;
	void UpdateLogScaler();
	bool recreate_slider = false;
	void UpdateSlider(bool update_value = false);
	double min;
	double max;
	double tick;
	bool text_edit_mode = false;
	bool logarithmic;
	const char *label = NULL;
	const char *min_label = NULL;
	const char *max_label = NULL;
	BMessage *change_msg = NULL;
	void set_tick(double value);
	void set_min(double min);
	void set_max(double max);
	void set_logarithmic(bool logarithmic);
	void SendChangeMsg();
	public:
	void SetMin(double min);
	double Min();
	void SetMax(double max);
	double Max();
	void SetLimits(double min, double max);
	void SetMinLabel(const char *label);
	void SetMaxLabel(const char *label);
	const char *MinLabel();
	const char *MaxLabel();
	void SetLimitLabels(const char *min, const char *max);
	void SetTick(double value);
	void SetValue(int32 value) override;
	double Tick();
	double ValueDouble();
	void SetValueDouble(double value);
	void SetLogarithmic(bool logarithmic);
	bool IsLogarithmic();
	void SetLabel(const char *label) override;
	void SetValueChangedMsg(BMessage *msg);
	void MessageReceived(BMessage *msg) override;
	void AttachedToWindow() override;
	HaikuLooperSlider(const char *name, const char *label, BMessage *msg, uint32_t flags, double min, double max, double tick = 0.0001, bool logarithmic = false);
	~HaikuLooperSlider();
};