"use strict";var FindoraWidget=(()=>{var f=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var L=(n,t)=>{for(var e in t)f(n,e,{get:t[e],enumerable:!0})},M=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of k(t))!T.call(n,r)&&r!==e&&f(n,r,{get:()=>t[r],enumerable:!(i=y(t,r))||i.enumerable});return n};var S=n=>M(f({},"__esModule",{value:!0}),n);var F={};L(F,{FindoraWidget:()=>c,default:()=>W});var g={"pt-BR":{searchPlaceholder:"Digite sua pesquisa...",searchSite:"Pesquisar no site",toNavigate:"para navegar",toSelect:"para selecionar",toClose:"para fechar",noResults:"Nenhum resultado encontrado",searchError:"Erro ao realizar a pesquisa. Tente novamente.",loadingText:"Buscando..."},en:{searchPlaceholder:"Type to search...",searchSite:"Search website",toNavigate:"to navigate",toSelect:"to select",toClose:"to close",noResults:"No results found",searchError:"Search error. Please try again.",loadingText:"Searching..."}};function w(n){return g[n]||g["pt-BR"]}function v(){return(typeof navigator<"u"&&(navigator.language||navigator.userLanguage)||"").startsWith("pt")?"pt-BR":"en"}var p=class{constructor(t,e=1e4){this.apiUrl=t.replace(/\/$/,""),this.timeout=e}async search(t,e=0,i=10,r){let s=new AbortController,o=setTimeout(()=>s.abort(),this.timeout);try{let a={query:t.trim(),page:e,limit:i};r&&r.length>0&&(a.excludePageIds=r);let d=await fetch(`${this.apiUrl}/search`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a),signal:s.signal});if(clearTimeout(o),!d.ok)throw new Error(`HTTP ${d.status}: ${d.statusText}`);let u=await d.json();if(!u.success)throw new Error(u.error||"Unknown error");let h=u.result?.result||u.result,m=(h?.results||[]).map(l=>({page_id:Number(l.page_id??l.pageId??0),url:String(l.url||""),title:String(l.title||""),featured_image:l.featured_image??l.featuredImage??null,excerpt:String(l.excerpt||""),relevance:Number(l.relevance||0),chunk_id:String(l.chunk_id??l.chunkId??"")})),E=h?.totalCount??h?.totalResults??m.length,x=h?.hasMore??!1;return{results:m,totalResults:E,hasMore:x}}catch(a){throw clearTimeout(o),a instanceof Error?a.name==="AbortError"?new Error("Request timeout"):a:new Error("Unknown error occurred")}}async recordEvent(t){try{await fetch(`${this.apiUrl}/event`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),keepalive:!0})}catch{}}};var I="bottom-right",C=300,H=400,c=class{constructor(t){this.resultElements={};this.currentAbortController=null;this.seenPageIds=new Set;this.isFetchingMore=!1;this.pendingPage=-1;this.debounceTimer=null;this.buttonEl=null;this.modalEl=null;this.inputEl=null;this.resultsEl=null;this.loadingEl=null;this.nativeInputEl=null;this.nativeInputHandler=null;this.scrollHandler=()=>{if(!this.state.hasMore||this.state.isLoading||this.isFetchingMore||this.state.results.length===0||!this.resultsEl)return;if(this.resultsEl.scrollTop+this.resultsEl.clientHeight>=this.resultsEl.scrollHeight-H){let i=this.state.page+1;this.isFetchingMore=!0,this.performSearch(this.state.query,i,!0)}};let e=t.language||v();this.translations=w(e),this.config={apiUrl:t.apiUrl||window.location.origin,position:t.position||I,theme:t.theme||"light",language:e,mode:t.mode||"modal",siteConfig:t.siteConfig},this.apiClient=new p(this.config.apiUrl),this.state={isOpen:!1,results:[],selectedIndex:-1,page:0,hasMore:!1,error:null,isLoading:!1,query:"",totalResults:0}}init(){this.injectStyles(),this.config.mode==="native"&&this.config.siteConfig?this.setupNativeMode():(this.createButton(),this.createModal(),this.attachEventListeners()),window.findoraWidgetInstance=this}setupNativeMode(){let t=this.config.siteConfig,e=document.querySelector(t.inputSelector);if(!e){console.error("[FindoraWidget] Native input not found:",t.inputSelector);return}this.nativeInputEl=e;let i=null;this.nativeInputHandler=s=>{let a=s.target.value.trim();if(i&&clearTimeout(i),a.length<3){this.clearNativeResults();return}i=setTimeout(()=>{this.injectIntoNativeSearch(a)},300)};let r=t.inputEvent==="both"?"input":t.inputEvent;e.addEventListener(r,this.nativeInputHandler),t.inputEvent==="both"&&e.addEventListener("keyup",this.nativeInputHandler)}clearNativeResults(){let t=this.config.siteConfig;if(!t)return;let e=document.querySelector(t.dropdownSelector);e&&(e.innerHTML="",e.classList.remove("active"))}openModalWithQuery(t){this.state.isOpen=!0,this.modalEl?.classList.add("fw-modal-open"),this.inputEl&&(this.inputEl.value=t,this.inputEl.dispatchEvent(new Event("input",{bubbles:!0}))),this.inputEl?.focus();let e=document.getElementById("search-results");e&&e.classList.remove("active")}cleanTitle(t){return t.replace(/ - ॐ Cantinho Místico ॐComentários$/,"")}injectStyles(){let t="fw-widget-styles";if(document.getElementById(t))return;let e=` .fw-modal-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(15, 23, 42, 0.8); z-index: 99999; display: none; } .fw-modal-overlay.fw-modal-open { display: block; } .fw-modal-overlay.fw-modal-closing { display: block; animation: fw-fade-out 0.2s ease-out forwards; } @keyframes fw-fade-out { from { opacity: 1; } to { opacity: 0; } } #searchButton { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 99999; } #searchButton.fw-bottom-left { left: 1.5rem; right: auto; } .fw-container { width: 100%; padding-left: 1rem; padding-right: 1rem; padding-top: 1rem; margin-left: auto; margin-right: auto; max-width: 42rem; } @media (min-width: 640px) { .fw-container { padding-top: 5rem; } } .fw-modal-content { background: white; width: 100%; border-radius: 16px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); margin-left: auto; margin-right: auto; height: auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; } @media (min-width: 640px) { .fw-modal-content { max-width: 42rem; height: auto; } } .fw-modal-close-mobile { display: flex; justify-content: flex-end; padding: 0.75rem 0.75rem 0 0.75rem; } .fw-modal-close-btn { appearance: none !important; -webkit-appearance: none !important; width: auto !important; min-width: 0 !important; height: auto !important; color: #6b7280 !important; background: transparent !important; box-shadow: none !important; border: 0 !important; border-radius: 0 !important; cursor: pointer; padding: 0 !important; margin: 0 !important; display: inline-flex !important; align-items: center; justify-content: center; line-height: 1 !important; text-align: center; text-transform: none !important; transition: none !important; transform: none !important; will-change: auto !important; } .fw-modal-close-btn:hover { color: #6b7280 !important; background: transparent !important; box-shadow: none !important; transition: none !important; transform: none !important; } .fw-icon-sm { width: 1.5rem; height: 1.5rem; } .fw-input-container { padding: 1rem; position: relative; } .fw-input-wrapper { position: relative; } .fw-search-input { width: 100%; padding: 0.5rem 2.5rem 0.5rem 2.5rem; font-size: 1rem; line-height: 1.5; color: #1f2937; background-color: #fff; border: 1px solid #d1d5db; border-radius: 0.5rem; outline: none; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; } .fw-search-input::placeholder { color: #9ca3af; } .fw-search-input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3); outline: none; } .fw-search-icon { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: #9ca3af; } .fw-clear-btn { position: absolute; right: 0.875rem; top: 50%; transform: translateY(-50%) !important; width: 18px !important; min-width: 0 !important; height: 18px !important; box-sizing: border-box; color: #6b7280 !important; background: transparent !important; box-shadow: none !important; border: 0 !important; cursor: pointer; padding: 0 !important; margin: 0 !important; border-radius: 0 !important; display: none !important; align-items: center; justify-content: center; opacity: 0.65 !important; appearance: none !important; -webkit-appearance: none !important; line-height: 1 !important; text-align: center; text-transform: none !important; transition: none !important; will-change: auto !important; } .fw-clear-btn:hover { color: #6b7280 !important; background: transparent !important; box-shadow: none !important; opacity: 0.65 !important; transition: none !important; } .fw-clear-btn svg { width: 10px; height: 10px; } .fw-clear-btn.fw-visible { display: flex !important; } .fw-results { overflow-y: auto; max-height: calc(100vh - 380px); padding-left: 1rem; padding-right: 1rem; } .fw-loading { padding: 1rem; text-align: center; display: none; } .fw-loading.fw-visible { display: block; } .fw-no-results { padding: 1rem; text-align: center; color: #6b7280; } .fw-loading-more { padding: 1rem; text-align: center; } .fw-spinner { display: inline-block; width: 2rem; height: 2rem; border: 4px solid #d1d5db; border-top-color: #2563eb; border-radius: 9999px; animation: fw-spin 1s linear infinite; } @keyframes fw-spin { to { transform: rotate(360deg); } } .fw-footer { background: #f9fafb; border-top: 1px solid #e5e7eb; padding: 0.5rem; font-size: 0.875rem; line-height: 1.25rem; color: #4b5563; text-align: center; border-bottom-left-radius: 0.5rem; border-bottom-left-radius: 16px; border-bottom-right-radius: 16px; } @media (max-width: 640px) { .fw-footer { display: none; } } .fw-footer-content { display: flex; justify-content: center; align-items: center; gap: 1rem; } .fw-footer-item { display: flex; align-items: center; gap: 0.25rem; } .fw-btn-search { background: #2563eb; color: white; border: none; border-radius: 9999px; padding: 1rem; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1); cursor: pointer; transition: all 0.3s; } .fw-btn-search:hover { background: #1d4ed8; } .fw-btn-search .fw-btn-icon { width: 1.5rem; height: 1.5rem; } .search-overlay { backdrop-filter: blur(5px); } .fw-results { scrollbar-width: thin; } .fw-results::-webkit-scrollbar { width: 6px; } .fw-results::-webkit-scrollbar-track { background: #f1f1f1; } .fw-results::-webkit-scrollbar-thumb { background: #888; border-radius: 3px; } .fw-result-card { background: rgba(66, 153, 225, 0.02); border: 2px solid rgba(66, 153, 225, 0.3); border-radius: 8px; box-shadow: 0 0 15px rgba(66, 153, 225, 0.1); margin-bottom: 8px; overflow: hidden; transition: all 0.2s ease; } .fw-result-card:hover, .fw-result-card.fw-selected { background: rgba(66, 153, 225, 0.1); border-color: rgba(66, 153, 225, 0.6); } .fw-result-card:hover .fw-result-title, .fw-result-card.fw-selected .fw-result-title { color: #1a365d; } .fw-result-card:hover .fw-result-excerpt, .fw-result-card.fw-selected .fw-result-excerpt { color: #2d3748; } .fw-result-link { display: block; text-decoration: none; color: inherit; } .fw-result-content { display: flex; gap: 12px; padding: 12px; } .fw-result-image-container { flex-shrink: 0; width: 80px; height: 120px; display: flex; align-items: center; justify-content: center; } .fw-result-image { width: 80px; height: 120px; object-fit: cover; border-radius: 4px; box-shadow: 0 0 10px rgba(66, 153, 225, 0.2); } .fw-result-info { flex-grow: 1; min-width: 0; } .fw-result-title { color: #2c3e50; font-size: 0.95rem; font-weight: 600; margin: 0 0 4px 0; line-height: 1.3; text-shadow: 0 0 3px rgba(66, 153, 225, 0.2); } .fw-result-excerpt { font-size: 0.85rem; color: #2c3e50; margin: 0; line-height: 1.4; overflow-wrap: anywhere; } .fw-result-excerpt mark, .fw-result-title mark { font-weight: bold; color: #d35400; background-color: inherit; } .fw-intercept-result { display: flex; align-items: center; padding: 8px; text-decoration: none; color: inherit; border-bottom: 1px solid #eee; } .fw-intercept-result:hover { background-color: #f5f5f5; } .fw-intercept-image { width: 50px; height: 50px; object-fit: contain; margin-right: 10px; flex-shrink: 0; } .fw-intercept-info { flex-grow: 1; min-width: 0; } .fw-intercept-title { font-weight: 600; color: #1f2937; font-size: 0.9rem; margin: 0 0 2px 0; } .fw-intercept-excerpt { font-size: 0.8rem; color: #6b7280; margin: 0; overflow: hidden; text-overflow: clip; white-space: normal; word-wrap: break-word; } .fw-intercept-excerpt mark { font-weight: bold; color: #d35400; background-color: inherit; } kbd { display: inline-block; padding: 0.2rem 0.4rem; font-size: 0.85rem; font-family: monospace; line-height: 1.4; color: #444; background-color: #f7f7f7; border: 1px solid #ccc; border-radius: 3px; box-shadow: 0 2px 0 rgba(0,0,0,0.2), 0 0 0 1px #fff inset; text-shadow: 0 1px 0 #fff; margin: 0 0.1rem; min-width: 1.6rem; text-align: center; position: relative; top: 0; transition: all 0.1s; } @media (max-width: 640px) { .search-overlay { backdrop-filter: blur(2px); } #searchModal .fw-container { padding: 0; margin: 0; max-width: 100%; } #searchModal .fw-modal-content { border-radius: 0; height: 100vh; max-width: 100%; } #searchModal .fw-input-container { padding-top: 0; } .fw-results { max-height: calc(100vh - 6rem); } .fw-results::-webkit-scrollbar { width: 0.25rem; } .fw-result-title { font-size: 0.9rem; } .fw-result-excerpt { font-size: 0.8rem; } .fw-result-content { padding: 1rem; } img { object-fit: cover; object-position: center; } .fw-footer { display: none; } } .fw-modal-body { display: block; padding: 0 1rem 1rem 1rem; } .fw-results-column { display: flex; flex-direction: column; } .fw-results-container { width: 100%; } @media (max-width: 768px) { .fw-modal-body { flex-direction: column; min-height: auto; } .fw-results-column { width: 100%; max-width: 100%; } } `,i=document.createElement("style");i.id=t,i.textContent=e,document.head.appendChild(i)}createButton(){let t=this.config.position==="bottom-left"?"fw-bottom-left":"";this.buttonEl=document.createElement("button"),this.buttonEl.id="searchButton",this.buttonEl.className=`fw-btn-search ${t}`,this.buttonEl.setAttribute("aria-label",this.translations.searchSite),this.buttonEl.innerHTML=` `,document.body.appendChild(this.buttonEl)}createModal(){let t=document.createElement("div");t.id="searchModal",t.className="fw-modal-overlay",t.onclick=()=>this.closeModal(),t.innerHTML=`