jupiter-dynamic-forms 1.11.0 β†’ 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-form.d.ts","sourceRoot":"","sources":["../../src/core/dynamic-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAE5C,OAAO,EACL,cAAc,EACd,QAAQ,EAGR,SAAS,EACT,eAAe,EAOhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAMrD,OAAO,gBAAgB,CAAC;AACxB,OAAO,uBAAuB,CAAC;AAE/B,qBACa,kBAAmB,SAAQ,UAAU;IACpB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,MAAM,EAAE,eAAe,CAAM;IAC7B,WAAW,EAAE,QAAQ,CAAM;IAC1B,QAAQ,UAAS;IACjB,QAAQ,UAAS;IAClB,eAAe,SAAgB;IAC/B,aAAa,SAAgB;IAC7B,QAAQ,SAAQ;IAChB,OAAO,EAAE,WAAW,GAAG,WAAW,CAAe;IACjD,IAAI,EAAE,WAAW,GAAG,OAAO,CAAe;IAEtE,2BAA2B,EAAE,MAAM,EAAE,CAAM;IAI3C,iBAAiB,CAAC,EAAE,GAAG,CAAC;IAExB,cAAc,CAAC,EAAE,GAAG,CAAC;IAEZ,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,cAAc,CAAC,CAAS;IAChC,OAAO,CAAC,kBAAkB,CAAgB;IAC1C,OAAO,CAAC,gBAAgB,CAA4D;IACpF,OAAO,CAAC,yBAAyB,CAA4D;IAC7F,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OA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,uBAAuB;IA8D/B,OAAO,CAAC,0BAA0B;IAWlC,OAAO,CAAC,sBAAsB;IA0D9B,OAAO,CAAC,sBAAsB;IAmD9B,OAAO,CAAC,sBAAsB;IA+EvB,OAAO,IAAI,QAAQ;IAInB,OAAO,CAAC,IAAI,EAAE,QAAQ;IAOtB,QAAQ,IAAI,OAAO;IAKnB,KAAK;IAIL,QAAQ,IAAI,SAAS;IAI5B,MAAM;CAkFP"}
package/dist/index.js CHANGED
@@ -1580,7 +1580,7 @@ const $={attribute:!0,type:String,converter:v,reflect:!1,hasChanged:x},I=(e=$,t,
1580
1580
  opacity: 0.6;
1581
1581
  cursor: not-allowed;
1582
1582
  }
1583
- `,W([S({type:Boolean,reflect:!0})],exports.JupiterFilterRolesDialog.prototype,"open",2),W([S({type:Array})],exports.JupiterFilterRolesDialog.prototype,"availableRoles",2),W([S({type:Array})],exports.JupiterFilterRolesDialog.prototype,"selectedRoleIds",2),W([S({type:Object})],exports.JupiterFilterRolesDialog.prototype,"periodPreferences",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_tempSelectedRoles",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_searchQuery",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_filteredRoles",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_tempPeriodPreferences",2),exports.JupiterFilterRolesDialog=W([t("jupiter-filter-roles-dialog")],exports.JupiterFilterRolesDialog);var X=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,ee=(e,t,i,o)=>{for(var r,n=o>1?void 0:o?Z(t,i):t,s=e.length-1;s>=0;s--)(r=e[s])&&(n=(o?r(t,i,n):r(n))||n);return o&&n&&X(t,i,n),n};exports.JupiterDynamicForm=class extends e.LitElement{constructor(){super(...arguments),this.config={},this.initialData={},this.disabled=!1,this.readonly=!1,this.periodStartDate="2025-01-01",this.periodEndDate="2025-12-31",this.language="en",this.display="accordion",this.mode="inputForm",this.financialStatementsTypeAxis=[],this._formData={},this._draftLoaded=!1,this._preservedFormData={},this._typedMemberData={},this._preservedTypedMemberData={},this._columns=[],this._errors=[],this._touched=new Set,this._dirty=!1,this._valid=!0,this._submitted=!1,this._allSections=[],this._selectedRoleIds=[],this._showFilterDialog=!1,this._periodPreferences={},this._activeSidePanelRoleId=null,this._adminRoleConfigs={},this._skipDraftLoading=!1}connectedCallback(){super.connectedCallback(),this._initializeForm()}updated(e){e.has("language")&&E.setLanguage(this.language),e.has("financialStatementsTypeAxis")&&console.log("πŸ”„ financialStatementsTypeAxis changed:",this.financialStatementsTypeAxis),(e.has("xbrlInput")||e.has("schema")||e.has("language")||e.has("periodStartDate")||e.has("periodEndDate")||e.has("financialStatementsTypeAxis"))&&this._initializeForm()}_initializeForm(){var e;if(this._draftStorageService||(this._draftStorageService=new k(!1)),this.xbrlInput)try{console.log("πŸ”„ Initializing form from XBRL input:",this.xbrlInput),console.log("πŸ“… Using period dates:",this.periodStartDate,"to",this.periodEndDate),console.log("🌐 Using language:",this.language),this._initializePeriodPreferencesFromData(),console.log("βš™οΈ Using period preferences:",this._periodPreferences),this._currentSchema=T.buildFormSchema(this.xbrlInput,this.periodStartDate,this.periodEndDate,this.language,this._periodPreferences),console.log("βœ… Generated schema with sections:",this._currentSchema.sections.length),this._allSections=[...this._currentSchema.sections],this.financialStatementsTypeAxis&&this.financialStatementsTypeAxis.length>0&&(console.log("πŸ” Applying financialStatementsTypeAxis filter:",this.financialStatementsTypeAxis),console.log("πŸ“Š Sections before filter:",this._allSections.length),this._allSections=this._filterRolesByFinancialStatementsType(this._allSections),console.log("πŸ“Š Sections after filter:",this._allSections.length)),0===this._selectedRoleIds.length&&(this._selectedRoleIds=this._allSections.map(e=>e.id),console.log("βœ… Auto-selected all roles:",this._selectedRoleIds.length)),this._applyRoleFilter(),this._columns=[{id:"base",title:"Value",description:"Base values for concepts",type:"base",order:0,removable:!1}]}catch(t){console.error("❌ Error building form from XBRL input:",t),this._currentSchema=this._getDefaultSchema(),this._allSections=[],this._selectedRoleIds=[],this._columns=this._getDefaultColumns()}else this.schema?(this._currentSchema=this.schema,this._allSections=[...this.schema.sections],this._selectedRoleIds=this._allSections.map(e=>e.id),this._columns=this._getDefaultColumns()):(this._currentSchema=this._getDefaultSchema(),this._allSections=[],this._selectedRoleIds=[],this._columns=this._getDefaultColumns());this._formData={...this.initialData},(null==(e=this.xbrlInput)?void 0:e.initialData)&&(this._formData={...this._formData,...this.xbrlInput.initialData}),this._skipDraftLoading?console.log("⏭️ Skipping draft loading during preference update"):this._loadDraftIfExists(),this._validateForm()}_getDefaultSchema(){return{version:"1.0",formId:"default-form",title:"Dynamic Form",description:"Please provide form schema or XBRL input data",sections:[]}}_getDefaultColumns(){return[{id:"base",title:"Value",description:"Base values for concepts",type:"base",order:0,removable:!1}]}_initializePeriodPreferencesFromData(){var e,t,i;if(!(null==(i=null==(t=null==(e=this.xbrlInput)?void 0:e.presentation)?void 0:t[0])?void 0:i.roles))return;const o={...this._periodPreferences};this.xbrlInput.presentation[0].roles.forEach(e=>{if(!o[e.id]){const t=!0===e.showPreviousYear,i=void 0===e.instant||!0===e.instant,r=void 0===e.duration||!0===e.duration;o[e.id]={showDuration:r,showInstant:i,showPreviousYear:t}}}),this._periodPreferences=o}_applyRoleFilter(){if(!this._currentSchema||!this._allSections.length)return;if(console.log(`πŸ” Applying role filter: ${this._selectedRoleIds.length} selected out of ${this._allSections.length} total`),0===this._selectedRoleIds.length)return console.log("πŸ“ No roles selected - showing empty form"),this._currentSchema={...this._currentSchema,sections:[]},void this.requestUpdate();this._preserveDataForHiddenSections();const e=this._allSections.filter(e=>this._selectedRoleIds.includes(e.id));console.log(`πŸ“Š Filtered sections: ${e.length} (IDs: ${e.map(e=>e.id).join(", ")})`),this._restoreDataForVisibleSections(e),this._currentSchema={...this._currentSchema,sections:e},console.log(`βœ… Schema updated. Current sections count: ${this._currentSchema.sections.length}`),this.requestUpdate()}_filterRolesByFinancialStatementsType(e){var t;if(!this.financialStatementsTypeAxis||0===this.financialStatementsTypeAxis.length)return e;if(!(null==(t=this.xbrlInput)?void 0:t.hypercubes)||0===this.xbrlInput.hypercubes.length)return e;const i=this.xbrlInput.hypercubes[0];return console.log("πŸ” Filter values:",this.financialStatementsTypeAxis),e.filter(e=>{var t;const o=null==(t=i.roles)?void 0:t.find(t=>t.roleId===e.id);if(!o||!o.items||0===o.items.length)return console.log(`βœ… ${e.title}: No hypercube entry - INCLUDED`),!0;let r=!1,n=!1;for(const i of o.items){if(!i.dimensions||0===i.dimensions.length)continue;const e=i.dimensions.find(e=>{var t;return"bw2-titel9_FinancialStatementsTypeAxis"===e.id||(null==(t=e.conceptName)?void 0:t.includes("FinancialStatementsTypeAxis"))});if(e&&(r=!0,e.members&&e.members.length>0)){if(e.members.some(e=>{if(e.conceptName){const t=e.conceptName.split(":"),i=t.length>1?t[1]:e.conceptName;return this.financialStatementsTypeAxis.some(e=>{const t=e.split(":"),o=t.length>1?t[1]:e;return i===o})}return this.financialStatementsTypeAxis.includes(e.id)})){n=!0;break}}}return!r||n})}_preserveDataForHiddenSections(){var e;((null==(e=this._currentSchema)?void 0:e.sections.map(e=>e.id))||[]).filter(e=>!this._selectedRoleIds.includes(e)).forEach(e=>{const t=this._allSections.find(t=>t.id===e);t&&this._preserveSectionData(t)})}_restoreDataForVisibleSections(e){e.forEach(e=>{this._restoreSectionData(e)}),console.log(`πŸ”„ Restored data for ${e.length} visible sections`)}_preserveSectionData(e){e.concepts.forEach(e=>{this._preserveConceptData(e)})}_preserveConceptData(e){this._formData[e.id]&&(this._preservedFormData[e.id]={...this._formData[e.id]}),e.fields.forEach(e=>{this._typedMemberData[e.columnId]&&(this._preservedTypedMemberData[e.columnId]={...this._typedMemberData[e.columnId]})}),e.children&&e.children.forEach(e=>{this._preserveConceptData(e)})}_restoreSectionData(e){e.concepts.forEach(e=>{this._restoreConceptData(e)})}_restoreConceptData(e){this._preservedFormData[e.id]&&(this._formData[e.id]={...this._preservedFormData[e.id]}),e.fields.forEach(e=>{this._preservedTypedMemberData[e.columnId]&&(this._typedMemberData[e.columnId]={...this._preservedTypedMemberData[e.columnId]})}),e.children&&e.children.forEach(e=>{this._restoreConceptData(e)})}_shouldShowFilterButton(){return!0}_handleFilterRolesClick(){this._showFilterDialog=!0}_handleFilterDialogCancel(){this._showFilterDialog=!1,console.log(`🚫 Filter dialog cancelled. Current selection: ${this._selectedRoleIds.length}/${this._allSections.length}`)}_handleRoleFilterApply(e){const{selectedRoleIds:t,periodPreferences:i}=e.detail;this._selectedRoleIds=t;if(JSON.stringify(this._periodPreferences)!==JSON.stringify(i)){if(this._periodPreferences=i,console.log("πŸ“Š Period preferences updated:",this._periodPreferences),this._skipDraftLoading=!0,this._initializeForm(),this._skipDraftLoading=!1,this._draftStorageService.hasDraft()){console.log("πŸ’Ύ Updating draft with new period preferences...");const e=this._generateSubmissionData(),t=this._draftStorageService.createMetadataSnapshot(this.periodStartDate,this.periodEndDate,this.language,this._selectedRoleIds,this._allSections,this._typedMemberData,this._periodPreferences);this._draftStorageService.saveDraft(e,t),console.log("βœ… Draft updated with new period preferences")}}else this._applyRoleFilter();this._showFilterDialog=!1,console.log(`🎯 Applied role filter: ${t.length}/${this._allSections.length} roles selected`),this.dispatchEvent(new CustomEvent("roles-filter-changed",{detail:{selectedRoleIds:t,totalRoles:this._allSections.length,visibleRoles:t.length,periodPreferences:i},bubbles:!0}))}_validateForm(){var e;const t=[],i=this._currentSchema;if(i){for(const o of i.sections)for(const i of o.concepts)for(const o of i.fields){const r=null==(e=this._formData[i.id])?void 0:e[o.columnId],n=C.validateField(o.id,i.id,o.columnId,r,o.type,o.validation||[]);t.push(...n)}this._errors=t,this._valid=0===t.filter(e=>"error"===e.severity).length}}_handleFieldChange(e){const{fieldId:t,conceptId:i,columnId:o,value:r}=e.detail;console.log(`πŸ“ Field change: conceptId=${i}, columnId=${o}, value=${r}, fieldId=${t}`);const n={...this._formData};n[i]||(n[i]={});const s=n[i][o];n[i]={...n[i],[o]:r},this._formData=n,console.log(`πŸ’Ύ Updated formData[${i}]:`,this._formData[i]),this._touched.add(`${i}-${o}`),this._dirty=!0,this._validateForm(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("field-change",{detail:{fieldId:t,conceptId:i,columnId:o,value:r,oldValue:s},bubbles:!0}))}_generateUniqueConceptKey(e,t){return`${e}::${t}`}_extractOriginalConceptId(e){const t=e.split("::");return t.length>1?t[1]:e}_handleTypedMemberChange(e){const{columnId:t,axisId:i,value:o}=e.detail;console.log(`πŸ” [DynamicForm] Typed member change: columnId=${t}, axisId=${i}, value=${o}`);const r={...this._typedMemberData};r[t]||(r[t]={}),r[t]={...r[t],[i]:o},this._typedMemberData=r,this._dirty=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("typed-member-change",{detail:{columnId:t,axisId:i,value:o},bubbles:!0}))}_handleSectionExpand(e){this.dispatchEvent(new CustomEvent("section-expand",{detail:e.detail,bubbles:!0}))}_handleConceptExpand(e){this.dispatchEvent(new CustomEvent("concept-expand",{detail:e.detail,bubbles:!0}))}_handleColumnRemove(e){const{columnId:t,sectionId:i}=e.detail;if(this._currentSchema&&i){const e=this._currentSchema.sections.find(e=>e.id===i);e&&e.columns&&(e.columns=e.columns.filter(e=>e.id!==t))}else this._columns=this._columns.filter(e=>e.id!==t),this._currentSchema&&this._currentSchema.sections.forEach(e=>{e.columns&&(e.columns=e.columns.filter(e=>e.id!==t))});this._removeColumnData(t,i),this._dirty=!0,this._validateForm(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("column-remove",{detail:{columnId:t,sectionId:i},bubbles:!0}))}_handleColumnAddRequest(e){const{sectionId:t,columnRequest:i}=e.detail;this._addColumnFromRequest(i,t)}_getAvailableDimensionsForSection(e){var t,i,o;if(!(null==(i=null==(t=this.xbrlInput)?void 0:t.hypercubes)?void 0:i[0]))return[];const r=this.xbrlInput.hypercubes[0].roles.find(t=>t.roleId===e);if(!(null==(o=null==r?void 0:r.items)?void 0:o.length))return console.log(`❌ No hypercube items found for role: ${e}`),[];const n=[];return r.items.forEach(e=>{e.dimensions&&e.dimensions.length>0&&e.dimensions.forEach(e=>{var t;if(!n.find(t=>t.id===e.id)){const i=(null==(t=e.labels.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:t.label)||e.conceptName,o={id:e.id,conceptName:e.conceptName,axisLabel:i};e.members&&e.members.length>0&&(o.members=e.members.map(e=>{var t,i;return{id:e.id,label:(null==(i=null==(t=e.labels)?void 0:t.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:i.label)||e.conceptName||e.id}})),e.typedMember&&(o.typedMember={id:e.typedMember.id,dataType:"string"}),n.push(o)}})}),n}_addColumnFromRequest(e,t){var i,o,r,n,s;const a=`col-${Date.now()}`;let l="",d="";"instant"===e.periodType?(l=e.instantDate||"",d=""):"duration"!==e.periodType&&"mixed"!==e.periodType||(l=`${e.startDate} / ${e.endDate}`,d="");let c={dimensionId:"period",memberValue:"instant"===e.periodType?`instant-${e.instantDate}`:`duration-${e.startDate}-${e.endDate}`,memberLabel:l};if(e.selectedDimensions&&e.selectedDimensions.length>0){const t=[],i=[];for(const r of e.selectedDimensions)r.isTyped&&r.typedValue?(t.push(`${r.axisLabel}: ${r.typedValue}`),i.push(`${r.axisId}|${r.typedValue}`)):r.memberId&&r.memberLabel&&(t.push(r.memberLabel),i.push(`${r.axisId}|${r.memberId}`));const o="instant"===e.periodType?`(${e.instantDate})`:`(${e.startDate} / ${e.endDate})`;t.length>0&&(l=`${t.join(" | ")} ${o}`,c={dimensionId:a,memberValue:t.join(" | "),memberLabel:t.join(" | "),memberKey:t.join(" | "),dimensionIdKey:i.join("::"),selectedDimensions:e.selectedDimensions},console.log(`πŸ“Š Applied selected dimensions to new column: ${c.memberKey}`))}else if(null==(o=null==(i=this.xbrlInput)?void 0:i.hypercubes)?void 0:o[0]){const i=this.xbrlInput.hypercubes[0].roles.find(e=>e.roleId===t);if(1===(null==(r=null==i?void 0:i.items)?void 0:r.length)){const t=i.items[0];if(1===t.dimensions.length){const i=t.dimensions[0];if(i.members&&i.members.length>0){const t=(null==(n=i.labels.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:n.label)||i.conceptName,o=i.members[0],r=(null==(s=o.labels.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:s.label)||o.conceptName;l=`${r} ${"instant"===e.periodType?`(${e.instantDate})`:`(${e.startDate} / ${e.endDate})`}`,c={dimensionId:a,axisId:i.id,memberId:o.id,memberValue:r,memberLabel:r,axis:t,axisLabel:t,memberKey:`${t} | ${r}`,dimensionIdKey:`${i.id} | ${o.id}`},console.log(`πŸ“Š Applied hypercube dimension to new column: ${c.memberKey}`)}}}}const p={id:a,title:l,description:d,type:(c.memberKey,"dimension"),order:this._columns.length,removable:!0,dimensionData:c};if(e.selectedDimensions&&e.selectedDimensions.length>0){const t={};let i=!1;for(const o of e.selectedDimensions)o.isTyped&&(t[o.axisId]=o.typedValue||"",i=!0);i&&(this._typedMemberData[a]=t,p.dimensionData&&(p.dimensionData.hasTypedMembers=!0,p.dimensionData.typedMembers=e.selectedDimensions.filter(e=>e.isTyped).map(e=>({axisId:e.axisId,axisLabel:e.axisLabel,typedMemberId:e.axisId,memberLabel:e.axisLabel}))))}if(this._currentSchema){const e=this._currentSchema.sections.find(e=>e.id===t);e&&(e.columns||(e.columns=[...this._columns]),e.columns=[...e.columns,p])}this._replicateFieldsForNewColumn(a,e,t),this._dirty=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("column-add",{detail:{column:p},bubbles:!0}))}_removeColumnData(e,t){if(this._currentSchema)if(t){const i=this._currentSchema.sections.find(e=>e.id===t);i&&this._removeColumnDataFromConcepts(i.concepts,e)}else for(const i in this._formData)void 0!==this._formData[i][e]&&delete this._formData[i][e]}_removeColumnDataFromConcepts(e,t){e.forEach(e=>{this._formData[e.id]&&void 0!==this._formData[e.id][t]&&delete this._formData[e.id][t],e.fields&&(e.fields=e.fields.filter(e=>e.columnId!==t)),e.children&&this._removeColumnDataFromConcepts(e.children,t)})}_shouldCreateFieldForConcept(e,t){if(e.abstract)return!1;if(e.periodType){if("instant"===t.periodType&&"instant"!==e.periodType)return!1;if("duration"===t.periodType&&"duration"!==e.periodType)return!1}return!0}_replicateFieldsForNewColumn(e,t,i){if(!this._currentSchema)return;const o=new T,r=this._currentSchema.sections.find(e=>e.id===i);r&&this._replicateFieldsForSection(r.concepts,e,t,o)}_replicateFieldsForSection(e,t,i,o){e.forEach(e=>{var r;if(this._shouldCreateFieldForConcept(e,i)){const o=null==(r=e.fields)?void 0:r[0];let n;n=o?{id:`${e.id}_${t}`,conceptId:e.id,columnId:t,type:o.type,label:o.label,placeholder:o.placeholder,required:o.required,disabled:o.disabled,validation:o.validation,defaultValue:o.defaultValue,periodStartDate:"instant"===i.periodType?i.instantDate:i.startDate,periodEndDate:"instant"===i.periodType?i.instantDate:i.endDate}:{id:`${e.id}_${t}`,conceptId:e.id,columnId:t,type:"text",label:e.label||e.name,placeholder:`Enter ${e.name}`,required:!1,disabled:!1,validation:[],defaultValue:"",periodStartDate:"instant"===i.periodType?i.instantDate:i.startDate,periodEndDate:"instant"===i.periodType?i.instantDate:i.endDate},e.fields||(e.fields=[]),e.fields.push(n)}e.children&&this._replicateFieldsForSection(e.children,t,i,o)})}_addColumn(){const e={id:`dim-${Date.now()}`,title:`Dimension ${this._columns.length}`,description:"Additional dimension column",type:"dimension",order:this._columns.length,removable:!0,dimensionData:{dimensionId:"custom",memberValue:"default",memberLabel:"Default Member"}};this._columns=[...this._columns,e],this.requestUpdate(),this.dispatchEvent(new CustomEvent("column-add",{detail:{column:e},bubbles:!0}))}_handleSubmit(){if(console.log("πŸ“ Form submission started..."),this._submitted=!0,"admin"===this.mode)return void this._handleAdminModeSubmit();this._validateForm();const e=this._generateSubmissionData();console.log("πŸ“Š Form Submission Data:",JSON.stringify(e,null,2)),this.dispatchEvent(new CustomEvent("form-submit",{detail:{data:this._formData,submissionData:e,valid:this._valid,errors:this._errors},bubbles:!0})),console.log("βœ… Form submit event dispatched")}_handleSaveDraft(){console.log("πŸ’Ύ Raw form data before submission generation:",this._formData);const e=this._generateSubmissionData();console.log("πŸ“€ Generated submission data:",e),console.log("πŸ“Š Submission data breakdown:"),e.forEach((e,t)=>{console.log(` [${t}] conceptId: ${e.conceptId}, columnId: ${e.columnId}, value: ${e.value}`)});const t=this._draftStorageService.createMetadataSnapshot(this.periodStartDate,this.periodEndDate,this.language,this._selectedRoleIds,this._allSections,this._typedMemberData,this._periodPreferences),i=this._draftStorageService.saveDraft(e,t);this.dispatchEvent(new CustomEvent("form-save-draft",{detail:{data:this._formData,draftData:e,metadata:t,saved:i,valid:this._valid,errors:this._errors,dynaformsFacts:e,dynaformsMetadata:t},bubbles:!0})),console.log("πŸ’Ύ Draft saved to localStorage",{entries:e.length,saved:i,roles:this._selectedRoleIds.length,customColumns:t.customColumns.length})}async _loadDraftIfExists(){if(console.log("πŸ“‹ Checking for saved draft..."),this.dynaformsFacts&&this.dynaformsMetadata){console.log("πŸ“¦ Using external draft data from properties");const e={formData:this.dynaformsFacts,metadata:this.dynaformsMetadata};return await this._restoreFromDraft(e),this._draftLoaded=!0,this._draftLoadedAt=this.dynaformsMetadata.savedAt||(new Date).toISOString(),this.dispatchEvent(new CustomEvent("form-draft-loaded",{detail:{draft:e,source:"external",compatible:!0,warnings:[]},bubbles:!0,composed:!0})),void console.log("πŸ“₯ External draft loaded successfully")}if(!this._draftStorageService.hasDraft())return void console.log("ℹ️ No saved draft found");const e=this._draftStorageService.loadDraft();if(!e)return void console.warn("⚠️ Failed to load draft");const{compatible:t,warnings:i}=this._draftStorageService.validateDraftCompatibility(e,this.periodStartDate,this.periodEndDate);i.length>0&&console.warn("⚠️ Draft compatibility warnings:",i),await this._restoreFromDraft(e),this.dispatchEvent(new CustomEvent("form-draft-loaded",{detail:{draft:e,compatible:t,warnings:i},bubbles:!0,composed:!0})),console.log("πŸ“₯ Draft loaded successfully",{entries:e.formData.length,savedAt:e.metadata.savedAt,age:this._draftStorageService.getDraftAge()})}async _restoreFromDraft(e){var t;const{formData:i,metadata:o}=e;o.selectedRoleIds&&o.selectedRoleIds.length>0&&(this._selectedRoleIds=o.selectedRoleIds,console.log(`πŸ”„ Restored ${this._selectedRoleIds.length} selected roles`)),o.typedMemberData&&(this._typedMemberData=o.typedMemberData,this._preservedTypedMemberData={},console.log("πŸ”„ Restored typed member data")),o.periodPreferences?(this._periodPreferences=o.periodPreferences,console.log("πŸ”„ Restored period preferences (including previous year settings):",this._periodPreferences),this.xbrlInput&&(console.log("πŸ”„ Rebuilding schema with restored period preferences..."),this._currentSchema=T.buildFormSchema(this.xbrlInput,this.periodStartDate,this.periodEndDate,this.language,this._periodPreferences),this._allSections=[...this._currentSchema.sections],this.financialStatementsTypeAxis&&this.financialStatementsTypeAxis.length>0&&(this._allSections=this._filterRolesByFinancialStatementsType(this._allSections)),console.log("βœ… Schema rebuilt with restored period preferences"),o.customColumns&&o.customColumns.length>0&&(this._mergeAdditionalCustomColumns(o.customColumns),console.log(`πŸ”„ Merged ${o.customColumns.length} additional custom columns`)))):o.customColumns&&o.customColumns.length>0&&(this._restoreCustomColumns(o.customColumns),console.log(`πŸ”„ Restored ${o.customColumns.length} custom columns`));const r={};i.forEach(e=>{let{conceptId:t,value:i,columnId:o,period:n}=e;if(!o&&n&&(o=this._inferColumnIdFromPeriod(n,t),!o))return void console.warn(`⚠️ Could not infer columnId for concept ${t}, skipping...`);const s=this._findActualConceptId(t)||t;r[s]||(r[s]={}),r[s][o]=i,console.log(`πŸ“¦ Restored: ${s}[${o}] = ${i}`)}),this._formData={...this._formData,...r},console.log(`πŸ”„ Restored ${Object.keys(r).length} concepts with data`),this._selectedRoleIds.length>0&&this._applyRoleFilter(),this._dirty=!0,this._touched.clear(),this._validateForm(),this._allSections=[...this._allSections],this.requestUpdate(),await this.updateComplete,await new Promise(e=>setTimeout(e,100));const n=(null==(t=this.shadowRoot)?void 0:t.querySelectorAll("input, textarea, select").length)||0;console.log(`πŸ” Found ${n} fields in DOM after update`),n>0?this._populateFieldValues(r):console.error("❌ No fields found in DOM even after updateComplete"),console.log("βœ… Draft restoration completed")}_findActualConceptId(e){for(const t of this._allSections){const i=this._findActualConceptIdInTree(t.concepts,e);if(i)return i}return null}_findActualConceptIdInTree(e,t){for(const i of e){if(i.originalConceptId===t||i.id===t)return i.id;if(i.children){const e=this._findActualConceptIdInTree(i.children,t);if(e)return e}}return null}_inferColumnIdFromPeriod(e,t){for(const i of this._allSections){if(this._findConceptInSection(i.concepts,t)&&i.columns){for(const o of i.columns){const i="instant"===e.type,r="duration"===e.type;if(i&&e.date){if(o.periodStartDate===e.date||o.periodStartDate===o.periodEndDate&&o.periodStartDate===e.date)return console.log(`βœ“ Inferred columnId: ${o.id} for concept ${t}`),o.id}else if(r&&e.startDate&&e.endDate&&o.periodStartDate===e.startDate&&o.periodEndDate===e.endDate)return console.log(`βœ“ Inferred columnId: ${o.id} for concept ${t}`),o.id}if("instant"===e.type){const e=i.columns.find(e=>"instant"===e.id);if(e)return e.id}else{const e=i.columns.find(e=>"duration"===e.id);if(e)return e.id}}}return null}_findConceptInSection(e,t){for(const i of e){if(i.id===t||i.originalConceptId===t)return i;if(i.children){const e=this._findConceptInSection(i.children,t);if(e)return e}}return null}_populateFieldValues(e){let t=0,i=0;console.log("πŸ” Starting field population..."),console.log("πŸ“¦ Form data to populate:",e),Object.keys(e).forEach(o=>{const r=e[o];Object.keys(r).forEach(e=>{var n,s;const a=r[e],l=`${o}__${e}`;console.log(`πŸ” Looking for field: ${l}`);const d=null==(n=this.shadowRoot)?void 0:n.querySelector(`#${CSS.escape(l)}`);d?(d instanceof HTMLInputElement||d instanceof HTMLTextAreaElement||d instanceof HTMLSelectElement)&&("checkbox"===d.type?d.checked=Boolean(a):d.value=null!=a?String(a):"",console.log(` βœ… Populated field ${l} with value:`,a),t++):(console.warn(` ❌ Field element NOT FOUND: ${l}`),console.warn(" Available fields in DOM:",Array.from((null==(s=this.shadowRoot)?void 0:s.querySelectorAll("input, textarea, select"))||[]).map(e=>e.id).filter(e=>e.includes(o.split("__")[0]))),i++)})}),console.log(`βœ… Field population complete: ${t} populated, ${i} not found`)}_restoreCustomColumns(e){const t=new Map;e.forEach(e=>{t.has(e.sectionId)||t.set(e.sectionId,[]),t.get(e.sectionId).push(e)}),this._allSections.forEach(e=>{const i=t.get(e.id);i&&(e.columns=i.map(e=>({id:e.columnId,title:e.label,type:e.dimensionData?"dimension":"base",periodStartDate:e.startDate||e.date,periodEndDate:e.endDate||e.date,dimensionData:e.dimensionData,order:0,removable:"duration"!==e.columnId&&"instant"!==e.columnId})),this._regenerateFieldsForSection(e),console.log(` └─ Restored ${i.length} columns for section ${e.id}`))}),this._currentSchema&&(this._currentSchema={...this._currentSchema,sections:this._allSections})}_mergeAdditionalCustomColumns(e){const t=new Map;e.forEach(e=>{e.columnId.startsWith("col-")&&(t.has(e.sectionId)||t.set(e.sectionId,[]),t.get(e.sectionId).push(e))}),this._allSections.forEach(e=>{const i=t.get(e.id);i&&i.length>0&&(e.columns||(e.columns=[]),i.forEach(t=>{if(!e.columns.find(e=>e.id===t.columnId)){const i={id:t.columnId,title:t.label,type:t.dimensionData?"dimension":"base",periodStartDate:t.startDate||t.date,periodEndDate:t.endDate||t.date,dimensionData:t.dimensionData,order:e.columns.length,removable:!0};e.columns.push(i),console.log(` └─ Added custom column ${t.columnId} to section ${e.id}`)}}),this._regenerateFieldsForSection(e))}),this._currentSchema&&(this._currentSchema={...this._currentSchema,sections:this._allSections})}_regenerateFieldsForSection(e){if(!e.columns)return;const t=this._periodPreferences[e.id]||{showDuration:!0,showInstant:!0,showPreviousYear:!1},i=o=>{o.forEach(o=>{o.fields=[];this._shouldShowConceptBasedOnPeriodPreferences(o,t)&&e.columns.forEach(e=>{const t=o.periodType,i=this._inferColumnPeriodType(e);o.abstract||t&&i&&t!==i||o.fields.push({id:`${o.id}_${e.id}`,conceptId:o.id,columnId:e.id,type:this._mapConceptTypeToFieldType(o.type),label:o.label,periodStartDate:e.periodStartDate,periodEndDate:e.periodEndDate})}),o.children&&i(o.children)})};i(e.concepts)}_shouldShowConceptBasedOnPeriodPreferences(e,t){return!!e.abstract||(!e.periodType||!("duration"===e.periodType&&!t.showDuration)&&!("instant"===e.periodType&&!t.showInstant))}_inferColumnPeriodType(e){return e.periodStartDate&&e.periodEndDate?e.periodStartDate===e.periodEndDate?"instant":"duration":e.periodStartDate&&!e.periodEndDate?"instant":void 0}_mapConceptTypeToFieldType(e){return e?e.includes("monetary")||e.includes("Monetary")?"number":e.includes("date")||e.includes("Date")?"date":e.includes("boolean")||e.includes("Boolean")?"boolean":e.includes("integer")||e.includes("Integer")||e.includes("decimal")||e.includes("Decimal")?"number":"text":"text"}_generateSubmissionData(){const e=[];if(!this._currentSchema)return e;this._currentSchema.sections.forEach(t=>{this._processConceptsForSubmission(t.concepts,e,t)}),this._includePreservedDataInSubmission(e);return this._removeDuplicateSubmissions(e)}_includePreservedDataInSubmission(e){Object.keys(this._preservedFormData).forEach(t=>{const i=this._preservedFormData[t];i&&Object.keys(i).forEach(o=>{const r=i[o];if(null!=r&&""!==r){const i=this._findConceptInAllSections(t);if(i){const n=this._findSectionForConcept(t);this._addConceptDataToSubmission(i,o,r,e,n||void 0)}}})}),console.log(`πŸ“€ Included preserved data in submission. Total entries: ${e.length}`)}_findConceptInAllSections(e){for(const t of this._allSections){const i=this._findConceptInSection(t.concepts,e);if(i)return i}return null}_findSectionForConcept(e){for(const t of this._allSections){if(this._findConceptInSection(t.concepts,e))return t}return null}_addConceptDataToSubmission(e,t,i,o,r){var n;const s=e.fields.find(e=>e.columnId===t);if(!s)return;const a="instant"===e.periodType,l=this._findColumnByIdInAllSections(t);console.log(`πŸ” [Submission] Concept: ${e.id}, Column: ${t}, Column Period: ${(null==l?void 0:l.periodStartDate)||"none"} - ${(null==l?void 0:l.periodEndDate)||"none"}`);const d={conceptId:e.originalConceptId||e.id,columnId:t,value:i,period:{type:e.periodType||"duration",...a?{date:(null==l?void 0:l.periodEndDate)||s.periodStartDate||this.periodStartDate}:{startDate:(null==l?void 0:l.periodStartDate)||s.periodStartDate||this.periodStartDate,endDate:(null==l?void 0:l.periodEndDate)||s.periodEndDate||this.periodEndDate}}};(null==(n=null==l?void 0:l.dimensionData)?void 0:n.memberLabel)&&(d.dimension=l.dimensionData.memberLabel),o.push(d)}_findColumnByIdInAllSections(e){for(const t of this._allSections)if(t.columns){const i=t.columns.find(t=>t.id===e);if(i)return i}}_removeDuplicateSubmissions(e){const t=new Map;return e.forEach(e=>{const i="instant"===e.period.type?e.period.date:`${e.period.startDate}_${e.period.endDate}`,o=`${e.conceptId}_${e.value}_${e.dimension||"no-dimension"}_${i}`;t.has(o)||t.set(o,e)}),Array.from(t.values())}_findColumnById(e){if(this._currentSchema)for(const t of this._currentSchema.sections)if(t.columns){const i=t.columns.find(t=>t.id===e);if(i)return i}}_findColumnByIdInSection(e,t){if(null==t?void 0:t.columns)return t.columns.find(t=>t.id===e)}_getTypedMemberNameForAxis(e,t){var i,o,r,n;if(!(null==(o=null==(i=this.xbrlInput)?void 0:i.hypercubes)?void 0:o[0]))return null;const s=null==t?void 0:t.id;if(!s)return null;const a=null==(r=this.xbrlInput.hypercubes[0].roles)?void 0:r.find(e=>e.roleId===s);if(!(null==a?void 0:a.items))return null;for(const l of a.items)if(l.dimensions){const t=l.dimensions.find(t=>t.id===e);if(null==(n=null==t?void 0:t.typedMember)?void 0:n.id)return t.typedMember.id}return null}_doesConceptApplyToTypedDimension(e,t,i){var o,r,n;if(!(null==(r=null==(o=this.xbrlInput)?void 0:o.hypercubes)?void 0:r[0]))return!1;const s=null==t?void 0:t.id;if(!s)return!1;const a=this.xbrlInput.hypercubes[0].roles.find(e=>e.roleId===s);if(!(null==(n=null==a?void 0:a.items)?void 0:n.length))return!1;for(const l of a.items){const t=e.originalConceptId||e.id;if(l.conceptIds&&l.conceptIds.includes(t)){const e=l.dimensions.some(e=>e.typedMember);return console.log(`πŸ” [DynamicForm] Concept ${t} found in hypercube item. Has typed dimensions:`,e),e}}return console.log(`πŸ” [DynamicForm] Concept ${e.originalConceptId||e.id} not found in any hypercube items for role ${s}`),!1}_getApplicableTypedDimensions(e,t){var i,o,r;if(!(null==(o=null==(i=this.xbrlInput)?void 0:i.hypercubes)?void 0:o[0])||!(null==t?void 0:t.id))return[];const n=this.xbrlInput.hypercubes[0].roles.find(e=>e.roleId===t.id);if(!(null==(r=null==n?void 0:n.items)?void 0:r.length))return[];const s=e.originalConceptId||e.id;for(const a of n.items)if(a.conceptIds&&a.conceptIds.includes(s)){const e=a.dimensions.filter(e=>e.typedMember).map(e=>e.id);return console.log(`πŸ” [DynamicForm] Found applicable typed dimensions for concept ${s}:`,e),e}return[]}_processConceptsForSubmission(e,t,i){const o="Toelichting op de geconsolideerde jaarrekening - FinanciΓ«le vaste activa: Deelnemingen: Volledig geconsolideerd: Specificatie",r=(null==i?void 0:i.title)||"Unknown";e.forEach(e=>{r===o&&(console.warn(`[DUPLICATE DEBUG] Processing concept ${e.originalConceptId||e.id} in target role`),e.fields&&(console.warn(`[DUPLICATE DEBUG] Concept has ${e.fields.length} fields`),e.fields.forEach((t,i)=>{var o;console.warn(`[DUPLICATE DEBUG] Field ${i}: columnId=${t.columnId}, current value=${null==(o=this._formData[e.id])?void 0:o[t.columnId]}`)}))),e.fields&&e.fields.length>1&&e.fields.forEach((e,t)=>{}),e.fields&&e.fields.length>0&&e.fields.forEach(n=>{var s,a;const l=this._formData[e.id],d=null==l?void 0:l[n.columnId];if(null!=d&&""!==d){const l=this._findColumnByIdInSection(n.columnId,i),c={conceptId:e.id,columnId:n.columnId,value:d,period:{type:e.periodType||"duration"}};if("instant"===e.periodType?c.period.date=(null==l?void 0:l.periodEndDate)||n.periodStartDate||this.periodStartDate:(c.period.startDate=(null==l?void 0:l.periodStartDate)||n.periodStartDate||this.periodStartDate,c.period.endDate=(null==l?void 0:l.periodEndDate)||n.periodEndDate||this.periodEndDate),console.log(`πŸ” [Submission] Concept: ${e.id}, Column: ${n.columnId}, Column Period: ${(null==l?void 0:l.periodStartDate)||"none"} - ${(null==l?void 0:l.periodEndDate)||"none"}, Used Period: ${"instant"===c.period.type?c.period.date:`${c.period.startDate} - ${c.period.endDate}`}`),"dimension"===(null==l?void 0:l.type)&&(null==(s=l.dimensionData)?void 0:s.dimensionIdKey)?(c.dimension=l.dimensionData.dimensionIdKey,console.log(`πŸ” [DynamicForm] Using dimension key from field's column (${n.columnId}):`,l.dimensionData.dimensionIdKey)):console.log(`πŸ” [DynamicForm] No dimension data found for field column ${n.columnId}. Column type: ${null==l?void 0:l.type}, has dimensionData: ${!!(null==l?void 0:l.dimensionData)}`),this._typedMemberData[n.columnId]){const t=this._getApplicableTypedDimensions(e,i);if(console.log(`πŸ” [DynamicForm] Concept ${e.id} applicable typed dimensions:`,t),t.length>0){const e={},o=this._typedMemberData[n.columnId];t.forEach(t=>{if(o[t]){const r=this._getTypedMemberNameForAxis(t,i);e[t]={value:o[t],memberName:r||"Unknown"}}}),Object.keys(e).length>0?(c.typedMembers=e,console.log("πŸ” [DynamicForm] Adding filtered typed members to submission:",e)):console.log("πŸ” [DynamicForm] No typed member values found for applicable dimensions:",t)}else console.log(`πŸ” [DynamicForm] Skipping typed members for concept ${e.id} - not applicable to this hypercube`)}else console.log(`πŸ” [DynamicForm] No typed member data found for column ${n.columnId}. Available columns:`,Object.keys(this._typedMemberData)),l&&console.log("πŸ” [DynamicForm] Column details:",{id:l.id,type:l.type,hasTypedMembers:null==(a=l.dimensionData)?void 0:a.hasTypedMembers,dimensionData:l.dimensionData});r===o&&console.warn("[DUPLICATE DEBUG] Final submission entry:",c),t.push(c)}}),e.children&&this._processConceptsForSubmission(e.children,t,i)})}_handleReset(){this._formData={...this.initialData},this._touched.clear(),this._dirty=!1,this._submitted=!1,this._preservedFormData={},this._preservedTypedMemberData={},console.log("πŸ”„ Form reset - all data and preserved data cleared"),this._validateForm(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("form-reset",{detail:{},bubbles:!0}))}_getFormState(){return{data:this._formData,errors:this._errors,touched:this._touched,dirty:this._dirty,valid:this._valid,submitted:this._submitted}}_handleSidePanelRoleClick(e){this._activeSidePanelRoleId=e}_renderAdminModeContent(t){var i,o,r;if(!t)return e.html`
1583
+ `,W([S({type:Boolean,reflect:!0})],exports.JupiterFilterRolesDialog.prototype,"open",2),W([S({type:Array})],exports.JupiterFilterRolesDialog.prototype,"availableRoles",2),W([S({type:Array})],exports.JupiterFilterRolesDialog.prototype,"selectedRoleIds",2),W([S({type:Object})],exports.JupiterFilterRolesDialog.prototype,"periodPreferences",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_tempSelectedRoles",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_searchQuery",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_filteredRoles",2),W([w()],exports.JupiterFilterRolesDialog.prototype,"_tempPeriodPreferences",2),exports.JupiterFilterRolesDialog=W([t("jupiter-filter-roles-dialog")],exports.JupiterFilterRolesDialog);var X=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,ee=(e,t,i,o)=>{for(var r,n=o>1?void 0:o?Z(t,i):t,s=e.length-1;s>=0;s--)(r=e[s])&&(n=(o?r(t,i,n):r(n))||n);return o&&n&&X(t,i,n),n};exports.JupiterDynamicForm=class extends e.LitElement{constructor(){super(...arguments),this.config={},this.initialData={},this.disabled=!1,this.readonly=!1,this.periodStartDate="2025-01-01",this.periodEndDate="2025-12-31",this.language="en",this.display="accordion",this.mode="inputForm",this.financialStatementsTypeAxis=[],this._formData={},this._draftLoaded=!1,this._preservedFormData={},this._typedMemberData={},this._preservedTypedMemberData={},this._columns=[],this._errors=[],this._touched=new Set,this._dirty=!1,this._valid=!0,this._submitted=!1,this._allSections=[],this._selectedRoleIds=[],this._showFilterDialog=!1,this._periodPreferences={},this._activeSidePanelRoleId=null,this._adminRoleConfigs={},this._skipDraftLoading=!1}connectedCallback(){super.connectedCallback(),this._initializeForm()}updated(e){e.has("language")&&E.setLanguage(this.language),e.has("financialStatementsTypeAxis")&&console.log("πŸ”„ financialStatementsTypeAxis changed:",this.financialStatementsTypeAxis),(e.has("xbrlInput")||e.has("schema")||e.has("language")||e.has("periodStartDate")||e.has("periodEndDate")||e.has("financialStatementsTypeAxis"))&&this._initializeForm()}_initializeForm(){var e;if(this._draftStorageService||(this._draftStorageService=new k(!1)),this.xbrlInput)try{console.log("πŸ”„ Initializing form from XBRL input:",this.xbrlInput),console.log("πŸ“… Using period dates:",this.periodStartDate,"to",this.periodEndDate),console.log("🌐 Using language:",this.language),this._initializePeriodPreferencesFromData(),console.log("βš™οΈ Using period preferences:",this._periodPreferences),this._currentSchema=T.buildFormSchema(this.xbrlInput,this.periodStartDate,this.periodEndDate,this.language,this._periodPreferences),console.log("βœ… Generated schema with sections:",this._currentSchema.sections.length),this._allSections=[...this._currentSchema.sections],this.financialStatementsTypeAxis&&this.financialStatementsTypeAxis.length>0&&(console.log("πŸ” Applying financialStatementsTypeAxis filter:",this.financialStatementsTypeAxis),console.log("πŸ“Š Sections before filter:",this._allSections.length),this._allSections=this._filterRolesByFinancialStatementsType(this._allSections),console.log("πŸ“Š Sections after filter:",this._allSections.length)),0===this._selectedRoleIds.length&&(this._selectedRoleIds=this._allSections.map(e=>e.id),console.log("βœ… Auto-selected all roles:",this._selectedRoleIds.length)),this._applyRoleFilter(),this._columns=[{id:"base",title:"Value",description:"Base values for concepts",type:"base",order:0,removable:!1}]}catch(t){console.error("❌ Error building form from XBRL input:",t),this._currentSchema=this._getDefaultSchema(),this._allSections=[],this._selectedRoleIds=[],this._columns=this._getDefaultColumns()}else this.schema?(this._currentSchema=this.schema,this._allSections=[...this.schema.sections],this._selectedRoleIds=this._allSections.map(e=>e.id),this._columns=this._getDefaultColumns()):(this._currentSchema=this._getDefaultSchema(),this._allSections=[],this._selectedRoleIds=[],this._columns=this._getDefaultColumns());this._formData={...this.initialData},(null==(e=this.xbrlInput)?void 0:e.initialData)&&(this._formData={...this._formData,...this.xbrlInput.initialData}),this._skipDraftLoading?console.log("⏭️ Skipping draft loading during preference update"):this._loadDraftIfExists(),this._validateForm()}_getDefaultSchema(){return{version:"1.0",formId:"default-form",title:"Dynamic Form",description:"Please provide form schema or XBRL input data",sections:[]}}_getDefaultColumns(){return[{id:"base",title:"Value",description:"Base values for concepts",type:"base",order:0,removable:!1}]}_initializePeriodPreferencesFromData(){var e,t,i;if(!(null==(i=null==(t=null==(e=this.xbrlInput)?void 0:e.presentation)?void 0:t[0])?void 0:i.roles))return;const o={...this._periodPreferences};this.xbrlInput.presentation[0].roles.forEach(e=>{if(!o[e.id]){const t=!0===e.showPreviousYear,i=void 0===e.instant||!0===e.instant,r=void 0===e.duration||!0===e.duration;o[e.id]={showDuration:r,showInstant:i,showPreviousYear:t}}}),this._periodPreferences=o}_applyRoleFilter(){if(!this._currentSchema||!this._allSections.length)return;if(console.log(`πŸ” Applying role filter: ${this._selectedRoleIds.length} selected out of ${this._allSections.length} total`),0===this._selectedRoleIds.length)return console.log("πŸ“ No roles selected - showing empty form"),this._currentSchema={...this._currentSchema,sections:[]},void this.requestUpdate();this._preserveDataForHiddenSections();const e=this._allSections.filter(e=>this._selectedRoleIds.includes(e.id));console.log(`πŸ“Š Filtered sections: ${e.length} (IDs: ${e.map(e=>e.id).join(", ")})`),this._restoreDataForVisibleSections(e),this._currentSchema={...this._currentSchema,sections:e},console.log(`βœ… Schema updated. Current sections count: ${this._currentSchema.sections.length}`),this.requestUpdate()}_filterRolesByFinancialStatementsType(e){var t;if(!this.financialStatementsTypeAxis||0===this.financialStatementsTypeAxis.length)return e;if(!(null==(t=this.xbrlInput)?void 0:t.hypercubes)||0===this.xbrlInput.hypercubes.length)return e;const i=this.xbrlInput.hypercubes[0];return console.log("πŸ” Filter values:",this.financialStatementsTypeAxis),e.filter(e=>{var t;const o=null==(t=i.roles)?void 0:t.find(t=>t.roleId===e.id);if(!o||!o.items||0===o.items.length)return console.log(`βœ… ${e.title}: No hypercube entry - INCLUDED`),!0;let r=!1,n=!1;for(const i of o.items){if(!i.dimensions||0===i.dimensions.length)continue;const e=i.dimensions.find(e=>{var t;return"bw2-titel9_FinancialStatementsTypeAxis"===e.id||(null==(t=e.conceptName)?void 0:t.includes("FinancialStatementsTypeAxis"))});if(e&&(r=!0,e.members&&e.members.length>0)){if(e.members.some(e=>{if(e.conceptName){const t=e.conceptName.split(":"),i=t.length>1?t[1]:e.conceptName;return this.financialStatementsTypeAxis.some(e=>{const t=e.split(":"),o=t.length>1?t[1]:e;return i===o})}return this.financialStatementsTypeAxis.includes(e.id)})){n=!0;break}}}return!r||n})}_preserveDataForHiddenSections(){var e;((null==(e=this._currentSchema)?void 0:e.sections.map(e=>e.id))||[]).filter(e=>!this._selectedRoleIds.includes(e)).forEach(e=>{const t=this._allSections.find(t=>t.id===e);t&&this._preserveSectionData(t)})}_restoreDataForVisibleSections(e){e.forEach(e=>{this._restoreSectionData(e)}),console.log(`πŸ”„ Restored data for ${e.length} visible sections`)}_preserveSectionData(e){e.concepts.forEach(e=>{this._preserveConceptData(e)})}_preserveConceptData(e){this._formData[e.id]&&(this._preservedFormData[e.id]={...this._formData[e.id]}),e.fields.forEach(e=>{this._typedMemberData[e.columnId]&&(this._preservedTypedMemberData[e.columnId]={...this._typedMemberData[e.columnId]})}),e.children&&e.children.forEach(e=>{this._preserveConceptData(e)})}_restoreSectionData(e){e.concepts.forEach(e=>{this._restoreConceptData(e)})}_restoreConceptData(e){this._preservedFormData[e.id]&&(this._formData[e.id]={...this._preservedFormData[e.id]}),e.fields.forEach(e=>{this._preservedTypedMemberData[e.columnId]&&(this._typedMemberData[e.columnId]={...this._preservedTypedMemberData[e.columnId]})}),e.children&&e.children.forEach(e=>{this._restoreConceptData(e)})}_shouldShowFilterButton(){return!0}_handleFilterRolesClick(){this._showFilterDialog=!0}_handleFilterDialogCancel(){this._showFilterDialog=!1,console.log(`🚫 Filter dialog cancelled. Current selection: ${this._selectedRoleIds.length}/${this._allSections.length}`)}_handleRoleFilterApply(e){const{selectedRoleIds:t,periodPreferences:i}=e.detail;this._selectedRoleIds=t;if(JSON.stringify(this._periodPreferences)!==JSON.stringify(i)){if(this._periodPreferences=i,console.log("πŸ“Š Period preferences updated:",this._periodPreferences),this._skipDraftLoading=!0,this._initializeForm(),this._skipDraftLoading=!1,this._draftStorageService.hasDraft()){console.log("πŸ’Ύ Updating draft with new period preferences...");const e=this._generateSubmissionData(),t=this._draftStorageService.createMetadataSnapshot(this.periodStartDate,this.periodEndDate,this.language,this._selectedRoleIds,this._allSections,this._typedMemberData,this._periodPreferences);this._draftStorageService.saveDraft(e,t),console.log("βœ… Draft updated with new period preferences")}}else this._applyRoleFilter();this._showFilterDialog=!1,console.log(`🎯 Applied role filter: ${t.length}/${this._allSections.length} roles selected`),this.dispatchEvent(new CustomEvent("roles-filter-changed",{detail:{selectedRoleIds:t,totalRoles:this._allSections.length,visibleRoles:t.length,periodPreferences:i},bubbles:!0}))}_validateForm(){var e;const t=[],i=this._currentSchema;if(i){for(const o of i.sections)for(const i of o.concepts)for(const o of i.fields){const r=null==(e=this._formData[i.id])?void 0:e[o.columnId],n=C.validateField(o.id,i.id,o.columnId,r,o.type,o.validation||[]);t.push(...n)}this._errors=t,this._valid=0===t.filter(e=>"error"===e.severity).length}}_handleFieldChange(e){const{fieldId:t,conceptId:i,columnId:o,value:r}=e.detail;console.log(`πŸ“ Field change: conceptId=${i}, columnId=${o}, value=${r}, fieldId=${t}`);const n={...this._formData};n[i]||(n[i]={});const s=n[i][o];n[i]={...n[i],[o]:r},this._formData=n,console.log(`πŸ’Ύ Updated formData[${i}]:`,this._formData[i]),this._touched.add(`${i}-${o}`),this._dirty=!0,this._validateForm(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("field-change",{detail:{fieldId:t,conceptId:i,columnId:o,value:r,oldValue:s},bubbles:!0}))}_generateUniqueConceptKey(e,t){return`${e}::${t}`}_extractOriginalConceptId(e){const t=e.split("::");return t.length>1?t[1]:e}_handleTypedMemberChange(e){const{columnId:t,axisId:i,value:o}=e.detail;console.log(`πŸ” [DynamicForm] Typed member change: columnId=${t}, axisId=${i}, value=${o}`);const r={...this._typedMemberData};r[t]||(r[t]={}),r[t]={...r[t],[i]:o},this._typedMemberData=r,this._dirty=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("typed-member-change",{detail:{columnId:t,axisId:i,value:o},bubbles:!0}))}_handleSectionExpand(e){this.dispatchEvent(new CustomEvent("section-expand",{detail:e.detail,bubbles:!0}))}_handleConceptExpand(e){this.dispatchEvent(new CustomEvent("concept-expand",{detail:e.detail,bubbles:!0}))}_handleColumnRemove(e){const{columnId:t,sectionId:i}=e.detail;if(this._currentSchema&&i){const e=this._currentSchema.sections.find(e=>e.id===i);e&&e.columns&&(e.columns=e.columns.filter(e=>e.id!==t))}else this._columns=this._columns.filter(e=>e.id!==t),this._currentSchema&&this._currentSchema.sections.forEach(e=>{e.columns&&(e.columns=e.columns.filter(e=>e.id!==t))});this._removeColumnData(t,i),this._dirty=!0,this._validateForm(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("column-remove",{detail:{columnId:t,sectionId:i},bubbles:!0}))}_handleColumnAddRequest(e){const{sectionId:t,columnRequest:i}=e.detail;this._addColumnFromRequest(i,t)}_getAvailableDimensionsForSection(e){var t,i,o;if(!(null==(i=null==(t=this.xbrlInput)?void 0:t.hypercubes)?void 0:i[0]))return[];const r=this.xbrlInput.hypercubes[0].roles.find(t=>t.roleId===e);if(!(null==(o=null==r?void 0:r.items)?void 0:o.length))return console.log(`❌ No hypercube items found for role: ${e}`),[];const n=[];return r.items.forEach(e=>{e.dimensions&&e.dimensions.length>0&&e.dimensions.forEach(e=>{var t;if(!n.find(t=>t.id===e.id)){const i=(null==(t=e.labels.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:t.label)||e.conceptName,o={id:e.id,conceptName:e.conceptName,axisLabel:i};e.members&&e.members.length>0&&(o.members=e.members.map(e=>{var t,i;return{id:e.id,label:(null==(i=null==(t=e.labels)?void 0:t.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:i.label)||e.conceptName||e.id}})),e.typedMember&&(o.typedMember={id:e.typedMember.id,dataType:"string"}),n.push(o)}})}),n}_addColumnFromRequest(e,t){var i,o,r,n,s;const a=`col-${Date.now()}`;let l="",d="";"instant"===e.periodType?(l=e.instantDate||"",d=""):"duration"!==e.periodType&&"mixed"!==e.periodType||(l=`${e.startDate} / ${e.endDate}`,d="");let c={dimensionId:"period",memberValue:"instant"===e.periodType?`instant-${e.instantDate}`:`duration-${e.startDate}-${e.endDate}`,memberLabel:l};if(e.selectedDimensions&&e.selectedDimensions.length>0){const t=[],i=[];for(const r of e.selectedDimensions)r.isTyped&&r.typedValue?(t.push(`${r.axisLabel}: ${r.typedValue}`),i.push(`${r.axisId}|${r.typedValue}`)):r.memberId&&r.memberLabel&&(t.push(r.memberLabel),i.push(`${r.axisId}|${r.memberId}`));const o="instant"===e.periodType?`(${e.instantDate})`:`(${e.startDate} / ${e.endDate})`;t.length>0&&(l=`${t.join(" | ")} ${o}`,c={dimensionId:a,memberValue:t.join(" | "),memberLabel:t.join(" | "),memberKey:t.join(" | "),dimensionIdKey:i.join("::"),selectedDimensions:e.selectedDimensions},console.log(`πŸ“Š Applied selected dimensions to new column: ${c.memberKey}`))}else if(null==(o=null==(i=this.xbrlInput)?void 0:i.hypercubes)?void 0:o[0]){const i=this.xbrlInput.hypercubes[0].roles.find(e=>e.roleId===t);if(1===(null==(r=null==i?void 0:i.items)?void 0:r.length)){const t=i.items[0];if(1===t.dimensions.length){const i=t.dimensions[0];if(i.members&&i.members.length>0){const t=(null==(n=i.labels.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:n.label)||i.conceptName,o=i.members[0],r=(null==(s=o.labels.find(e=>"http://www.xbrl.org/2003/role/label"===e.role))?void 0:s.label)||o.conceptName;l=`${r} ${"instant"===e.periodType?`(${e.instantDate})`:`(${e.startDate} / ${e.endDate})`}`,c={dimensionId:a,axisId:i.id,memberId:o.id,memberValue:r,memberLabel:r,axis:t,axisLabel:t,memberKey:`${t} | ${r}`,dimensionIdKey:`${i.id} | ${o.id}`},console.log(`πŸ“Š Applied hypercube dimension to new column: ${c.memberKey}`)}}}}const p={id:a,title:l,description:d,type:(c.memberKey,"dimension"),order:this._columns.length,removable:!0,dimensionData:c};if(e.selectedDimensions&&e.selectedDimensions.length>0){const t={};let i=!1;for(const o of e.selectedDimensions)o.isTyped&&(t[o.axisId]=o.typedValue||"",i=!0);i&&(this._typedMemberData[a]=t,p.dimensionData&&(p.dimensionData.hasTypedMembers=!0,p.dimensionData.typedMembers=e.selectedDimensions.filter(e=>e.isTyped).map(e=>({axisId:e.axisId,axisLabel:e.axisLabel,typedMemberId:e.axisId,memberLabel:e.axisLabel}))))}if(this._currentSchema){const e=this._currentSchema.sections.find(e=>e.id===t);e&&(e.columns||(e.columns=[...this._columns]),e.columns=[...e.columns,p])}this._replicateFieldsForNewColumn(a,e,t),this._dirty=!0,this.requestUpdate(),this.dispatchEvent(new CustomEvent("column-add",{detail:{column:p},bubbles:!0}))}_removeColumnData(e,t){if(this._currentSchema)if(t){const i=this._currentSchema.sections.find(e=>e.id===t);i&&this._removeColumnDataFromConcepts(i.concepts,e)}else for(const i in this._formData)void 0!==this._formData[i][e]&&delete this._formData[i][e]}_removeColumnDataFromConcepts(e,t){e.forEach(e=>{this._formData[e.id]&&void 0!==this._formData[e.id][t]&&delete this._formData[e.id][t],e.fields&&(e.fields=e.fields.filter(e=>e.columnId!==t)),e.children&&this._removeColumnDataFromConcepts(e.children,t)})}_shouldCreateFieldForConcept(e,t){if(e.abstract)return!1;if(e.periodType){if("instant"===t.periodType&&"instant"!==e.periodType)return!1;if("duration"===t.periodType&&"duration"!==e.periodType)return!1}return!0}_replicateFieldsForNewColumn(e,t,i){if(!this._currentSchema)return;const o=new T,r=this._currentSchema.sections.find(e=>e.id===i);r&&this._replicateFieldsForSection(r.concepts,e,t,o)}_replicateFieldsForSection(e,t,i,o){e.forEach(e=>{var r;if(this._shouldCreateFieldForConcept(e,i)){const o=null==(r=e.fields)?void 0:r[0];let n;n=o?{id:`${e.id}_${t}`,conceptId:e.id,columnId:t,type:o.type,label:o.label,placeholder:o.placeholder,required:o.required,disabled:o.disabled,validation:o.validation,defaultValue:o.defaultValue,periodStartDate:"instant"===i.periodType?i.instantDate:i.startDate,periodEndDate:"instant"===i.periodType?i.instantDate:i.endDate}:{id:`${e.id}_${t}`,conceptId:e.id,columnId:t,type:"text",label:e.label||e.name,placeholder:`Enter ${e.name}`,required:!1,disabled:!1,validation:[],defaultValue:"",periodStartDate:"instant"===i.periodType?i.instantDate:i.startDate,periodEndDate:"instant"===i.periodType?i.instantDate:i.endDate},e.fields||(e.fields=[]),e.fields.push(n)}e.children&&this._replicateFieldsForSection(e.children,t,i,o)})}_addColumn(){const e={id:`dim-${Date.now()}`,title:`Dimension ${this._columns.length}`,description:"Additional dimension column",type:"dimension",order:this._columns.length,removable:!0,dimensionData:{dimensionId:"custom",memberValue:"default",memberLabel:"Default Member"}};this._columns=[...this._columns,e],this.requestUpdate(),this.dispatchEvent(new CustomEvent("column-add",{detail:{column:e},bubbles:!0}))}_handleSubmit(){if(console.log("πŸ“ Form submission started..."),this._submitted=!0,"admin"===this.mode)return void this._handleAdminModeSubmit();this._validateForm();const e=this._generateSubmissionData();console.log("πŸ“Š Form Submission Data:",JSON.stringify(e,null,2)),this.dispatchEvent(new CustomEvent("form-submit",{detail:{data:this._formData,submissionData:e,valid:this._valid,errors:this._errors},bubbles:!0})),console.log("βœ… Form submit event dispatched")}_handleSaveDraft(){console.log("πŸ’Ύ Raw form data before submission generation:",this._formData);const e=this._generateSubmissionData();console.log("πŸ“€ Generated submission data:",e),console.log("πŸ“Š Submission data breakdown:"),e.forEach((e,t)=>{console.log(` [${t}] conceptId: ${e.conceptId}, columnId: ${e.columnId}, value: ${e.value}`)});const t=this._draftStorageService.createMetadataSnapshot(this.periodStartDate,this.periodEndDate,this.language,this._selectedRoleIds,this._allSections,this._typedMemberData,this._periodPreferences),i=this._draftStorageService.saveDraft(e,t);this.dynaformsFacts=e,this.dynaformsMetadata=t,this.dispatchEvent(new CustomEvent("form-save-draft",{detail:{data:this._formData,draftData:e,metadata:t,saved:i,valid:this._valid,errors:this._errors,dynaformsFacts:e,dynaformsMetadata:t},bubbles:!0,composed:!0})),console.log("πŸ’Ύ Draft saved - localStorage + event emitted",{entries:e.length,saved:i,roles:this._selectedRoleIds.length,customColumns:t.customColumns.length,eventEmitted:!0})}async _loadDraftIfExists(){if(console.log("πŸ“‹ Checking for saved draft..."),this.dynaformsFacts&&this.dynaformsMetadata){console.log("πŸ“¦ Using external draft data from properties");const e={formData:this.dynaformsFacts,metadata:this.dynaformsMetadata};return await this._restoreFromDraft(e),this._draftLoaded=!0,this._draftLoadedAt=this.dynaformsMetadata.savedAt||(new Date).toISOString(),this.dispatchEvent(new CustomEvent("form-draft-loaded",{detail:{draft:e,source:"external",compatible:!0,warnings:[]},bubbles:!0,composed:!0})),void console.log("πŸ“₯ External draft loaded successfully")}if(!this._draftStorageService.hasDraft())return void console.log("ℹ️ No saved draft found");const e=this._draftStorageService.loadDraft();if(!e)return void console.warn("⚠️ Failed to load draft");const{compatible:t,warnings:i}=this._draftStorageService.validateDraftCompatibility(e,this.periodStartDate,this.periodEndDate);i.length>0&&console.warn("⚠️ Draft compatibility warnings:",i),await this._restoreFromDraft(e),this.dispatchEvent(new CustomEvent("form-draft-loaded",{detail:{draft:e,compatible:t,warnings:i},bubbles:!0,composed:!0})),console.log("πŸ“₯ Draft loaded successfully",{entries:e.formData.length,savedAt:e.metadata.savedAt,age:this._draftStorageService.getDraftAge()})}async _restoreFromDraft(e){var t;const{formData:i,metadata:o}=e;o.selectedRoleIds&&o.selectedRoleIds.length>0&&(this._selectedRoleIds=o.selectedRoleIds,console.log(`πŸ”„ Restored ${this._selectedRoleIds.length} selected roles`)),o.typedMemberData&&(this._typedMemberData=o.typedMemberData,this._preservedTypedMemberData={},console.log("πŸ”„ Restored typed member data")),o.periodPreferences?(this._periodPreferences=o.periodPreferences,console.log("πŸ”„ Restored period preferences (including previous year settings):",this._periodPreferences),this.xbrlInput&&(console.log("πŸ”„ Rebuilding schema with restored period preferences..."),this._currentSchema=T.buildFormSchema(this.xbrlInput,this.periodStartDate,this.periodEndDate,this.language,this._periodPreferences),this._allSections=[...this._currentSchema.sections],this.financialStatementsTypeAxis&&this.financialStatementsTypeAxis.length>0&&(this._allSections=this._filterRolesByFinancialStatementsType(this._allSections)),console.log("βœ… Schema rebuilt with restored period preferences"),o.customColumns&&o.customColumns.length>0&&(this._mergeAdditionalCustomColumns(o.customColumns),console.log(`πŸ”„ Merged ${o.customColumns.length} additional custom columns`)))):o.customColumns&&o.customColumns.length>0&&(this._restoreCustomColumns(o.customColumns),console.log(`πŸ”„ Restored ${o.customColumns.length} custom columns`));const r={};i.forEach(e=>{let{conceptId:t,value:i,columnId:o,period:n}=e;if(!o&&n&&(o=this._inferColumnIdFromPeriod(n,t),!o))return void console.warn(`⚠️ Could not infer columnId for concept ${t}, skipping...`);const s=this._findActualConceptId(t)||t;r[s]||(r[s]={}),r[s][o]=i,console.log(`πŸ“¦ Restored: ${s}[${o}] = ${i}`)}),this._formData={...this._formData,...r},console.log(`πŸ”„ Restored ${Object.keys(r).length} concepts with data`),this._selectedRoleIds.length>0&&this._applyRoleFilter(),this._dirty=!0,this._touched.clear(),this._validateForm(),this._allSections=[...this._allSections],this.requestUpdate(),await this.updateComplete,await new Promise(e=>setTimeout(e,100));const n=(null==(t=this.shadowRoot)?void 0:t.querySelectorAll("input, textarea, select").length)||0;console.log(`πŸ” Found ${n} fields in DOM after update`),n>0?this._populateFieldValues(r):console.error("❌ No fields found in DOM even after updateComplete"),console.log("βœ… Draft restoration completed")}_findActualConceptId(e){for(const t of this._allSections){const i=this._findActualConceptIdInTree(t.concepts,e);if(i)return i}return null}_findActualConceptIdInTree(e,t){for(const i of e){if(i.originalConceptId===t||i.id===t)return i.id;if(i.children){const e=this._findActualConceptIdInTree(i.children,t);if(e)return e}}return null}_inferColumnIdFromPeriod(e,t){for(const i of this._allSections){if(this._findConceptInSection(i.concepts,t)&&i.columns){for(const o of i.columns){const i="instant"===e.type,r="duration"===e.type;if(i&&e.date){if(o.periodStartDate===e.date||o.periodStartDate===o.periodEndDate&&o.periodStartDate===e.date)return console.log(`βœ“ Inferred columnId: ${o.id} for concept ${t}`),o.id}else if(r&&e.startDate&&e.endDate&&o.periodStartDate===e.startDate&&o.periodEndDate===e.endDate)return console.log(`βœ“ Inferred columnId: ${o.id} for concept ${t}`),o.id}if("instant"===e.type){const e=i.columns.find(e=>"instant"===e.id);if(e)return e.id}else{const e=i.columns.find(e=>"duration"===e.id);if(e)return e.id}}}return null}_findConceptInSection(e,t){for(const i of e){if(i.id===t||i.originalConceptId===t)return i;if(i.children){const e=this._findConceptInSection(i.children,t);if(e)return e}}return null}_populateFieldValues(e){let t=0,i=0;console.log("πŸ” Starting field population..."),console.log("πŸ“¦ Form data to populate:",e),Object.keys(e).forEach(o=>{const r=e[o];Object.keys(r).forEach(e=>{var n,s;const a=r[e],l=`${o}__${e}`;console.log(`πŸ” Looking for field: ${l}`);const d=null==(n=this.shadowRoot)?void 0:n.querySelector(`#${CSS.escape(l)}`);d?(d instanceof HTMLInputElement||d instanceof HTMLTextAreaElement||d instanceof HTMLSelectElement)&&("checkbox"===d.type?d.checked=Boolean(a):d.value=null!=a?String(a):"",console.log(` βœ… Populated field ${l} with value:`,a),t++):(console.warn(` ❌ Field element NOT FOUND: ${l}`),console.warn(" Available fields in DOM:",Array.from((null==(s=this.shadowRoot)?void 0:s.querySelectorAll("input, textarea, select"))||[]).map(e=>e.id).filter(e=>e.includes(o.split("__")[0]))),i++)})}),console.log(`βœ… Field population complete: ${t} populated, ${i} not found`)}_restoreCustomColumns(e){const t=new Map;e.forEach(e=>{t.has(e.sectionId)||t.set(e.sectionId,[]),t.get(e.sectionId).push(e)}),this._allSections.forEach(e=>{const i=t.get(e.id);i&&(e.columns=i.map(e=>({id:e.columnId,title:e.label,type:e.dimensionData?"dimension":"base",periodStartDate:e.startDate||e.date,periodEndDate:e.endDate||e.date,dimensionData:e.dimensionData,order:0,removable:"duration"!==e.columnId&&"instant"!==e.columnId})),this._regenerateFieldsForSection(e),console.log(` └─ Restored ${i.length} columns for section ${e.id}`))}),this._currentSchema&&(this._currentSchema={...this._currentSchema,sections:this._allSections})}_mergeAdditionalCustomColumns(e){const t=new Map;e.forEach(e=>{e.columnId.startsWith("col-")&&(t.has(e.sectionId)||t.set(e.sectionId,[]),t.get(e.sectionId).push(e))}),this._allSections.forEach(e=>{const i=t.get(e.id);i&&i.length>0&&(e.columns||(e.columns=[]),i.forEach(t=>{if(!e.columns.find(e=>e.id===t.columnId)){const i={id:t.columnId,title:t.label,type:t.dimensionData?"dimension":"base",periodStartDate:t.startDate||t.date,periodEndDate:t.endDate||t.date,dimensionData:t.dimensionData,order:e.columns.length,removable:!0};e.columns.push(i),console.log(` └─ Added custom column ${t.columnId} to section ${e.id}`)}}),this._regenerateFieldsForSection(e))}),this._currentSchema&&(this._currentSchema={...this._currentSchema,sections:this._allSections})}_regenerateFieldsForSection(e){if(!e.columns)return;const t=this._periodPreferences[e.id]||{showDuration:!0,showInstant:!0,showPreviousYear:!1},i=o=>{o.forEach(o=>{o.fields=[];this._shouldShowConceptBasedOnPeriodPreferences(o,t)&&e.columns.forEach(e=>{const t=o.periodType,i=this._inferColumnPeriodType(e);o.abstract||t&&i&&t!==i||o.fields.push({id:`${o.id}_${e.id}`,conceptId:o.id,columnId:e.id,type:this._mapConceptTypeToFieldType(o.type),label:o.label,periodStartDate:e.periodStartDate,periodEndDate:e.periodEndDate})}),o.children&&i(o.children)})};i(e.concepts)}_shouldShowConceptBasedOnPeriodPreferences(e,t){return!!e.abstract||(!e.periodType||!("duration"===e.periodType&&!t.showDuration)&&!("instant"===e.periodType&&!t.showInstant))}_inferColumnPeriodType(e){return e.periodStartDate&&e.periodEndDate?e.periodStartDate===e.periodEndDate?"instant":"duration":e.periodStartDate&&!e.periodEndDate?"instant":void 0}_mapConceptTypeToFieldType(e){return e?e.includes("monetary")||e.includes("Monetary")?"number":e.includes("date")||e.includes("Date")?"date":e.includes("boolean")||e.includes("Boolean")?"boolean":e.includes("integer")||e.includes("Integer")||e.includes("decimal")||e.includes("Decimal")?"number":"text":"text"}_generateSubmissionData(){const e=[];if(!this._currentSchema)return e;this._currentSchema.sections.forEach(t=>{this._processConceptsForSubmission(t.concepts,e,t)}),this._includePreservedDataInSubmission(e);return this._removeDuplicateSubmissions(e)}_includePreservedDataInSubmission(e){Object.keys(this._preservedFormData).forEach(t=>{const i=this._preservedFormData[t];i&&Object.keys(i).forEach(o=>{const r=i[o];if(null!=r&&""!==r){const i=this._findConceptInAllSections(t);if(i){const n=this._findSectionForConcept(t);this._addConceptDataToSubmission(i,o,r,e,n||void 0)}}})}),console.log(`πŸ“€ Included preserved data in submission. Total entries: ${e.length}`)}_findConceptInAllSections(e){for(const t of this._allSections){const i=this._findConceptInSection(t.concepts,e);if(i)return i}return null}_findSectionForConcept(e){for(const t of this._allSections){if(this._findConceptInSection(t.concepts,e))return t}return null}_addConceptDataToSubmission(e,t,i,o,r){var n;const s=e.fields.find(e=>e.columnId===t);if(!s)return;const a="instant"===e.periodType,l=this._findColumnByIdInAllSections(t);console.log(`πŸ” [Submission] Concept: ${e.id}, Column: ${t}, Column Period: ${(null==l?void 0:l.periodStartDate)||"none"} - ${(null==l?void 0:l.periodEndDate)||"none"}`);const d={conceptId:e.originalConceptId||e.id,columnId:t,value:i,period:{type:e.periodType||"duration",...a?{date:(null==l?void 0:l.periodEndDate)||s.periodStartDate||this.periodStartDate}:{startDate:(null==l?void 0:l.periodStartDate)||s.periodStartDate||this.periodStartDate,endDate:(null==l?void 0:l.periodEndDate)||s.periodEndDate||this.periodEndDate}}};(null==(n=null==l?void 0:l.dimensionData)?void 0:n.memberLabel)&&(d.dimension=l.dimensionData.memberLabel),o.push(d)}_findColumnByIdInAllSections(e){for(const t of this._allSections)if(t.columns){const i=t.columns.find(t=>t.id===e);if(i)return i}}_removeDuplicateSubmissions(e){const t=new Map;return e.forEach(e=>{const i="instant"===e.period.type?e.period.date:`${e.period.startDate}_${e.period.endDate}`,o=`${e.conceptId}_${e.value}_${e.dimension||"no-dimension"}_${i}`;t.has(o)||t.set(o,e)}),Array.from(t.values())}_findColumnById(e){if(this._currentSchema)for(const t of this._currentSchema.sections)if(t.columns){const i=t.columns.find(t=>t.id===e);if(i)return i}}_findColumnByIdInSection(e,t){if(null==t?void 0:t.columns)return t.columns.find(t=>t.id===e)}_getTypedMemberNameForAxis(e,t){var i,o,r,n;if(!(null==(o=null==(i=this.xbrlInput)?void 0:i.hypercubes)?void 0:o[0]))return null;const s=null==t?void 0:t.id;if(!s)return null;const a=null==(r=this.xbrlInput.hypercubes[0].roles)?void 0:r.find(e=>e.roleId===s);if(!(null==a?void 0:a.items))return null;for(const l of a.items)if(l.dimensions){const t=l.dimensions.find(t=>t.id===e);if(null==(n=null==t?void 0:t.typedMember)?void 0:n.id)return t.typedMember.id}return null}_doesConceptApplyToTypedDimension(e,t,i){var o,r,n;if(!(null==(r=null==(o=this.xbrlInput)?void 0:o.hypercubes)?void 0:r[0]))return!1;const s=null==t?void 0:t.id;if(!s)return!1;const a=this.xbrlInput.hypercubes[0].roles.find(e=>e.roleId===s);if(!(null==(n=null==a?void 0:a.items)?void 0:n.length))return!1;for(const l of a.items){const t=e.originalConceptId||e.id;if(l.conceptIds&&l.conceptIds.includes(t)){const e=l.dimensions.some(e=>e.typedMember);return console.log(`πŸ” [DynamicForm] Concept ${t} found in hypercube item. Has typed dimensions:`,e),e}}return console.log(`πŸ” [DynamicForm] Concept ${e.originalConceptId||e.id} not found in any hypercube items for role ${s}`),!1}_getApplicableTypedDimensions(e,t){var i,o,r;if(!(null==(o=null==(i=this.xbrlInput)?void 0:i.hypercubes)?void 0:o[0])||!(null==t?void 0:t.id))return[];const n=this.xbrlInput.hypercubes[0].roles.find(e=>e.roleId===t.id);if(!(null==(r=null==n?void 0:n.items)?void 0:r.length))return[];const s=e.originalConceptId||e.id;for(const a of n.items)if(a.conceptIds&&a.conceptIds.includes(s)){const e=a.dimensions.filter(e=>e.typedMember).map(e=>e.id);return console.log(`πŸ” [DynamicForm] Found applicable typed dimensions for concept ${s}:`,e),e}return[]}_processConceptsForSubmission(e,t,i){const o="Toelichting op de geconsolideerde jaarrekening - FinanciΓ«le vaste activa: Deelnemingen: Volledig geconsolideerd: Specificatie",r=(null==i?void 0:i.title)||"Unknown";e.forEach(e=>{r===o&&(console.warn(`[DUPLICATE DEBUG] Processing concept ${e.originalConceptId||e.id} in target role`),e.fields&&(console.warn(`[DUPLICATE DEBUG] Concept has ${e.fields.length} fields`),e.fields.forEach((t,i)=>{var o;console.warn(`[DUPLICATE DEBUG] Field ${i}: columnId=${t.columnId}, current value=${null==(o=this._formData[e.id])?void 0:o[t.columnId]}`)}))),e.fields&&e.fields.length>1&&e.fields.forEach((e,t)=>{}),e.fields&&e.fields.length>0&&e.fields.forEach(n=>{var s,a;const l=this._formData[e.id],d=null==l?void 0:l[n.columnId];if(null!=d&&""!==d){const l=this._findColumnByIdInSection(n.columnId,i),c={conceptId:e.id,columnId:n.columnId,value:d,period:{type:e.periodType||"duration"}};if("instant"===e.periodType?c.period.date=(null==l?void 0:l.periodEndDate)||n.periodStartDate||this.periodStartDate:(c.period.startDate=(null==l?void 0:l.periodStartDate)||n.periodStartDate||this.periodStartDate,c.period.endDate=(null==l?void 0:l.periodEndDate)||n.periodEndDate||this.periodEndDate),console.log(`πŸ” [Submission] Concept: ${e.id}, Column: ${n.columnId}, Column Period: ${(null==l?void 0:l.periodStartDate)||"none"} - ${(null==l?void 0:l.periodEndDate)||"none"}, Used Period: ${"instant"===c.period.type?c.period.date:`${c.period.startDate} - ${c.period.endDate}`}`),"dimension"===(null==l?void 0:l.type)&&(null==(s=l.dimensionData)?void 0:s.dimensionIdKey)?(c.dimension=l.dimensionData.dimensionIdKey,console.log(`πŸ” [DynamicForm] Using dimension key from field's column (${n.columnId}):`,l.dimensionData.dimensionIdKey)):console.log(`πŸ” [DynamicForm] No dimension data found for field column ${n.columnId}. Column type: ${null==l?void 0:l.type}, has dimensionData: ${!!(null==l?void 0:l.dimensionData)}`),this._typedMemberData[n.columnId]){const t=this._getApplicableTypedDimensions(e,i);if(console.log(`πŸ” [DynamicForm] Concept ${e.id} applicable typed dimensions:`,t),t.length>0){const e={},o=this._typedMemberData[n.columnId];t.forEach(t=>{if(o[t]){const r=this._getTypedMemberNameForAxis(t,i);e[t]={value:o[t],memberName:r||"Unknown"}}}),Object.keys(e).length>0?(c.typedMembers=e,console.log("πŸ” [DynamicForm] Adding filtered typed members to submission:",e)):console.log("πŸ” [DynamicForm] No typed member values found for applicable dimensions:",t)}else console.log(`πŸ” [DynamicForm] Skipping typed members for concept ${e.id} - not applicable to this hypercube`)}else console.log(`πŸ” [DynamicForm] No typed member data found for column ${n.columnId}. Available columns:`,Object.keys(this._typedMemberData)),l&&console.log("πŸ” [DynamicForm] Column details:",{id:l.id,type:l.type,hasTypedMembers:null==(a=l.dimensionData)?void 0:a.hasTypedMembers,dimensionData:l.dimensionData});r===o&&console.warn("[DUPLICATE DEBUG] Final submission entry:",c),t.push(c)}}),e.children&&this._processConceptsForSubmission(e.children,t,i)})}_handleReset(){this._formData={...this.initialData},this._touched.clear(),this._dirty=!1,this._submitted=!1,this._preservedFormData={},this._preservedTypedMemberData={},console.log("πŸ”„ Form reset - all data and preserved data cleared"),this._validateForm(),this.requestUpdate(),this.dispatchEvent(new CustomEvent("form-reset",{detail:{},bubbles:!0}))}_getFormState(){return{data:this._formData,errors:this._errors,touched:this._touched,dirty:this._dirty,valid:this._valid,submitted:this._submitted}}_handleSidePanelRoleClick(e){this._activeSidePanelRoleId=e}_renderAdminModeContent(t){var i,o,r;if(!t)return e.html`
1584
1584
  <div class="admin-mode-container">
1585
1585
  <p>No role selected</p>
1586
1586
  </div>