{-  
 *  Programmer:	Piotr Borek
 *  E-mail:     piotrborek@op.pl
 *  Copyright 2014 Piotr Borek
 *
 *  Distributed under the terms of the GPL (GNU Public License)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}

module Mp.UI.Menu (
    Menu (..),
    MenuWidget,
	makeUIMenu
) where

import qualified Data.Text as T

import Graphics.Vty.Widgets.All
import Data.ConfigFile

import Mp.Utils.Colors
import Mp.Utils.I18N

type MenuWidget = (Widget (Box (Box (Box (Box FormattedText FormattedText) FormattedText) FormattedText) HFill))

data Menu = Menu {
    menuWidget   :: MenuWidget,
    menuActivate :: Int -> IO ()
}

activateMenu :: [Widget a] -> ConfigParser -> Int -> IO ()
activateMenu m_list conf n = do
    mapM_ (withTabAttribute conf) m_list
    _ <- withTabActiveAttribute conf $ m_list !! n
    return ()

makeUIMenu :: ConfigParser -> IO Menu
makeUIMenu conf = do
    m1 <- plainText (T.pack $ __ " [1]   Help     ")
          >>= withTabAttribute conf
    m2 <- plainText (T.pack $ __ " [2]  Queue     ")
          >>= withTabAttribute conf
    m3 <- plainText (T.pack $ __ " [3] Playlists  ")
          >>= withTabAttribute conf
    m4 <- plainText (T.pack $ __ " [4]  Browser   ")
          >>= withTabAttribute conf
    m5 <- hFill ' ' 1
          >>= withTabAttribute conf

    menu <- return m1 <++> return m2 <++> return m3 <++> return m4 <++> return m5

    return Menu {
        menuWidget   = menu,
        menuActivate = activateMenu [m1, m2, m3, m4] conf
    }
