package com.friendvilla.bucksbuddy.controls;

import static android.widget.Toast.LENGTH_SHORT;
import static android.widget.Toast.makeText;

import android.app.Activity;
import android.os.Bundle;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import androidx.annotation.Nullable;

import com.friendvilla.bucksbuddy.R;
import com.friendvilla.bucksbuddy.WalletActivity;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

public class DepositBox extends BottomSheetDialogFragment {
    private final Activity ctx;
    public DepositBox(Activity ctx) {
        this.ctx = ctx;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.deposit,container,false);
        setStyle(BottomSheetDialogFragment.STYLE_NORMAL,R.style.CustomSheet);
        EditText amount = v.findViewById(R.id.am);
        EditText email = v.findViewById(R.id.em);
        EditText phone = v.findViewById(R.id.ph);
        v.findViewById(R.id.btn).setOnClickListener(view -> {
            String amnt = amount.getText().toString();
            String mail = email.getText().toString();
            String phn = phone.getText().toString();
            if(amnt.equals("")) {
                makeText(ctx,"Fill Amount",LENGTH_SHORT).show();
            } else if(Integer.parseInt(amnt) < 10) {
                makeText(ctx,"Min Amount Rs.10",LENGTH_SHORT).show();
            } else if(!Patterns.EMAIL_ADDRESS.matcher(mail).matches()) {
                makeText(ctx,"Invalid email",LENGTH_SHORT).show();
            } else if(!Patterns.PHONE.matcher(phn).matches()) {
                makeText(ctx,"Invalid mobile",LENGTH_SHORT).show();
            } else {
                int amt = Integer.parseInt(amnt);dismiss();
                WalletActivity.startPayment(ctx,amt,mail,phn);
            }
        });
        setCancelable(true);
        return v;
    }

}
