package com.cpm.lorealbaMabeline.fragements;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.cpm.lorealbaMabeline.Database.Lorealba_Database;
import com.cpm.lorealbaMabeline.R;
import com.cpm.lorealbaMabeline.constant.CommonString;
import com.cpm.lorealbaMabeline.delegates.NavMenuItemGetterSetter;
import com.cpm.lorealbaMabeline.delegates.PrefHelper;

import java.util.ArrayList;
import java.util.List;

public class MakeupExpertMenuFragment extends Fragment {
    // TODO: Customize parameter argument names
    private static final String ARG_COLUMN_COUNT = "column-count";
    Lorealba_Database db;
    String counterId, visit_date = "", username;

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public MakeupExpertMenuFragment() {
    }

    // TODO: Customize parameter initialization
    @SuppressWarnings("unused")
    public static MakeupExpertMenuFragment newInstance(int columnCount) {
        MakeupExpertMenuFragment fragment = new MakeupExpertMenuFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_COLUMN_COUNT, columnCount);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            // TODO: Customize parameters
            int mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.fragment_item_me, container, false);
        db = new Lorealba_Database(getActivity());
        db.open();
        SharedPreferences preferences = PrefHelper.getPrefs(getActivity());
        counterId = preferences.getString(CommonString.KEY_COUNTER_ID, "");
        visit_date = preferences.getString(CommonString.KEY_DATE, "");
        username = preferences.getString(CommonString.KEY_USERNAME, null);

        if (view instanceof RecyclerView) {
            Context context = view.getContext();
            RecyclerView recyclerView = (RecyclerView) view;
            recyclerView.setAdapter(new MyAdaperForIcon(context, getdata(), "3"));
            recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        }
        return view;
    }

    public List<NavMenuItemGetterSetter> getdata() {
        List<NavMenuItemGetterSetter> data = new ArrayList<>();
        int counter_image = 0, makeover_capturing = 0, sales = 0, quiz = 0;
        db.open();
        String saleable_status = db.getStatus(CommonString.KEY_SaleableStatus, counterId);
        counter_image = R.mipmap.counter_image;
        makeover_capturing = R.mipmap.makeover;
        quiz = R.mipmap.quiz;
        sales = (saleable_status != null && saleable_status.equalsIgnoreCase("Complete")) ? R.mipmap.me_sale : R.mipmap.me_sales_grey;
        db.open();
        int[] img = {counter_image, makeover_capturing, sales, quiz};
        String[] name = {"Counter Image", "Makeover Capturing", "ME_Sales", "Quiz"};
        for (int i = 0; i < img.length; i++) {
            NavMenuItemGetterSetter recData = new NavMenuItemGetterSetter();
            recData.setIconImg(img[i]);
            recData.setIconName(name[i]);
            data.add(recData);
        }
        return data;
    }
}
