package com.xplora.xpsettings.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

import com.xplora.xpsettings.Model.WifiModel;
import com.xplora.xpsettings.R;


public class WiFiControlActivity extends BaseActivity {
    String ssid;
    String bssid;
    int status;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wifi_connected_activity);
        initData();
        initView();
    }

    private void initData() {
        Intent intent = getIntent();
        ssid = intent.getStringExtra("ssid");
        bssid = intent.getStringExtra("bssid");
        status = intent.getIntExtra("status", WifiModel.STATUS.NA.ordinal());
    }

    private void initView() {
        Button btnDisconnect = findViewById(R.id.button0);
        Button btnForget = findViewById(R.id.button1);
        Button btnCancel = findViewById(R.id.button2);

        assert btnDisconnect != null;
        if(status == WifiModel.STATUS.CONNECTED.ordinal()) {
            btnDisconnect.setText(R.string.button_disconnected);
            btnDisconnect.setOnClickListener(v -> {
                Intent intent = new Intent();
                intent.putExtra("ssid", getIntent().getStringExtra("ssid"));
                intent.putExtra("bssid", getIntent().getStringExtra("bssid"));
                intent.putExtra("operation", WiFiActivity.OPERATE_DISCONNECT);
                setResult(-1, intent);
                finish();
            });
        } else if(status == WifiModel.STATUS.SAVED.ordinal()) {
            btnDisconnect.setText(R.string.button_connect);
            btnDisconnect.setOnClickListener(v -> {
                Intent intent = new Intent();
                intent.putExtra("ssid", getIntent().getStringExtra("ssid"));
                intent.putExtra("bssid", getIntent().getStringExtra("bssid"));
                intent.putExtra("operation", WiFiActivity.OPERATE_CONNECT);
                setResult(-1, intent);
                finish();
            });
        }


        assert btnForget != null;
        btnForget.setText(R.string.button_forget);
        btnForget.setOnClickListener(v -> {
            Intent intent = new Intent();
            intent.putExtra("ssid", getIntent().getStringExtra("ssid"));
            intent.putExtra("bssid", getIntent().getStringExtra("bssid"));
            intent.putExtra("operation", WiFiActivity.OPERATE_FORGET);
            setResult(-1, intent);
            finish();
        });

        assert btnCancel != null;
        btnCancel.setText(R.string.button_cancel);
        btnCancel.setOnClickListener(v -> finish());
    }
}