/*
Copyright © Brian Buller <brian@bullercodeworks.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package widgets

import (
	t "git.bullercodeworks.com/brian/tcell-widgets"
	"github.com/gdamore/tcell"
)

type StatusBar struct {
	id      string
	style   tcell.Style
	x, y    int
	w, h    int
	visible bool
	keyMap  *t.KeyMap

	logger func(string, ...any)
}

func NewStatusBar(id string, s tcell.Style) *StatusBar {
	ret := &StatusBar{}
	ret.Init(id, s)
	return ret
}

func (w *StatusBar) Init(id string, s tcell.Style) {
	w.id = id
	w.style = s
	w.visible = true
}

func (w *StatusBar) Id() string { return w.id }
func (w *StatusBar) HandleResize(ev *tcell.EventResize) {
	w.w, w.h = ev.Size()
}

func (w *StatusBar) GetKeyMap() *t.KeyMap   { return w.keyMap }
func (w *StatusBar) SetKeyMap(km *t.KeyMap) { w.keyMap = km }

func (w *StatusBar) HandleKey(ev *tcell.EventKey) bool {
	return false
}

func (w *StatusBar) HandleTime(ev *tcell.EventTime) {}

func (w *StatusBar) Draw(screen tcell.Screen) {
	if !w.visible {
		return
	}
}

func (w *StatusBar) Active() bool        { return false }
func (w *StatusBar) SetActive(a bool)    {}
func (w *StatusBar) Visible() bool       { return w.visible }
func (w *StatusBar) SetVisible(a bool)   { w.visible = a }
func (w *StatusBar) Focusable() bool     { return false }
func (w *StatusBar) SetFocusable(b bool) {}
func (w *StatusBar) SetX(x int)          { w.x = x }
func (w *StatusBar) SetY(y int)          { w.y = y }
func (w *StatusBar) GetX() int           { return w.x }
func (w *StatusBar) GetY() int           { return w.y }
func (w *StatusBar) GetPos() t.Coord     { return t.Coord{X: w.x, Y: w.y} }
func (w *StatusBar) SetPos(c t.Coord)    { w.x, w.y = c.X, c.Y }
func (w *StatusBar) GetW() int           { return w.w }
func (w *StatusBar) GetH() int           { return w.h }
func (w *StatusBar) SetW(wd int)         { w.w = wd }
func (w *StatusBar) SetH(h int)          { w.h = h }
func (w *StatusBar) SetSize(c t.Coord)   { w.w, w.h = c.X, c.Y }
func (w *StatusBar) WantW() int          { return w.w }
func (w *StatusBar) WantH() int          { return w.h }
func (w *StatusBar) MinW() int           { return w.w }
func (w *StatusBar) MinH() int           { return 1 }

func (w *StatusBar) SetLogger(l func(string, ...any)) { w.logger = l }
func (w *StatusBar) Log(txt string, args ...any)      { w.logger(txt, args...) }
