package in.techware.carrefour.activity.elie;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import in.techware.carrefour.R;
import in.techware.carrefour.activity.BaseAppCompatNoDrawerActivity;
import in.techware.carrefour.adapters.MenuListRecyclerAdapter;
import in.techware.carrefour.dialogs.ConfirmationDialog;
import in.techware.carrefour.model.MenuBean;
import in.techware.carrefour.model.MenuListBean;
import in.techware.carrefour.util.menuUtils.ELIERestoreMenuUtil;
import in.techware.carrefour.util.menuUtils.MerchandiseMenuUtil;

public class ELIERestoreActivity extends BaseAppCompatNoDrawerActivity {

    RecyclerView rvELIERestore;
    private MenuListBean menuListBean;
    private ConfirmationDialog confirmationDialog;
    private MenuBean selectedMenuBean;
    private MenuListRecyclerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_elie_restore);


        initViews();

        if (getSupportActionBar() != null) {
            setTitle(R.string.title_restore);
            getSupportActionBar().setTitle("");
            getSupportActionBar().setHomeButtonEnabled(true);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowTitleEnabled(true);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        menuListBean = ELIERestoreMenuUtil.getAllMenu();
        populateMenu();
    }

    private void initViews() {
        rvELIERestore = findViewById(R.id.rv_elie_restore);
        rvELIERestore.setHasFixedSize(true);
        rvELIERestore.setLayoutManager(new GridLayoutManager(getApplicationContext(), 2));


        confirmationDialog = new ConfirmationDialog(this);
        confirmationDialog.setConfirmationDialogActionListener(new ConfirmationDialog.ConfirmationDialogActionListener() {
            @Override
            public void onYesClicked() {
                finishAffinity();
            }

            @Override
            public void onNoClicked() {

            }
        });
    }


    public void showConfirmationDialog(String s) {
        confirmationDialog.show(R.string.message_do_you_really_want_to_exit);
    }


    private void populateMenu() {

        if (adapter == null) {
            adapter = new MenuListRecyclerAdapter(this, menuListBean);
            adapter.setMenuListRecyclerAdapterListener(new MenuListRecyclerAdapter.MenuListRecyclerAdapterListener() {
                @Override
                public void onMenuClicked(int position, MenuBean menuBean) {
                    selectedMenuBean = menuBean;
                    Intent intent;
                    switch (menuBean.getCode()) {
                        case ELIERestoreMenuUtil.CODE_EXPIRY_CAPTURE: {

                        }
                        break;

                        case ELIERestoreMenuUtil.CODE_EXPIRED_ACTION: {

                        }
                        break;

                        case ELIERestoreMenuUtil.CODE_EXIT: {
                            showConfirmationDialog("");
                        }
                        break;
                    }
                }

                @Override
                public void onSwipeRefreshingChange(boolean isSwipeRefreshing) {
                    swipeView.setRefreshing(isSwipeRefreshing);

                }

                @Override
                public void onSnackBarShow(String message) {
                    Snackbar.make(coordinatorLayout, message, Snackbar.LENGTH_LONG)
                            .setAction(R.string.btn_dismiss, snackBarDismissOnClickListener).show();

                }

            });
            rvELIERestore.setAdapter(adapter);
        } else {
            adapter.setLoadMore(false);
            adapter.setMenuListBean(menuListBean);
            adapter.notifyDataSetChanged();
        }

        setProgressScreenVisibility(false, false);
    }

}
