/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright (C) 2019 KylinSoft  Co., Ltd.
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
#ifndef AREAUI_H
#define AREAUI_H

#include "languageframe.h"
#include "addlanguagedialog.h"
#include "addinputmethoddialog.h"
#include "addbutton.h"
#include "settinggroup.h"
#include "comboxwidget.h"
#include <QWidget>
#include <QVBoxLayout>
#include "ukcccommon.h"
#include <klabel.h>

using namespace ukcc;
using namespace kdk;

class AreaUi : public QWidget
{
    Q_OBJECT

public:
    enum ComboBoxOrder {
        COUNTRY = 0,
        CALENDAR,
        FIRSTDAY,
        DATEFORMAT,
#ifdef Nile
        SHORTDATEFORMAT,
        LONGDATEFORMAT,
#endif
        TIMEFORMAT
    };
    AreaUi(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
    virtual ~AreaUi();
    void initUi();
    void initLanguageFormat();
    void initSystemLanguage();
    void settingForIntel();

public:
    inline QComboBox *countryComboBox()
    {
        if (countryWidget) {
            return countryWidget->comboBox();
        } else {
            return nullptr;
        }
    }

    inline QComboBox *calendarComboBox()
    {
        if (calendarWidget) {
            return calendarWidget->comboBox();
        } else {
            return nullptr;
        }
    }

    inline QComboBox *firstDayComboBox()
    {
        if (dayWidget) {
            return dayWidget->comboBox();
        } else {
            return nullptr;
        }
    }

    inline QComboBox *dateComboBox()
    {
        if (shortDateWidget) {
            return shortDateWidget->comboBox();
        } else {
            return nullptr;
        }
    }

    inline QComboBox *shortDateComboBox()
    {
        if (shortDateWidget) {
            return shortDateWidget->comboBox();
        } else {
            return nullptr;
        }
    }

    inline QComboBox *longDateComboBox()
    {
        if (longDateWidget) {
            return longDateWidget->comboBox();
        } else {
            return nullptr;
        }
    }

    inline QComboBox *timeComboBox()
    {
        if (timeWidget) {
            return timeWidget->comboBox();
        } else {
            return nullptr;
        }
    }

    inline AddButton *addbutton()
    {
        return addLanguageBtn;
    }

    inline AddLanguageDialog *languageDialog()
    {
        return addLanguageDialog;
    }

    inline AddInputMethodDialog *inputMethodDialog()
    {
        return addInputMehtodDialog;
    }

    inline UkccFrame* formatDateFrame() {
        return m_formatDateFrame;
    }

    inline KLabel* formatDateValueLabel() {
        return m_formatDateValueLabel;
    }

    inline KLabel* getLanguageTitleLable() {
        return languageTitleLable;
    }

    inline SettingGroup* getlanguageGroup() {
        return languageGroup;
    }

    void addShowLanguage(QString languageCode, QString languageName, bool selected = false);
    void clearShowLanguage();
    void reloadLanguageFrameIcon();

Q_SIGNALS:
    void languageChanged(QString languageCode);
    void showLanguageListRemoved(QString languageCode, QString languageName);

private:
    QVBoxLayout *uiLayout       = nullptr;
    QVBoxLayout *formatLayout   = nullptr;
    QVBoxLayout *LanguageLayout = nullptr;

private:
    KLabel   *formatTitleLabel = nullptr;
    SettingGroup *formatGroup      = nullptr;
    ComboxWidget *countryWidget    = nullptr;
    ComboxWidget *calendarWidget   = nullptr;
    ComboxWidget *dayWidget        = nullptr;
    ComboxWidget *shortDateWidget  = nullptr;
    ComboxWidget *longDateWidget   = nullptr;
    ComboxWidget *timeWidget       = nullptr;

private:
    KLabel           *languageTitleLable   = nullptr;
    AddButton            *addLanguageBtn       = nullptr;
    SettingGroup         *languageGroup        = nullptr;
    AddLanguageDialog    *addLanguageDialog    = nullptr;
    AddInputMethodDialog *addInputMehtodDialog = nullptr;
    UkccFrame* m_formatDateFrame = nullptr;
    KLabel* m_formatDateNameLabel = nullptr;
    KLabel* m_formatDateValueLabel = nullptr;

private:
    QList<LanguageFrame*> languageFrameList = {};
};

#endif // AREAUI_H
