package in.techware.carrefour.activity.receive;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;

import in.techware.carrefour.R;
import in.techware.carrefour.activity.FileTransferActivity;
import in.techware.carrefour.util.AppConstants;

public class ReturnActivity extends AppCompatActivity {

    String selectedSubMenu;
    CheckBox mQtyCheckBox;
    EditText mQtyEditText;
    EditText mBarcodeEditText;
    EditText mSupplierEditText;

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

        mQtyCheckBox = findViewById(R.id.check_qty);
        mQtyEditText = findViewById(R.id.etxt_waste_quantity);
        mBarcodeEditText = findViewById(R.id.etxt_barcode);
        mSupplierEditText = findViewById(R.id.etxt_supplier);

        if (getIntent() != null && getIntent().getStringExtra("submenu") != null){
            selectedSubMenu = getIntent().getStringExtra("submenu");
        }

        mQtyCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mQtyEditText.setEnabled(isChecked);
            }
        });

        handleKeyboard();
    }

    private void handleKeyboard() {
        if (getSharedPreferences(AppConstants.PREF_FILE, 0).getBoolean(AppConstants.KEYBOARD_STATUS, false)){
            mQtyEditText.setFocusableInTouchMode(true);
            mBarcodeEditText.setFocusableInTouchMode(true);
            mSupplierEditText.setFocusableInTouchMode(true);
        }
    }

    public void onBackClick(View view){
        finish();
    }

    public void onModifyClick(View view){
        Intent intent = new Intent(getApplicationContext(), FileTransferActivity.class);
        intent.putExtra("submenu", selectedSubMenu);
        startActivity(intent);
    }
}
