import"./bootstrap.esm-Bb7dPm-H.js";import{c as A}from"./csrf-N3H8jAeb.js";let I=!1,M=[],y=0,F=0,L=!1,q=null;const ue=6;async function pe(C,k,E){for(let m=0;m<C.length;m+=E){const h=C.slice(m,m+E);await Promise.all(h.map(k))}}let $=null,N="",U=[],b=null;document.addEventListener("DOMContentLoaded",()=>{const C=document.getElementById("domainSearchForm");if(!C)return;C.dataset.captchaAjax="1";const k=document.getElementById("domain_name"),E=document.getElementById("searchResultsSection"),m=document.getElementById("domainResults"),h=document.getElementById("loadingIndicator"),W=document.getElementById("clearSearchBtn");let w=null;function fe(e){return/[^\x00-\x7F]/.test(e)}function we(){var e;E.style.display="block",m.innerHTML=`
            <div class="col-12">
                <div class="alert alert-warning mb-0">
                    <i class="fas fa-globe me-2"></i>
                    ${((e=window.translations)==null?void 0:e.idnNotAllowed)||"Internationalized domain names (IDN) are not supported. Please use only ASCII characters (a-z, 0-9, -)."}
                </div>
            </div>
        `,h.style.display="none"}C.addEventListener("submit",async e=>{var s;e.preventDefault();const t=k.value.trim().toLowerCase();if(!t||I)return;const n=t.replace(/^(https?:\/\/)?(www\.)?/,"");if(!(($==null?void 0:$.idn)??((s=window.domainSettings)==null?void 0:s.allowIdn)??!0)&&fe(n)){we();return}n.includes(".")&&n.split(".").length>=2?await Q(n,"register"):await ye(n)}),document.querySelectorAll(".quick-search-btn").forEach(e=>{e.addEventListener("click",async()=>{const t=e.dataset.tld,n=k.value.trim().toLowerCase();if(!n||n.startsWith(".")){k.value="",k.focus();return}const i=n.replace(/^(https?:\/\/)?(www\.)?/,"").split(".")[0];await Q(i+t,"register")})}),W&&W.addEventListener("click",()=>{M=[],y=0,N="",U=[],m.innerHTML="",E.style.display="none",k.value="",k.focus(),v(),G()});function j(){var t;const e=Math.max(0,F-y);if(e<=0){v();return}if(!w)w=document.createElement("div"),w.className="col-12 text-center mt-3",w.id="loadMoreContainer",w.innerHTML=`
                <button type="button" class="btn btn-outline-primary btn-lg" id="loadMoreBtn">
                    <i class="fas fa-plus-circle me-2"></i>
                    ${((t=window.translations)==null?void 0:t.loadMore)||"Daha Fazla Göster"}
                    <span class="badge bg-primary ms-2">${e}</span>
                </button>
            `,m.insertAdjacentElement("afterend",w),document.getElementById("loadMoreBtn").addEventListener("click",V);else{w.style.display="block";const n=w.querySelector(".badge");n&&(n.textContent=e)}}function v(){w&&(w.style.display="none")}function he(){var e;b?b.style.display="block":(b=document.createElement("div"),b.className="col-12 text-center mt-3",b.id="extendMoreContainer",b.innerHTML=`
                <button type="button" class="btn btn-outline-secondary" id="extendMoreBtn">
                    <i class="fas fa-search-plus me-2"></i>
                    ${((e=window.translations)==null?void 0:e.searchMoreTlds)||"Diğer TLD'leri sorgula"}
                </button>
            `,m.insertAdjacentElement("afterend",b),document.getElementById("extendMoreBtn").addEventListener("click",ge))}function G(){b&&(b.style.display="none")}async function ge(){var n,i,o,s;if(!N||I)return;const e=document.getElementById("extendMoreBtn");e&&(e.disabled=!0,e.innerHTML=`<span class="spinner-border spinner-border-sm me-2"></span>${((n=window.translations)==null?void 0:n.checking)||"Kontrol ediliyor..."}`);const t=window.apiDomainSearchUrl||"/api/store/domain/search";try{const d={name:N};if(typeof window.captchaToken=="function"){const r=await window.captchaToken();r&&(d[window.captchaFieldName]=r)}const u=await A.post(t,d),l=await u.json();if(!u.ok||!l.success)throw new Error(l.message||"failed");q=d,F=l.total_count||0,L=!!l.has_more;const c=new Set(M.map(r=>r.name)),a=(l.results||[]).filter(r=>!c.has(r.name));if(a.length===0){L?(y=(l.offset||0)+(l.results||[]).length,j()):e&&(e.disabled=!0,e.innerHTML=`<i class="fas fa-check me-2"></i>${((i=window.translations)==null?void 0:i.allTldsChecked)||"Tüm TLD'ler sorgulandı"}`);return}M.push(...a);for(const r of a)r.blocked?f(r.name,null,r.pricing,"blocked",null,r):r.char_error?f(r.name,null,r.pricing,"char_error",null,r):f(r.name,null,r.pricing,"checking",r.token);y=(l.offset||0)+(l.results||[]).length;const p=a.filter(r=>r.token&&!r.char_error&&!r.blocked);await pe(p,r=>R(r.name,r.token,r.pricing),ue),L&&j(),e&&(e.disabled=!0,e.innerHTML=`<i class="fas fa-check me-2"></i>${((o=window.translations)==null?void 0:o.allTldsChecked)||"Tüm TLD'ler sorgulandı"}`)}catch(d){console.error("Extend search error:",d),e&&(e.disabled=!1,e.innerHTML=`<i class="fas fa-search-plus me-2"></i>${((s=window.translations)==null?void 0:s.searchMoreTlds)||"Diğer TLD'leri sorgula"}`)}}async function ye(e){var i;if(I)return;I=!0,M=[],y=0,F=0,L=!1,N=e,E.style.display="block",h.style.display="block",m.innerHTML="",v(),G();const t=window.domainSearchFilter||{},n={name:e};Array.isArray(t.selected_tlds)&&t.selected_tlds.length?(n.tlds=t.selected_tlds,U=[...t.selected_tlds]):U=[],Array.isArray(t.priority_tlds)&&t.priority_tlds.length&&(n.priority_tlds=t.priority_tlds),q=n;try{const o=await X(0);if(!o)throw new Error("Search failed");o.allowed_actions&&($=o.allowed_actions);try{if(window.procpFireCustomEvent){const s=Array.from(new Set((o.results||[]).map(d=>{const l=(d.name||"").split(".");return l.length>1?l.slice(1).join("."):""}).filter(Boolean)));window.procpFireCustomEvent("DomainSearch",{query:e,results_count:o.total_count||(o.results||[]).length,tlds_checked:s.length})}}catch(s){console.warn("[tracking] DomainSearch emit failed",s)}await J(o.results||[]),U.length>0&&he()}catch(o){console.error("Search error:",o),m.innerHTML=`
                <div class="col-12">
                    <div class="alert alert-danger">
                        <i class="fas fa-exclamation-triangle me-2"></i>
                        ${((i=window.translations)==null?void 0:i.errorOccurred)||"An error occurred"}
                    </div>
                </div>
            `}finally{h.style.display="none",I=!1}}async function V(){if(!q||!L){v();return}const e=await X(y);if(!e){v();return}await J(e.results||[])}async function X(e){const t=window.apiDomainSearchUrl||"/api/store/domain/search",n={...q,offset:e};if(typeof window.captchaToken=="function"){const i=await window.captchaToken();i&&(n[window.captchaFieldName]=i)}try{const i=await A.post(t,n),o=await i.json();return!i.ok||!o.success?(console.error("Batch fetch failed",o),null):(F=o.total_count||0,L=!!o.has_more,o)}catch(i){return console.error("fetchDomainBatch error:",i),null}}async function J(e){if(e.length===0){v();return}M.push(...e),e.forEach(n=>{n.blocked?f(n.name,null,n.pricing,"blocked",null,n):n.char_error?f(n.name,null,n.pricing,"char_error",null,n):f(n.name,null,n.pricing,"checking",n.token)}),y+=e.length;const t=e.filter(n=>n.token&&!n.char_error&&!n.blocked);await pe(t,n=>R(n.name,n.token,n.pricing),ue),L?j():v()}async function R(e,t,n){const i=window.apiDomainCheckUrl||"/api/store/domain/check";try{const s=await(await A.post(i,{token:t,action:"register"})).json();s.success?(s.allowed_actions&&($=s.allowed_actions),O(e,s)):O(e,{available:!1,error:s.error||"unknown",message:s.message,pricing:n})}catch(o){console.error(`Error checking ${e}:`,o),O(e,{available:!1,error:"network_error",pricing:n})}}async function Q(e,t="register"){var o,s;E.style.display="block",h.style.display="block",m.innerHTML="",M=[],y=0,v();const n=e.split(".");if(n.length<2){m.innerHTML=`
                <div class="col-12">
                    <div class="alert alert-danger">
                        <i class="fas fa-exclamation-triangle me-2"></i>
                        Geçersiz domain formatı
                    </div>
                </div>
            `,h.style.display="none";return}const i=window.apiDomainSearchUrl||"/api/store/domain/search";try{const d={name:e};if(typeof window.captchaToken=="function"){const p=await window.captchaToken();p&&(d[window.captchaFieldName]=p)}const l=await(await A.post(i,d)).json();if(!l.success||!l.results)throw new Error("Search failed");const c=l.results;l.allowed_actions&&($=l.allowed_actions);const a=c.length>0&&c[0].name===e?c[0]:null;if(!a){const p="."+n.slice(1).join(".");m.innerHTML=`
                    <div class="col-12">
                        <div class="card border-warning">
                            <div class="card-body">
                                <h6 class="card-title mb-2">${e}</h6>
                                <span class="badge bg-warning text-dark">
                                    <i class="fas fa-exclamation-triangle me-1"></i>
                                    ${((o=window.translations)==null?void 0:o.notSupported)||"TLD not supported"}
                                </span>
                                <p class="text-muted mt-2 mb-0 small">
                                    ${p} uzantısı sistemde desteklenmiyor.
                                </p>
                            </div>
                        </div>
                    </div>
                `,h.style.display="none";return}M=c;try{if(window.procpFireCustomEvent){const p=Array.from(new Set((c||[]).map(r=>{const S=(r.name||"").split(".");return S.length>1?S.slice(1).join("."):""}).filter(Boolean)));window.procpFireCustomEvent("DomainSearch",{query:e,results_count:(c||[]).length,tlds_checked:p.length})}}catch(p){console.warn("[tracking] DomainSearch emit failed",p)}a.blocked?f(a.name,null,a.pricing,"blocked",null,a):a.char_error?f(a.name,null,a.pricing,"char_error",null,a):(f(a.name,null,a.pricing,"checking",a.token),await R(a.name,a.token,a.pricing)),y=1,await V()}catch(d){console.error(`Error checking ${e}:`,d),m.innerHTML=`
                <div class="col-12">
                    <div class="alert alert-danger">
                        <i class="fas fa-exclamation-triangle me-2"></i>
                        ${((s=window.translations)==null?void 0:s.errorOccurred)||"An error occurred"}
                    </div>
                </div>
            `}finally{h.style.display="none"}}function f(e,t,n,i="checked",o=null,s=null){var z,S,Y,Z,x,D,ee,ne,se,te,ie,ae,re,oe,le,ce,de,me;const d=`domain-card-${e.replace(/\./g,"-")}`;let u="",l="",c="",a="";if(s!=null&&s.is_premium&&(a='<span class="badge bg-warning text-dark ms-1"><i class="fas fa-star me-1"></i>Premium</span>'),i==="blocked")u=`<span class="badge bg-danger"><i class="fas fa-ban me-1"></i>${(s==null?void 0:s.blocked_reason)||((z=window.translations)==null?void 0:z.domainBlocked)||"Bu domain rezerve edilmiş veya yasaklıdır."}</span>`;else if(i==="char_error"){const g=(s==null?void 0:s.char_limit)||"?";u=`<span class="badge bg-secondary"><i class="fas fa-ruler me-1"></i>${(s==null?void 0:s.char_error)==="min_chars"?((S=window.translations)==null?void 0:S.minCharsError)||`Min. ${g} karakter gerekli`:((Y=window.translations)==null?void 0:Y.maxCharsError)||`Max. ${g} karakter olmalı`}</span>`}else if(i==="checking")u=`
                <span class="badge bg-secondary">
                    <span class="spinner-border spinner-border-sm me-1"></span>
                    ${((Z=window.translations)==null?void 0:Z.checking)||"Checking..."}
                </span>
            `;else if(t===!0){u=`<span class="badge bg-success">${((x=window.translations)==null?void 0:x.available)||"Available"}</span>${a}`;const g=$||window.domainSettings||{},_=(s==null?void 0:s.domain_actions)||null,H=_?!!_.register:g.register!==!1&&g.allowRegistration!==!1;if(!!(s!=null&&s.premium_blocked))c=`
                    <div class="mt-2">
                        <small class="text-muted d-block">
                            <i class="fas fa-info-circle me-1"></i>${((D=window.translations)==null?void 0:D.premiumNotAvailable)||"Bu premium alan adı burada kayıt/transfer için uygun değildir."}
                        </small>
                    </div>
                `,_&&_.use&&(l=`
                        <button class="btn btn-outline-secondary btn-sm w-100 mt-2 add-to-cart-btn"
                                data-domain="${e}"
                                data-action="use">
                            <i class="fas fa-globe me-1"></i>
                            ${((ee=window.translations)==null?void 0:ee.useOwnDomain)||"Kendi domainimi kullan"}
                        </button>
                    `);else if(n&&n.register&&H){const T=(s==null?void 0:s.is_premium)&&(s==null?void 0:s.premium_pricing),B=n.register,K=T?s.premium_pricing.register:B.amount,ke=T?s.premium_pricing.currency:null;c=`
                    <div class="mt-2">
                        <small class="text-muted">${((ne=window.translations)==null?void 0:ne.registrationPrice)||"Registration"}:</small>
                        <div class="fw-bold text-primary">
                            ${T?"":B.currency.prefix||""}${parseFloat(K).toFixed(2)}${T?" "+ke:B.currency.suffix||""}
                            <small class="text-muted">/${((se=window.translations)==null?void 0:se.year)||"year"}</small>
                        </div>
                    </div>
                `,l=`
                    <button class="btn btn-primary btn-sm w-100 mt-2 add-to-cart-btn"
                            data-domain="${e}"
                            data-action="register"
                            ${T?`data-is-premium="1" data-premium-price="${K}"`:""}>
                        <i class="fas fa-shopping-cart me-1"></i>
                        ${((te=window.translations)==null?void 0:te.addToCart)||"Add to Cart"}
                    </button>
                `}}else if(t===!1){u=`<span class="badge bg-secondary">${((ie=window.translations)==null?void 0:ie.unavailable)||"Unavailable"}</span>`;const g=$||window.domainSettings||{},_=(s==null?void 0:s.domain_actions)||null,H=_?!!_.transfer:g.transfer!==!1&&g.allowTransfer!==!1;if(n&&n.transfer&&H){u+=`<span class="badge bg-info ms-2">${((ae=window.translations)==null?void 0:ae.transferable)||"Transferable"}</span>`;const P=n.transfer;c=`
                    <div class="mt-2">
                        <small class="text-muted">${((re=window.translations)==null?void 0:re.transferPrice)||"Transfer"}:</small>
                        <div class="fw-bold text-primary">
                            ${P.currency.prefix||""}${parseFloat(P.amount).toFixed(2)}${P.currency.suffix||""}
                            <small class="text-muted">/${((oe=window.translations)==null?void 0:oe.year)||"year"}</small>
                        </div>
                    </div>
                `;const T=e.replace(/\./g,"-"),B=(s==null?void 0:s.epp_required)!==!1;l=`
                    <div class="mt-2">
                        ${B?`
                    <div class="input-group input-group-sm mb-2">
                        <input type="text" class="form-control epp-code-input" id="epp-${T}"
                               placeholder="${((le=window.translations)==null?void 0:le.eppCodePlaceholder)||"EPP/Auth Code"}"
                               data-domain="${e}">
                    </div>
                `:`<small class="text-muted d-block mb-2"><i class="fas fa-info-circle me-1"></i>${((ce=window.translations)==null?void 0:ce.eppNotRequired)||"EPP code is not required for this TLD"}</small>`}
                        <button class="btn btn-primary btn-sm w-100 add-to-cart-btn"
                                data-domain="${e}"
                                data-action="transfer"
                                ${B?`data-epp-input="epp-${T}"`:""}>
                            <i class="fas fa-exchange-alt me-1"></i>
                            ${((de=window.translations)==null?void 0:de.transferToCart)||"Transfer Et"}
                        </button>
                    </div>
                `}}else u=`<span class="badge bg-warning">${((me=window.translations)==null?void 0:me.unknown)||"Unknown"}</span>`;const p=`
            <div class="col-md-6 col-lg-4" id="${d}">
                <div class="card h-100 border">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-start mb-2">
                            <h6 class="card-title mb-0">${e}</h6>
                            <div class="domain-status">${u}</div>
                        </div>
                        <div class="domain-pricing">${c}</div>
                        <div class="domain-actions">${l}</div>
                    </div>
                </div>
            </div>
        `,r=document.getElementById(d);r?r.outerHTML=p:m.insertAdjacentHTML("beforeend",p)}function O(e,t){const n=t.available||!1,i=t.pricing||null;if(t.error||null)f(e,null,null,"error");else{const s={is_premium:t.is_premium||!1,premium_pricing:t.premium_pricing||null,epp_required:t.epp_required!==void 0?t.epp_required:!0,domain_actions:t.domain_actions||null,premium_blocked:t.premium_blocked||null};f(e,n,i,"checked",null,s)}be()}function be(){document.querySelectorAll(".add-to-cart-btn").forEach(e=>{e.dataset.listenerAttached||(e.addEventListener("click",async function(){var d,u,l;const t=this.dataset.domain,n=this.dataset.action,i=this;let o=null;if(n==="transfer"){const c=this.dataset.eppInput;if(c){const a=document.getElementById(c);if(o=a?a.value.trim():"",!o){a&&(a.classList.add("is-invalid"),a.focus());return}a&&a.classList.remove("is-invalid")}}const s=i.innerHTML;i.disabled=!0,i.innerHTML='<span class="spinner-border spinner-border-sm me-1"></span>'+(((d=window.translations)==null?void 0:d.adding)||"Ekleniyor...");try{const c=window.basketAddUrl||"/api/store/basket/add",a={domain_name:t,domain_action:n,period:1};o&&(a.epp_code=o),i.dataset.isPremium==="1"&&(a.is_premium=!0,a.premium_price=parseFloat(i.dataset.premiumPrice));const r=await(await A.post(c,a)).json();if(r.success)i.innerHTML='<i class="fas fa-check me-1"></i>'+(((u=window.translations)==null?void 0:u.added)||"Eklendi"),setTimeout(()=>{i.style.display="none"},2e3),window.dispatchEvent(new CustomEvent("basketUpdated",{detail:{source:"addDomain",action:n,domain:t}}));else throw new Error(r.message||"Sepete eklenemedi")}catch(c){console.error("Add to cart error:",c),i.disabled=!1,i.innerHTML=s,window.showError(((l=window.translations)==null?void 0:l.addToCartError)||"Sepete eklenirken hata oluştu: "+c.message)}}),e.dataset.listenerAttached="true")})}});
