package com.yono.messeripos;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.alimuzaffar.lib.pin.PinEntryEditText;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.UsersService;
import com.yono.messeripos.models.ForgotPasswordModels;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.response.DataResponse;
import com.yono.messeripos.utils.Utils;

public class ForgotCode extends BottomSheetDialogFragment {
    private static final String TAG = "FORGOT CODE";
    Utils utils;
    BottomSheetBehavior sheetBehavior;
    BottomSheetDialog sheetDialog;
    RelativeLayout fpass;
    View view;
    PinEntryEditText pinEntry;
    DataResponse response;
    ForgotPasswordModels forgotPasswordModels;

    Context context;
    public ForgotCode(Context context, DataResponse response) {
        this.context = context;
        this.response = response;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        sheetDialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);

//        inflating layout
        view = View.inflate(getContext(), R.layout.forgot_password_code, null);

//        bindUI
        fpass = view.findViewById(R.id.fpasswd);

//        utils
        utils = new Utils();

        sheetDialog.setContentView(view);

        sheetBehavior = BottomSheetBehavior.from((View) (view.getParent()));

//        get Window size
        int setHeight = utils.getWindowHeight() - (utils.getWindowHeight() * 50) / 100;

//        set max height
        sheetBehavior.setPeekHeight(setHeight);
        fpass.setMinimumHeight(setHeight);

        utils = new Utils();

//        Log.d(TAG, "onCreateDialog: "+utils.convertGson(mainViewModels));

        pinEntry = view.findViewById(R.id.txt_pin_entry);
        if (pinEntry != null) {
            pinEntry.setOnPinEnteredListener(new PinEntryEditText.OnPinEnteredListener() {
                @Override
                public void onPinEntered(CharSequence str) {
                    if (str.toString().equals(forgotPasswordModels.getMessage())) {
                        Toast.makeText(context, "SUCCESS", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(context, "FAIL", Toast.LENGTH_SHORT).show();
                        pinEntry.setText(null);
                    }
                }
            });
        }

        return sheetDialog;
    }
}
