import{r as i,c as t,h as e,H as s}from"./p-9f21f85f.js";import{D as o}from"./p-d93d87fd.js";import{D as n}from"./p-fb51892f.js";import{r}from"./p-aac7454b.js";import{D as d}from"./p-33652948.js";import{g as a}from"./p-a1d8623c.js";import{d as l}from"./p-499f0d68.js";import"./p-e78d5616.js";import"./p-3968aca6.js";import"./p-105f7627.js";import"./p-d343a062.js";import"./p-e7b87b96.js";import"./p-7737f905.js";import"./p-03b520ca.js";import"./p-84876749.js";import"./p-814af281.js";const p=class{constructor(e){i(this,e),this.cellFormCancel=t(this,"cellFormCancel",7),this.cellFormSubmit=t(this,"cellFormSubmit",7)}onAction(i){if("dvn-field-input-cell-reference.remove-item"===i.detail.name){i.stopImmediatePropagation();const t=i.detail.params.item;this.internalValue=this.internalValue.filter((i=>i._id!==t._id))}}componentWillLoad(){this.internalValue=this.value||[],this.dataProvider=function(i){const t=new n(l,{Authorization:`Bearer ${a().token}`});return new d(t,i.otherCollection,{fields:i.fields,sort:[{id:i.titleField,order:1}]},void 0,{fields:[{fieldId:i.imageField},{fieldId:i.titleField}]})}(this.field)}render(){const{field:i,internalValue:t,meta:n}=this,d=this.value||[];return e(s,null,Array.isArray(d)?d.map((t=>r(i,t,n))):r(i,d,n),e("dvn-dialog",{shown:!0,onDismiss:()=>this.cellFormCancel.emit()},e("dvn-select",{dataAdapter:new o(i.titleField,"_id"),dataProvider:this.dataProvider,onChange:i=>{var t,e;i.stopImmediatePropagation();const s=null===(e=null===(t=this.dataProvider.list)||void 0===t?void 0:t.data)||void 0===e?void 0:e.find((t=>t._id===i.detail));this.internalValue=[...this.internalValue,s]},leaned:!0,width:"100%",value:[]}),e("dvn-list-view-table",{config:{hideHeader:!0,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:i.imageField},{fieldId:i.titleField}],columns:{[i.imageField]:{width:50}}},fields:i.fields,items:t,isEndReached:!0}),e("div",{slot:"actions"},e("dvn-button",{view:"flat",onClick:i=>{i.stopImmediatePropagation(),this.cellFormCancel.emit()}},"Cancel"),e("dvn-button",{tint:"primary",view:"flat",onClick:t=>{t.stopImmediatePropagation(),this.cellFormSubmit.emit({value:this.internalValue,apiValue:this.internalValue.map((t=>function(i,{_id:t}){return{_ref:i.otherCollection,_id:t}}(i,t)))})}},"Save"))))}};p.style="dvn-field-input-cell-reference{display:-ms-flexbox;display:flex;overflow:auto;padding:0 4px}";export{p as dvn_field_input_cell_reference}