var __spreadArray=this&&this.__spreadArray||function(e,t,i){if(i||arguments.length===2)for(var r=0,a=t.length,n;r<a;r++){if(n||!(r in t)){if(!n)n=Array.prototype.slice.call(t,0,r);n[r]=t[r]}}return e.concat(n||Array.prototype.slice.call(t))};import{r as registerInstance,c as createEvent,h,H as Host}from"./index-ecdfb761.js";import{D as DvnDataAdapter}from"./DvnDataAdapter-536a3258.js";import{D as DataApiImpl}from"./dataApi-c77b0bad.js";import{r as renderReference}from"./util-214b9543.js";import{D as DvnDataProvider}from"./DvnDataProvider-86fd3a3b.js";import{g as getSessionData}from"./index-7d83a942.js";import{d as dataApiEndpoint}from"./env-bd518340.js";import"./apiBase-648a161d.js";import"./data-transfer-field-2f305919.js";import"./BaseField-0b01dc2c.js";import"./filter-cbaa3d7d.js";import"./list-fetch-state-d8c2f8ef.js";import"./data-model-f7ccf826.js";import"./kimlik-api-66e341bd.js";import"./cookie-9f22e0fb.js";import"./_commonjsHelpers-27f122dd.js";var dvnFieldInputCellReferenceCss="dvn-field-input-cell-reference{display:-ms-flexbox;display:flex;overflow:auto;padding:0 4px}";var DvnFieldInputCellReference=function(){function e(e){registerInstance(this,e);this.cellFormCancel=createEvent(this,"cellFormCancel",7);this.cellFormSubmit=createEvent(this,"cellFormSubmit",7)}e.prototype.onAction=function(e){if(e.detail.name==="dvn-field-input-cell-reference.remove-item"){e.stopImmediatePropagation();var t=e.detail.params.item;this.internalValue=this.internalValue.filter((function(e){return e._id!==t._id}))}};e.prototype.componentWillLoad=function(){this.internalValue=this.value||[];this.dataProvider=getDataProvider(this.field)};e.prototype.render=function(){var e;var t=this;var i=this,r=i.field,a=i.internalValue,n=i.meta;var l=this.value||[];return h(Host,null,Array.isArray(l)?l.map((function(e){return renderReference(r,e,n)})):renderReference(r,l,n),h("dvn-dialog",{shown:true,onDismiss:function(){return t.cellFormCancel.emit()}},h("dvn-select",{dataAdapter:new DvnDataAdapter(r.titleField,"_id"),dataProvider:this.dataProvider,onChange:function(e){var i,r;e.stopImmediatePropagation();var a=(r=(i=t.dataProvider.list)===null||i===void 0?void 0:i.data)===null||r===void 0?void 0:r.find((function(t){return t._id===e.detail}));t.internalValue=__spreadArray(__spreadArray([],t.internalValue,true),[a],false)},leaned:true,width:"100%",value:[]}),h("dvn-list-view-table",{config:{hideHeader:true,separation:1,actions:[{ui:{name:"dvn-field-input-cell-reference.remove-item",buttonType:"icon-button",iconName:"uil uil-trash-alt",tint:"danger",view:"flat"}}],fields:[{fieldId:r.imageField},{fieldId:r.titleField}],columns:(e={},e[r.imageField]={width:50},e)},fields:r.fields,items:a,isEndReached:true}),h("div",{slot:"actions"},h("dvn-button",{view:"flat",onClick:function(e){e.stopImmediatePropagation();t.cellFormCancel.emit()}},"Cancel"),h("dvn-button",{tint:"primary",view:"flat",onClick:function(e){e.stopImmediatePropagation();t.cellFormSubmit.emit({value:t.internalValue,apiValue:t.internalValue.map((function(e){return convertToRef(r,e)}))})}},"Save"))))};return e}();function getDataProvider(e){var t=new DataApiImpl(dataApiEndpoint,{Authorization:"Bearer ".concat(getSessionData().token)});return new DvnDataProvider(t,e.otherCollection,{fields:e.fields,sort:[{id:e.titleField,order:1}]},undefined,{fields:[{fieldId:e.imageField},{fieldId:e.titleField}]})}function convertToRef(e,t){var i=t._id;return{_ref:e.otherCollection,_id:i}}DvnFieldInputCellReference.style=dvnFieldInputCellReferenceCss;export{DvnFieldInputCellReference as dvn_field_input_cell_reference};