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.Button;
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 PriceSurveyActivity extends AppCompatActivity {

    CheckBox mQtyCheckBox;
    EditText mQtyEditText;
    EditText mStoreEditText, mOriginEditText;
    EditText priceEditText;
    EditText barcodeEditText;
    Button mChangeButton, mChangeSectionButton;
    Button mBackButton;
    Button mModifyButton;
    Button mDeleteButton;
    String selectedSubMenu;

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

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

        initViews();
        handleKeyboard();
    }

    private void initViews() {
        mQtyEditText = findViewById(R.id.etxt_waste_quantity);
        mQtyCheckBox = findViewById(R.id.check_qty);
        mStoreEditText = findViewById(R.id.etxt_waste_type);
        mOriginEditText = findViewById(R.id.etxt_change_section);
        mChangeButton = findViewById(R.id.btn_change);
        mChangeSectionButton = findViewById(R.id.btn_change_section);
        mBackButton = findViewById(R.id.btn_back);
        mModifyButton = findViewById(R.id.btn_modify);
        mDeleteButton = findViewById(R.id.btn_delete);
        priceEditText = findViewById(R.id.etxt_price);
        barcodeEditText = findViewById(R.id.etxt_barcode);

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

    private void handleKeyboard() {
        if (getSharedPreferences(AppConstants.PREF_FILE, 0).getBoolean(AppConstants.KEYBOARD_STATUS, false)){
            barcodeEditText.setFocusableInTouchMode(true);
            mQtyEditText.setFocusableInTouchMode(true);
            mStoreEditText.setFocusableInTouchMode(true);
            mOriginEditText.setFocusableInTouchMode(true);
            priceEditText.setFocusableInTouchMode(true);
            barcodeEditText.setFocusableInTouchMode(true);
        }
    }

    public void onChangeStoreClick(View v){
        mStoreEditText.setEnabled(true);
    }

    public void onChangeOriginClick(View c){
        mOriginEditText.setEnabled(true);
    }

    public void onBackButtonClick(View c){
        finish();
    }

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