"use strict";(globalThis.webpackChunkcomplianz_gdpr=globalThis.webpackChunkcomplianz_gdpr||[]).push([[1629],{81629:(e,i,t)=>{t.r(i),t.d(i,{default:()=>c});var n=t(81621),s=t(16535),o=t(9588),d=t(73710);const c=(0,n.vt)(((e,i)=>({documentsLoaded:!1,region:"",fileName:"",serviceName:"",fetching:!1,updating:!1,loadingFields:!1,documents:[],regions:[],fields:[],editDocumentId:!1,resetEditDocumentId:i=>{e({editDocumentId:!1,region:"",serviceName:""})},editDocument:async i=>{e({updating:!0}),await o.doAction("load_processing_agreement",{id:i}).then((i=>{e({fields:i.fields,region:i.region,serviceName:i.serviceName,updating:!1,fileName:i.file_name})})).catch((e=>{console.error(e)})),e({editDocumentId:i})},setRegion:i=>{e({region:i})},setServiceName:i=>{e({serviceName:i})},updateField:(t,n)=>{let o=!1,c=!1;e((0,s.Ay)((e=>{e.fields.forEach((function(e,i){e.id===t&&(c=i,o=!0)})),!1!==c&&(e.fields[c].value=n)})));let a=(0,d.updateFieldsListWithConditions)(i().fields);e({fields:a})},save:async(t,n)=>{e({updating:!0});let s=i().editDocumentId;await o.doAction("save_processing_agreement",{fields:i().fields,region:t,serviceName:n,post_id:s}).then((i=>(e({updating:!1}),i))).catch((e=>{console.error(e)})),i().fetchData()},deleteDocuments:async t=>{let n=i().documents.filter((e=>t.includes(e.id)));e((e=>({documents:e.documents.filter((e=>!t.includes(e.id)))})));let s={};s.documents=n,await o.doAction("delete_processing_agreement",s).then((e=>e)).catch((e=>{console.error(e)}))},fetchData:async()=>{if(i().fetching)return;e({fetching:!0});const{documents:t,regions:n}=await o.doAction("get_processing_agreements",{}).then((e=>e)).catch((e=>{console.error(e)}));e((()=>({documentsLoaded:!0,documents:t,regions:n,fetching:!1})))},fetchFields:async i=>{let t={region:i};e({loadingFields:!0});const{fields:n}=await o.doAction("get_processing_agreement_fields",t).then((e=>e)).catch((e=>{console.error(e)}));let s=(0,d.updateFieldsListWithConditions)(n);e((e=>({fields:s,loadingFields:!1})))}})))}}]);