package com.google.maps.android.compose;

import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.SnapshotStateKt__SnapshotStateKt;
import androidx.compose.runtime.saveable.Saver;
import androidx.compose.runtime.saveable.SaverKt;
import androidx.compose.runtime.saveable.SaverScope;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.maps.android.compose.CameraPositionState;
import java.util.concurrent.CancellationException;
import kotlin.Metadata;
import kotlin.Result;
import kotlin.ResultKt;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlinx.coroutines.CancellableContinuation;

/* JADX INFO: compiled from: CameraPositionState.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000V\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0011\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0007\u0018\u0000 F2\u00020\u0001:\u0002EFB\u0011\u0012\b\b\u0002\u0010\u0002\u001a\u00020\u0003¢\u0006\u0004\b\u0004\u0010\u0005J\u0010\u00102\u001a\u00020\"2\u0006\u00103\u001a\u00020+H\u0002J\u0017\u0010(\u001a\u00020\"2\b\u0010%\u001a\u0004\u0018\u00010$H\u0000¢\u0006\u0002\b:J \u0010;\u001a\u00020\"2\u0006\u0010<\u001a\u00020=2\b\b\u0002\u0010>\u001a\u00020?H\u0087@¢\u0006\u0002\u0010@J.\u0010A\u001a\u00020\"2\u0006\u0010%\u001a\u00020$2\u0006\u0010<\u001a\u00020=2\u0006\u0010>\u001a\u00020?2\f\u0010B\u001a\b\u0012\u0004\u0012\u00020\"0CH\u0002J\u0010\u0010D\u001a\u00020\"2\u0006\u0010<\u001a\u00020=H\u0007R+\u0010\b\u001a\u00020\u00072\u0006\u0010\u0006\u001a\u00020\u00078F@@X\u0086\u008e\u0002¢\u0006\u0012\n\u0004\b\f\u0010\r\u001a\u0004\b\b\u0010\t\"\u0004\b\n\u0010\u000bR+\u0010\u000f\u001a\u00020\u000e2\u0006\u0010\u0006\u001a\u00020\u000e8F@@X\u0086\u008e\u0002¢\u0006\u0012\n\u0004\b\u0014\u0010\r\u001a\u0004\b\u0010\u0010\u0011\"\u0004\b\u0012\u0010\u0013R\u0013\u0010\u0015\u001a\u0004\u0018\u00010\u00168F¢\u0006\u0006\u001a\u0004\b\u0017\u0010\u0018R+\u0010\u0019\u001a\u00020\u00032\u0006\u0010\u0006\u001a\u00020\u00038@@@X\u0080\u008e\u0002¢\u0006\u0012\n\u0004\b\u001d\u0010\r\u001a\u0004\b\u001a\u0010\u001b\"\u0004\b\u001c\u0010\u0005R$\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u001e\u001a\u00020\u00038F@FX\u0086\u000e¢\u0006\f\u001a\u0004\b\u001f\u0010\u001b\"\u0004\b \u0010\u0005R\u0010\u0010!\u001a\u00020\"X\u0082\u0004¢\u0006\u0004\n\u0002\u0010#R/\u0010%\u001a\u0004\u0018\u00010$2\b\u0010\u0006\u001a\u0004\u0018\u00010$8B@BX\u0082\u008e\u0002¢\u0006\u0012\n\u0004\b*\u0010\r\u001a\u0004\b&\u0010'\"\u0004\b(\u0010)R/\u0010,\u001a\u0004\u0018\u00010+2\b\u0010\u0006\u001a\u0004\u0018\u00010+8B@BX\u0082\u008e\u0002¢\u0006\u0012\n\u0004\b1\u0010\r\u001a\u0004\b-\u0010.\"\u0004\b/\u00100R/\u00104\u001a\u0004\u0018\u00010\u00012\b\u0010\u0006\u001a\u0004\u0018\u00010\u00018B@BX\u0082\u008e\u0002¢\u0006\u0012\n\u0004\b9\u0010\r\u001a\u0004\b5\u00106\"\u0004\b7\u00108¨\u0006G"}, d2 = {"Lcom/google/maps/android/compose/CameraPositionState;", "", "position", "Lcom/google/android/gms/maps/model/CameraPosition;", "<init>", "(Lcom/google/android/gms/maps/model/CameraPosition;)V", "<set-?>", "", "isMoving", "()Z", "setMoving$maps_compose_release", "(Z)V", "isMoving$delegate", "Landroidx/compose/runtime/MutableState;", "Lcom/google/maps/android/compose/CameraMoveStartedReason;", "cameraMoveStartedReason", "getCameraMoveStartedReason", "()Lcom/google/maps/android/compose/CameraMoveStartedReason;", "setCameraMoveStartedReason$maps_compose_release", "(Lcom/google/maps/android/compose/CameraMoveStartedReason;)V", "cameraMoveStartedReason$delegate", "projection", "Lcom/google/android/gms/maps/Projection;", "getProjection", "()Lcom/google/android/gms/maps/Projection;", "rawPosition", "getRawPosition$maps_compose_release", "()Lcom/google/android/gms/maps/model/CameraPosition;", "setRawPosition$maps_compose_release", "rawPosition$delegate", "value", "getPosition", "setPosition", "lock", "", "Lkotlin/Unit;", "Lcom/google/android/gms/maps/GoogleMap;", "map", "getMap", "()Lcom/google/android/gms/maps/GoogleMap;", "setMap", "(Lcom/google/android/gms/maps/GoogleMap;)V", "map$delegate", "Lcom/google/maps/android/compose/CameraPositionState$OnMapChangedCallback;", "onMapChanged", "getOnMapChanged", "()Lcom/google/maps/android/compose/CameraPositionState$OnMapChangedCallback;", "setOnMapChanged", "(Lcom/google/maps/android/compose/CameraPositionState$OnMapChangedCallback;)V", "onMapChanged$delegate", "doOnMapChangedLocked", "callback", "movementOwner", "getMovementOwner", "()Ljava/lang/Object;", "setMovementOwner", "(Ljava/lang/Object;)V", "movementOwner$delegate", "setMap$maps_compose_release", "animate", "update", "Lcom/google/android/gms/maps/CameraUpdate;", "durationMs", "", "(Lcom/google/android/gms/maps/CameraUpdate;ILkotlin/coroutines/Continuation;)Ljava/lang/Object;", "performAnimateCameraLocked", "continuation", "Lkotlinx/coroutines/CancellableContinuation;", "move", "OnMapChangedCallback", "Companion", "maps-compose_release"}, k = 1, mv = {2, 0, 0}, xi = 48)
public final class CameraPositionState {
    public static final int $stable = 0;

    /* JADX INFO: renamed from: Companion, reason: from kotlin metadata */
    public static final Companion INSTANCE = new Companion(null);
    private static final Saver<CameraPositionState, CameraPosition> Saver = SaverKt.Saver(new Function2() { // from class: com.google.maps.android.compose.CameraPositionState$$ExternalSyntheticLambda0
        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(Object obj, Object obj2) {
            return CameraPositionState.Saver$lambda$7((SaverScope) obj, (CameraPositionState) obj2);
        }
    }, new Function1() { // from class: com.google.maps.android.compose.CameraPositionState$$ExternalSyntheticLambda1
        @Override // kotlin.jvm.functions.Function1
        public final Object invoke(Object obj) {
            return CameraPositionState.Saver$lambda$8((CameraPosition) obj);
        }
    });

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

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

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

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

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

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

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: compiled from: CameraPositionState.kt */
    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\bâ\u0080\u0001\u0018\u00002\u00020\u0001J\u0012\u0010\u0002\u001a\u00020\u00032\b\u0010\u0004\u001a\u0004\u0018\u00010\u0005H&J\b\u0010\u0006\u001a\u00020\u0003H\u0016¨\u0006\u0007"}, d2 = {"Lcom/google/maps/android/compose/CameraPositionState$OnMapChangedCallback;", "", "onMapChangedLocked", "", "newMap", "Lcom/google/android/gms/maps/GoogleMap;", "onCancelLocked", "maps-compose_release"}, k = 1, mv = {2, 0, 0}, xi = 48)
    interface OnMapChangedCallback {

        /* JADX INFO: compiled from: CameraPositionState.kt */
        @Metadata(k = 3, mv = {2, 0, 0}, xi = 48)
        public static final class DefaultImpls {
            public static void onCancelLocked(OnMapChangedCallback onMapChangedCallback) {
            }
        }

        void onCancelLocked();

        void onMapChangedLocked(GoogleMap newMap);
    }

    /* JADX INFO: renamed from: com.google.maps.android.compose.CameraPositionState$animate$1, reason: invalid class name */
    /* JADX INFO: compiled from: CameraPositionState.kt */
    @Metadata(k = 3, mv = {2, 0, 0}, xi = 48)
    @DebugMetadata(c = "com.google.maps.android.compose.CameraPositionState", f = "CameraPositionState.kt", i = {0, 0, 0, 0}, l = {324}, m = "animate", n = {"this", "update", "myJob", "durationMs"}, s = {"L$0", "L$1", "L$2", "I$0"})
    static final class AnonymousClass1 extends ContinuationImpl {
        int I$0;
        Object L$0;
        Object L$1;
        Object L$2;
        int label;
        /* synthetic */ Object result;

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

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) {
            this.result = obj;
            this.label |= Integer.MIN_VALUE;
            return CameraPositionState.this.animate(null, 0, this);
        }
    }

    public CameraPositionState() {
        this(null, 1, 0 == true ? 1 : 0);
    }

    public CameraPositionState(CameraPosition position) {
        Intrinsics.checkNotNullParameter(position, "position");
        this.isMoving = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(false, null, 2, null);
        this.cameraMoveStartedReason = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(CameraMoveStartedReason.NO_MOVEMENT_YET, null, 2, null);
        this.rawPosition = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(position, null, 2, null);
        this.lock = Unit.INSTANCE;
        this.map = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(null, null, 2, null);
        this.onMapChanged = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(null, null, 2, null);
        this.movementOwner = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(null, null, 2, null);
    }

    public /* synthetic */ CameraPositionState(CameraPosition cameraPosition, int i, DefaultConstructorMarker defaultConstructorMarker) {
        this((i & 1) != 0 ? new CameraPosition(new LatLng(0.0d, 0.0d), 0.0f, 0.0f, 0.0f) : cameraPosition);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final boolean isMoving() {
        return ((Boolean) this.isMoving.getValue()).booleanValue();
    }

    public final void setMoving$maps_compose_release(boolean z) {
        this.isMoving.setValue(Boolean.valueOf(z));
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final CameraMoveStartedReason getCameraMoveStartedReason() {
        return (CameraMoveStartedReason) this.cameraMoveStartedReason.getValue();
    }

    public final void setCameraMoveStartedReason$maps_compose_release(CameraMoveStartedReason cameraMoveStartedReason) {
        Intrinsics.checkNotNullParameter(cameraMoveStartedReason, "<set-?>");
        this.cameraMoveStartedReason.setValue(cameraMoveStartedReason);
    }

    public final Projection getProjection() {
        GoogleMap map = getMap();
        if (map != null) {
            return map.getProjection();
        }
        return null;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final CameraPosition getRawPosition$maps_compose_release() {
        return (CameraPosition) this.rawPosition.getValue();
    }

    public final void setRawPosition$maps_compose_release(CameraPosition cameraPosition) {
        Intrinsics.checkNotNullParameter(cameraPosition, "<set-?>");
        this.rawPosition.setValue(cameraPosition);
    }

    public final CameraPosition getPosition() {
        return getRawPosition$maps_compose_release();
    }

    public final void setPosition(CameraPosition value) {
        Intrinsics.checkNotNullParameter(value, "value");
        synchronized (this.lock) {
            GoogleMap map = getMap();
            if (map == null) {
                setRawPosition$maps_compose_release(value);
            } else {
                map.moveCamera(CameraUpdateFactory.newCameraPosition(value));
            }
            Unit unit = Unit.INSTANCE;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    public final GoogleMap getMap() {
        return (GoogleMap) this.map.getValue();
    }

    private final void setMap(GoogleMap googleMap) {
        this.map.setValue(googleMap);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final OnMapChangedCallback getOnMapChanged() {
        return (OnMapChangedCallback) this.onMapChanged.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void setOnMapChanged(OnMapChangedCallback onMapChangedCallback) {
        this.onMapChanged.setValue(onMapChangedCallback);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void doOnMapChangedLocked(OnMapChangedCallback callback) {
        OnMapChangedCallback onMapChanged = getOnMapChanged();
        if (onMapChanged != null) {
            onMapChanged.onCancelLocked();
        }
        setOnMapChanged(callback);
    }

    private final Object getMovementOwner() {
        return this.movementOwner.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void setMovementOwner(Object obj) {
        this.movementOwner.setValue(obj);
    }

    public final void setMap$maps_compose_release(GoogleMap map) {
        synchronized (this.lock) {
            if (getMap() == null && map == null) {
                return;
            }
            if (getMap() != null && map != null) {
                throw new IllegalStateException("CameraPositionState may only be associated with one GoogleMap at a time".toString());
            }
            setMap(map);
            if (map == null) {
                setMoving$maps_compose_release(false);
            } else {
                map.moveCamera(CameraUpdateFactory.newCameraPosition(getPosition()));
            }
            OnMapChangedCallback onMapChanged = getOnMapChanged();
            if (onMapChanged != null) {
                setOnMapChanged(null);
                onMapChanged.onMapChangedLocked(map);
                Unit unit = Unit.INSTANCE;
            }
        }
    }

    public static /* synthetic */ Object animate$default(CameraPositionState cameraPositionState, CameraUpdate cameraUpdate, int i, Continuation continuation, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            i = Integer.MAX_VALUE;
        }
        return cameraPositionState.animate(cameraUpdate, i, continuation);
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x00b4  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00dc  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0014  */
    /* JADX WARN: Type inference failed for: r6v1, types: [com.google.maps.android.compose.CameraPositionState$animate$2$1$animateOnMapAvailable$1] */
    /*
        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 animate(final com.google.android.gms.maps.CameraUpdate r9, final int r10, kotlin.coroutines.Continuation<? super kotlin.Unit> r11) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 247
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.maps.android.compose.CameraPositionState.animate(com.google.android.gms.maps.CameraUpdate, int, kotlin.coroutines.Continuation):java.lang.Object");
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void performAnimateCameraLocked(final GoogleMap map, CameraUpdate update, int durationMs, final CancellableContinuation<? super Unit> continuation) {
        GoogleMap.CancelableCallback cancelableCallback = new GoogleMap.CancelableCallback() { // from class: com.google.maps.android.compose.CameraPositionState$performAnimateCameraLocked$cancelableCallback$1
            @Override // com.google.android.gms.maps.GoogleMap.CancelableCallback
            public void onCancel() {
                CancellableContinuation<Unit> cancellableContinuation = continuation;
                Result.Companion companion = Result.INSTANCE;
                cancellableContinuation.resumeWith(Result.m8388constructorimpl(ResultKt.createFailure(new CancellationException("Animation cancelled"))));
            }

            @Override // com.google.android.gms.maps.GoogleMap.CancelableCallback
            public void onFinish() {
                CancellableContinuation<Unit> cancellableContinuation = continuation;
                Result.Companion companion = Result.INSTANCE;
                cancellableContinuation.resumeWith(Result.m8388constructorimpl(Unit.INSTANCE));
            }
        };
        if (durationMs == Integer.MAX_VALUE) {
            map.animateCamera(update, cancelableCallback);
        } else {
            map.animateCamera(update, durationMs, cancelableCallback);
        }
        doOnMapChangedLocked(new OnMapChangedCallback() { // from class: com.google.maps.android.compose.CameraPositionState.performAnimateCameraLocked.1
            @Override // com.google.maps.android.compose.CameraPositionState.OnMapChangedCallback
            public void onCancelLocked() {
                OnMapChangedCallback.DefaultImpls.onCancelLocked(this);
            }

            @Override // com.google.maps.android.compose.CameraPositionState.OnMapChangedCallback
            public final void onMapChangedLocked(GoogleMap googleMap) {
                if (googleMap != null) {
                    throw new IllegalStateException("New GoogleMap unexpectedly set while an animation was still running".toString());
                }
                map.stopAnimation();
            }
        });
    }

    public final void move(final CameraUpdate update) {
        Intrinsics.checkNotNullParameter(update, "update");
        synchronized (this.lock) {
            GoogleMap map = getMap();
            setMovementOwner(null);
            if (map == null) {
                doOnMapChangedLocked(new OnMapChangedCallback() { // from class: com.google.maps.android.compose.CameraPositionState$move$1$1
                    @Override // com.google.maps.android.compose.CameraPositionState.OnMapChangedCallback
                    public void onCancelLocked() {
                        CameraPositionState.OnMapChangedCallback.DefaultImpls.onCancelLocked(this);
                    }

                    @Override // com.google.maps.android.compose.CameraPositionState.OnMapChangedCallback
                    public final void onMapChangedLocked(GoogleMap googleMap) {
                        if (googleMap != null) {
                            googleMap.moveCamera(update);
                        }
                    }
                });
            } else {
                map.moveCamera(update);
            }
            Unit unit = Unit.INSTANCE;
        }
    }

    /* JADX INFO: compiled from: CameraPositionState.kt */
    @Metadata(d1 = {"\u0000\u001c\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0002\u0010\u0003R\u001d\u0010\u0004\u001a\u000e\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\u00070\u0005¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\t¨\u0006\n"}, d2 = {"Lcom/google/maps/android/compose/CameraPositionState$Companion;", "", "<init>", "()V", "Saver", "Landroidx/compose/runtime/saveable/Saver;", "Lcom/google/maps/android/compose/CameraPositionState;", "Lcom/google/android/gms/maps/model/CameraPosition;", "getSaver", "()Landroidx/compose/runtime/saveable/Saver;", "maps-compose_release"}, k = 1, mv = {2, 0, 0}, xi = 48)
    public static final class Companion {
        public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        public final Saver<CameraPositionState, CameraPosition> getSaver() {
            return CameraPositionState.Saver;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final CameraPosition Saver$lambda$7(SaverScope Saver2, CameraPositionState it) {
        Intrinsics.checkNotNullParameter(Saver2, "$this$Saver");
        Intrinsics.checkNotNullParameter(it, "it");
        return it.getPosition();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final CameraPositionState Saver$lambda$8(CameraPosition it) {
        Intrinsics.checkNotNullParameter(it, "it");
        return new CameraPositionState(it);
    }
}