package org.thoughtcrime.securesms;

import android.os.Bundle;
import android.view.Window;

import androidx.appcompat.app.AlertDialog;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity;
import org.thoughtcrime.securesms.keyvalue.SignalStore;

public class DeviceProvisioningActivity extends PassphraseRequiredActivity {

  private static final String TAG = Log.tag(DeviceProvisioningActivity.class);

  @Override
  protected void onPreCreate() {
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
  }

  @Override
  protected void onCreate(Bundle bundle, boolean ready) {
    if (SignalStore.account().isLinkedDevice()) {
      Log.i(TAG, "Cannot link a device from a linked device. Ignoring provisioning intent.");
      startActivity(MainActivity.clearTop(this));
      finish();
      return;
    }

    AlertDialog dialog = new MaterialAlertDialogBuilder(this)
        .setTitle(getString(R.string.DeviceProvisioningActivity_link_a_signal_device))
        .setMessage(getString(R.string.DeviceProvisioningActivity_to_link_a_desktop_or_ipad_to_this_signal_account))
        .setPositiveButton(R.string.DeviceProvisioningActivity_continue, (dialog1, which) -> {
          startActivity(AppSettingsActivity.linkedDevices(this));
          finish();
        })
        .setNegativeButton(android.R.string.cancel, (dialog12, which) -> {
          dialog12.dismiss();
          finish();
        })
        .setOnDismissListener(dialog13 -> finish())
        .create();

    dialog.show();
  }
}
