package com.sistemasolton.itranvias;

import android.app.Application;
import android.content.ComponentCallbacks;
import androidx.core.view.MotionEventCompat;
import com.sistemasolton.itranvias.data.preferences.CreateDataStore_androidKt;
import com.sistemasolton.itranvias.data.preferences.OldSettingsMigration;
import com.sistemasolton.itranvias.data.preferences.SettingsRepository;
import com.sistemasolton.itranvias.home.di.HomeModuleKt;
import kotlin.Lazy;
import kotlin.LazyKt;
import kotlin.LazyThreadSafetyMode;
import kotlin.Metadata;
import kotlin.ResultKt;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.IntrinsicsKt;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlinx.coroutines.BuildersKt__Builders_commonKt;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.CoroutineScopeKt;
import kotlinx.coroutines.Dispatchers;
import kotlinx.coroutines.Job;
import kotlinx.coroutines.SupervisorKt;
import org.koin.android.ext.android.AndroidKoinScopeExtKt;
import org.koin.android.ext.koin.KoinExtKt;
import org.koin.core.KoinApplication;
import org.koin.core.qualifier.Qualifier;

/* JADX INFO: compiled from: ITranviasApp.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\b\u0007\u0018\u00002\u00020\u0001B\u0007¢\u0006\u0004\b\u0002\u0010\u0003J\b\u0010\u0006\u001a\u00020\u0007H\u0016J\b\u0010\b\u001a\u00020\u0007H\u0002R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\t²\u0006\n\u0010\n\u001a\u00020\u000bX\u008a\u0084\u0002"}, d2 = {"Lcom/sistemasolton/itranvias/ITranviasApp;", "Landroid/app/Application;", "<init>", "()V", "applicationScope", "Lkotlinx/coroutines/CoroutineScope;", "onCreate", "", "migrateOldSettingsIfNeeded", "composeApp_release", "settingsRepository", "Lcom/sistemasolton/itranvias/data/preferences/SettingsRepository;"}, k = 1, mv = {2, 1, 0}, xi = 48)
public final class ITranviasApp extends Application {
    public static final int $stable = 8;
    private final CoroutineScope applicationScope = CoroutineScopeKt.CoroutineScope(SupervisorKt.SupervisorJob$default((Job) null, 1, (Object) null).plus(Dispatchers.getDefault()));

    @Override // android.app.Application
    public void onCreate() {
        super.onCreate();
        CreateDataStore_androidKt.initDataStore(this);
        HomeModuleKt.initKoin(new Function1() { // from class: com.sistemasolton.itranvias.ITranviasApp$$ExternalSyntheticLambda0
            @Override // kotlin.jvm.functions.Function1
            public final Object invoke(Object obj) {
                return ITranviasApp.onCreate$lambda$0(this.f$0, (KoinApplication) obj);
            }
        });
        migrateOldSettingsIfNeeded();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final Unit onCreate$lambda$0(ITranviasApp iTranviasApp, KoinApplication initKoin) {
        Intrinsics.checkNotNullParameter(initKoin, "$this$initKoin");
        KoinExtKt.androidContext(initKoin, iTranviasApp);
        return Unit.INSTANCE;
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.ITranviasApp$migrateOldSettingsIfNeeded$1, reason: invalid class name */
    /* JADX INFO: compiled from: ITranviasApp.kt */
    @Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u0001*\u00020\u0002H\n"}, d2 = {"<anonymous>", "", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 1, 0}, xi = 48)
    @DebugMetadata(c = "com.sistemasolton.itranvias.ITranviasApp$migrateOldSettingsIfNeeded$1", f = "ITranviasApp.kt", i = {0, 1, 1, 1}, l = {MotionEventCompat.AXIS_GENERIC_14, 58, 70}, m = "invokeSuspend", n = {"settingsRepository$delegate", "oldLanguage", "oldTheme", "oldPreferredTab"}, s = {"L$0", "L$0", "L$1", "L$2"})
    static final class AnonymousClass1 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        Object L$0;
        Object L$1;
        Object L$2;
        int label;

        AnonymousClass1(Continuation<? super AnonymousClass1> continuation) {
            super(2, continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
            return ITranviasApp.this.new AnonymousClass1(continuation);
        }

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
            return ((AnonymousClass1) create(coroutineScope, continuation)).invokeSuspend(Unit.INSTANCE);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            Lazy lazy;
            String oldLanguage;
            String str;
            String str2;
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            final Qualifier qualifier = null;
            byte b = 0;
            try {
            } catch (Exception e) {
                System.out.println((Object) (" Error migrating old settings: " + e.getMessage()));
            }
            if (i == 0) {
                ResultKt.throwOnFailure(obj);
                final ITranviasApp iTranviasApp = ITranviasApp.this;
                LazyThreadSafetyMode lazyThreadSafetyMode = LazyThreadSafetyMode.SYNCHRONIZED;
                final byte b2 = b == true ? 1 : 0;
                lazy = LazyKt.lazy(lazyThreadSafetyMode, (Function0) new Function0<SettingsRepository>() { // from class: com.sistemasolton.itranvias.ITranviasApp$migrateOldSettingsIfNeeded$1$invokeSuspend$$inlined$inject$default$1
                    /* JADX WARN: Type inference failed for: r0v2, types: [com.sistemasolton.itranvias.data.preferences.SettingsRepository, java.lang.Object] */
                    @Override // kotlin.jvm.functions.Function0
                    public final SettingsRepository invoke() {
                        ComponentCallbacks componentCallbacks = iTranviasApp;
                        return AndroidKoinScopeExtKt.getKoinScope(componentCallbacks).get(Reflection.getOrCreateKotlinClass(SettingsRepository.class), qualifier, b2);
                    }
                });
                this.L$0 = lazy;
                this.label = 1;
                obj = invokeSuspend$lambda$0(lazy).isMigrationCompleted(this);
                if (obj == coroutine_suspended) {
                    return coroutine_suspended;
                }
            } else {
                if (i != 1) {
                    if (i != 2) {
                        if (i != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        ResultKt.throwOnFailure(obj);
                        System.out.println((Object) " No old settings found to migrate");
                        return Unit.INSTANCE;
                    }
                    str = (String) this.L$2;
                    str2 = (String) this.L$1;
                    oldLanguage = (String) this.L$0;
                    ResultKt.throwOnFailure(obj);
                    System.out.println((Object) " Settings migrated successfully from SharedPreferences to DataStore");
                    System.out.println((Object) ("   - Language: " + oldLanguage));
                    System.out.println((Object) ("   - Theme: " + str2));
                    System.out.println((Object) ("   - Preferred Tab: " + str));
                    return Unit.INSTANCE;
                }
                lazy = (Lazy) this.L$0;
                ResultKt.throwOnFailure(obj);
            }
            if (((Boolean) obj).booleanValue()) {
                return Unit.INSTANCE;
            }
            OldSettingsMigration oldSettingsMigration = new OldSettingsMigration(ITranviasApp.this);
            if (oldSettingsMigration.hasOldSettings()) {
                oldLanguage = oldSettingsMigration.getOldLanguage();
                String oldTheme = oldSettingsMigration.getOldTheme();
                String oldPreferredTab = oldSettingsMigration.getOldPreferredTab();
                this.L$0 = oldLanguage;
                this.L$1 = oldTheme;
                this.L$2 = oldPreferredTab;
                this.label = 2;
                if (invokeSuspend$lambda$0(lazy).migrateFromOldSettings(oldLanguage, oldTheme, oldPreferredTab, this) == coroutine_suspended) {
                    return coroutine_suspended;
                }
                str = oldPreferredTab;
                str2 = oldTheme;
                System.out.println((Object) " Settings migrated successfully from SharedPreferences to DataStore");
                System.out.println((Object) ("   - Language: " + oldLanguage));
                System.out.println((Object) ("   - Theme: " + str2));
                System.out.println((Object) ("   - Preferred Tab: " + str));
                return Unit.INSTANCE;
            }
            this.L$0 = null;
            this.label = 3;
            if (invokeSuspend$lambda$0(lazy).migrateFromOldSettings(null, null, null, this) == coroutine_suspended) {
                return coroutine_suspended;
            }
            System.out.println((Object) " No old settings found to migrate");
            return Unit.INSTANCE;
        }

        private static final SettingsRepository invokeSuspend$lambda$0(Lazy<SettingsRepository> lazy) {
            return lazy.getValue();
        }
    }

    private final void migrateOldSettingsIfNeeded() {
        BuildersKt__Builders_commonKt.launch$default(this.applicationScope, null, null, new AnonymousClass1(null), 3, null);
    }
}