Ext.define("App.view.MessageContainer", {
    extend: "Ext.container.Container",
    xtype: "messageContainer",
    alias: "widget.messageContainer",

    requires: ["Ext.ux.layout.ResponsiveColumn"],

    layout: {
        type: "responsivecolumn",
        align: "stretch"
    },

    params: {},

    initComponent: function() {
        var me = this;
        Ext.apply(me, {
            items: [
                {
                    xtype: "messagePanel",
                    userCls: "big-100 small-100"
                }
            ],
            listeners: {
                added: function(panel, parent, pos, opts) {
                    var container = me.up("maincontainerwrap");
                    var height = container.getHeight();
                    me.down("#messagePanel").setHeight(height - 60);
                }
            }
        });
        me.callParent(arguments);
    }
});

Ext.define("App.view.MessagePanel", {
    extend: "Ext.panel.Panel",
    xtype: "messagePanel",
    alias: "widget.messagePanel",
    itemId: "messagePanel",
    layout: "border",
    width: "100%",
    bodyPadding: "5px",

    defaults: {
        split: true
    },

    params: {},

    initComponent: function() {
        var me = this;

        Ext.apply(me, {
            dockedItems: [
                {
                    xtype: "toolbar",
                    dock: "top",
                    padding: 5,
                    items: [
                        // {
                        //     xtype: "button",
                        //     itemId: "inboxBtn",
                        //     text: App.localeRes("Inbox"),
                        //     iconCls: "x-fa fa-inbox",
                        //     enableToggle: true,
                        //     pressed: true,
                        //     handler: function() {
                        //         if (this.pressed) {
                        //             me.down("#sentBoxBtn").setPressed(false);
                        //             console.log("inbox button pressed");
                        //         } else {
                        //             me.down("#inboxBtn").setPressed(true);
                        //         }
                        //     }
                        // },
                        // {
                        //     xtype: "button",
                        //     itemId: "sentBoxBtn",
                        //     text: App.localeRes("Sent Box"),
                        //     iconCls: "x-fa fa-check-circle",
                        //     enableToggle: true,
                        //     pressed: false,
                        //     handler: function() {
                        //         if (this.pressed) {
                        //             console.log("sent btn pressed");
                        //             me.down("#inboxBtn").setPressed(false);
                        //         } else {
                        //             me.down("#sentBoxBtn").setPressed(true);
                        //         }
                        //     }
                        // },
                        {
                            xtype: "button",
                            text: App.localeRes("Refresh"),
                            iconCls: "x-fa fa-refresh",
                            handler: function() {
                                me.down("messageInbox").reloadStore();
                            }
                        },
                        "|",
                        {
                            xtype: "textfield",
                            text: ""
                        },
                        {
                            xtype: "button",
                            text: "Search",
                            iconCls: "x-fa fa-search",
                            handler: function(button) {
                                console.log("search btn pressed");
                                // var inboxGrid = me.down("inboxGrid");
                                // inboxGrid.getStore().getProxy().extraParams.query = button.prev("textfield").getValue();
                                // inboxGrid.loadStore();
                            }
                        },
                    ]
                }
            ],
            items: [
                {
                    xtype: "messageInbox",
                    region: "center",
                    collapsible: false
                },
                {
                    xtype: "messageDetail",
                    // title: "Email from: Matthew Ng",
                    region: "east",
                    // itemId: "eastid",
                    width: "50%",
                    collapsible: true,
                    hidden: true
                }
            ],

            listeners: {
                added: function(panel, parent, pos, opts) {
                    // me.doSearch();
                }
            }
        });

        me.callParent(arguments);
    }
});
