package com.fastvpnapp;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.RecyclerView;

public class SidebarAdapter extends RecyclerView.Adapter<SidebarAdapter.MyViewHolder> {

    private final Context mContext;
    private final DrawerLayout drawerLayout;
    private final String[] optionList = new String[]{"Share App","Rate App","privacy Policy","About App"};
    private final int[] iconList = new int[]{R.drawable.share,R.drawable.star,R.drawable.lock,R.drawable.info};

    public SidebarAdapter(Context context, DrawerLayout drawerLayout) {
        this.mContext = context;
        this.drawerLayout = drawerLayout;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.side,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.option.setText(optionList[position]);
        holder.option.setCompoundDrawablesWithIntrinsicBounds(iconList[position],0,0,0);
        holder.itemView.setOnClickListener(v -> {
            drawerLayout.closeDrawer(GravityCompat.START);
            if(position == 0) {
                Intent shareint = new Intent(Intent.ACTION_SEND);
                shareint.setType("text/plain");
                shareint.putExtra(Intent.EXTRA_SUBJECT,mContext.getString(R.string.app_name));
                shareint.putExtra(Intent.EXTRA_TEXT,"\n\n\nDownload the india's fastest & secure vpn app- https://play.google.com/store/apps/details?id=" + mContext.getPackageName());
                mContext.startActivity(Intent.createChooser(shareint, "Share Via"));
            } else if(position == 1) {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + mContext.getPackageName())));
            } else if(position == 2) {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://google.com")));
            } else if(position == 3) {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + mContext.getPackageName())));
            }
        });
    }

    @Override
    public int getItemCount() {
        return optionList.length;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView option;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            option = itemView.findViewById(R.id.side);
        }
    }
}
