package com.sistemasolton.itranvias.home.presentation.linedetail;

import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.SnapshotStateKt__SnapshotStateKt;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelKt;
import com.sistemasolton.itranvias.home.data.local.entity.LineFavoriteEntity;
import com.sistemasolton.itranvias.home.data.remote.dto.horariodto.HorarioDto;
import com.sistemasolton.itranvias.home.data.remote.dto.infodto.InfoDto;
import com.sistemasolton.itranvias.home.domain.usecase.AddStopToHistoryUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.GetInfoLocalUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.GetInfoUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.GetLineDetailUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.GetLineMapUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.GetScheduleUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.stopfavorites.AddLineFavoriteUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.stopfavorites.DeleteFavoriteLineByCodeUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.stopfavorites.GetAllLinesFavoriteUseCase;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
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.Function2;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import kotlinx.coroutines.BuildersKt__Builders_commonKt;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.flow.FlowKt;
import kotlinx.datetime.LocalDate;

/* JADX INFO: compiled from: LineDetailViewModel.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000h\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0007\u0018\u00002\u00020\u0001B_\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t\u0012\u0006\u0010\n\u001a\u00020\u000b\u0012\u0006\u0010\f\u001a\u00020\r\u0012\u0006\u0010\u000e\u001a\u00020\u000f\u0012\u0006\u0010\u0010\u001a\u00020\u0011\u0012\u0006\u0010\u0012\u001a\u00020\u0013\u0012\u0006\u0010\u0014\u001a\u00020\u0015\u0012\u0006\u0010\u0016\u001a\u00020\u0015¢\u0006\u0004\b\u0017\u0010\u0018J\u0018\u0010\"\u001a\u00020#2\u0006\u0010$\u001a\u00020\u00152\b\b\u0002\u0010%\u001a\u00020&J\u0016\u0010'\u001a\u00020#2\u0006\u0010$\u001a\u00020\u00152\u0006\u0010(\u001a\u00020)J\u000e\u0010*\u001a\u00020#2\u0006\u0010\u0016\u001a\u00020\u0015J\u000e\u0010+\u001a\u00020#2\u0006\u0010,\u001a\u00020\u0015R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\f\u001a\u00020\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u000e\u001a\u00020\u000fX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0010\u001a\u00020\u0011X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0012\u001a\u00020\u0013X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0014\u001a\u00020\u0015X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0016\u001a\u00020\u0015X\u0082\u0004¢\u0006\u0002\n\u0000R+\u0010\u001b\u001a\u00020\u001a2\u0006\u0010\u0019\u001a\u00020\u001a8F@BX\u0086\u008e\u0002¢\u0006\u0012\n\u0004\b \u0010!\u001a\u0004\b\u001c\u0010\u001d\"\u0004\b\u001e\u0010\u001f¨\u0006-"}, d2 = {"Lcom/sistemasolton/itranvias/home/presentation/linedetail/LineDetailViewmodel;", "Landroidx/lifecycle/ViewModel;", "addStopToHistoryUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/AddStopToHistoryUseCase;", "getInfoUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoUseCase;", "getLineDetailUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/GetLineDetailUseCase;", "getAllLinesFavoriteUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/GetAllLinesFavoriteUseCase;", "addLineFavoriteUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/AddLineFavoriteUseCase;", "deleteFavoriteLineByCodeUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/DeleteFavoriteLineByCodeUseCase;", "getScheduleUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/GetScheduleUseCase;", "getLineMapUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/GetLineMapUseCase;", "getLocalInfoUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoLocalUseCase;", "language", "", "lineId", "<init>", "(Lcom/sistemasolton/itranvias/home/domain/usecase/AddStopToHistoryUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/GetLineDetailUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/GetAllLinesFavoriteUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/AddLineFavoriteUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/DeleteFavoriteLineByCodeUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/GetScheduleUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/GetLineMapUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoLocalUseCase;Ljava/lang/String;Ljava/lang/String;)V", "<set-?>", "Lcom/sistemasolton/itranvias/home/presentation/linedetail/LineDetailState;", "state", "getState", "()Lcom/sistemasolton/itranvias/home/presentation/linedetail/LineDetailState;", "setState", "(Lcom/sistemasolton/itranvias/home/presentation/linedetail/LineDetailState;)V", "state$delegate", "Landroidx/compose/runtime/MutableState;", "loadDynamicInfo", "", "lineaId", "fullLoad", "", "loadScheduleForDate", "date", "Lkotlinx/datetime/LocalDate;", "toggleFavorite", "onStopClicked", "stopId", "composeApp_release"}, k = 1, mv = {2, 1, 0}, xi = 48)
public final class LineDetailViewmodel extends ViewModel {
    public static final int $stable = 8;
    private final AddLineFavoriteUseCase addLineFavoriteUseCase;
    private final AddStopToHistoryUseCase addStopToHistoryUseCase;
    private final DeleteFavoriteLineByCodeUseCase deleteFavoriteLineByCodeUseCase;
    private final GetAllLinesFavoriteUseCase getAllLinesFavoriteUseCase;
    private final GetInfoUseCase getInfoUseCase;
    private final GetLineDetailUseCase getLineDetailUseCase;
    private final GetLineMapUseCase getLineMapUseCase;
    private final GetInfoLocalUseCase getLocalInfoUseCase;
    private final GetScheduleUseCase getScheduleUseCase;
    private final String language;
    private final String lineId;

    /* JADX INFO: renamed from: state$delegate, reason: from kotlin metadata */
    private final MutableState state;

    public LineDetailViewmodel(AddStopToHistoryUseCase addStopToHistoryUseCase, GetInfoUseCase getInfoUseCase, GetLineDetailUseCase getLineDetailUseCase, GetAllLinesFavoriteUseCase getAllLinesFavoriteUseCase, AddLineFavoriteUseCase addLineFavoriteUseCase, DeleteFavoriteLineByCodeUseCase deleteFavoriteLineByCodeUseCase, GetScheduleUseCase getScheduleUseCase, GetLineMapUseCase getLineMapUseCase, GetInfoLocalUseCase getLocalInfoUseCase, String language, String lineId) {
        Intrinsics.checkNotNullParameter(addStopToHistoryUseCase, "addStopToHistoryUseCase");
        Intrinsics.checkNotNullParameter(getInfoUseCase, "getInfoUseCase");
        Intrinsics.checkNotNullParameter(getLineDetailUseCase, "getLineDetailUseCase");
        Intrinsics.checkNotNullParameter(getAllLinesFavoriteUseCase, "getAllLinesFavoriteUseCase");
        Intrinsics.checkNotNullParameter(addLineFavoriteUseCase, "addLineFavoriteUseCase");
        Intrinsics.checkNotNullParameter(deleteFavoriteLineByCodeUseCase, "deleteFavoriteLineByCodeUseCase");
        Intrinsics.checkNotNullParameter(getScheduleUseCase, "getScheduleUseCase");
        Intrinsics.checkNotNullParameter(getLineMapUseCase, "getLineMapUseCase");
        Intrinsics.checkNotNullParameter(getLocalInfoUseCase, "getLocalInfoUseCase");
        Intrinsics.checkNotNullParameter(language, "language");
        Intrinsics.checkNotNullParameter(lineId, "lineId");
        this.addStopToHistoryUseCase = addStopToHistoryUseCase;
        this.getInfoUseCase = getInfoUseCase;
        this.getLineDetailUseCase = getLineDetailUseCase;
        this.getAllLinesFavoriteUseCase = getAllLinesFavoriteUseCase;
        this.addLineFavoriteUseCase = addLineFavoriteUseCase;
        this.deleteFavoriteLineByCodeUseCase = deleteFavoriteLineByCodeUseCase;
        this.getScheduleUseCase = getScheduleUseCase;
        this.getLineMapUseCase = getLineMapUseCase;
        this.getLocalInfoUseCase = getLocalInfoUseCase;
        this.language = language;
        this.lineId = lineId;
        this.state = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(new LineDetailState(false, false, null, null, null, false, null, null, null, null, 1023, null), null, 2, null);
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new AnonymousClass1(null), 3, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void setState(LineDetailState lineDetailState) {
        this.state.setValue(lineDetailState);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final LineDetailState getState() {
        return (LineDetailState) this.state.getValue();
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel$1, reason: invalid class name */
    /* JADX INFO: compiled from: LineDetailViewModel.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.home.presentation.linedetail.LineDetailViewmodel$1", f = "LineDetailViewModel.kt", i = {}, l = {49}, m = "invokeSuspend", n = {}, s = {})
    static final class AnonymousClass1 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        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 LineDetailViewmodel.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 {
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            if (i == 0) {
                ResultKt.throwOnFailure(obj);
                this.label = 1;
                if (FlowKt.collectLatest(LineDetailViewmodel.this.getLocalInfoUseCase.invoke(), new C01171(LineDetailViewmodel.this, null), this) == coroutine_suspended) {
                    return coroutine_suspended;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
            }
            return Unit.INSTANCE;
        }

        /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel$1$1, reason: invalid class name and collision with other inner class name */
        /* JADX INFO: compiled from: LineDetailViewModel.kt */
        @Metadata(d1 = {"\u0000\f\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u00012\b\u0010\u0002\u001a\u0004\u0018\u00010\u0003H\n"}, d2 = {"<anonymous>", "", "localInfo", "Lcom/sistemasolton/itranvias/home/data/remote/dto/infodto/InfoDto;"}, k = 3, mv = {2, 1, 0}, xi = 48)
        @DebugMetadata(c = "com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel$1$1", f = "LineDetailViewModel.kt", i = {0}, l = {51}, m = "invokeSuspend", n = {"localInfo"}, s = {"L$0"})
        static final class C01171 extends SuspendLambda implements Function2<InfoDto, Continuation<? super Unit>, Object> {
            /* synthetic */ Object L$0;
            int label;
            final /* synthetic */ LineDetailViewmodel this$0;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C01171(LineDetailViewmodel lineDetailViewmodel, Continuation<? super C01171> continuation) {
                super(2, continuation);
                this.this$0 = lineDetailViewmodel;
            }

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
                C01171 c01171 = new C01171(this.this$0, continuation);
                c01171.L$0 = obj;
                return c01171;
            }

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

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Object invokeSuspend(Object obj) throws Throwable {
                Object objFirst;
                InfoDto infoDto;
                boolean z;
                Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
                int i = this.label;
                if (i == 0) {
                    ResultKt.throwOnFailure(obj);
                    InfoDto infoDto2 = (InfoDto) this.L$0;
                    this.L$0 = infoDto2;
                    this.label = 1;
                    objFirst = FlowKt.first(this.this$0.getAllLinesFavoriteUseCase.invoke(), this);
                    if (objFirst == coroutine_suspended) {
                        return coroutine_suspended;
                    }
                    infoDto = infoDto2;
                } else {
                    if (i != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    InfoDto infoDto3 = (InfoDto) this.L$0;
                    ResultKt.throwOnFailure(obj);
                    objFirst = obj;
                    infoDto = infoDto3;
                }
                List list = (List) objFirst;
                LineDetailViewmodel lineDetailViewmodel = this.this$0;
                if ((list instanceof Collection) && list.isEmpty()) {
                    z = false;
                } else {
                    Iterator it = list.iterator();
                    while (it.hasNext()) {
                        if (Intrinsics.areEqual(((LineFavoriteEntity) it.next()).getLineCode(), lineDetailViewmodel.lineId)) {
                            z = true;
                            break;
                        }
                    }
                    z = false;
                }
                LineDetailViewmodel lineDetailViewmodel2 = this.this$0;
                LineDetailState state = lineDetailViewmodel2.getState();
                lineDetailViewmodel2.setState(state.copy((987 & 1) != 0 ? state.isLoading : false, (987 & 2) != 0 ? state.isError : false, (987 & 4) != 0 ? state.infoDto : infoDto, (987 & 8) != 0 ? state.errorMessage : null, (987 & 16) != 0 ? state.detalleLineaDto : null, (987 & 32) != 0 ? state.isFavorite : z, (987 & 64) != 0 ? state.schedule : null, (987 & 128) != 0 ? state.lineMap : null, (987 & 256) != 0 ? state.lastUpdateTime : null, (987 & 512) != 0 ? state.selectedScheduleDate : null));
                return Unit.INSTANCE;
            }
        }
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel$loadDynamicInfo$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: LineDetailViewModel.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.home.presentation.linedetail.LineDetailViewmodel$loadDynamicInfo$1", f = "LineDetailViewModel.kt", i = {0, 1, 1, 1, 2, 2, 2, 2, 3}, l = {71, 81, 82, 101}, m = "invokeSuspend", n = {"success", "detalle", "formattedTime", "success", "detalle", "formattedTime", "schedule", "success", "success"}, s = {"I$0", "L$0", "L$1", "I$0", "L$0", "L$1", "L$2", "I$0", "I$0"})
    static final class C06461 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        final /* synthetic */ boolean $fullLoad;
        final /* synthetic */ String $lineaId;
        int I$0;
        Object L$0;
        Object L$1;
        Object L$2;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        C06461(String str, boolean z, Continuation<? super C06461> continuation) {
            super(2, continuation);
            this.$lineaId = str;
            this.$fullLoad = z;
        }

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

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

        /* JADX WARN: Removed duplicated region for block: B:26:0x006a A[Catch: Exception -> 0x005e, TRY_ENTER, TryCatch #0 {Exception -> 0x005e, blocks: (B:26:0x006a, B:29:0x0086, B:31:0x00e0, B:35:0x0104, B:39:0x0128, B:40:0x0148, B:13:0x0037, B:17:0x004e, B:20:0x0058), top: B:48:0x000f }] */
        /* JADX WARN: Removed duplicated region for block: B:46:0x01b9  */
        /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:43:0x01b3 -> B:9:0x001e). Please report as a decompilation issue!!! */
        /*  JADX ERROR: JadxOverflowException in pass: RegionMakerVisitor
            jadx.core.utils.exceptions.JadxOverflowException: Regions count limit reached
            	at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:59)
            	at jadx.core.utils.ErrorsCounter.error(ErrorsCounter.java:31)
            	at jadx.core.dex.attributes.nodes.NotificationAttrNode.addError(NotificationAttrNode.java:19)
            */
        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct code enable 'Show inconsistent code' option in preferences
        */
        public final java.lang.Object invokeSuspend(java.lang.Object r27) {
            /*
                Method dump skipped, instruction units count: 444
                To view this dump change 'Code comments level' option to 'DEBUG'
            */
            throw new UnsupportedOperationException("Method not decompiled: com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel.C06461.invokeSuspend(java.lang.Object):java.lang.Object");
        }
    }

    public static /* synthetic */ void loadDynamicInfo$default(LineDetailViewmodel lineDetailViewmodel, String str, boolean z, int i, Object obj) {
        if ((i & 2) != 0) {
            z = true;
        }
        lineDetailViewmodel.loadDynamicInfo(str, z);
    }

    public final void loadDynamicInfo(String lineaId, boolean fullLoad) {
        Intrinsics.checkNotNullParameter(lineaId, "lineaId");
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new C06461(lineaId, fullLoad, null), 3, null);
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel$loadScheduleForDate$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: LineDetailViewModel.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.home.presentation.linedetail.LineDetailViewmodel$loadScheduleForDate$1", f = "LineDetailViewModel.kt", i = {}, l = {116}, m = "invokeSuspend", n = {}, s = {})
    static final class C06471 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        final /* synthetic */ LocalDate $date;
        final /* synthetic */ String $lineaId;
        int label;
        final /* synthetic */ LineDetailViewmodel this$0;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        C06471(LocalDate localDate, String str, LineDetailViewmodel lineDetailViewmodel, Continuation<? super C06471> continuation) {
            super(2, continuation);
            this.$date = localDate;
            this.$lineaId = str;
            this.this$0 = lineDetailViewmodel;
        }

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

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

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            Object objInvoke;
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            try {
                if (i == 0) {
                    ResultKt.throwOnFailure(obj);
                    String str = this.$date.getYear() + StringsKt.padStart(String.valueOf(this.$date.getMonthNumber()), 2, '0') + StringsKt.padStart(String.valueOf(this.$date.getDayOfMonth()), 2, '0');
                    System.out.println((Object) ("📅 Solicitando schedule para línea " + this.$lineaId + " con fecha " + str));
                    this.label = 1;
                    objInvoke = this.this$0.getScheduleUseCase.invoke(this.$lineaId, str, this);
                    if (objInvoke == coroutine_suspended) {
                        return coroutine_suspended;
                    }
                } else {
                    if (i != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    ResultKt.throwOnFailure(obj);
                    objInvoke = obj;
                }
                HorarioDto horarioDto = (HorarioDto) objInvoke;
                System.out.println((Object) ("✅ Schedule recibido: " + horarioDto.getServicios().size() + " servicios"));
                LineDetailViewmodel lineDetailViewmodel = this.this$0;
                LineDetailState state = lineDetailViewmodel.getState();
                lineDetailViewmodel.setState(state.copy((987 & 1) != 0 ? state.isLoading : false, (987 & 2) != 0 ? state.isError : false, (987 & 4) != 0 ? state.infoDto : null, (987 & 8) != 0 ? state.errorMessage : null, (987 & 16) != 0 ? state.detalleLineaDto : null, (987 & 32) != 0 ? state.isFavorite : false, (987 & 64) != 0 ? state.schedule : horarioDto, (987 & 128) != 0 ? state.lineMap : null, (987 & 256) != 0 ? state.lastUpdateTime : null, (987 & 512) != 0 ? state.selectedScheduleDate : this.$date));
            } catch (Exception e) {
                System.out.println((Object) ("❌ Error al cargar schedule para " + this.$date + ": " + e.getMessage()));
                e.printStackTrace();
            }
            return Unit.INSTANCE;
        }
    }

    public final void loadScheduleForDate(String lineaId, LocalDate date) {
        Intrinsics.checkNotNullParameter(lineaId, "lineaId");
        Intrinsics.checkNotNullParameter(date, "date");
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new C06471(date, lineaId, this, null), 3, null);
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel$toggleFavorite$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: LineDetailViewModel.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.home.presentation.linedetail.LineDetailViewmodel$toggleFavorite$1", f = "LineDetailViewModel.kt", i = {0, 1}, l = {135, 137}, m = "invokeSuspend", n = {"isCurrentlyFavorite", "isCurrentlyFavorite"}, s = {"Z$0", "Z$0"})
    static final class C06491 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        final /* synthetic */ String $lineId;
        boolean Z$0;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        C06491(String str, Continuation<? super C06491> continuation) {
            super(2, continuation);
            this.$lineId = str;
        }

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

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

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            boolean z;
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            if (i == 0) {
                ResultKt.throwOnFailure(obj);
                boolean zIsFavorite = LineDetailViewmodel.this.getState().isFavorite();
                if (zIsFavorite) {
                    this.Z$0 = zIsFavorite;
                    this.label = 1;
                    if (LineDetailViewmodel.this.deleteFavoriteLineByCodeUseCase.invoke(this.$lineId, this) == coroutine_suspended) {
                        return coroutine_suspended;
                    }
                } else {
                    this.Z$0 = zIsFavorite;
                    this.label = 2;
                    if (LineDetailViewmodel.this.addLineFavoriteUseCase.invoke(new LineFavoriteEntity(this.$lineId), this) == coroutine_suspended) {
                        return coroutine_suspended;
                    }
                }
                z = zIsFavorite;
            } else {
                if (i != 1 && i != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                z = this.Z$0;
                ResultKt.throwOnFailure(obj);
            }
            LineDetailViewmodel lineDetailViewmodel = LineDetailViewmodel.this;
            LineDetailState state = lineDetailViewmodel.getState();
            lineDetailViewmodel.setState(state.copy((987 & 1) != 0 ? state.isLoading : false, (987 & 2) != 0 ? state.isError : false, (987 & 4) != 0 ? state.infoDto : null, (987 & 8) != 0 ? state.errorMessage : null, (987 & 16) != 0 ? state.detalleLineaDto : null, (987 & 32) != 0 ? state.isFavorite : !z, (987 & 64) != 0 ? state.schedule : null, (987 & 128) != 0 ? state.lineMap : null, (987 & 256) != 0 ? state.lastUpdateTime : null, (987 & 512) != 0 ? state.selectedScheduleDate : null));
            return Unit.INSTANCE;
        }
    }

    public final void toggleFavorite(String lineId) {
        Intrinsics.checkNotNullParameter(lineId, "lineId");
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new C06491(lineId, null), 3, null);
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.linedetail.LineDetailViewmodel$onStopClicked$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: LineDetailViewModel.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.home.presentation.linedetail.LineDetailViewmodel$onStopClicked$1", f = "LineDetailViewModel.kt", i = {}, l = {146}, m = "invokeSuspend", n = {}, s = {})
    static final class C06481 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        final /* synthetic */ String $stopId;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        C06481(String str, Continuation<? super C06481> continuation) {
            super(2, continuation);
            this.$stopId = str;
        }

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

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

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            if (i == 0) {
                ResultKt.throwOnFailure(obj);
                this.label = 1;
                if (LineDetailViewmodel.this.addStopToHistoryUseCase.invoke(this.$stopId, this) == coroutine_suspended) {
                    return coroutine_suspended;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
            }
            return Unit.INSTANCE;
        }
    }

    public final void onStopClicked(String stopId) {
        Intrinsics.checkNotNullParameter(stopId, "stopId");
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new C06481(stopId, null), 3, null);
    }
}