import{g as S,r as x}from"./api-DZ3cXm1m.js";import{M as _,a as q}from"./bootstrap.esm-Bb7dPm-H.js";const i=window.verificationSettingsConfig||{};let v={},M=[],k=null,m=null,$=null;async function b(e,n={}){const t={headers:{Authorization:`Bearer ${S()}`,Accept:"application/json","Content-Type":"application/json"}},o=await fetch(e,{...t,...n,headers:{...t.headers,...n.headers}});if(o.status===401){const r=await x();if(r)return t.headers.Authorization=`Bearer ${r}`,fetch(e,{...t,...n,headers:{...t.headers,...n.headers}})}return o}async function h(){try{Object.keys(v).length===0&&await I();const n=await(await b(i.routes.countrySettings)).json();n.success&&O(n.data)}catch(e){console.error("Verification country settings loading error:",e)}}async function I(){try{const n=await(await b(i.routes.availableModules)).json();n.success&&(v=n.modules||{},M=n.countries||[],L(),A())}catch(e){console.error("Available modules loading error:",e)}}function L(){const e=document.getElementById("verCountryCode"),n=document.getElementById("verCountryEditId").value;if(e.innerHTML=`<option value="">${i.translations.selectCountry}</option>`,M.forEach(t=>{const o=document.createElement("option");o.value=t.code,o.textContent=`${t.name} (${t.code})`,e.appendChild(o)}),n){const t=e.dataset.editCountry;if(t&&!Array.from(e.options).some(o=>o.value===t)){const o=document.createElement("option");o.value=t,o.textContent=t,e.appendChild(o)}}}function A(){const e=document.getElementById("verModuleSelect");e.innerHTML=`<option value="">${i.translations.selectModule}</option>`,Object.entries(v).forEach(([n,t])=>{const o=document.createElement("option");o.value=n,o.textContent=`${t.label||n} — ${t.description||""}`,e.appendChild(o)})}function w(){const e=document.getElementById("verCountryCode").value,n=document.getElementById("verModuleSelect");if(!e){n.value="",B();return}v[e]?(n.value=e,E()):v.Generic&&(n.value="Generic",E())}async function E(){const e=document.getElementById("verModuleSelect").value;if(document.getElementById("verCountryCode").value,!e){B();return}try{const n=`${i.routes.moduleInfo}?country_code=${e}`,o=await(await b(n)).json();o.success&&(k=o,T(o))}catch(n){console.error("Module info loading error:",n)}}function T(e){var r,c,a;const n=document.getElementById("verModuleFieldsSection");n.style.display="";const t=document.getElementById("verModuleDescription");t&&e.module&&(t.textContent=e.module.description||""),j(e.verification_fields||((r=e.module)==null?void 0:r.verification_fields)||{});const o=document.getElementById("verApiSection");o&&(o.style.display=(a=(c=e.module)==null?void 0:c.features)!=null&&a.api_verification?"":"none"),H(e.config_fields||{}),D(e.api_providers||{},e.current_api_provider)}function D(e,n){const t=document.getElementById("verApiProvider"),o=document.getElementById("verApiProviderSection"),r=document.getElementById("verApiProviderDescription");if(!t||!o)return;const c=Object.entries(e);if(c.length===0){o.style.display="none",t.innerHTML='<option value="">—</option>',r&&(r.textContent="");return}t.innerHTML='<option value="">—</option>',c.forEach(([s,d])=>{const l=document.createElement("option");l.value=s,l.textContent=d.label||s,d.description&&(l.title=d.description),t.appendChild(l)});const a=$??n??"";t.value=a,o.style.display=""}function j(e){const n=document.getElementById("verDynamicFieldsContainer");n.innerHTML="";const t=Object.entries(e);if(t.length===0)return;const o={};t.forEach(([c,a])=>{const s=a.group||"general";o[s]||(o[s]=[]),o[s].push({key:c,...a})});const r={individual:"Bireysel",company:"Kurumsal",general:"Genel"};Object.entries(o).forEach(([c,a])=>{Object.keys(o).length>1&&(n.innerHTML+=`<div class="mb-2"><small class="text-muted fw-bold text-uppercase">${r[c]||c}</small></div>`),a.forEach(s=>{var f,u;const d=`verField_${s.key}`,l=((f=m==null?void 0:m[s.key])==null?void 0:f.enabled)??!1,p=((u=m==null?void 0:m[s.key])==null?void 0:u.required)??!1;n.innerHTML+=`
                <div class="mb-2 row align-items-center">
                    <label class="col-sm-4 col-form-label">${s.label}</label>
                    <div class="col-sm-8">
                        <div class="d-flex gap-3">
                            <div class="form-check">
                                <input class="form-check-input ver-field-toggle" type="checkbox" id="${d}_enabled"
                                       data-field-key="${s.key}" data-toggle-type="enabled" ${l?"checked":""}>
                                <label class="form-check-label" for="${d}_enabled">${i.translations.enabled}</label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input ver-field-toggle" type="checkbox" id="${d}_required"
                                       data-field-key="${s.key}" data-toggle-type="required" ${p?"checked":""}>
                                <label class="form-check-label" for="${d}_required">${i.translations.required}</label>
                            </div>
                        </div>
                    </div>
                </div>`})})}function B(){document.getElementById("verModuleFieldsSection").style.display="none",document.getElementById("verModuleDescription").textContent="",document.getElementById("verDynamicFieldsContainer").innerHTML="";const e=document.getElementById("verApiProviderSection");e&&(e.style.display="none"),k=null}function H(e){const n=document.getElementById("verModuleConfigSection");n.innerHTML="";const t=Object.entries(e);t.length!==0&&(n.innerHTML='<hr class="my-3"><h6 class="mb-3"><i class="fas fa-key me-1"></i> Module Configuration</h6>',t.forEach(([o,r])=>{const c=`verConfig_${o}`;let a;if(r.type==="boolean")a=`
                <div class="form-check form-switch">
                    <input class="form-check-input module-config-field" type="checkbox" id="${c}" data-config-key="${o}"
                           ${r.default?"checked":""}>
                </div>`;else if(r.type==="textarea")a=`<textarea class="form-control module-config-field" id="${c}" data-config-key="${o}"
                         rows="4" placeholder="${r.label||o}">${r.default||""}</textarea>`;else if(r.type==="select"&&r.options){const s=Object.entries(r.options).map(([d,l])=>`<option value="${d}" ${d===r.default?"selected":""}>${l}</option>`).join("");a=`<select class="form-select module-config-field" id="${c}" data-config-key="${o}">${s}</select>`}else a=`<input type="${r.type==="password"?"password":"text"}" class="form-control module-config-field"
                         id="${c}" data-config-key="${o}" placeholder="${r.label||o}"
                         value="${r.default||""}">`;n.innerHTML+=`
            <div class="mb-3 row align-items-center">
                <label class="col-sm-4 col-form-label" for="${c}">${r.label||o}</label>
                <div class="col-sm-8">
                    ${a}
                    ${r.description?`<small class="form-text text-muted">${r.description}</small>`:""}
                </div>
            </div>`}))}function O(e){const n=document.getElementById("verificationCountryBody");if(!e||e.length===0){n.innerHTML=`<tr><td colspan="6" class="text-center text-muted">${i.translations.noCountries}</td></tr>`;return}n.innerHTML=e.map(t=>{const o=F(t);return`
        <tr data-id="${t.id}">
            <td>
                <strong>${t.country_code}</strong> <span class="text-muted">${t.country_name||""}</span>
                ${t.verification_module?`<br><span class="badge bg-info bg-opacity-25 text-info mt-1"><i class="fas fa-puzzle-piece me-1"></i>${t.verification_module}</span>`:""}
            </td>
            <td>${o}</td>
            <td class="text-center">
                ${V(t.document_upload_enabled,t.document_upload_required)}
            </td>
            <td class="text-center">
                ${t.api_verification_enabled?'<span class="badge bg-success"><i class="fas fa-check"></i></span>':'<span class="badge bg-secondary"><i class="fas fa-times"></i></span>'}
            </td>
            <td>
                <button type="button" class="btn btn-sm btn-outline-primary edit-ver-country-btn" data-setting='${JSON.stringify(t)}'>
                    <i class="fas fa-edit"></i>
                </button>
                <button type="button" class="btn btn-sm btn-outline-danger delete-ver-country-btn" data-id="${t.id}">
                    <i class="fas fa-trash"></i>
                </button>
            </td>
        </tr>`}).join(""),n.querySelectorAll(".edit-ver-country-btn").forEach(t=>{t.addEventListener("click",function(){R(JSON.parse(this.dataset.setting))})}),n.querySelectorAll(".delete-ver-country-btn").forEach(t=>{t.addEventListener("click",function(){J(this.dataset.id)})})}function F(e){const n=e.field_settings;if(n&&Object.keys(n).length>0){const o=v[e.verification_module||e.country_code],r=(o==null?void 0:o.verification_fields)||{};return Object.entries(n).filter(([c,a])=>a.enabled).map(([c,a])=>{var u,g;const s=((u=r[c])==null?void 0:u.label)||c,d=((g=r[c])==null?void 0:g.group)||"",l=d==="individual"?'<i class="fas fa-user me-1"></i>':d==="company"?'<i class="fas fa-building me-1"></i>':"",p=a.required?"bg-success":"bg-info bg-opacity-75",f=a.required?" *":"";return`<span class="badge ${p} me-1 mb-1">${l}${s}${f}</span>`}).join("")||'<span class="text-muted small">—</span>'}const t=[];return e.individual_id_enabled&&t.push(`<span class="badge ${e.individual_id_required?"bg-success":"bg-info"} me-1 mb-1"><i class="fas fa-user me-1"></i>Individual ID${e.individual_id_required?" *":""}</span>`),e.company_id_enabled&&t.push(`<span class="badge ${e.company_id_required?"bg-success":"bg-info"} me-1 mb-1"><i class="fas fa-building me-1"></i>Company ID${e.company_id_required?" *":""}</span>`),t.join("")||'<span class="text-muted small">—</span>'}function V(e,n){return e?n?`<span class="badge bg-success">${i.translations.required}</span>`:`<span class="badge bg-info">${i.translations.enabled}</span>`:'<span class="badge bg-secondary">Off</span>'}function P(){document.getElementById("verCountryEditId").value="",document.getElementById("verCountryCode").value="",document.getElementById("verCountryCode").disabled=!1,document.getElementById("verModuleSelect").value="",m=null,$=null;const e=document.getElementById("verDocumentEnabled"),n=document.getElementById("verDocumentRequired"),t=document.getElementById("verApiVerify");e&&(e.checked=!1),n&&(n.checked=!1),t&&(t.checked=!1),document.getElementById("verificationCountryModalLabel").textContent=i.translations.addCountry,B(),I(),new _(document.getElementById("verificationCountryModal")).show()}function R(e){document.getElementById("verCountryEditId").value=e.id,document.getElementById("verCountryCode").dataset.editCountry=e.country_code,m=e.field_settings||{},$=e.api_provider||null;const n=document.getElementById("verDocumentEnabled"),t=document.getElementById("verDocumentRequired"),o=document.getElementById("verApiVerify");n&&(n.checked=!!e.document_upload_enabled),t&&(t.checked=!!e.document_upload_required),o&&(o.checked=!!e.api_verification_enabled),document.getElementById("verificationCountryModalLabel").textContent=i.translations.editCountry,I().then(()=>{const c=document.getElementById("verCountryCode");if(!Array.from(c.options).some(s=>s.value===e.country_code)){const s=document.createElement("option");s.value=e.country_code,s.textContent=`${e.country_name||e.country_code} (${e.country_code})`,c.appendChild(s)}c.value=e.country_code,c.disabled=!0;const a=document.getElementById("verModuleSelect");e.verification_module?(a.value=e.verification_module,E()):w()}),new _(document.getElementById("verificationCountryModal")).show()}function z(){const e={};return document.querySelectorAll(".ver-field-toggle").forEach(n=>{const t=n.dataset.fieldKey,o=n.dataset.toggleType;e[t]||(e[t]={enabled:!1,required:!1}),e[t][o]=n.checked}),e}function N(){const e={};return document.querySelectorAll(".module-config-field").forEach(n=>{const t=n.dataset.configKey;n.type==="checkbox"?e[t]=n.checked?"1":"0":e[t]=n.value}),e}async function G(){var r,c,a,s,d,l,p,f;const e=document.getElementById("verCountryEditId").value,n=document.getElementById("verCountryCode").value;if(!n){y("error",i.translations.error,"Country is required");return}const t=z(),o={country_code:n.toUpperCase(),verification_module:document.getElementById("verModuleSelect").value||null,individual_id_enabled:((r=document.getElementById("verIndividualEnabled"))==null?void 0:r.checked)??!1,individual_id_required:((c=document.getElementById("verIndividualRequired"))==null?void 0:c.checked)??!1,company_id_enabled:((a=document.getElementById("verCompanyEnabled"))==null?void 0:a.checked)??!1,company_id_required:((s=document.getElementById("verCompanyRequired"))==null?void 0:s.checked)??!1,document_upload_enabled:((d=document.getElementById("verDocumentEnabled"))==null?void 0:d.checked)??!1,document_upload_required:((l=document.getElementById("verDocumentRequired"))==null?void 0:l.checked)??!1,api_verification_enabled:((p=document.getElementById("verApiVerify"))==null?void 0:p.checked)??!1,api_provider:((f=document.getElementById("verApiProvider"))==null?void 0:f.value)||null,field_settings:t,module_config:N()};try{let u=i.routes.countrySettingStore,g="POST";e&&(u=`${i.routes.countrySettingUpdate}/${e}`,g="PUT");const C=await(await b(u,{method:g,body:JSON.stringify(o)})).json();C.success?(_.getInstance(document.getElementById("verificationCountryModal")).hide(),y("success",i.translations.success,i.translations.countrySaved),h()):y("error",i.translations.error,C.error||C.message||i.translations.saveFailed)}catch(u){console.error("Verification country setting save error:",u),y("error",i.translations.error,i.translations.saveError)}}async function J(e){if(confirm(i.translations.deleteConfirm))try{const t=await(await b(`${i.routes.countrySettingDelete}/${e}`,{method:"DELETE"})).json();t.success?(y("success",i.translations.success,i.translations.countryDeleted),h()):y("error",i.translations.error,t.error)}catch(n){console.error("Verification country setting delete error:",n),y("error",i.translations.error,i.translations.saveError)}}function y(e,n,t){if(typeof toastr<"u")toastr[e](t,n);else{const o=`
            <div class="toast align-items-center text-white bg-${e==="success"?"success":"danger"} border-0" role="alert">
                <div class="d-flex">
                    <div class="toast-body"><strong>${n}:</strong> ${t}</div>
                    <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
                </div>
            </div>`;let r=document.getElementById("toast-container");r||(r=document.createElement("div"),r.id="toast-container",r.className="toast-container position-fixed top-0 end-0 p-3",r.style.zIndex="9999",document.body.appendChild(r)),r.innerHTML=o,new q(r.querySelector(".toast")).show()}}document.addEventListener("DOMContentLoaded",function(){var t,o,r,c,a;(t=document.getElementById("verCountryCode"))==null||t.addEventListener("change",w),(o=document.getElementById("verModuleSelect"))==null||o.addEventListener("change",E),(r=document.getElementById("addVerificationCountryBtn"))==null||r.addEventListener("click",P),(c=document.getElementById("saveVerificationCountryBtn"))==null||c.addEventListener("click",G);const e=document.getElementById("verification-tab");e&&e.addEventListener("shown.bs.tab",()=>h()),((e==null?void 0:e.classList.contains("active"))||window.location.hash==="#verification"||((a=document.getElementById("verification"))==null?void 0:a.classList.contains("show")))&&setTimeout(()=>h(),300)});
