import{r as i,c as t,h as s,H as r}from"./p-ec7718e6.js";import"./p-2d511d0e.js";import"./p-3c3b4f3f.js";import"./p-d66fb38c.js";import{g as e}from"./p-e249790d.js";import"./p-552063c3.js";import{S as o}from"./p-9c626387.js";import"./p-d343a062.js";import{I as n,N as a}from"./p-6cf8ecf7.js";import{I as c}from"./p-4b573471.js";import{f as p}from"./p-38c6a29e.js";import"./p-f46dff5e.js";import{I as l}from"./p-db7d4eb0.js";import{c as m}from"./p-29c0ca6e.js";const d=(i,t={})=>{const s=m(i.conversionConfig,t);return i.ui.fields.map((t=>{var r;const n=e((a=t).field||p(i.table.fields,a.fieldId));var a;const c=s[n.id];if(c&&n.type===o.type){const i=n;i.dataProvider&&i.dataProvider.setInitialData([c]),n.setValue((null===(r=i.dataAdapter)||void 0===r?void 0:r.value(c))||c)}else n.setValue(c);return n}))},f=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=c.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 n&&this.invalidation.emit(i),i instanceof a&&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:o}=r;e&&(this.itemDataProvider=new l(t,{itemId:s.itemId},o,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:e,isProgressing:o}=this,{i18n:n}=i.ui;if(!i.query)return s(r,null,s("h3",null,i.title),s("doldurma-form",{fields:d(i,t),onSubmit:this.onSubmit,submitButtonLabel:n.submit||"Submit",progressing:o,formErrors:e}));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:d(i,Object.assign(Object.assign({},t),{item:a.data})),onSubmit:this.onSubmit,submitButtonLabel:n.submit||"Submit",progressing:o,formErrors:e}),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)))}};f.style=".sc-dvn-app-view-form-view-h{display:flex;flex:1;padding:calc(4 * var(--spacing-unit));flex-direction:column}.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{f as dvn_app_view_form_view}