import{r as i,c as e,h as t,H as s}from"./p-a0569a5f.js";import{D as o}from"./p-d93d87fd.js";import{D as n}from"./p-69daa26b.js";import{r}from"./p-3195c585.js";import{D as a,d}from"./p-04642aa0.js";import{g as l}from"./p-4ebc5d09.js";import"./p-e476a838.js";import"./p-944da115.js";import"./p-eebad85b.js";import"./p-d343a062.js";import"./p-e7b87b96.js";import"./p-7737f905.js";import"./p-31309282.js";import"./p-1bea6126.js";import"./p-814af281.js";let p=class{constructor(t){i(this,t),this.cellFormCancel=e(this,"cellFormCancel",7),this.cellFormSubmit=e(this,"cellFormSubmit",7)}onAction(i){if("dvn-field-input-cell-reference.remove-item"===i.detail.name){i.stopImmediatePropagation();const e=i.detail.params.item;this.internalValue=this.internalValue.filter((i=>i._id!==e._id))}}componentWillLoad(){this.internalValue=this.value||[],this.dataProvider=function(i){const e=new n(d,{Authorization:`Bearer ${l().token}`});return new a(e,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:e,meta:n}=this,a=this.value||[];return t(s,null,Array.isArray(a)?a.map((e=>r(i,e,n))):r(i,a,n),t("dvn-dialog",{clip:!1,shown:!0,onDismiss:()=>this.cellFormCancel.emit()},t("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:e,isEndReached:!0}),t("br",null),t("dvn-select",{dataAdapter:new o(i.titleField,"_id"),dataProvider:this.dataProvider,onChange:i=>{var e,t;i.stopImmediatePropagation();const s=null===(t=null===(e=this.dataProvider.list)||void 0===e?void 0:e.data)||void 0===t?void 0:t.find((e=>e._id===i.detail));this.internalValue=[...this.internalValue,s]},leaned:!0,width:"100%",value:[]}),t("div",{slot:"actions"},t("dvn-button",{view:"flat",onClick:i=>{i.stopImmediatePropagation(),this.cellFormCancel.emit()}},"Cancel"),t("dvn-button",{tint:"primary",view:"flat",onClick:e=>{e.stopImmediatePropagation(),this.cellFormSubmit.emit({value:this.internalValue,apiValue:this.internalValue.map((e=>function(i,{_id:e}){return{_ref:i.otherCollection,_id:e}}(i,e)))})}},"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}