package ve;

import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.p0;
import androidx.lifecycle.c1;
import androidx.lifecycle.d1;
import androidx.lifecycle.e1;
import androidx.lifecycle.g0;
import androidx.lifecycle.u;
import androidx.lifecycle.z0;
import com.google.android.gms.common.internal.ServiceSpecificExtraArgs;
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.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MapStyleOptions;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.analytics.FirebaseAnalytics;
import dn.l;
import kotlin.Metadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import q8.a;
import re.o;
import rm.i;
import rm.n0;
import u7.x;

@Metadata(d1 = {"\u0000\u0098\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\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\u0002\b\u0004\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u001d\u0018\u0000 a2\u00020\u00012\b\u0012\u0004\u0012\u00020\u00030\u00022\u00020\u00042\u00020\u0005:\u0001bB\u0007¢\u0006\u0004\b_\u0010`J\b\u0010\u0007\u001a\u00020\u0006H\u0002J\b\u0010\b\u001a\u00020\u0006H\u0002J\b\u0010\t\u001a\u00020\u0006H\u0002J5\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u000b\u001a\u00020\n2\b\u0010\r\u001a\u0004\u0018\u00010\f2\b\u0010\u000f\u001a\u0004\u0018\u00010\u000e2\u0006\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u0012H\u0096\u0001J$\u0010\u0016\u001a\u00020\u00142\u0006\u0010\u000b\u001a\u00020\n2\b\u0010\r\u001a\u0004\u0018\u00010\f2\b\u0010\u000f\u001a\u0004\u0018\u00010\u000eH\u0016J\u001a\u0010\u0018\u001a\u00020\u00062\u0006\u0010\u0017\u001a\u00020\u00142\b\u0010\u000f\u001a\u0004\u0018\u00010\u000eH\u0016J\b\u0010\u001a\u001a\u00020\u0019H\u0016J\u0010\u0010\u001d\u001a\u00020\u00062\u0006\u0010\u001c\u001a\u00020\u001bH\u0016J\u0006\u0010\u001e\u001a\u00020\u0006J\u000e\u0010!\u001a\u00020\u00062\u0006\u0010 \u001a\u00020\u001fJ\u0010\u0010%\u001a\u0004\u0018\u00010$2\u0006\u0010#\u001a\u00020\"J\u000e\u0010(\u001a\u00020\u00062\u0006\u0010'\u001a\u00020&J\u0014\u0010*\u001a\u00020\u00062\f\u0010'\u001a\b\u0012\u0004\u0012\u00020\u001f0)J\u0014\u0010,\u001a\u00020\u00062\f\u0010+\u001a\b\u0012\u0004\u0012\u00020\u00190)J\b\u0010-\u001a\u00020\u0006H\u0016J\b\u0010.\u001a\u00020\u0006H\u0016J\b\u0010/\u001a\u00020\u0006H\u0016J\u0010\u00101\u001a\u00020\u00062\u0006\u00100\u001a\u00020\u000eH\u0016J\b\u00102\u001a\u00020\u0006H\u0016R\u001b\u0010\u0013\u001a\u0002038BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b4\u00105\u001a\u0004\b6\u00107R\u0018\u0010\u001c\u001a\u0004\u0018\u00010\u001b8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b8\u00109R\u0018\u0010=\u001a\u0004\u0018\u00010:8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b;\u0010<R\"\u0010E\u001a\u00020>8\u0004@\u0004X\u0085.¢\u0006\u0012\n\u0004\b?\u0010@\u001a\u0004\bA\u0010B\"\u0004\bC\u0010DR\"\u0010M\u001a\u00020F8\u0004@\u0004X\u0085.¢\u0006\u0012\n\u0004\bG\u0010H\u001a\u0004\bI\u0010J\"\u0004\bK\u0010LR\u0018\u0010P\u001a\u0004\u0018\u00010&8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bN\u0010OR\u001e\u0010S\u001a\n\u0012\u0004\u0012\u00020\u001f\u0018\u00010)8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bQ\u0010RR\u001e\u0010U\u001a\n\u0012\u0004\u0012\u00020\u0019\u0018\u00010)8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bT\u0010RR\u001e\u0010+\u001a\n\u0012\u0004\u0012\u00020\u0019\u0018\u00010)8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bV\u0010RR\u0016\u0010Y\u001a\u00020\u00198\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bW\u0010XR\u0016\u0010[\u001a\u00020\u00198\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\bZ\u0010XR\u0014\u0010^\u001a\u00020\u00038\u0016X\u0096\u0005¢\u0006\u0006\u001a\u0004\b\\\u0010]¨\u0006c"}, d2 = {"Lve/d;", "Lu8/b;", "", "Lse/e;", "Lcom/google/android/gms/maps/OnMapReadyCallback;", "Lcom/google/android/gms/maps/GoogleMap$OnMyLocationButtonClickListener;", "Lrm/n0;", "a0", "Y", "W", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/os/Bundle;", "savedInstanceState", "Landroidx/lifecycle/u;", "viewLifecycleOwner", "Landroidx/lifecycle/z0;", "viewModel", "Landroid/view/View;", "R", "onCreateView", "view", "onViewCreated", "", "onMyLocationButtonClick", "Lcom/google/android/gms/maps/GoogleMap;", "googleMap", "onMapReady", "b0", "Landroid/location/Location;", FirebaseAnalytics.Param.LOCATION, "S", "Lcom/google/android/gms/maps/model/MarkerOptions;", "options", "Lcom/google/android/gms/maps/model/Marker;", "M", "Lcom/google/android/gms/maps/GoogleMap$OnMarkerClickListener;", ServiceSpecificExtraArgs.CastExtraArgs.LISTENER, "V", "Lw8/f;", "T", "onLocationTurnOnListener", "U", "onPause", "onResume", "onDestroy", "outState", "onSaveInstanceState", "onLowMemory", "Lve/f;", "t", "Lrm/o;", "Q", "()Lve/f;", "u", "Lcom/google/android/gms/maps/GoogleMap;", "Lcom/google/android/gms/maps/MapView;", "v", "Lcom/google/android/gms/maps/MapView;", "mMapView", "Lg8/a;", "w", "Lg8/a;", "O", "()Lg8/a;", "setLocationService", "(Lg8/a;)V", "locationService", "Lq8/a;", "x", "Lq8/a;", "P", "()Lq8/a;", "setPermissionServices", "(Lq8/a;)V", "permissionServices", "y", "Lcom/google/android/gms/maps/GoogleMap$OnMarkerClickListener;", "onMarkerClickListener", "z", "Lw8/f;", "initialLocationListener", "A", "onMapReadyListener", "B", "C", "Z", "noLocationCheck", "D", "hideLocationButton", "N", "()Lse/e;", "binding", "<init>", "()V", "E", "a", "findpostal_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class d extends u8.b implements OnMapReadyCallback, GoogleMap.OnMyLocationButtonClickListener {

    /* renamed from: E, reason: from kotlin metadata */
    public static final Companion INSTANCE = new Companion(null);
    private static final String F;
    private static final LatLng G;

    /* renamed from: A, reason: from kotlin metadata */
    private w8.f onMapReadyListener;

    /* renamed from: B, reason: from kotlin metadata */
    private w8.f onLocationTurnOnListener;

    /* renamed from: C, reason: from kotlin metadata */
    private boolean noLocationCheck;

    /* renamed from: D, reason: from kotlin metadata */
    private boolean hideLocationButton;

    /* renamed from: s, reason: collision with root package name */
    private final /* synthetic */ x f39653s = new x(o.f34676c);

    /* renamed from: t, reason: collision with root package name and from kotlin metadata */
    private final rm.o viewModel = p0.a(this, kotlin.jvm.internal.p0.b(ve.f.class), new e(new C0945d(this)), new f());

    /* renamed from: u, reason: collision with root package name and from kotlin metadata */
    private GoogleMap googleMap;

    /* renamed from: v, reason: collision with root package name and from kotlin metadata */
    private MapView mMapView;

    /* renamed from: w, reason: collision with root package name and from kotlin metadata */
    protected g8.a locationService;

    /* renamed from: x, reason: collision with root package name and from kotlin metadata */
    protected q8.a permissionServices;

    /* renamed from: y, reason: collision with root package name and from kotlin metadata */
    private GoogleMap.OnMarkerClickListener onMarkerClickListener;

    /* renamed from: z, reason: collision with root package name and from kotlin metadata */
    private w8.f initialLocationListener;

    /* renamed from: ve.d$a, reason: from kotlin metadata */
    /* loaded from: classes4.dex */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(k kVar) {
            this();
        }

        public final String a() {
            return d.F;
        }
    }

    /* loaded from: classes4.dex */
    static final class b extends v implements l {
        b() {
            super(1);
        }

        public final void a(Boolean bool) {
            t.d(bool);
            if (bool.booleanValue()) {
                d.this.a0();
            }
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Boolean) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class c implements g0, n {

        /* renamed from: a, reason: collision with root package name */
        private final /* synthetic */ l f39662a;

        c(l function) {
            t.g(function, "function");
            this.f39662a = function;
        }

        @Override // kotlin.jvm.internal.n
        public final i b() {
            return this.f39662a;
        }

        @Override // androidx.lifecycle.g0
        public final /* synthetic */ void d(Object obj) {
            this.f39662a.invoke(obj);
        }

        public final boolean equals(Object obj) {
            if ((obj instanceof g0) && (obj instanceof n)) {
                return t.b(b(), ((n) obj).b());
            }
            return false;
        }

        public final int hashCode() {
            return b().hashCode();
        }
    }

    /* renamed from: ve.d$d, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    public static final class C0945d extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ androidx.fragment.app.f f39663p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C0945d(androidx.fragment.app.f fVar) {
            super(0);
            this.f39663p = fVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final androidx.fragment.app.f invoke() {
            return this.f39663p;
        }
    }

    /* loaded from: classes4.dex */
    public static final class e extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ dn.a f39664p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public e(dn.a aVar) {
            super(0);
            this.f39664p = aVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final d1 invoke() {
            d1 viewModelStore = ((e1) this.f39664p.invoke()).getViewModelStore();
            t.f(viewModelStore, "ownerProducer().viewModelStore");
            return viewModelStore;
        }
    }

    /* loaded from: classes4.dex */
    static final class f extends v implements dn.a {
        f() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final c1.c invoke() {
            return d.this.y();
        }
    }

    static {
        String name = d.class.getName();
        t.f(name, "getName(...)");
        F = name;
        G = new LatLng(53.0d, -95.0d);
    }

    private final ve.f Q() {
        return (ve.f) this.viewModel.getValue();
    }

    private final void W() {
        O().b(new w8.f() { // from class: ve.c
            @Override // w8.f
            public final void accept(Object obj) {
                d.X(d.this, (Location) obj);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void X(d this$0, Location location) {
        t.g(this$0, "this$0");
        if (this$0.Q().R().f() == null) {
            t.d(location);
            this$0.S(location);
            w8.f fVar = this$0.initialLocationListener;
            if (fVar != null && fVar != null) {
                fVar.accept(location);
            }
        }
        this$0.O().a();
    }

    private final void Y() {
        GoogleMap googleMap = this.googleMap;
        if (googleMap != null) {
            googleMap.setOnMarkerClickListener(this.onMarkerClickListener);
        }
        GoogleMap googleMap2 = this.googleMap;
        if (googleMap2 != null) {
            Context context = getContext();
            googleMap2.setMapStyle(context != null ? MapStyleOptions.loadRawResourceStyle(context, h7.k.f21112a) : null);
        }
        final boolean z10 = false;
        if (this.hideLocationButton) {
            GoogleMap googleMap3 = this.googleMap;
            UiSettings uiSettings = googleMap3 != null ? googleMap3.getUiSettings() : null;
            if (uiSettings != null) {
                uiSettings.setMyLocationButtonEnabled(false);
            }
        }
        if (!P().a("android.permission.ACCESS_FINE_LOCATION") && !P().a("android.permission.ACCESS_COARSE_LOCATION")) {
            z10 = true;
        }
        if (this.noLocationCheck && z10) {
            return;
        }
        P().c(new String[]{"android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"}, new w8.f() { // from class: ve.a
            @Override // w8.f
            public final void accept(Object obj) {
                d.Z(d.this, z10, (a.EnumC0774a) obj);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Z(d this$0, boolean z10, a.EnumC0774a enumC0774a) {
        GoogleMap googleMap;
        CameraUpdate newLatLngZoom;
        t.g(this$0, "this$0");
        a.EnumC0774a enumC0774a2 = a.EnumC0774a.GRANTED;
        if (enumC0774a == enumC0774a2 && (googleMap = this$0.googleMap) != null) {
            if (googleMap != null) {
                googleMap.setOnMyLocationButtonClickListener(this$0);
            }
            if (this$0.Q().R().f() != null) {
                Object f10 = this$0.Q().R().f();
                t.d(f10);
                Location location = (Location) f10;
                LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
                Object f11 = this$0.Q().Q().f();
                t.d(f11);
                newLatLngZoom = CameraUpdateFactory.newLatLngZoom(latLng, ((Number) f11).floatValue());
            } else {
                newLatLngZoom = CameraUpdateFactory.newLatLngZoom(G, 2.0f);
            }
            t.d(newLatLngZoom);
            GoogleMap googleMap2 = this$0.googleMap;
            if (googleMap2 != null) {
                googleMap2.moveCamera(newLatLngZoom);
            }
            this$0.W();
        }
        if (z10) {
            if (enumC0774a == enumC0774a2) {
                w8.f fVar = this$0.onLocationTurnOnListener;
                if (fVar != null) {
                    fVar.accept(Boolean.TRUE);
                    return;
                }
                return;
            }
            w8.f fVar2 = this$0.onLocationTurnOnListener;
            if (fVar2 != null) {
                fVar2.accept(Boolean.FALSE);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void a0() {
        MapView mapView = this.mMapView;
        if (mapView != null) {
            mapView.getMapAsync(this);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void c0(d this$0, Location location) {
        t.g(this$0, "this$0");
        t.d(location);
        this$0.S(location);
        w8.f fVar = this$0.initialLocationListener;
        if (fVar != null && fVar != null) {
            fVar.accept(location);
        }
        this$0.O().a();
    }

    public final Marker M(MarkerOptions options) {
        t.g(options, "options");
        GoogleMap googleMap = this.googleMap;
        if (googleMap == null || googleMap == null) {
            return null;
        }
        return googleMap.addMarker(options);
    }

    public se.e N() {
        return (se.e) this.f39653s.b();
    }

    protected final g8.a O() {
        g8.a aVar = this.locationService;
        if (aVar != null) {
            return aVar;
        }
        t.y("locationService");
        return null;
    }

    protected final q8.a P() {
        q8.a aVar = this.permissionServices;
        if (aVar != null) {
            return aVar;
        }
        t.y("permissionServices");
        return null;
    }

    public View R(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, u viewLifecycleOwner, z0 viewModel) {
        t.g(inflater, "inflater");
        t.g(viewLifecycleOwner, "viewLifecycleOwner");
        t.g(viewModel, "viewModel");
        return this.f39653s.c(inflater, container, savedInstanceState, viewLifecycleOwner, viewModel);
    }

    public final void S(Location location) {
        t.g(location, "location");
        if (this.googleMap != null) {
            CameraUpdate newLatLngZoom = CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 17.0f);
            t.f(newLatLngZoom, "newLatLngZoom(...)");
            GoogleMap googleMap = this.googleMap;
            if (googleMap != null) {
                googleMap.moveCamera(newLatLngZoom);
            }
            Q().U(location);
            Q().T(17.0f);
        }
    }

    public final void T(w8.f listener) {
        t.g(listener, "listener");
        this.initialLocationListener = listener;
    }

    public final void U(w8.f onLocationTurnOnListener) {
        t.g(onLocationTurnOnListener, "onLocationTurnOnListener");
        this.onLocationTurnOnListener = onLocationTurnOnListener;
    }

    public final void V(GoogleMap.OnMarkerClickListener listener) {
        t.g(listener, "listener");
        this.onMarkerClickListener = listener;
        GoogleMap googleMap = this.googleMap;
        if (googleMap != null) {
            googleMap.setOnMarkerClickListener(listener);
        }
    }

    public final void b0() {
        O().b(new w8.f() { // from class: ve.b
            @Override // w8.f
            public final void accept(Object obj) {
                d.c0(d.this, (Location) obj);
            }
        });
    }

    @Override // androidx.fragment.app.f
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        t.g(inflater, "inflater");
        u viewLifecycleOwner = getViewLifecycleOwner();
        t.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
        View R = R(inflater, container, savedInstanceState, viewLifecycleOwner, Q());
        MapView mapView = N().A;
        this.mMapView = mapView;
        if (mapView != null) {
            mapView.onCreate(savedInstanceState);
        }
        return R;
    }

    @Override // androidx.fragment.app.f
    public void onDestroy() {
        super.onDestroy();
        MapView mapView = this.mMapView;
        if (mapView != null) {
            mapView.onDestroy();
        }
    }

    @Override // androidx.fragment.app.f, android.content.ComponentCallbacks
    public void onLowMemory() {
        super.onLowMemory();
        MapView mapView = this.mMapView;
        if (mapView != null) {
            mapView.onLowMemory();
        }
    }

    @Override // com.google.android.gms.maps.OnMapReadyCallback
    public void onMapReady(GoogleMap googleMap) {
        t.g(googleMap, "googleMap");
        this.googleMap = googleMap;
        Y();
        w8.f fVar = this.onMapReadyListener;
        if (fVar == null || fVar == null) {
            return;
        }
        fVar.accept(Boolean.TRUE);
    }

    @Override // com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener
    public boolean onMyLocationButtonClick() {
        return false;
    }

    @Override // androidx.fragment.app.f
    public void onPause() {
        super.onPause();
        MapView mapView = this.mMapView;
        if (mapView != null) {
            mapView.onPause();
        }
        O().a();
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onResume() {
        super.onResume();
        MapView mapView = this.mMapView;
        if (mapView != null) {
            mapView.onResume();
        }
    }

    @Override // androidx.fragment.app.f
    public void onSaveInstanceState(Bundle outState) {
        t.g(outState, "outState");
        super.onSaveInstanceState(outState);
        MapView mapView = this.mMapView;
        if (mapView != null) {
            mapView.onSaveInstanceState(outState);
        }
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        t.g(view, "view");
        super.onViewCreated(view, bundle);
        Bundle arguments = getArguments();
        if (arguments != null) {
            if (arguments.containsKey("GOOGLE_MAP_NO_LOCATION_CHECK")) {
                this.noLocationCheck = arguments.getBoolean("GOOGLE_MAP_NO_LOCATION_CHECK", false);
            }
            if (arguments.containsKey("GOOGLE_MAP_HIDE_LOCATION_BUTTON")) {
                this.hideLocationButton = arguments.getBoolean("GOOGLE_MAP_HIDE_LOCATION_BUTTON", false);
            }
        }
        Q().S().j(getViewLifecycleOwner(), new c(new b()));
    }
}
