package com.google.maps.android.compose;

import android.content.Context;
import android.view.View;
import androidx.compose.runtime.Applier;
import androidx.compose.runtime.ComposablesKt;
import androidx.compose.runtime.Composer;
import androidx.compose.runtime.CompositionContext;
import androidx.compose.ui.platform.AbstractComposeView;
import com.google.android.gms.maps.MapView;
import com.google.maps.android.compose.ComposeUiViewRenderer;
import java.io.IOException;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.io.CloseableKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;

/* JADX INFO: compiled from: MapComposeViewRender.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u00006\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\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\u0002\b\u0002\u001a4\u0010\u0000\u001a\u00020\u0001*\u00020\u00022\u0006\u0010\u0003\u001a\u00020\u00042\u0016\b\u0002\u0010\u0005\u001a\u0010\u0012\u0004\u0012\u00020\u0007\u0012\u0004\u0012\u00020\u0001\u0018\u00010\u00062\u0006\u0010\b\u001a\u00020\tH\u0000\u001a\u001c\u0010\n\u001a\u00020\u000b*\u00020\u00022\u0006\u0010\u0003\u001a\u00020\u00042\u0006\u0010\b\u001a\u00020\tH\u0000\u001a\f\u0010\f\u001a\u00020\r*\u00020\u0002H\u0002\u001a\r\u0010\u000e\u001a\u00020\u000fH\u0007¢\u0006\u0002\u0010\u0010¨\u0006\u0011"}, d2 = {"renderComposeViewOnce", "", "Lcom/google/android/gms/maps/MapView;", "view", "Landroidx/compose/ui/platform/AbstractComposeView;", "onAddedToWindow", "Lkotlin/Function1;", "Landroid/view/View;", "parentContext", "Landroidx/compose/runtime/CompositionContext;", "startRenderingComposeView", "Lcom/google/maps/android/compose/ComposeUiViewRenderer$RenderHandle;", "ensureContainerView", "Lcom/google/maps/android/compose/NoDrawContainerView;", "rememberComposeUiViewRenderer", "Lcom/google/maps/android/compose/ComposeUiViewRenderer;", "(Landroidx/compose/runtime/Composer;I)Lcom/google/maps/android/compose/ComposeUiViewRenderer;", "maps-compose_release"}, k = 2, mv = {2, 0, 0}, xi = 48)
public final class MapComposeViewRenderKt {
    public static /* synthetic */ void renderComposeViewOnce$default(MapView mapView, AbstractComposeView abstractComposeView, Function1 function1, CompositionContext compositionContext, int i, Object obj) throws IOException {
        if ((i & 2) != 0) {
            function1 = null;
        }
        renderComposeViewOnce(mapView, abstractComposeView, function1, compositionContext);
    }

    public static final void renderComposeViewOnce(MapView mapView, AbstractComposeView view, Function1<? super View, Unit> function1, CompositionContext parentContext) throws IOException {
        Intrinsics.checkNotNullParameter(mapView, "<this>");
        Intrinsics.checkNotNullParameter(view, "view");
        Intrinsics.checkNotNullParameter(parentContext, "parentContext");
        ComposeUiViewRenderer.RenderHandle renderHandleStartRenderingComposeView = startRenderingComposeView(mapView, view, parentContext);
        try {
            ComposeUiViewRenderer.RenderHandle renderHandle = renderHandleStartRenderingComposeView;
            if (function1 != null) {
                function1.invoke(view);
                Unit unit = Unit.INSTANCE;
            }
            CloseableKt.closeFinally(renderHandleStartRenderingComposeView, null);
        } finally {
        }
    }

    public static final ComposeUiViewRenderer.RenderHandle startRenderingComposeView(MapView mapView, final AbstractComposeView view, CompositionContext parentContext) {
        Intrinsics.checkNotNullParameter(mapView, "<this>");
        Intrinsics.checkNotNullParameter(view, "view");
        Intrinsics.checkNotNullParameter(parentContext, "parentContext");
        final NoDrawContainerView noDrawContainerViewEnsureContainerView = ensureContainerView(mapView);
        noDrawContainerViewEnsureContainerView.addView(view);
        view.setParentCompositionContext(parentContext);
        return new ComposeUiViewRenderer.RenderHandle() { // from class: com.google.maps.android.compose.MapComposeViewRenderKt.startRenderingComposeView.2
            @Override // com.google.maps.android.compose.ComposeUiViewRenderer.RenderHandle, java.io.Closeable, java.lang.AutoCloseable
            public void close() {
                ComposeUiViewRenderer.RenderHandle.DefaultImpls.close(this);
            }

            @Override // com.google.maps.android.compose.ComposeUiViewRenderer.RenderHandle
            public void dispose() {
                noDrawContainerViewEnsureContainerView.removeView(view);
            }
        };
    }

    private static final NoDrawContainerView ensureContainerView(MapView mapView) {
        NoDrawContainerView noDrawContainerView = (NoDrawContainerView) mapView.findViewById(R.id.maps_compose_nodraw_container_view);
        if (noDrawContainerView != null) {
            return noDrawContainerView;
        }
        Context context = mapView.getContext();
        Intrinsics.checkNotNullExpressionValue(context, "getContext(...)");
        NoDrawContainerView noDrawContainerView2 = new NoDrawContainerView(context);
        noDrawContainerView2.setId(R.id.maps_compose_nodraw_container_view);
        mapView.addView(noDrawContainerView2);
        return noDrawContainerView2;
    }

    public static final ComposeUiViewRenderer rememberComposeUiViewRenderer(Composer composer, int i) {
        composer.startReplaceableGroup(124209494);
        Applier<?> applier = composer.getApplier();
        Intrinsics.checkNotNull(applier, "null cannot be cast to non-null type com.google.maps.android.compose.MapApplier");
        MapView mapView = ((MapApplier) applier).getMapView();
        CompositionContext compositionContextRememberCompositionContext = ComposablesKt.rememberCompositionContext(composer, 0);
        composer.startReplaceableGroup(1287412339);
        boolean zChanged = composer.changed(compositionContextRememberCompositionContext);
        Object objRememberedValue = composer.rememberedValue();
        if (zChanged || objRememberedValue == Composer.INSTANCE.getEmpty()) {
            objRememberedValue = new MapComposeViewRenderKt$rememberComposeUiViewRenderer$1$1(mapView, compositionContextRememberCompositionContext);
            composer.updateRememberedValue(objRememberedValue);
        }
        composer.endReplaceableGroup();
        composer.endReplaceableGroup();
        return (MapComposeViewRenderKt$rememberComposeUiViewRenderer$1$1) objRememberedValue;
    }
}