package com.atmob.map_amap_android.amap;

import android.app.Activity;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleOwner;

import java.util.Map;

import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;

public class MapViewFactory extends PlatformViewFactory {

    private final Activity activity;
    private final BinaryMessenger messenger;
    private final LifecycleOwner lifecycleProvider;

    public MapViewFactory(Activity activity, BinaryMessenger messenger, LifecycleOwner lifecycleProvider) {
        super(StandardMessageCodec.INSTANCE);
        this.activity = activity;
        this.messenger = messenger;
        this.lifecycleProvider = lifecycleProvider;
    }

    @NonNull
    @Override
    public PlatformView create(Context context, int viewId, @Nullable Object args) {
        Map<String, Object> params = null;
        if (args instanceof Map) {
            params = (Map<String, Object>) args;
        }
        return new AmapView(context, activity, messenger, viewId, params,lifecycleProvider);
    }
}
