/***********************************************************************************

    Copyright (C) 2007-2026 Ahmet Öztürk (aoz_2@yahoo.com)

    This file is part of Lifeograph.

    Lifeograph 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 3 of the License, or
    (at your option) any later version.

    Lifeograph 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 Lifeograph.  If not, see <http://www.gnu.org/licenses/>.

***********************************************************************************/


#ifndef LIFEOGRAPH_PO_ENTRY_HEADER
#define LIFEOGRAPH_PO_ENTRY_HEADER


#include <gtkmm/drawingarea.h>
#include <gtkmm/builder.h>

#include "../helpers.hpp"
#include "../diaryelements/entry.hpp"


namespace LoG
{

using namespace HELPERS;

using FuncEntriesGetter = std::function< EntrySelection() >;
using FuncBoolEntry = std::function< bool( Entry* ) >;


class PoEntry
{
    public:
        enum class Mode { ENTRY, LIST, POPUP };

        PoEntry( Mode );

        void
        set( Entry*, Gtk::Widget&, Gdk::Rectangle* );

        Gtk::Popover*               get_Po()
        { return m_Po_entry; }

        void                        refresh();
        static void                 refresh_DD_spellchecking( const DiaryElemTag*,
                                                              DropDownAdvanced< String >* );
        void                        update_editing_controls();

        R2Action                    get_action( const Ustring& );

        void                        show();

        void
        hide()
        { if( m_Po_entry ) m_Po_entry->hide(); }

        void                        set_editing_enabled( bool );
        void                        handle_logout();

    protected:
        bool                        has_locked_entry_selected() const;
        void                        do_for_sel_entries( const FuncBoolEntry& );
        bool                        handle_favorite( Entry* );
        bool                        handle_todo( Entry*, ElemStatus );
        bool                        handle_color( Entry* );
        bool                        handle_spellchk( Entry*, const String& );
        bool                        handle_unit( Entry* );
        bool                        handle_title_style( Entry* );
        bool                        handle_lock( Entry* );
        bool                        handle_scripting( Entry* );
        bool                        handle_comment_style( Entry* );

        Glib::RefPtr< Gtk::Builder >
                                    m_builder;

        Gtk::Popover*               m_Po_entry;
        Gtk::Box*                   m_Bx_group_editing;
        Gtk::Box*                   m_Bx_locked;
        Gtk::ToggleButton*          m_RB_not_todo;
        Gtk::ToggleButton*          m_RB_todo;
        Gtk::ToggleButton*          m_RB_progressed;
        Gtk::ToggleButton*          m_RB_done;
        Gtk::ToggleButton*          m_RB_canceled;
        Gtk::ToggleButton*          m_TB_favorite;
        Gtk::ColorButton*           m_ClB_color;
        Gtk::DropDown*              m_DD_title_style;

        Gtk::Box*                   m_Bx_unit;
        Gtk::ComboBoxText*          m_CB_unit;
        Gtk::Entry*                 m_E_unit;

        DropDownAdvanced< String >* m_DD_spellchk;

        Gtk::Switch*                m_Sw_locked;

        Gtk::Switch*                m_Sw_reg_scripts;

        Gtk::ComboBoxText*          m_CB_comment_style;

        Entry*                      m_p2entry           { nullptr };

        Mode                        m_mode              { Mode::ENTRY };
        int                         m_F_update_size     { 0 };

    friend class UIDiary;
};

} // end of namespace LoG

#endif
