'use strict';
import { apiGetWithOData } from '../../../../fd-toolbox/api/api-client.js';
import { getPropertyMeta } from '../../edit-resource/services/property-metas.js';
import { setMultiBrowserDescription } from '../../services/multi-browser.js';
import { getPropertyValue } from '../../../../fd-toolbox/objects/property-value.js';
import { getViewMultiListFiltersForManyToManyBrowserField } from '../../services/property-fields.js';
import { fetchUiResourceMeta } from '../../ui-meta-providers.js';
import { clearBrowserSelection } from '../browser-selection.js';

var __defProp=Object['defineProperty'],__name=(_0x3c233d,_0x1a116a)=>__defProp(_0x3c233d,'name',{'value':_0x1a116a,'configurable':!![]});async function writeValue(_0x234853,_0x3a72a0,_0x40eed9,_0x2507ae,_0x5035d2,_0xfb18ca,_0x2160f4,_0x58e371){const _0x1bc225=await fetchManyToManyBrowserRelatedResources(_0x234853,_0x2160f4);let _0x45a0e3,_0x4e607d=[];_0x234853['relation']['manyToManyInfo']['isMirrorManyToManyResource']&&(_0x4e607d=_0x1bc225['data']['map'](_0x470397=>{const _0xda4335=_0x234853['relation']['manyToManyInfo']['firstExpandPropertyName'];return getPropertyValue(_0x470397,_0xda4335);}));let _0x4a71f4=_0x1bc225['data']['map'](_0x3b023b=>{const _0x350161=_0x234853['relation']['manyToManyInfo']['secondExpandPropertyName'];return getPropertyValue(_0x3b023b,_0x350161);});_0x45a0e3=[..._0x4e607d,..._0x4a71f4]['filter'](_0x2264e6=>_0x2264e6?.['id']!==_0x2160f4),_0x3a72a0(_0x45a0e3);const _0x32b828=await getManyToManyBrowserRelatedResourcePropertyMeta(_0x234853);_0x5035d2(_0x32b828);const _0x10a8e0=await getManyToManyBrowserPropertyResourceMeta(_0x234853,_0xfb18ca);_0x40eed9(_0x10a8e0),_0x58e371?.(_0x45a0e3['map'](_0x5e4e6f=>_0x5e4e6f['id'])),_0x2507ae(!![]);}__name(writeValue,'writeValue');async function closeManyToManyBrowserDialog(_0x1799e4,_0x70284a,_0x1569ea,_0x1c6d1e,_0x14fad9,_0x225d42){const _0x364812=await getManyToManyBrowserPropertyResourceMeta(_0x1569ea,_0x14fad9);_0x1c6d1e(_0x364812),_0x70284a(_0x1799e4),_0x225d42?.(_0x1799e4,_0x364812);}__name(closeManyToManyBrowserDialog,'closeManyToManyBrowserDialog');async function getManyToManyBrowserRelatedResourcePropertyMeta(_0x574eba){const _0x41ed11=await getPropertyMeta(_0x574eba['relation']['manyToManyInfo']['manyToManySecondPropertyName'],_0x574eba['relation']['manyToManyInfo']['manyToManyResourceName']);return _0x41ed11;}__name(getManyToManyBrowserRelatedResourcePropertyMeta,'getManyToManyBrowserRelatedResourcePropertyMeta');async function setManyToManyDescription(_0x5cea8e,_0x17b5f3,_0x20cccc){setMultiBrowserDescription(_0x17b5f3,_0x20cccc,_0x5cea8e);}__name(setManyToManyDescription,'setManyToManyDescription');function onManyToManyBrowserInputUpdate(_0x1e4769,_0x1c5d4e,_0x37dd60,_0x4a830c){_0x1e4769===''&&clearBrowserSelection(_0x1c5d4e,_0x37dd60,_0x4a830c);}__name(onManyToManyBrowserInputUpdate,'onManyToManyBrowserInputUpdate');function fetchManyToManyBrowserRelatedResources(_0x1003b8,_0x341505){let _0x556828;return _0x1003b8['relation']['manyToManyInfo']['isMirrorManyToManyResource']?_0x556828=[_0x1003b8['relation']['manyToManyInfo']['firstExpandPropertyName'],_0x1003b8['relation']['manyToManyInfo']['secondExpandPropertyName']]:_0x556828=[_0x1003b8['relation']['manyToManyInfo']['secondExpandPropertyName']],apiGetWithOData(_0x1003b8['relation']['manyToManyInfo']['manyToManyResourceName'],{'filters':getViewMultiListFiltersForManyToManyBrowserField(_0x1003b8,_0x341505),'expands':_0x556828});}__name(fetchManyToManyBrowserRelatedResources,'fetchManyToManyBrowserRelatedResources');async function getManyToManyBrowserPropertyResourceMeta(_0x2338ed,_0x5c2019){if(_0x5c2019)return _0x5c2019;const _0x2b05ec=await getManyToManyBrowserRelatedResourcePropertyMeta(_0x2338ed),_0xe3232=await fetchUiResourceMeta(_0x2b05ec['relation']['relatedResourceName']);return _0xe3232['resourceMeta'];}__name(getManyToManyBrowserPropertyResourceMeta,'getManyToManyBrowserPropertyResourceMeta');

export { closeManyToManyBrowserDialog, getManyToManyBrowserRelatedResourcePropertyMeta, onManyToManyBrowserInputUpdate, setManyToManyDescription, writeValue };
