package in.techware.carrefour.activity.it;

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.EditText;

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

public class CompetitionActivity extends AppCompatActivity implements View.OnClickListener {

    Button mBackButton;
    Button mModifyButton;
    Button mDeleteButton;
    String selectedSubMenu;
    Button mChangeButton;
    EditText mStoreEditText;
    EditText mPriceEditText;
    EditText mBarcodeEditText;
    boolean isTypeSelected = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_competition);
        mBackButton = findViewById(R.id.btn_back);
        mModifyButton = findViewById(R.id.btn_modify);
        mDeleteButton = findViewById(R.id.btn_delete);
        mChangeButton = findViewById(R.id.btn_change);
        mStoreEditText = findViewById(R.id.etxt_store);
        mPriceEditText = findViewById(R.id.etxt_price);
        mBarcodeEditText = findViewById(R.id.etxt_barcode);

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

        mBackButton.setOnClickListener(this);
        mModifyButton.setOnClickListener(this);
        mDeleteButton.setOnClickListener(this);
        mChangeButton.setOnClickListener(this);

        handleKeyboard();
    }

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

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_delete:
                break;

            case R.id.btn_back:
                finish();
                break;

            case R.id.btn_modify:
                Intent intent = new Intent(getApplicationContext(), FileTransferActivity.class);
                intent.putExtra("submenu", selectedSubMenu);
                startActivity(intent);
                break;

            case R.id.btn_change:
                if (!isTypeSelected){
                    mStoreEditText.setEnabled(true);
                    isTypeSelected = true;
                }else{
                    mStoreEditText.setEnabled(false);
                    isTypeSelected = false;
                }
                break;
        }
    }
}
