import{r as i,c as t,h as s,H as r}from"./p-9f21f85f.js";import{I as o}from"./p-f7077f5c.js";import{c as e}from"./p-ec967453.js";import{g as n}from"./p-62d6b6a7.js";import{S as a}from"./p-1187cc7c.js";import{I as p,N as c}from"./p-6cf8ecf7.js";import{I as m}from"./p-1dd4a9a0.js";import{f as l}from"./p-35eb47f9.js";import"./p-7737f905.js";import"./p-d343a062.js";import"./p-f46dff5e.js";import"./p-0563ceba.js";import"./p-105f7627.js";import"./p-1e47e7bd.js";import"./p-31e77e7b.js";import"./p-825ab276.js";import"./p-6c8be41c.js";import"./p-9f31253b.js";import"./p-881a2bb8.js";import"./p-968ee2ec.js";const f=(i,t={})=>{const s=e(i.conversionConfig,t);return i.ui.fields.map((t=>{var r;const o=n((e=t).field||l(i.table.fields,e.fieldId));var e;const p=s[o.id];if(p&&o.type===a.type){const i=o;i.dataProvider&&i.dataProvider.setInitialData([p]),o.setValue((null===(r=i.dataAdapter)||void 0===r?void 0:r.value(p))||p)}else p&&o.setValue(p);return o}))},d=class{constructor(s){i(this,s),this.action=t(this,"action",7),this.invalidation=t(this,"invalidation",7),this.notification=t(this,"notification",7),this.isProgressing=!1,this.itemFetchState=m.init(),this.onSubmit=i=>{this.view.handler.onSubmit&&(this.isProgressing=!0,this.formErrors=void 0,this.view.handler.onSubmit(i).then((i=>{this.isProgressing=!1,(null==i?void 0:i.events)&&i.events.forEach((i=>{i instanceof p&&this.invalidation.emit(i),i instanceof c&&this.notification.emit(i)})),(null==i?void 0:i.navigation)&&this.action.emit(i.navigation)})).catch((i=>{this.isProgressing=!1,this.formErrors=i})))}}componentWillLoad(){var i;const{apiData:t,params:s,view:r}=this,{query:e,table:n}=r;e&&(this.itemDataProvider=new o(t,{itemId:s.itemId},n,e,e.fields,(i=>{this.itemFetchState=i})),null===(i=this.itemDataProvider)||void 0===i||i.fetchData(this.itemFetchState))}componentDidUpdate(){var i;const{itemFetchState:t}=this;t.data||t.isPending||t.error||null===(i=this.itemDataProvider)||void 0===i||i.fetchData(this.itemFetchState)}async invalidate(i){var t;null===(t=this.itemDataProvider)||void 0===t||t.fetchData(this.itemFetchState)}render(){const{view:i,params:t,formErrors:o,isProgressing:e}=this,{i18n:n={}}=i.ui;if(!i.query)return s(r,null,s("h3",null,i.title),s("doldurma-form",{fields:f(i,t),onSubmit:this.onSubmit,submitButtonLabel:n.submit||"Submit",progressing:e,formErrors:o}));const{itemFetchState:a}=this;return s(r,null,!a.isPending&&!a.error&&s("h3",null,i.title),!a.isPending&&!a.error&&s("doldurma-form",{fields:f(i,Object.assign(Object.assign({},t),{item:a.data})),onSubmit:this.onSubmit,submitButtonLabel:n.submit||"Submit",progressing:e,formErrors:o}),a.isPending&&s("div",{class:"d-flex flex-grow-1 align-items-center justify-content-center detail-view-progress-container"},s("dvn-progress",{indefinite:!0,tint:"primary"})),a.error&&s("div",{class:"d-flex flex-grow-1 align-items-center justify-content-center flex-column detail-view-progress-container"},n.fetchError||"Fetching data failed.",s("dvn-button",{onClick:()=>{var i;return null===(i=this.itemDataProvider)||void 0===i?void 0:i.fetchData(this.itemFetchState)}},n.retry)))}};d.style=".sc-dvn-app-view-form-view-h{display:-ms-flexbox;display:flex;-ms-flex:1;flex:1;padding:calc(4 * var(--spacing-unit));-ms-flex-direction:column;flex-direction:column;overflow:auto}.sc-dvn-app-view-form-view-h .progress-container.sc-dvn-app-view-form-view{padding:calc(4 * var(--spacing-unit))}.sc-dvn-app-view-form-view-h h3.sc-dvn-app-view-form-view{margin:0 0 calc(6 * var(--spacing-unit))}";export{d as dvn_app_view_form_view}