import{r as i,c as t,h as s,H as r}from"./p-1ea36ff3.js";import{I as e}from"./p-2536e466.js";import{c as o}from"./p-bccc4b1c.js";import{g as n}from"./p-28c66a78.js";import{S as a}from"./p-240d1ae7.js";import{I as c,N as p}from"./p-6cf8ecf7.js";import{I as l}from"./p-b3906d17.js";import{f as m}from"./p-8f7a6cc9.js";import"./p-d50d0ec8.js";import"./p-d343a062.js";import"./p-f46dff5e.js";import"./p-6eb29778.js";import"./p-eebad85b.js";import"./p-681f800a.js";import"./p-3b35e507.js";import"./p-35267d98.js";const d=(i,t={})=>{const s=o(i.conversionConfig,t);return i.ui.fields.map((t=>{var r;const e=n((o=t).field||m(i.table.fields,o.fieldId));var o;const c=s[e.id];if(c&&e.type===a.type){const i=e;i.dataProvider&&i.dataProvider.setInitialData([c]),e.setValue((null===(r=i.dataAdapter)||void 0===r?void 0:r.value(c))||c)}else e.setValue(c);return e}))};let 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=l.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 c&&this.invalidation.emit(i),i instanceof p&&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:o,table:n}=r;o&&(this.itemDataProvider=new e(t,{itemId:s.itemId},n,o,o.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:-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{f as dvn_app_view_form_view}