import {YMapMiniMapProps} from '@yandex/ymaps3-minimap';
import {YMapControl} from '@yandex/ymaps3-types';
import {MINIMAP_BOUNDS_STYLE} from './variables';

import type {Feature} from '@yandex/ymaps3-types';
import type {YMapDefaultMarkerProps} from '@yandex/ymaps3-default-ui-theme';
import type {YMapLocationRequest} from '@yandex/ymaps3-types/imperative/YMap';

ymaps3.import.registerCdn('https://cdn.jsdelivr.net/npm/{package}', ['@yandex/ymaps3-minimap@0.0.3','@yandex/ymaps3-default-ui-theme@0.0','@yandex/ymaps3-clusterer@0.0','@yandex/ymaps3-hint@0.1']);


export const MINIMAP_PROPS: YMapMiniMapProps = {
    size: [220, 130],
    showCollapsedControl: false,
    zoomOffset: 3,
    showBounds: true,
    boundsDrawingStyle: MINIMAP_BOUNDS_STYLE
};

export const COMMON_LOCATION_PARAMS: YMapLocationRequest = {easing: 'ease-in-out', duration: 2000, zoom: 16};

export type ExtendedFeature = {
    properties: Feature['properties'] & {
        id: string;
        iconName: YMapDefaultMarkerProps['iconName'];
    };
    geometry: Feature['geometry'];
};

export function searchFromList(text: string, objects: ExtendedFeature[]): Feature[] {
    const trimmedText = text.trim().toLowerCase();
    return objects.filter((object) => {
        const trimmedObjectName = object.properties.name.trim().toLowerCase();
        const trimmedObjectDescription = object.properties.id.trim().toLowerCase();
        return trimmedObjectDescription.includes(trimmedText) || trimmedObjectName.includes(trimmedText);
    });
}


export const MARKER_PROPS: Omit<YMapDefaultMarkerProps, 'popup'> = {
    coordinates: [82.9291, 55.0111] as LngLat,
    size: 'normal',
    iconName: 'fallback',
    properties: {
        hint: {
            title: 'Title of that pop up',
            text: 'Some useful information about a place. You can add whatever you want: pictures, buttons, different headings.'
        }
    }
};
