#pragma once

#include "holly/ta_parameter.hpp"
#include "ta_multiwriter.hpp"
#include "widget/widget.hpp"

namespace widget {

  constexpr inline int str_length(const char * s)
  {
    int l = 0;
    while (*s++) {
      l += 1;
    }
    return l;
  }

  struct button : widget {
    const char * const label;
    const int label_length;
    void (* const on_click)();

    inline button(float _width, float _height, const char * _label)
      : widget(0, 0, _width, _height), label(_label), label_length(str_length(_label)), on_click(nullptr)
    { }

    inline button(float _width, float _height, const char * _label, void (* const _on_click)())
      : widget(0, 0, _width, _height), label(_label), label_length(str_length(_label)), on_click(_on_click)
    { }

    inline button(float _x, float _y, float _width, float _height, const char * _label)
      : widget(_x, _y, _width, _height), label(_label), label_length(str_length(_label)), on_click(nullptr)
    { }

    inline button(float _x, float _y, float _width, float _height, const char * _label, void (* const _on_click)())
      : widget(_x, _y, _width, _height), label(_label), label_length(str_length(_label)), on_click(_on_click)
    { }

    void draw_shadow(ta_parameter_writer& writer);
    void draw_lowlight(ta_parameter_writer& writer);
    void draw_highlight(ta_parameter_writer& writer);
    void draw_background(ta_parameter_writer& writer);
    void draw_label(ta_parameter_writer& writer);
    void draw(ta_multiwriter& multi) override;

    void click() override;
  };
}
