1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9216],{2177:(e,t,a)=>{a.d(t,{N0:()=>r,N6:()=>p,RO:()=>o,_d:()=>s,cE:()=>i,st:()=>d,ys:()=>c});let l=["default","on","off"];function s(e){let t=null==e?void 0:e.aiSuggestions;return l.includes(t)?t:(null==e?void 0:e.suggestions)===!0?"on":"default"}function r(e,t){let a=s(e);return"on"===a||"off"!==a&&(null==t?void 0:t.enableAiSuggestions)===!0}function i(e){return e&&"object"==typeof e?"whatsapp"===e.source||"WhatsApp"===e.fullUrl||e.waTime?"whatsapp":"instagram"===e.msgType||e.instaTime?"instagram":"facebook"===e.msgType||e.faTime?"facebook":"string"==typeof e.type&&e.type.includes("email")||e.emailTime?"email":"chat":""}function n(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(!Array.isArray(e))return null;for(let t=e.length-1;t>=0;t-=1){let a=e[t];if(a&&"note"!==a.type)return a}return null}function o(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=n(e);return!!(t&&("visitor"===t.type||"bot"===t.type))}function d(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],a=n(t),l=a?a.mid||a.id:"";if(l)return"".concat(e||"",":").concat(l);let s=Array.isArray(t)?t.length:0;return"".concat(e||"",":").concat(s,":").concat((null==a?void 0:a.timestamp)||"")}let c=1e4;function p(e,t){let{debounceMs:a=1500,minIntervalMs:l=6e3,typingHoldMs:s=2500,visitorTyping:r=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return Math.max(a,Math.max(0,l-(Number.isFinite(t)?e-t:1/0)),r?s:0)}},23968:(e,t,a)=>{a.d(t,{A:()=>s});var l=a(37876);function s(e){let{minHeight:t="60vh"}=e;return(0,l.jsx)("div",{style:{minHeight:t},className:"flex flex-col items-center justify-center text-lightning-500",children:(0,l.jsx)("img",{width:"70px",src:"https://cdn.serviceform.com/assets/images/oop-loader.gif",alt:"loading"})})}a(14232)},30025:(e,t,a)=>{a.d(t,{A:()=>et});var l=a(37876),s=a(14232),r=a(80772),i=a(21632),n=a(73559),o=a.n(n),d=a(4139),c=a(2123),p=a(77564),m=a(10841),u=a.n(m),x=a(2827),g=a(2786),h=a(82750),f=a(54153);let y={cars:["id","title","brand","model","price","year","condition","fuel","mileage"],properties_rental:["id","name","rent","city","type","rooms","size","status","hood"],ecommerce:["id","title","price","brand","category","sku","availability","sale_price"],properties_ecommerce:["id","title","price","city","type","category","beds","area","sku"],locations:["id","title","country","category","type","rating","district","region"],courses:["id","title","level","institution","modality","language"],blogs:["id","title","description","link"]},b=["id","title","name","price","category","type","brand","sku"],v=function(e){var t;let{index:a,searchData:n,searchQuery:o,onSearch:d,onClose:c}
1=e,[p,m]=(0,s.useState)(o||""),[u,x]=(0,s.useState)(null),g=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>clearTimeout(g.current),[]),(0,s.useEffect)(()=>{x(null)},[n]);let h=(e=>{if(!(null==e?void 0:e.length))return[];let t=Object.keys(e[0]),l=y[null==a?void 0:a.dataType]||b;return[...l.filter(e=>t.includes(e)),...t.filter(e=>!l.includes(e))].slice(0,6)})(null==n?void 0:n.results);return(0,l.jsx)(i.A,{title:"Search: ".concat((null==a?void 0:a.name)||"Index"),onClose:c,fullWidth:!0,children:(0,l.jsxs)("div",{className:"flex flex-col gap-4 mt-4",children:[(0,l.jsxs)("div",{className:"flex gap-2 items-stretch",children:[(0,l.jsx)("input",{type:"text",value:p,onChange:e=>{var t;m(t=e.target.value),clearTimeout(g.current),g.current=setTimeout(()=>{d(t||"*")},400)},placeholder:(0,f.A)("Search by keyword or ID..."),className:"flex-1 rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-blue-500 focus:ring-1 focus:ring-blue-500"}),(0,l.jsx)(r.A,{className:"text-[13px] !h-auto",variant:"primary",small:!0,onClick:()=>d(p||"*"),children:"Search"})]}),(0,l.jsx)("div",{className:"data-table-container",children:(null==n?void 0:n.loading)?(0,l.jsx)("div",{className:"data-table-state text-gray-500",children:(0,f.A)("Loading...")}):(null==n?void 0:n.error)?(0,l.jsx)("div",{className:"data-table-state text-red-500",children:n.error}):(null==n||null==(t=n.results)?void 0:t.length)>0?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("p",{className:"text-xs text-gray-500 mb-2 shrink-0",children:(0,f.A)("Showing ".concat(n.results.length," of ").concat(n.count," results"))}),(0,l.jsx)("div",{className:"data-table-scroll min-h-[400px]",children:(0,l.jsxs)("table",{className:"data-table",children:[(0,l.jsx)("thead",{className:"bg-gray-50 sticky top-0 z-10",children:(0,l.jsxs)("tr",{children:[h.map(e=>(0,l.jsx)("th",{className:"data-table-th",children:e},e)),(0,l.jsx)("th",{className:"data-table-th",children:(0,f.A)("Details")})]})}),(0,l.jsx)("tbody",{className:"divide-y divide-gray-100 bg-white",children:n.results.map((e,t)=>(0,l.jsxs)(s.Fragment,{children:[(0,l.jsxs)("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>x(u===t?null:t),children:[h.map(t=>{var a;return(0,l.jsx)("td",{className:"data-table-td",children:null==(a=e[t])?"-":Array.isArray(a)?a.join(", "):"object"==typeof a?JSON.stringify(a):"string"==typeof a&&a.length>80?a.slice(0,80)+"...":String(a)},t)}),(0,l.jsx)("td",{className:"data-table-td text-blue-600",children:u===t?(0,f.A)("Hide"):(0,f.A)("View")})]}),u===t&&(0,l.jsx)("tr",{children:(0,l.jsx)("td",{colSpan:h.length+1,className:"data-table-expanded-cell",children:(0,l.jsx)("pre",{className:"data-table-pre",children:JSON.stringify(e,null,2)})})})]},e.id||t))})]})})]}):(0,l.jsx)("div",{className:"data-table-state text-gray-400",children:(0,f.A)("No results found")})})]})})};var j=a(59307),N=a(96864),w=a(1480),S=a(78485),C=a(42358),k=a(72678),F=a(26285),A=a(26639),P=a(2273);let T=function(e){let{index:t,indexingStatus:a,onTestAI:i,onTrainUpsells:n,onRecommendations:o,onRunIndex:d,onRebuildIndex:c,onEdit:p,onDelete:m,onPreview:u,onSearch:x}=e,[g,h]=(0,s.useState)(!1),[y,b]=(0,s.useState)({top:0,left:0}),v=(0,s.useRef)(null),T=(0,s.useRef)(null);(0,s.useEffect)(()=>{function e(e){v.current&&!v.current.contains(e.target)&&h(!1)}function t(){h(!1)}return g&&(document.addEventListener("mousedown",e),window.addEventListener("scroll",t,!0)),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("scroll",t,!0)}},[g]);let R=(null==a?void 0:a.status)==="indexing",_="file_upload"===t.feedFormat,D=[{label:(0,f.A)("Search"),icon:j.A,onClick:x},{label:(0,f.A)("Train upsells"),icon:N.A,onClick:n},{label:(0,f.A)("Rebuild from scratch"),icon:w.A,onClick:c,disabled:R||_},{label:(0,f.A)("Delete"),icon:S.A,onClick:m,danger:!0}],E="!rounded-none !-ml-0.5 first:!ml-0 first:!rounded-l-md last:!rounded-r-md !px-1.5 !py-1 !min-w-0 !text-[10px] !font-medium !text-gray-700 hover:!z-10 focus:!z-10 [&_svg]:!w-3 [&_svg]:!h-3 [&_svg]:!mr-0";return(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)(r.A,{variant:"outline",small:!0,className:E,onClick:u,disabled:_,title:_?(0,f.A)("Preview not available for file uploads"):(0,f.A)("Preview data"),children:(0,l.jsx)(C.A,{className:"w-3.5 h-3.5"})}),(0,l.jsx)(r.A,{small:!0,variant:"outline",className:E,onClick:p,title:(0,f.A)("Edit"),children:(0,l.jsx)(k.A,{className:"w-3.5 h-3.5"})}),(0,l.jsxs)(r.A,{variant:"outline",small:!0,className:E,onClick:d,disabled:R||_,title:_?(0,f.A)("Re-indexing not available for file uploads. Edit and upload new file."):(0,f.A)("Run indexing"),children:[(0,l.jsx)(w.A,{className:"w-3.5 h-3.5 ".concat(R?"animate-spin":"")}),R?(0,f.A)("Indexing..."):(0,f.A)("Run Index")]}),(0,l.jsxs)(r.A,{variant:"outline",small:!0,className:E,onClick:i,title:(0,f.A)("Test AI"),children:[(0,l.jsx)(F.A,{className:"w-3.5 h-3.5"}),(0,f.A)("Test AI")]}),(0,l.jsxs)(r.A,{variant:"outline",small:!0,className:E,onClick:o,title:(0,f.A)("Recommendations"),children:[(0,l.jsx)(A.A,{className:"w-3.5 h-3.5"}),(0,f.A)("Recs")]})]}),(0,l.jsxs)("div",{className:"relative",ref:v,children:[(0,l.jsx)("button",{ref:T,onClick:e=>{e.stopPropagation(),h(e=>{if(!e&&T.current){let e=T.current.getBoundingClientRect();b({top:e.bottom+4,left:e.right})}return!e})},className:"inline-flex items-center justify-center w-7 h-7 text-gray-500 hover:text-gray-700 hover:bg-gray-100 rounded transition-colors",title:(0,f.A)("More options"),children:(0,l.jsx)(P.A,{className:"w-4 h-4"})}),g&&(0,l.jsx)("div",{className:"fixed -translate-x-full min-w-[160px] bg-white border border-gray-200 rounded-lg py-1 shadow-[0_4px_16px_rgba(0,0,0,0.1)] z-50",style:{to
1p:y.top,left:y.left},children:D.map(e=>{let t=e.icon;return(0,l.jsxs)("button",{type:"button",disabled:e.disabled,onClick:t=>{t.stopPropagation(),e.onClick(),h(!1)},className:"flex items-center gap-2 w-full px-3 py-[7px] text-[11px] font-medium whitespace-nowrap transition-colors disabled:opacity-40 disabled:cursor-not-allowed ".concat(e.danger?"text-red-500 hover:bg-red-50":"text-gray-700 hover:bg-gray-100"),children:[(0,l.jsx)(t,{className:"w-3.5 h-3.5"}),e.label]},e.label)})})]})]})};var R=a(62152),_=a(14664),D=a(54287),E=a(63727),B=a(98644);let z=[{value:"exact",label:"Exact match"},{value:"different",label:"Different"},{value:"similar",label:"Similar (soft)"},{value:"range",label:"Range"},{value:"any",label:"Any (no constraint)"}],I=[{value:"required",label:"Required"},{value:"preferred",label:"Preferred"},{value:"optional",label:"Optional"},{value:"ignored",label:"Ignored"}],U=[{value:"both",label:"Both (+/-)"},{value:"lower",label:"Lower only"},{value:"higher",label:"Higher only"}],O=new Set(["int32","int64","float"]),L=function(e){var t,a,s;let{id:r,field:i,attrConfig:n,isActive:o,engineKey:d,onToggle:c,onUpdateAttribute:p}=e,{attributes:m,listeners:u,setNodeRef:x,transform:g,transition:h,isDragging:f}=(0,D.gl)({id:r}),y={transform:E.Ks.Transform.toString(g),transition:h,zIndex:f?10:1,opacity:f?.8:1},b=O.has(i.type),v=(null==n?void 0:n.match)==="range"&&b;return(0,l.jsxs)("tr",{ref:x,style:y,className:"border-t border-gray-100 ".concat(o?"bg-blue-50/30":""," ").concat(f?"shadow-lg":""),children:[(0,l.jsx)("td",{className:"px-2 py-2 w-8",children:(0,l.jsx)("button",{...m,...u,className:"cursor-grab active:cursor-grabbing text-gray-400 hover:text-gray-600 p-0.5",title:"Drag to reorder priority",children:(0,l.jsx)(B.A,{className:"w-3.5 h-3.5"})})}),(0,l.jsx)("td",{className:"px-2 py-2 font-mono text-xs",children:i.name}),(0,l.jsx)("td",{className:"px-2 py-2 text-xs text-gray-500",children:i.type}),(0,l.jsx)("td",{className:"px-2 py-2",children:(0,l.jsx)("input",{type:"checkbox",checked:o,onChange:()=>c(d,i.name,i),className:"rounded border-gray-300"})}),(0,l.jsx)("td",{className:"px-2 py-2",children:o&&(0,l.jsx)("select",{value:n.match,onChange:e=>p(d,i.name,"match",e.target.value),className:"text-xs border border-gray-300 rounded px-1 py-0.5",children:z.filter(e=>b||"range"!==e.value).map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,l.jsx)("td",{className:"px-2 py-2",children:o&&(0,l.jsx)("select",{value:n.weight,onChange:e=>p(d,i.name,"weight",e.target.value),className:"text-xs border border-gray-300 rounded px-1 py-0.5",children:I.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,l.jsx)("td",{className:"px-2 py-2",children:v&&(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsx)("input",{type:"number",value:(null==(t=n.range)?void 0:t.value)||10,onChange:e=>{let t={...n.range||{},value:Number(e.target.value)};p(d,i.name,"range",t)},className:"w-14 text-xs border border-gray-300 rounded px-1 py-0.5",min:0,max:1e3}),(0,l.jsxs)("select",{value:(null==(a=n.range)?void 0:a.type)||"percentage",onChange:e=>{let t={...n.range||{},type:e.target.value};p(d,i.name,"range",t)},className:"text-xs border border-gray-300 rounded px-1 py-0.5",children:[(0,l.jsx)("option",{value:"percentage",children:"%"}),(0,l.jsx)("option",{value:"absolute",children:"abs"})]}),(0,l.jsx)("select",{value:(null==(s=n.range)?void 0:s.direction)||"both",onChange:e=>{let t={...n.range||{},direction:e.target.value};p(d,i.name,"range",t)},className:"text-xs border border-gray-300 rounded px-1 py-0.5",children:U.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))})]})})]})},M=[{key:"engine_type",label:"Engine type"},{key:"product_name",label:"Product name"},{key:"title_keywords",label:"Title keywords"},{key:"category",label:"Category"},{key:"sub_category",label:"Subcategory"},{key:"price",label:"Price"},{key:"brand",label:"Brand"},{key:"color",label:"Color"},{key:"size",label:"Size"},{key:"cart_summary",label:"Cart summary"},{key:"candidate_list",label:"Candidate list"},{key:"limit",label:"Result count"}],W={similar:{template:"",reranking:!0},complementary:{template:"",reranking:!0}},q=e=>{var t,a,l,s,r,i,n,o,d,c,p,m,u,x,g,h;let f=null==e?void 0:e.prompt;return{similar:{template:null!=(c=null!=(d=null==e||null==(a=e.prompts)||null==(t=a.similar)?void 0:t.template)?d:null==f?void 0:f.template)?c:"",reranking:null==(m=null!=(p=null==e||null==(s=e.prompts)||null==(l=s.similar)?void 0:l.reranking)?p:null==f?void 0:f.reranking)||m},complementary:{template:null!=(x=null!=(u=null==e||null==(i=e.prompts)||null==(r=i.complementary)?void 0:r.template)?u:null==f?void 0:f.template)?x:"",reranking:null==(h=null!=(g=null==e||null==(o=e.prompts)||null==(n=o.complementary)?void 0:n.reranking)?g:null==f?void 0:f.reranking)||h}}},J=async()=>{var e;(null===R.j||void 0===R.j?void 0:R.j.authStateReady)&&await R.j.authStateReady();let t=await (null==(e=R.j.currentUser)?void 0:e.getIdToken());return t||window.localStorage.getItem("token")},H=function(e){var t,a,n,o,d,c,m,u,x,g,h,y,b,v,j,N,w,S,C;let{index:k,userTenantData:F,onClose:A,onSave:P}
1=e,[T,R]=(0,s.useState)(!0),[E,B]=(0,s.useState)(!1),[z,I]=(0,s.useState)(!1),[U,H]=(0,s.useState)(null),[K,G]=(0,s.useState)([]),[V,Y]=(0,s.useState)("ecommerce"),[Q,$]=(0,s.useState)(null),[X,Z]=(0,s.useState)({complementary:null,similar:null}),[ee,et]=(0,s.useState)(W),[ea,el]=(0,s.useState)("popular_pairings"),[es,er]=(0,s.useState)({complementary:[],similar:[]}),[ei,en]=(0,s.useState)(""),[eo,ed]=(0,s.useState)(""),[ec,ep]=(0,s.useState)([]),[em,eu]=(0,s.useState)(!1),[ex,eg]=(0,s.useState)(!1),[eh,ef]=(0,s.useState)(null),[ey,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)({source:{},candidate:{}}),eN=(0,s.useRef)(null),ew=(0,s.useRef)(0),eS=(0,_.FR)((0,_.MS)(_.AN,{activationConstraint:{distance:5}}),(0,_.MS)(_.uN)),eC=(0,s.useCallback)(async()=>{R(!0),H(null);try{var e,t,a,l,s,r,i,n;let[o,d]=await Promise.all([fetch("/api/recommendation-settings?indexId=".concat(k.id,"&master=").concat(F.master)),fetch("/api/recommendation-settings?indexId=".concat(k.id,"&master=").concat(F.master,"&attributes=true"))]),c=await o.json(),p=await d.json();if(!o.ok)throw Error(c.error);if(!d.ok)throw Error(p.error);Y(c.dataType||"ecommerce"),$(c.defaults);let m=(p.fields||[]).filter(e=>!["image_link","additional_images","link","description","keywords","title","objectID","sku","gtin","shipping_weight","embedding"].includes(e.name));G(m),(null==(e=c.config)?void 0:e.engines)?(Z(c.config.engines),et(q(c.config)),er({complementary:(null==(a=c.config.engines.complementary)?void 0:a.attributeOrder)||[],similar:(null==(l=c.config.engines.similar)?void 0:l.attributeOrder)||[]})):(null==(t=c.defaults)?void 0:t.engines)&&(Z(c.defaults.engines),er({complementary:(null==(s=c.defaults.engines.complementary)?void 0:s.attributeOrder)||Object.keys((null==(r=c.defaults.engines.complementary)?void 0:r.attributes)||{}),similar:(null==(i=c.defaults.engines.similar)?void 0:i.attributeOrder)||Object.keys((null==(n=c.defaults.engines.similar)?void 0:n.attributes)||{})}))}catch(e){H(e.message)}finally{R(!1)}},[k.id,F.master]);(0,s.useEffect)(()=>{eC()},[eC]),(0,s.useEffect)(()=>()=>{eN.current&&clearTimeout(eN.current)},[]);let ek=()=>{ew.current+=1,eN.current&&clearTimeout(eN.current),eu(!1)},eF=(e,t,a,l)=>{Z(s=>{let r=JSON.parse(JSON.stringify(s));return r[e]||(r[e]={enabled:!0,attributes:{}}),r[e].attributes[t]||(r[e].attributes[t]={match:"any",weight:"ignored"}),r[e].attributes[t][a]=l,"match"!==a||"range"!==l||r[e].attributes[t].range||(r[e].attributes[t].range={type:"percentage",value:10,direction:"both"}),r})},eA=(e,t,a)=>{Z(l=>{let s=JSON.parse(JSON.stringify(l));s[e]||(s[e]={enabled:!0,attributes:{}});let r=s[e].attributes;if(r[t]&&"ignored"!==r[t].weight)r[t]={match:"any",weight:"ignored"};else{let e=O.has(a.type);r[t]={match:e?"range":"exact",weight:"preferred",...e?{range:{type:"percentage",value:10,direction:"both"}}:{}}}return s})},eP=async()=>{var e;let t=JSON.parse(JSON.stringify(X));t.complementary&&(t.complementary.attributeOrder=es.complementary),t.similar&&(t.similar.attributeOrder=es.similar);let a={engines:t,prompts:ee},l=await fetch("/api/recommendation-settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({indexId:k.id,master:F.master,config:a})}),s=await l.json();if(!l.ok)throw Error(s.error||(null==(e=s.details)?void 0:e.join(", ")));return a},eT=async()=>{B(!0),H(null);try{let e=await eP();P&&P(e)}catch(e){H(e.message)}finally{B(!1)}},eR=async()=>{if(ei.trim()){I(!0),ef(null),eb(null);try{await eP();let e={engineType:ea,type:{complementary:"cross_sell",similar:"similar",popular_pairings:"cross_sell"}[ea]||"similar",collectionName:k.collectionName,productId:ei.trim(),indexId:k.id,master:F.master,limit:4,engineScope:"selected",includeExplanation:!0};("complementary"===ea||"popular_pairings"===ea)&&(e.cartItems=[{id:ei.trim(),quantity:1}]);let t=await J(),a={"Content-Type":"application/json"};t&&(a.Authorization="Bearer ".concat(t));let{isMasquerade:l}=p.default.getState(),s=window.localStorage.getItem("sf-user");l&&s&&(a["sf-masquerade"]="true",a["sf-user"]=s);let r=await fetch("/api/recommend",{method:"POST",headers:a,body:JSON.stringify(e)}),i=await r.json();if(!r.ok)throw Error(i.error);ef(i)}catch(e){eb(e.message)}finally{I(!1)}}},e_=async e=>{let t=++ew.current;if(!e||e.trim().length<2){ep([]),eg(!1),eu(!1);return}eu(!0);try{let a=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:k.collectionName,query:e.trim(),limit:10})}),l=await a.json();if(t!==ew.current)return;let s=l.success&&l.results?l.results:[];ep(s),eg(s.length>0)}catch(e){if(t!==ew.current)return;ep([]),eg(!1)}finally{t===ew.current&&eu(!1)}},eD=e=>e.split(",").map(e=>
1e.trim()).filter(Boolean),eE=(e,t,a)=>{ej(l=>({...l,["sourceContains"===t?"source":"candidate"]:{...l["sourceContains"===t?"source":"candidate"],[e]:a}})),Z(l=>{let s=JSON.parse(JSON.stringify(l));s.complementary||(s.complementary={enabled:!0,attributes:{},rules:[]});let r=s.complementary.rules||[];return r[e]={...r[e]||{sourceContains:[],candidateContains:[]},[t]:eD(a)},s.complementary.rules=r,s})},eB=(e,t,a)=>{var l;return null!=(l=ev["sourceContains"===t?"source":"candidate"][e])?l:(a[t]||[]).join(", ")},ez=(e,t,a,l)=>{Z(s=>{var r,i,n,o,d,c,p,m,u,x;let g=JSON.parse(JSON.stringify(s));g[e]||(g[e]={enabled:!0,attributes:{}});let h=g[e].sortOrder||{},f={primary:{field:null!=(c=null!=(d=null==(r=h.primary)?void 0:r.field)?d:h.field)?c:"",direction:null!=(m=null!=(p=null==(i=h.primary)?void 0:i.direction)?p:h.direction)?m:"asc"},secondary:{field:null!=(u=null==(n=h.secondary)?void 0:n.field)?u:"",direction:null!=(x=null==(o=h.secondary)?void 0:o.direction)?x:"asc"}};return g[e].sortOrder={...f,[t]:{...f[t],[a]:l}},g})},eI="similar"===ea||"complementary"===ea?ee[ea]:null,eU=e=>{("similar"===ea||"complementary"===ea)&&et(t=>({...t,[ea]:{...t[ea],...e}}))},eO=X[ea],eL=(null==eO?void 0:eO.attributes)||{},eM=((e,t)=>{let a=new Map(e.map(e=>[e.name,e])),l=[],s=new Set;if(t&&t.length>0)for(let e of t)a.has(e)&&!s.has(e)&&(l.push(a.get(e)),s.add(e));for(let t of e)s.has(t.name)||(l.push(t),s.add(t.name));return l})(K,es[ea]||[]),eW=K.filter(e=>O.has(e.type)&&!["embedding","description","image_link","additional_images"].includes(e.name)),eq={ecommerce:"E-commerce",cars:"Automotive",properties_ecommerce:"Real estate (sales)",properties_rental:"Real estate (rental)"};return T?(0,l.jsx)(i.A,{title:"Recommendation settings",onClose:A,children:(0,l.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,l.jsx)("p",{className:"text-gray-500",children:(0,f.A)("Loading...")})})}):(0,l.jsx)(i.A,{title:"Recommendation settings: ".concat((null==k?void 0:k.name)||"Index"),onClose:A,fullWidth:!0,children:(0,l.jsxs)("div",{className:"flex flex-col gap-4 mt-4",children:[U&&(0,l.jsx)("div",{className:"bg-red-50 text-red-700 px-4 py-2 rounded-md text-sm",children:U}),(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-2",children:[(0,l.jsxs)("span",{className:"text-sm text-gray-500",children:["Industry: ",(0,l.jsx)("strong",{children:eq[V]||V})]}),(0,l.jsxs)("button",{onClick:()=>{if(null==Q?void 0:Q.engines){var e,t,a,l;let s=JSON.parse(JSON.stringify(Q.engines));Z(s),et(q(Q)),ej({source:{},candidate:{}}),er({complementary:(null==(e=s.complementary)?void 0:e.attributeOrder)||Object.keys((null==(t=s.complementary)?void 0:t.attributes)||{}),similar:(null==(a=s.similar)?void 0:a.attributeOrder)||Object.keys((null==(l=s.similar)?void 0:l.attributes)||{})})}},className:"text-xs text-blue-600 hover:text-blue-800 underline",children:["Reset to ",eq[V]||V," defaults"]})]}),(0,l.jsx)("div",{className:"flex border-b border-gray-200",children:[{key:"popular_pairings",label:"Popular pairings"},{key:"similar",label:"Similar products"},{key:"complementary",label:"Complementary products"}].map(e=>{let{key:t,label:a}=e;return(0,l.jsx)("button",{onClick:()=>{ek(),el(t),en(""),ed(""),ep([]),eg(!1),ef(null),eb(null),I(!1)},className:"px-4 py-2 text-sm font-medium border-b-2 transition-colors ".concat(ea===t?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:a},t)})}),(0,l.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,l.jsx)("input",{type:"checkbox",checked:"popular_pairings"===ea?null!=(y=null==(t=X.popular_pairings)?void 0:t.enabled)&&y:null==(b=null==eO?void 0:eO.enabled)||b,onChange:e=>{if("popular_pairings"===ea)Z(t=>({...t,popular_pairings:{...t.popular_pairings||{purchaseWeight:70,cartWeight:30,lookbackDays:90},enabled:e.target.checked}}));else{var t;t=e.target.checked,Z(e=>{let a=JSON.parse(JSON.stringify(e));return a[ea]?a[ea].enabled=t:a[ea]={enabled:t,attributes:{}},a})}},className:"rounded border-gray-300"}),"Enable ","popular_pairings"===ea?"popular pairings":ea," engine"]}),"popular_pairings"===ea&&(0,l.jsxs)("div",{className:"border border-gray-200 rounded-lg p-4 flex flex-col gap-4",children:[(0,l.jsx)("p",{className:"text-xs text-gray-500",children:"Recommends products based on real user behavior: what people actually buy together and what they browse together. No attribute matching needed."}),(0,l.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Purchase signal weight: ",null!=(v=null==(a=X.popular_pairings)?void 0:a.purchaseWeight)?v:70,"%"]}),(0,l.jsx)("input",{type:"range",min:0,max:100,value:null!=(j=null==(n=X.popular_pairings)?void 0:n.purchaseWeight)?j:70,onChange:e=>Z(t=>({...t,popular_pairings:{...t.popular_pairings,purchaseWeight:Number(e.target.value)}})),className:"w-full"}),(0,l.jsx)("p",{className:"text-xs text-gray-400",children:"Products actually purchased together (strongest signal)"})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:["Cart signal weight: ",null!=(N=null==(o=X.popular_pairings)?void 0:o.cartWeight)?N:30,"%"]}),(0,l.jsx)("input",{type:"range",min:0,max:100,value:null!=(w=null==(d=X.popular_pairings)?void 0:d.cartWeight)?w:30,onChange:e=>Z(t=>({...t,popular_pairings:{...t.popular_pairings,cartWeight:Number(e.target.value)}})),className:"w-full"}),(0,l.jsx)("p",{className:"text-xs text-gray-400",children:"Products browsed while other products are in cart (more volume, weaker signal)"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Lookback period (days)"}),(0,l.jsx)("input",{type:"number",min:1,max:365,value:null!=(S=null==(c=X.popular_pairings)?void 0:c.lookbackDays)?S:90,onChange:e=>Z(t=>({...t,popular_pairings:{...t.popular_pairings,lookbackDays:Number(e.target.value)}})),className:"w-20 text-sm border border-gray-300 rounded-md px-2 py-1"}),(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"How far back to analyze purchase and cart data"})]})]})]}),"popular_pairings"!==ea&&(0,l.jsxs)(l.Fragment,{children:["similar"===ea&&(0,l.jsxs)("label",{className:"flex items-start gap-2 text-sm border border-gray-200 rounded-lg p-3 bg-gray-50",children:[(0,l.jsx)("input",{type:"checkbox",checked:(null==(m=X.similar)?void 0:m.titleKeywordMatch)===!0,onChange:e=>{var t;return t=e.target.checked,void Z(e=>{let a=JSON.parse(JSON.stringify(e));return a.similar||(a.similar={enabled:!0,attributes:{},titleKeywordMatch:!1}),a.similar.titleKeywordMatch=t,a})},className:"rounded border-gray-300 mt-0.5"}),(0,l.jsxs)("span",{children:[(0,l.jsx)("span",{className:"font-medium text-gray-800",children:(0,f.A)("Use smart product name match")}),(0,l.jsx)("span",{className:"block text-xs text-gray-500 mt-1",children:(0,f.A)("Finds meaningful words in the product title (not brand or capitalized words, ignores text after a comma) and uses them to match similar products.")})]})]}),(0,l.jsxs)("div",{className:"border border-gray-200 rounded-lg overflow-hidden",children:[(0,l.jsx)("div",{className:"px-3 py-2 bg-gray-50 border-b border-gray-200",children:(0,l.jsx)("p",{className:"text-xs text-gray-500",children:"Drag rows to set priority order. Top attributes take precedence when building recommendations."})}),(0,l.jsxs)("table",{className:"w-full text-sm",children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{className:"bg-gray-50",children:[(0,l.jsx)("th",{className:"w-8 px-2 py-2"}),(0,l.jsx)("th",{className:"text-left px-2 py-2 font-medium text-gray-600",children:"Attribute"}),(0,l.jsx)("th",{className:"text-left px-2 py-2 font-medium text-gray-600",children:"Type"}),(0,l.jsx)("th",{className:"text-left px-2 py-2 font-medium text-gray-600",children:"Active"}),(0,l.jsx)("th",{className:"text-left px-2 py-2 font-medium text-gray-600",children:"Match"}),(0,l.jsx)("th",{className:"text-left px-2 py-2 font-medium text-gray-600",children:"Weight"}),(0,l.jsx)("th",{className:"text-left px-2 py-2 font-medium text-gray-600",children:"Range config"})]})}),(0,l.jsx)(_.Mp,{sensors:eS,collisionDetection:_.fp,onDragEnd:e=>{let{active:t,over:a}=e;if(!a||t.id===a.id)return;let l=eM.map(e=>e.name),s=l.indexOf(t.id),r=l.indexOf(a.id);if(-1===s||-1===r)return;let i=(0,D.be)(l,s,r);er(e=>({...e,[ea]:i}))},children:(0,l.jsx)(D.gB,{items:eM.map(e=>e.name),strategy:D._G,children:(0,l.jsx)("tbody",{children:eM.map(e=>{let t=eL[e.name],a=t&&"ignored"!==t.weight;return(0,l.jsx)(L,{id:e.name,field:e,attrConfig:t,isActive:a,engineKey:ea,onToggle:eA,onUpdateAttribute:eF},e.name)})})})})]})]}),("similar"===ea||"complementary"===ea)&&(0,l.jsxs)("div",{className:"border border-gray-200 rounded-lg p-4",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between gap-3 mb-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"text-sm font-semibold text-gray-700",children:"Rules"}),(0,l.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Set the base sort order and optionally boost preferred brands already found in results."})]}),"complementary"===ea&&(0,l.jsx)(r.A,{variant:"outline",small:!0,onClick:()=>{Z(e=>{let t=JSON.parse(JSON.stringify(e));return t.complementary||(t.complementary={enabled:!0,attributes:{},rules:[]}),t.complementary.rules=[...t.complementary.rules||[],{sourceContains:[],candidateContains:[]}],t})},children:"+ Add rule"})]}),(0,l.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,l.jsxs)("div",{className:"flex flex-col gap-2",children:[[{key:"primary",label:"Primary sort"},{key:"secondary",label:"Secondary sort"}].map(e=>{let{key:t,label:a}=e,s=(e=>{let t=(null==eO?void 0:eO.sortOrder)||{};return"primary"===e?t.primary||{field:t.field||"",direction:t.direction||"asc"}:t.secondary||{field:"",direction:"asc"}})(t);return(0,l.jsxs)("div",{className:"grid grid-cols-[120px_1fr_140px] gap-2 items-end",children:[(0,l.jsx)("label",{className:"text-xs font-medium text-gray-500 pb-2",children:a}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Field"}),(0,l.jsxs)("select",{value:s.field||"",onChange:e=>ez(ea,t,"field",e.target.value),className:"w-full text-sm border border-gray-300 rounded-md px-2 py-1.5",children:[(0,l.jsx)("option",{value:"",children:"Default relevance"}),eW.map(e=>(0,l.jsx)("option",{value:e.name,children:e.name},e.name))]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Direction"}),(0,l.jsxs)("select",{value:s.direction||"asc",onChange:e=>ez(ea,t,"direction",e.target.value),className:"w-full text-sm border border-gray-300 rounded-md px-2 py-1.5",children:[(0,l.jsx)("option",{value:"asc",children:"Ascending"}),(0,l.jsx)("option",{value:"desc",children:"Descending"})]})]})]},t)}),(0,l.jsx)("p",{className:"text-xs text-gray-400",children:"Secondary sort is used when primary values are equal or missing. Only numeric sort fields are shown."})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Preferred brands"}),(0,l.jsx)("input",{type:"text",value:((null==eO?void 0:eO.preferredBrands)||[]).join(", "),onChange:e=>{var t;return t=eD(e.target.value),void Z(e=>{let a=JSON.parse(JSON.stringify(e));return a[ea]||(a[ea]={enabled:!0,attributes:{}}),a[ea].preferredBrands=t,a})},placeholder:"Satisfyer, EasyGlide, Pjur",className:"w-full text-sm border border-gray-300 rounded-md px-2 py-1.5"}),(0,l.jsx)("p",{className:"text-xs text-gray-400 mt-1",children:"Comma separated. Only boosts products that are already in the result set."})]}),"complementary"===ea&&(0,l.jsxs)("div",{className:"flex flex-col gap-2 border-t border-gray-100 pt-3",children:[(0,l.jsx)("div",{className:"flex items-center justify-between gap-3",children:(0,l.jsx)("p",{className:"text-xs font-medium text-gray-600",children:"Contains rules"})}),((null==(u=X.complementary)?void 0:u.rules)||[]).map((e,t)=>(0,l.jsxs)("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-2 items-start",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"If product contains"}),(0,l.jsx)("input",{type:"text",value:eB(t,"sourceContains",e),onChange:e=>eE(t,"sourceContains",e.target.value),placeholder:"anaali, dildo",className:"w-full text-sm border border-gray-300 rounded-md px-2 py-1.5"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Find products containing"}),(0,l.jsx)("input",{type:"text",value:eB(t,"candidateContains",e),onChange:e=>eE(t,"candidateContains",e.target.value),placeholder:"anaaliliukuvoide, liukuvoide",className:"w-full text-sm border border-gray-300 rounded-md px-2 py-1.5"})]}),(0,l.jsx)(r.A,{variant:"outline",small:!0,onClick:()=>(e=>{let t=t=>Object.entries(t||{}).reduce((t,a)=>{let[l,s]=a,r=Number(l);return r<e?t[r]=s:r>e&&(t[r-1]=s),t},{});ej(e=>({source:t(e.source),candidate:t(e.candidate)})),Z(t=>{var a;let l=JSON.parse(JSON.stringify(t));return(null==(a=l.complementary)?void 0:a.rules)&&(l.complementary.rules=l.complementary.rules.filter((t,a)=>a!==e)),l})})(t),children:"Remove"})]},t)),0===((null==(x=X.complementary)?void 0:x.rules)||[]).length&&(0,l.jsx)("p",{className:"text-xs text-gray-400",children:"No contains rules yet. The
1se are optional and only affect complementary candidate search."})]})]})]})]}),"popular_pairings"!==ea&&eI&&(0,l.jsxs)("div",{className:"border border-gray-200 rounded-lg p-4",children:[(0,l.jsxs)("h3",{className:"text-sm font-semibold text-gray-700 mb-1",children:["AI reranking prompt",(0,l.jsxs)("span",{className:"font-normal text-gray-500",children:[" ","(","similar"===ea?(0,f.A)("Similar products"):(0,f.A)("Complementary products"),")"]})]}),(0,l.jsxs)("label",{className:"flex items-center gap-2 text-sm mb-3",children:[(0,l.jsx)("input",{type:"checkbox",checked:null==(C=eI.reranking)||C,onChange:e=>eU({reranking:e.target.checked}),className:"rounded border-gray-300"}),"Enable AI reranking"]}),eI.reranking&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex flex-wrap gap-1 mb-2",children:M.map(e=>(0,l.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.key,void(("similar"===ea||"complementary"===ea)&&et(e=>{var a;return{...e,[ea]:{...e[ea],template:((null==(a=e[ea])?void 0:a.template)||"")+"{".concat(t,"}")}}}))},className:"text-xs bg-gray-100 hover:bg-gray-200 text-gray-700 px-2 py-1 rounded border border-gray-300",title:"Insert {".concat(e.key,"}"),children:e.label},e.key))}),(0,l.jsx)("textarea",{value:eI.template||"",onChange:e=>eU({template:e.target.value}),placeholder:"similar"===ea?"Custom similar-products prompt, or leave empty for the default...":"Custom complementary-products prompt, or leave empty for the default...",className:"w-full h-32 text-xs font-mono border border-gray-300 rounded-md p-2 resize-y"}),(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-1",children:["Use curly braces for variables, e.g. ","{product_name}",". Each tab has its own prompt. Leave empty to use the default for that engine."]})]})]}),(0,l.jsxs)("div",{className:"border border-gray-200 rounded-lg p-4",children:[(0,l.jsxs)("h3",{className:"text-sm font-semibold text-gray-700 mb-2",children:["Test ",ea," engine"]}),(0,l.jsxs)("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(180px,240px)_auto] gap-2 items-start",children:[(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("input",{type:"text",value:eo,onChange:e=>{var t;ed(t=e.target.value),en(""),ef(null),eb(null),eN.current&&clearTimeout(eN.current),eN.current=setTimeout(()=>e_(t),250)},onFocus:()=>eg(ec.length>0),placeholder:(0,f.A)("Search product by name..."),className:"w-full text-sm border border-gray-300 rounded-md px-3 py-1.5",autoComplete:"off"}),em&&(0,l.jsx)("span",{className:"absolute right-3 top-2 text-xs text-gray-400",children:(0,f.A)("Searching...")}),ex&&ec.length>0&&(0,l.jsx)("div",{className:"absolute z-20 mt-1 w-full max-h-72 overflow-y-auto rounded-md border border-gray-200 bg-white shadow-lg",children:ec.map(e=>(0,l.jsxs)("button",{type:"button",onClick:()=>{ek(),en(String(e.id||"")),ed(e.title||e.name||e.id||""),eg(!1),ep([]),ef(null),eb(null)},className:"w-full text-left flex items-center gap-2 px-3 py-2 border-b border-gray-100 hover:bg-gray-50",children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title||e.name||"",className:"w-9 h-9 object-cover rounded"}),(0,l.jsxs)("span",{className:"min-w-0",children:[(0,l.jsx)("span",{className:"block text-xs font-medium text-gray-800 truncate",children:e.title||e.name||e.id}),(0,l.jsxs)("span",{className:"block text-xs text-gray-500 truncate",children:[e.id," ",e.brand?"- ".concat(e.brand):""," ",e.category?"- ".concat(e.category):""]})]})]},e.id))})]}),(0,l.jsx)("div",{children:(0,l.jsx)("input",{type:"text",value:ei,onChange:e=>{en(e.target.value),ed(""),ep([]),eg(!1),ek(),ef(null),eb(null)},placeholder:(0,f.A)("Or enter product ID..."),className:"w-full text-sm border border-gray-300 rounded-md px-3 py-1.5"})}),(0,l.jsx)(r.A,{variant:"outline",small:!0,onClick:eR,disabled:z||!ei.trim(),children:z?(0,f.A)("Saving and testing..."):(0,f.A)("Save and test")})]}),ey&&(0,l.jsx)("div",{className:"mt-2 text-sm text-red-600",children:ey}),eh&&(0,l.jsxs)("div",{className:"mt-3",children:[(0,l.jsxs)("p",{className:"text-xs text-gray-500 mb-2",children:[eh.count," results via ",eh._method||"legacy"]}),eh.warning&&(0,l.jsx)("div",{className:"mb-2 text-xs text-amber-700 bg-amber-50 border border-amber-200 rounded px-2 py-1",children:eh.warning}),(0,l.jsx)("div",{className:"grid grid-cols-2 gap-2 max-h-60 overflow-y-auto",children:(eh.recommendations||[]).map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-gray-50 rounded text-xs",children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title||"",className:"w-10 h-10 object-cover rounded"}),(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsx)("p",{className:"font-medium truncate",children:e.title}),(0,l.jsxs)("p",{className:"text-gray-500",children:[e.category," - ",((e.sale_price||e.price||0)/100).toFixed(2)]})]})]},e.id||t))}),(null==(g=eh.explanation)?void 0:g.text)&&(0,l.jsxs)("div",{className:"mt-3",children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:(0,f.A)("Why these results?")}),(0,l.jsx)("textarea",{readOnly:!0,value:eh.explanation.text,className:"w-full h-44 text-xs border border-gray-300 rounded-md p-2 bg-gray-50 text-gray-700 resize-y"})]}),!(null==(h=eh.explanation)?void 0:h.text)&&eh.explanationUnavailableReason&&(0,l.jsxs)("div",{className:"mt-3 rounded-md border border-yellow-200 bg-yellow-50 p-2 text-xs text-yellow-800",children:[(0,f.A)("Why these results? Explanation is only available for authenticated dashboard test requests."),"auth_required"===eh.explanationUnavailableReason?" ".concat((0,f.A)("Refresh the dashboard or log in again if this persists.")):""]})]})]}),(0,l.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-gray-200",children:[(0,l.jsx)(r.A,{variant:"outline",onClick:A,children:(0,f.A)("Cancel")}),(0,l.jsx)(r.A,{variant:"primary",onClick:eT,disabled:E,children:E?(0,f.A)("Saving..."):(0,f.A)("Save configuration")})]})]})})};var K=a(55578),G=a(41705);let V={cars:"bg-blue-500",properties_rental:"bg-emerald-500",properties_e
1commerce:"bg-violet-500",locations:"bg-pink-500",courses:"bg-cyan-500"},Y=[...G.SUPPORTED_LANGUAGES].sort((e,t)=>e.name.localeCompare(t.name)),Q=e=>{var t;let{index:a,onClose:n,onSave:d,onSaveAndIndex:c,userTenantData:p}=e,[m,u]=(0,s.useState)(!1),[f,y]=(0,s.useState)(null),[b,v]=(0,s.useState)(null),[j,N]=(0,s.useState)("auto"),[w,S]=(0,s.useState)(null),C=e=>e&&Array.isArray(e)?e.map(e=>({...e,id:e.id||(0,h.$)(10)})):[],[k,F]=(0,s.useState)({id:(null==a?void 0:a.id)||null,name:(null==a?void 0:a.name)||"",dataType:(null==a?void 0:a.dataType)||"cars",feedUrl:(null==a?void 0:a.feedUrl)||"",feedFormat:(null==a?void 0:a.feedFormat)||"auto",collectionName:(null==a?void 0:a.collectionName)||"",useModelMakeAsTitle:(null==a?void 0:a.useModelMakeAsTitle)||!1,pricesInCents:(null==a?void 0:a.pricesInCents)||!1,fieldMapping:(null==a?void 0:a.fieldMapping)||{},extraFields:C(null==a?void 0:a.extraFields),attributeRules:C(null==a?void 0:a.attributeRules),synonyms:C(null==a?void 0:a.synonyms),username:(null==a?void 0:a.username)||"",password:(null==a?void 0:a.password)||"",headers:(null==a?void 0:a.headers)||"",getApiResultPath:(null==a?void 0:a.getApiResultPath)||"",getApiPageSize:(null==a?void 0:a.getApiPageSize)||20,getApiPaginationType:(null==a?void 0:a.getApiPaginationType)||"offset",getApiOffsetParam:(null==a?void 0:a.getApiOffsetParam)||"offset",getApiPageParam:(null==a?void 0:a.getApiPageParam)||"page",getApiLimitParam:(null==a?void 0:a.getApiLimitParam)||"limit",getApiTotalCountPath:(null==a?void 0:a.getApiTotalCountPath)||"",addsearchKey:(null==a?void 0:a.addsearchKey)||"",addsearchQuery:(null==a?void 0:a.addsearchQuery)||"*",addsearchPageSize:(null==a?void 0:a.addsearchPageSize)||100,linearApiKey:(null==a?void 0:a.linearApiKey)||"",linearLanguage:(null==a?void 0:a.linearLanguage)||"fi",linearBaseUrl:(null==a?void 0:a.linearBaseUrl)||"",linearUrlPath:(null==a?void 0:a.linearUrlPath)||"",groupingField:(null==a?void 0:a.groupingField)||"",postApiBody:(null==a?void 0:a.postApiBody)||"",postApiResultPath:(null==a?void 0:a.postApiResultPath)||"",postApiPagePath:(null==a?void 0:a.postApiPagePath)||"page",postApiPageSize:(null==a?void 0:a.postApiPageSize)||100,frequency:(null==a?void 0:a.frequency)||"manual",mainCategories:(null==a?void 0:a.mainCategories)||"",subCategories:(null==a?void 0:a.subCategories)||"",mainCategoryFilter:(null==a?void 0:a.mainCategoryFilter)||"",exclusionFilters:C(null==a?void 0:a.exclusionFilters),scrapingSitemapUrl:(null==a?void 0:a.scrapingSitemapUrl)||"",scrapingUrlPattern:(null==a?void 0:a.scrapingUrlPattern)||"",scrapingFieldRules:(null==a?void 0:a.scrapingFieldRules)||"",scrapingDelayMs:(null==a?void 0:a.scrapingDelayMs)||150,scrapingLimit:(null==a?void 0:a.scrapingLimit)||0,defaultCountry:(null==a?void 0:a.defaultCountry)||"",language:(null==a?void 0:a.language)||"",enableSemanticSearch:(null==a?void 0:a.enableSemanticSearch)||!1,enableInfixSearch:(null==a?void 0:a.enableInfixSearch)===void 0||a.enableInfixSearch,linkStripPath:(null==a?void 0:a.linkStripPath)||"",linkPrependUrl:(null==a?void 0:a.linkPrependUrl)||"",shopifyLanguage:(null==a?void 0:a.shopifyLanguage)||"",shopifyCurrencies:(null==a?void 0:a.shopifyCurrencies)||"",purchaseRequiredProductIds:(null==a?void 0:a.purchaseRequiredProductIds)||[],purchaseRequiredMessage:(null==a?void 0:a.purchaseRequiredMessage)||"",updatedAt:new Date().toISOString()}),[A,P]=(0,s.useState)((null==a?void 0:a.collectionName)||""),[T,R]=(0,s.use
1State)(!1),[_,D]=(0,s.useState)(null),[E,B]=(0,s.useState)(!1),[z,I]=(0,s.useState)(null),[U,O]=(0,s.useState)(null),[L,M]=(0,s.useState)("basic"),[W,q]=(0,s.useState)({}),[J,H]=(0,s.useState)([]),[G,V]=(0,s.useState)(""),[Q,$]=(0,s.useState)([]),[X,Z]=(0,s.useState)(!1),ee=(0,s.useRef)(null),[et,ea]=(0,s.useState)(()=>(null==a?void 0:a.fieldMapping)&&Object.keys(a.fieldMapping).length>0?Object.entries(a.fieldMapping).map(e=>{let[t,a]=e;return{id:(0,h.$)(10),source:a,target:t}}):[]),el=[{value:"cars",label:"\uD83D\uDE97 Cars (Automotive)"},{value:"properties_rental",label:"\uD83C\uDFE0 Rental Properties"},{value:"properties_ecommerce",label:"\uD83C\uDFE2 For-Sale Properties"},{value:"ecommerce",label:"\uD83D\uDED2 E-commerce Products"},{value:"locations",label:"\uD83D\uDCCD Locations (Golf Clubs, Venues, Restaurants)"},{value:"blogs",label:"\uD83D\uDCDD Blog Posts"},{value:"courses",label:"\uD83C\uDF93 Courses (Schools)"}],es=[{value:"auto",label:"⨠Auto-detect"},{value:"json",label:"{ } JSON"},{value:"xml",label:"</> XML"},{value:"csv",label:"\uD83D\uDCCA CSV"},{value:"file_upload",label:"\uD83D\uDCC1 Local File Upload"},{value:"paginated_get_api",label:"\uD83D\uDCC4 Paginated GET API"},{value:"woocommerce_api",label:"\uD83D\uDED2 WooCommerce API (Serviceform Plugin)"},{value:"shopify_api",label:"\uD83D\uDECDï¸ Shopify API (Serviceform App)"},{value:"addsearch",label:"\uD83D\uDD0D AddSearch API"},{value:"post_api",label:"\uD83D\uDCE1 Custom POST API"},{value:"scraping",label:"\uD83D\uDD77ï¸ Web Scraping (Sitemap)"},{value:"linear_api",label:"\uD83C\uDFE0 Linear Property API"}],er=[{value:"auto",label:"⨠Auto-detect"},{value:"json",label:"{ } JSON"},{value:"xml",label:"</> XML"},{value:"csv",label:"\uD83D\uDCCA CSV"}],ei=[{value:"manual",label:"â Re-index manually"},{value:"daily",label:"\uD83D\uDCC5 Index daily (use with caution, expensive)"},{value:"12hourly",label:"â° Index every 12 hours (use with caution, expensive)"},{value:"weekly",label:"\uD83D\uDCC6 Index weekly"},{value:"monthly",label:"\uD83D\uDCCA Index monthly"}];(0,s.useEffect)(()=>{if(!a&&k.name){let e=(e=>{let t=e.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").substring(0,30),a=Date.now().toString().slice(-6);return"".concat(t,"_").concat(a)})(k.name,k.dataType);P(e),F(t=>({...t,collectionName:e}))}},[k.name,k.dataType,a]);let en=async()=>{if(!k.feedFormat)return void alert("Please select a feed format first");
1if("addsearch"===k.feedFormat){if(!k.addsearchKey)return void alert("Please enter AddSearch public key first")}else if("post_api"===k.feedFormat){if(!k.feedUrl)return void alert("Please enter API endpoint URL first");if(!k.postApiBody)return void alert("Please enter request body first")}else if("file_upload"===k.feedFormat){if(!b)return void alert("Please upload a file first")}else if("scraping"===k.feedFormat){if(!k.scrapingSitemapUrl)return void alert("Please enter a sitemap URL first")}else if("linear_api"===k.feedFormat){if(!k.linearApiKey)return void alert("Please enter a Linear API key first")}else if("shopify_api"===k.feedFormat){if(!k.feedUrl)return void alert("Please enter a Shopify store URL first")}else if(!k.feedUrl)return void alert("Please enter a feed URL first");R(!0),D(null);try{let a={feedFormat:k.feedFormat,dataType:k.dataType,master:p.master};"addsearch"===k.feedFormat?(a.addsearchKey=k.addsearchKey,a.addsearchQuery=k.addsearchQuery):"post_api"===k.feedFormat?(a.feedUrl=k.feedUrl,a.postApiBody=k.postApiBody,a.postApiResultPath=k.postApiResultPath,a.headers=k.headers):"linear_api"===k.feedFormat?(a.linearApiKey=k.linearApiKey,a.linearLanguage=k.linearLanguage,a.linearBaseUrl=k.linearBaseUrl,a.linearUrlPath=k.linearUrlPath):"file_upload"===k.feedFormat?(a.fileContent=b,a.fileFormat=j):(a.feedUrl=k.feedUrl,a.username=k.username,a.password=k.password,a.headers=k.headers);let l=await fetch("/api/indexes/analyze-feed",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),s=await l.json();if(s.success){var e,t;F(e=>({...e,fieldMapping:s.fieldMapping||{}}));let a=Object.entries(s.fieldMapping||{}).map(e=>{let[t,a]=e;return{id:(0,h.$)(10),source:a,target:t}});if(ea(a),D(s),s.sampleItem){let e=eo(s.sampleItem),a=new Map;e.forEach(e=>{a.set(e.path,e)}),s.allFieldNames&&Array.isArray(s.allFieldNames)&&s.allFieldNames.forEach(e=>{a.has(e)||a.set(e,{path:e,sampleValue:"(not in first item)",isArray:!1,type:"string"})});let l=Array.from(a.values());H(l),console.log("\uD83D\uDCCB Detected fields (merged):",l.length,{fromSample:e.length,total:(null==(t=s.allFieldNames)?void 0:t.length)||0})}if(console.log("\uD83D\uDD0D Checking for suggested rules...",{hasSuggestedRules:!!s.suggestedAttributeRules,rulesLength:null==(e=s.suggestedAttributeRules)?void 0:e.length,dataType:k.dataType,suggestedRules:s.suggestedAttributeRules}),s.suggestedAttributeRules&&s.suggestedAttributeRules.length>0&&"ecommerce"===k.dataType){let e=s.suggestedAttributeRules.map(e=>({...e,id:(0,h.$)(10)}));console.log("\uD83C\uDFF7ï¸ Auto-populated attribute rules:",e),console.log("\uD83D\uDCCA Current data.attributeRules before update:",k.attributeRules),F(t=>(console.log("\uD83D\uDCCA Previous attributeRules:",t.attributeRules),console.log("\uD83D\uDCCA New attributeRules:",e),{...t,attributeRules:e})),setTimeout(()=>{console.log("\uD83D\uDD04 Switching to attributes tab"),M("attributes")},500)}else console.warn("â ï¸ No attribute rules to populate",{suggestedRules:s.suggestedAttributeRules,dataType:k.dataType});console.log("\uD83E\uDD16 AI Field Mapping:",s)}else alert(s.error||"Failed to analyze feed")}catch(e){console.error("AI analysis error:",e),alert("Failed to analyze feed")}finally{R(!1)}},eo=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",a=[],l=(e,t)=>{e&&"object"==typeof e&&Object.keys(e).forEach(s=>{let r=t?"".concat(t,".").concat(s):s,i=e[s];if(null!=i&&""!==i){let e=Array.isArray(i)?"[".concat(i.slice(0,2).join(", ")).concat(i.length>2?"...":"","]"):String(i).slice(0,50);a.push({path:r,sampleValue:e,isArray:Array.isArray(i),type:typeof i})}"object"!=typeof i||Array.isArray(i)||l(i,r)})};return l(e,t),a},ed=async e=>{let t=k.collectionName||A;if(!t||!e.trim())return void $([]);Z(!0);try{let a=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:t,query:e,limit:10})}),l=await a.json();$((l.results||[]).map(e=>({id:String(e.id||e._id||""),name:e.title||e.name||String(e.id)||"Unknown"})))}catch(e){console.error("Search error:",e),$([])}Z(!1)},ec=async e=>{e.preventDefault(),u(!0);try{let e={};et.forEach(t=>{t.source&&t.target&&(e[t.target]=t.source)});let t={...k,fieldMapping:e};if("file_upload"===k.feedFormat){if(!b){alert("Please upload a file first"),u(!1);return}await c(t,b,j)}else await d(t)}catch(e){console.error("Error saving document:",e),alert("Error saving index")}finally{u(!1)}},ep=(e,t)=>"feedFormat"===e&&"woocommerce_api"===t?void F(e=>({...e,feedFormat:"woocommerce_api",getApiResultPath:"products",getApiPageSize:500,getApiPaginationType:"page",getApiPageParam:"page",getApiLimitParam:"per_page",getApiTotalCountPath:"total"})):"feedFormat"===e&&"shopify_api"===t?void F(e=>({...e,feedFormat:"shopify_api",dataType:"ecommerce",getApiResultPath:"products",getApiPageSize:100,getApiPaginationType:"page",getApiPageParam:"page",getApiLimitParam:"per_page",getApiTotalCountPath:"total",headers:e.headers||"X-API-Key=sf_live_serviceform_default_2024"})):"feedFormat"===e&&"linear_api"===t?void F(e=>
1({...e,feedFormat:"linear_api",dataType:"properties_ecommerce"})):void F(a=>({...a,[e]:t})),em=(e,t,a)=>{F(l=>({...l,extraFields:(l.extraFields||[]).map(l=>l.id===e?{...l,[t]:a}:l)}))},eu=(e,t,a)=>{F(l=>({...l,attributeRules:(l.attributeRules||[]).map(l=>l.id===e?{...l,[t]:a}:l)}))},ex=(e,t,a)=>{F(l=>({...l,synonyms:(l.synonyms||[]).map(l=>l.id===e?{...l,[t]:a}:l)}))},[eg,eh]=(0,s.useState)([]),[ef,ey]=(0,s.useState)({}),[eb,ev]=(0,s.useState)({}),[ej,eN]=(0,s.useState)(!1),ew=[{value:"equals",label:"equals"},{value:"not_equals",label:"does not equal"},{value:"contains",label:"contains"},{value:"not_contains",label:"does not contain"},{value:"greater_than",label:"greater than"},{value:"less_than",label:"less than"},{value:"is_empty",label:"is empty"},{value:"is_not_empty",label:"is not empty"},{value:"field_missing",label:"field does not exist"},{value:"field_exists",label:"field exists"}],eS=async()=>{if(k.collectionName&&!ej){try{let e=await fetch("/api/indexes/schema",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:k.collectionName})}),t=await e.json();if(t.success&&t.fields){eh(t.fields);let e=(k.exclusionFilters||[]).map(e=>e.field).filter(Boolean),a=t.fields.filter(e=>e.facet).map(e=>e.name);e.forEach(e=>{a.includes(e)&&eC(e)})}}catch(e){console.error("Failed to fetch index schema:",e)}eN(!0)}},eC=async e=>{if(k.collectionName&&e&&!ef[e]){ev(t=>({...t,[e]:!0}));try{let t=await fetch("/api/indexes/facets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:k.collectionName,facetField:e})}),a=await t.json();a.success&&a.values&&ey(t=>({...t,[e]:a.values}))}catch(t){console.error("Failed to fetch facet values for ".concat(e,":"),t)}ev(t=>({...t,[e]:!1}))}},ek=(e,t,a)=>{F(l=>({...l,exclusionFilters:(l.exclusionFilters||[]).map(l=>l.id===e?{...l,[t]:a}:l)})),"field"===t&&a&&eC(a)},eF=[["sku","Plain top-level key"],["custom_fields.myKey","Dot path into a nested object"],["attributes.attribute[0]","Index into a nested array"],["tags[prefix:Color:]",'Find array item starting with "Color:", return the remainder (e.g. "Red")'],["tags[contains:_not_buyable]","Check if an exact, unprefixed flag/value exists in a comma-separated or array field, returns true/false"],["options[name=Hintaryhm\xe4].values",(0,l.jsxs)(l.Fragment,{children:["Find object in array where name matches, return its ",(0,l.jsx)("code",{className:"bg-gray-100 px-1 rounded",children:"values"})," field"]})],["options[name=Size].values|lower|join","Extract values, lowercase, then join into a single string"],["Use these to modify the extracted value",(0,l.jsx)("code",{className:"bg-gray-100 px-1 rounded",children:"|lower |upper |trim |join"},"modifiers-hint")]];return(0,l.jsx)(i.A,{title:k.id?"Edit Typesense Index":"Create New Typesense Index",onClose:n,children:(0,l.jsxs)("form",{onSubmit:ec,children:[(0,l.jsxs)("div",{style:{borderBottom:"2px solid #e5e7eb",marginBottom:"20px",display:"flex",gap:"0"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>M("basic"),style:{padding:"12px 24px",border:"none",background:"transparent",borderBottom:"basic"===L?"3px solid #3b82f6":"3px solid transparent",color:"basic"===L?"#3b82f6":"#6b7280",fontWeight:"basic"===L?"600":"500",fontSize:"14px",cursor:"pointer",transition:"all 0.2s"},children:"\uD83D\uDCCB Basic Settings"}),(0,l.jsx)("button",{type:"button",onClick:()=>M("mapping"),style:{padding:"12px 24px",border:"none",background:"transparent",borderBottom:"mapping"===L?"3px solid #3b82f6":"3px solid transparent",color:"mapping"===L?"#3b82f6":"#6b7280",fontWeight:"mapping"===L?"600":"500",fontSize:"14px",cursor:"pointer",transition:"all 0.2s"},children:"\uD83D\uDDFAï¸ Field Mapping"}),"ecommerce"===k.dataType&&(0,l.jsx)("button",{type:"button",onClick:()=>M("attributes"),style:{padding:"12px 24px",border:"none",background:"transparent",borderBottom:"attributes"===L?"3px solid #3b82f6":"3px solid transparent",color:"attributes"===L?"#3b82f6":"#6b7280",fontWeight:"attributes"===L?"600":"500",fontSize:"14px",cursor:"pointer",transition:"all 0.2s"},children:"\uD83C\uDFF7ï¸ Attributes Builder"}),(0,l.jsx)("button",{type:"button",onClick:()=>M("advanced"),style:{padding:"12px 24px",border:"none",background:"transparent",borderBottom:"advanced"===L?"3px solid #3b82f6":"3px solid transparent",color:"advanced"===L?"#3b82f6":"#6b7280",fontWeight:"advanced"===L?"600":"500",fontSize:"14px",cursor:"pointer",transition:"all 0.2s"},children:"âï¸ Advanced"})]}),"basic"===L&&(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"name",children:"Index Name"}),(0,l.jsx)("input",{type:"text",required:!0,placeholder:"e.g., Kamux Cars Finland",id:"index-name",value:k.name,onChange:e=>ep("name",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]})}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"dataType",children:"Data Type"}),(0,l.jsx)(x.Ay,{id:"dataType",value:el.find(e=>e.value===k.dataType),onChange:e=>ep("dataType",e.value),options:el}),(0,l.jsx)("small",{className:"text-gray-500",children:"Data will be automatically transformed to match our standard schema"})]})}),"addsearch"!==k.feedFormat&&"post_api"!==k.feedFormat&&"scraping"!==k.feedFormat&&"f
1ile_upload"!==k.feedFormat&&"linear_api"!==k.feedFormat&&(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"feedUrl",children:"woocommerce_api"===k.feedFormat?"WordPress Site URL(s)":"shopify_api"===k.feedFormat?"Shopify store URL":"Feed URL(s)"}),(0,l.jsx)("input",{type:"text",required:!0,placeholder:"woocommerce_api"===k.feedFormat?"https://yoursite.com":"shopify_api"===k.feedFormat?"your-store.myshopify.com or https://ecomapp.serviceform.com/api/products?shop=your-store.myshopify.com":"https://api.example.com/feed1.json, https://api.example.com/feed2.json",id:"feedUrl",value:k.feedUrl,onChange:e=>ep("feedUrl",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"woocommerce_api"===k.feedFormat?"Enter site URL(s). Separate multiple URLs with commas to combine feeds into one index.":"shopify_api"===k.feedFormat?"Enter your myshopify.com domain or the full ecomapp feed URL. Language is set separately below.":"Separate multiple URLs with commas to combine feeds into one index."})]})}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"feedFormat",children:"Feed Format"}),(0,l.jsx)(x.Ay,{id:"feedFormat",value:es.find(e=>e.value===k.feedFormat),onChange:e=>ep("feedFormat",e.value),options:es})]})}),"file_upload"===k.feedFormat&&(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"fileUpload",children:"Upload File (CSV, JSON, or XML)"}),(0,l.jsx)("div",{className:"mt-1 flex items-center space-x-4",children:(0,l.jsx)("input",{type:"file",id:"fileUpload",accept:".csv,.json,.xml",onChange:e=>{var t;let a=null==(t=e.target.files)?void 0:t[0];if(S(null),!a){y(null),v(null);return}if(a.size>0xa00000){S("File too large. Maximum size is ".concat(10,"MB")),y(null),v(null);return}let l=a.name.toLowerCase();if(![".csv",".json",".xml"].some(e=>l.endsWith(e))){S("Invalid file type. Supported formats: CSV, JSON, XML"),y(null),v(null);return}"auto"===j&&(l.endsWith(".csv")?N("csv"):l.endsWith(".json")?N("json"):l.endsWith(".xml")&&N("xml"));let s=new FileReader;s.onload=e=>{y(a),v(e.target.result)},s.onerror=()=>{S("Failed to read file"),y(null),v(null)},s.readAsText(a)},className:"block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"})}),f&&(0,l.jsxs)("div",{className:"mt-2 text-sm text-green-600",children:["Loaded: ",f.name," (",(f.size/1024).toFixed(1)," KB)"]}),w&&(0,l.jsx)("div",{className:"mt-2 text-sm text-red-600",children:w}),(0,l.jsx)("small",{className:"text-gray-500",children:"Maximum file size: 10MB. Supported formats: CSV, JSON, XML"})]}),(0,l.jsxs)("div",{className:"w-1/3",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"uploadedFileFormat",children:"File Format"}),(0,l.jsx)(x.Ay,{id:"uploadedFileFormat",value:er.find(e=>e.value===j),onChange:e=>N(e.value),options:er}),(0,l.jsx)("small",{className:"text-gray-500",children:"Auto-detects from file extension"})]})]}),"shopify_api"===k.feedFormat&&(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-1/2",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"shopifyLanguage",children:"Language (optional)"}),(0,l.jsx)("div",{className:"typesense-helper",children:(0,l.jsx)(K.A,{content:"Two-letter language code appended to feed URL. Leave empty for default store language."})})]}),(0,l.jsx)("input",{type:"text",placeholder:"e.g., en, fi, sv, de",id:"shopifyLanguage",value:k.shopifyLanguage,onChange:e=>ep("shopifyLanguage",e.target.value.trim().toLowerCase()),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]}),(0,l.jsxs)("div",{className:"w-1/2",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"shopifyCurrencies",children:"Currencies to index (optional)"}),(0,l.jsx)("div",{className:"typesense-helper",children:(0,l.jsx)(K.A,{content:"Comma-separated 3-letter currency codes. Leave empty to default currency."})})]}),(0,l.jsx)("input",{type:"text",placeholder:"e.g., EUR, USD, CAD",id:"shopifyCurrencies",value:k.shopifyCurrencies,onChange:e=>ep("shopifyCurrencies",e.target.value.toUpperCase()),onBlur:e=>{ep("shopifyCurrencies",Array.from(new Set((e.target.value||"").split(",").map(e=>e.trim().toUpperCase()).filter(e=>/^[A-Z]{3}$/.test(e)))).join(","))},className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]})]}),"addsearch"!==k.feedFormat&&"post_api"!==k.feedFormat&&"scraping"!==k.feedFormat&&"f
1ile_upload"!==k.feedFormat&&"woocommerce_api"!==k.feedFormat&&"shopify_api"!==k.feedFormat&&"linear_api"!==k.feedFormat&&(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("label",{className:"text-sm font-medium",htmlFor:"getApiResultPath",children:["Nested Data Path ","paginated_get_api"===k.feedFormat?"(Required)":"(Optional)"]}),(0,l.jsx)("input",{type:"text",placeholder:"e.g., documents.documents or data.items or data",id:"getApiResultPath",value:k.getApiResultPath,onChange:e=>ep("getApiResultPath",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"paginated_get_api"===k.feedFormat?"Path to the array in the API response (e.g., documents.documents for nested structure)":"If your data is nested (e.g., {data: {items: [...]}}), enter the path like data.items. Leave empty if array is at root level."})]}),"paginated_get_api"===k.feedFormat&&(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"getApiPageSize",children:"Page Size"}),(0,l.jsx)("input",{type:"number",min:"1",max:"1000",placeholder:"20",id:"getApiPageSize",value:k.getApiPageSize,onChange:e=>ep("getApiPageSize",parseInt(e.target.value)||20),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Results per page/request"})]})]}),"paginated_get_api"===k.feedFormat&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"getApiPaginationType",children:"Pagination Type"}),(0,l.jsx)(x.Ay,{id:"getApiPaginationType",value:[{value:"offset",label:"\uD83D\uDCCA Offset-based (offset=0, 1000, 2000...)"},{value:"page",label:"\uD83D\uDCC4 Page-based (page=1, 2, 3...)"}].find(e=>e.value===k.getApiPaginationType),onChange:e=>ep("getApiPaginationType",e.value),options:[{value:"offset",label:"\uD83D\uDCCA Offset-based (offset=0, 1000, 2000...)"},{value:"page",label:"\uD83D\uDCC4 Page-based (page=1, 2, 3...)"}]}),(0,l.jsx)("small",{className:"text-gray-500",children:"Choose based on your API: Remax uses page-based, most others use offset-based"})]})}),(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:["offset"===k.getApiPaginationType?(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"getApiOffsetParam",children:"Offset Parameter Name"}),(0,l.jsx)("input",{type:"text",placeholder:"offset (or skip)",id:"getApiOffsetParam",value:k.getApiOffsetParam,onChange:e=>ep("getApiOffsetParam",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"URL param for offset (default: offset, some APIs use skip)"})]}):(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"getApiPageParam",children:"Page Parameter Name"}),(0,l.jsx)("input",{type:"text",placeholder:"page",id:"getApiPageParam",value:k.getApiPageParam,onChange:e=>ep("getApiPageParam",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"URL param for page number (default: page)"})]}),(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"getApiLimitParam",children:"Limit Parameter Name"}),(0,l.jsx)("input",{type:"text",placeholder:"limit",id:"getApiLimitParam",value:k.getApiLimitParam,onChange:e=>ep("getApiLimitParam",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"URL param for page size (default: limit)"})]})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"getApiTotalCountPath",children:"Total Count Path (Optional)"}),(0,l.jsx)("input",{type:"text",placeholder:"e.g., meta.total_records or data.matches",id:"getApiTotalCountPath",value:k.getApiTotalCountPath,onChange:e=>ep("getApiTotalCountPath",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Path to total count in response. Auto-detects: meta.total_records, meta.total_pages, total, count"})]})})]}),"addsearch"===k.feedFormat&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"addsearchKey",children:"AddSearch Public Key"}),(0,l.jsx)("input",{type:"text",required:!0,placeholder:"e.g., 19ceebd039b6c7726eceb60b726fa675",id:"addsearchKey",value:k.addsearchKey,onChange:e=>ep("addsearchKey",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Your AddSearch public API key"})]})}),(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"addsearchQuery",children:"Search Query"}),(0,l.jsx)("input",{type:"text",placeholder:"* (all documents)",id:"addsearchQuery",value:k.addsearchQuery,onChange:e=>ep("addsearchQuery",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Search query to fetch documents (* for all)"})]}),(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"addsearchPageSize",children:"Page Size"}),(0,l.jsx)("input",{type:"number",min:"1",max:"1000",placeholder:"100",i
1d:"addsearchPageSize",value:k.addsearchPageSize,onChange:e=>ep("addsearchPageSize",parseInt(e.target.value)||100),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Results per page (1-1000)"})]})]})]}),"linear_api"===k.feedFormat&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"linearApiKey",children:"Linear API Key"}),(0,l.jsx)("input",{type:"password",required:!0,placeholder:"Enter Linear API key",id:"linearApiKey",value:k.linearApiKey,onChange:e=>ep("linearApiKey",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"API key for Linear property management system"})]}),(0,l.jsxs)("div",{className:"w-1/3",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"linearLanguage",children:"Language"}),(0,l.jsx)(x.Ay,{id:"linearLanguage",value:[{value:"fi",label:"\uD83C\uDDEB\uD83C\uDDEE Finnish"},{value:"en",label:"\uD83C\uDDEC\uD83C\uDDE7 English"},{value:"sv",label:"\uD83C\uDDF8\uD83C\uDDEA Swedish"},{value:"et",label:"\uD83C\uDDEA\uD83C\uDDEA Estonian"},{value:"es",label:"\uD83C\uDDEA\uD83C\uDDF8 Spanish"},{value:"pt",label:"\uD83C\uDDF5\uD83C\uDDF9 Portuguese"}].find(e=>e.value===k.linearLanguage),onChange:e=>ep("linearLanguage",e.value),options:[{value:"fi",label:"\uD83C\uDDEB\uD83C\uDDEE Finnish"},{value:"en",label:"\uD83C\uDDEC\uD83C\uDDE7 English"},{value:"sv",label:"\uD83C\uDDF8\uD83C\uDDEA Swedish"},{value:"et",label:"\uD83C\uDDEA\uD83C\uDDEA Estonian"},{value:"es",label:"\uD83C\uDDEA\uD83C\uDDF8 Spanish"},{value:"pt",label:"\uD83C\uDDF5\uD83C\uDDF9 Portuguese"}]}),(0,l.jsx)("small",{className:"text-gray-500",children:"Listing language"})]})]}),(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-2/3",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"linearBaseUrl",children:"Website Base URL"}),(0,l.jsx)("input",{type:"text",placeholder:"https://westhouse.fi",id:"linearBaseUrl",value:k.linearBaseUrl,onChange:e=>ep("linearBaseUrl",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Base URL for property listing links"})]}),(0,l.jsxs)("div",{className:"w-1/3",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"linearUrlPath",children:"URL Path"}),(0,l.jsx)("input",{type:"text",placeholder:"/kohteet",id:"linearUrlPath",value:k.linearUrlPath,onChange:e=>ep("linearUrlPath",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Path prefix before the address slug"})]})]})]}),"post_api"===k.feedFormat&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"feedUrl",children:"API Endpoint URL(s)"}),(0,l.jsx)("input",{type:"text",required:!0,placeholder:"https://example/api/search, https://example2/api/search",id:"feedUrl",value:k.feedUrl,onChange:e=>ep("feedUrl",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Separate multiple URLs with commas to combine feeds into one index."})]})}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"postApiBody",children:"Request Body (JSON)"}),(0,l.jsx)("textarea",{required:!0,placeholder:'{"page": 1, "limit": 100, "f
1ilter": {}}',id:"postApiBody",value:k.postApiBody,onChange:e=>ep("postApiBody",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",rows:"6",style:{fontFamily:"monospace",fontSize:"12px"}}),(0,l.jsxs)("small",{className:"text-gray-500",children:["JSON body for the POST request. Use ",(0,l.jsx)("code",{children:'{"page": 1}'})," as placeholder - it will be incremented for pagination."]})]})}),(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"postApiResultPath",children:"Result Array Path"}),(0,l.jsx)("input",{type:"text",required:!0,placeholder:"hits (or data, apartments, results, items)",id:"postApiResultPath",value:k.postApiResultPath,onChange:e=>ep("postApiResultPath",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Path to array in response."})]}),(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"postApiPagePath",children:"Page Field Path"}),(0,l.jsx)("input",{type:"text",placeholder:"page (field name in request body)",id:"postApiPagePath",value:k.postApiPagePath,onChange:e=>ep("postApiPagePath",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Field name for page number in request body"})]})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"postApiPageSize",children:"Page Size"}),(0,l.jsx)("input",{type:"number",min:"1",max:"1000",placeholder:"100",id:"postApiPageSize",value:k.postApiPageSize,onChange:e=>ep("postApiPageSize",parseInt(e.target.value)||100),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Results per page (1-1000)"})]})})]}),"scraping"===k.feedFormat&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"scrapingSitemapUrl",children:"Sitemap URL"}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("input",{type:"url",required:!0,placeholder:"https://example.com/sitemap.xml",id:"scrapingSitemapUrl",value:k.scrapingSitemapUrl,onChange:e=>ep("scrapingSitemapUrl",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("button",{type:"button",onClick:async()=>{if(!k.scrapingSitemapUrl)return void alert("Please enter a sitemap URL first");B(!0),I(null),O(null);try{let e=await fetch("/api/indexes/generate-scraping-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sitemapUrl:k.scrapingSitemapUrl,productUrlPattern:k.scrapingUrlPattern||null})}),t=await e.json();e.ok?(O(t),t.suggestedUrlPattern&&ep("scrapingUrlPattern",t.suggestedUrlPattern),t.fieldRulesJson&&ep("scrapingFieldRules",t.fieldRulesJson)):(I(t.error||"Failed to generate config"),t.sitemapPreview&&O({sitemapPreview:t.sitemapPreview}))}catch(e){I(e.message)}finally{B(!1)}},disabled:E||!k.scrapingSitemapUrl,className:"mt-1 px-4 py-2 bg-purple-600 text-white rounded-md hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap text-sm font-medium",children:E?"\uD83D\uDD04 Analyzing...":"\uD83E\uDD16 Generate Config with AI"})]}),(0,l.jsx)("small",{className:"text-gray-500",children:"The sitemap.xml URL to discover product pages"})]})}),z&&(0,l.jsxs)("div",{className:"mt-4 p-4 bg-red-50 border border-red-200 rounded-lg",children:[(0,l.jsxs)("p",{className:"text-red-700 font-medium",children:["â ",z]}),(null==U?void 0:U.sitemapPreview)&&(0,l.jsxs)("details",{className:"mt-2",children:[(0,l.jsx)("summary",{className:"text-sm text-red-600 cursor-pointer",children:"View sitemap preview"}),(0,l.jsx)("pre",{className:"mt-2 p-2 bg-red-100 rounded text-xs overflow-auto max-h-40",children:U.sitemapPreview})]})]}),U&&!z&&(0,l.jsxs)("div",{className:"mt-4 p-4 bg-green-50 border border-green-200 rounded-lg",children:[(0,l.jsx)("p",{className:"text-green-700 font-medium mb-3",children:"â
Config generated successfully!"}),(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-gray-700",children:"\uD83D\uDCCA Sitemap Info"}),(0,l.jsxs)("p",{className:"text-gray-600",children:["Found ",U.totalProductsFound," products"]}),(0,l.jsxs)("p",{className:"text-gray-600 text-xs truncate",children:["First: ",U.productUrl]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-medium text-gray-700",children:"\uD83D\uDD17 Sample URLs"}),null==(t=U.sampleUrls)?void 0:t.slice(0,3).map((e,t)=>(0,l.jsx)("p",{className:"text-gray-600 text-xs truncate",children:e},t))]})]}),U.extractedData&&(0,l.jsxs)("div",{className:"mt-4",children:[(0,l.jsx)("p",{className:"font-medium text-gray-700 mb-2",children:"\uD83D\uDCE6 Extracted from first product:"}),(0,l.jsx)("div",{className:"bg-white p-3 rounded border border-green-200 text-xs font-mono overflow-auto max-h-60",children:(0,l.jsx)("table",{className:"w-full",children:(0,l.jsx)("tbody",{children:Object.entries(U.extractedData).map(e=>
1{let[t,a]=e;return(0,l.jsxs)("tr",{className:"border-b border-gray-100",children:[(0,l.jsx)("td",{className:"py-1 pr-4 font-semibold text-gray-600 align-top whitespace-nowrap",children:t}),(0,l.jsx)("td",{className:"py-1 text-gray-800",children:Array.isArray(a)?(0,l.jsxs)("span",{className:"text-blue-600",children:["[",a.length," items] ",a.slice(0,2).join(", "),a.length>2?"...":""]}):"string"==typeof a&&a.length>60?a.substring(0,60)+"...":String(a)})]},t)})})})}),(0,l.jsx)("p",{className:"mt-2 text-xs text-gray-500",children:"⨠URL pattern and field rules have been auto-filled below. Review and adjust if needed."})]})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"scrapingUrlPattern",children:"Product URL Pattern (Regex)"}),(0,l.jsx)("input",{type:"text",required:!0,placeholder:"https://example\\\\.com/products/[^<]+",id:"scrapingUrlPattern",value:k.scrapingUrlPattern,onChange:e=>ep("scrapingUrlPattern",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm font-mono text-xs"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Regex pattern to match product URLs in sitemap (escape dots with \\\\)"})]})}),(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-1/2",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"scrapingDelayMs",children:"Delay Between Requests (ms)"}),(0,l.jsx)("input",{type:"number",min:"50",max:"5000",placeholder:"150",id:"scrapingDelayMs",value:k.scrapingDelayMs||150,onChange:e=>ep("scrapingDelayMs",parseInt(e.target.value)||150),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Rate limit: wait this long between requests"})]}),(0,l.jsxs)("div",{className:"w-1/2",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"scrapingLimit",children:"Max Products (0 = all)"}),(0,l.jsx)("input",{type:"number",min:"0",placeholder:"0",id:"scrapingLimit",value:k.scrapingLimit||0,onChange:e=>ep("scrapingLimit",parseInt(e.target.value)||0),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Limit number of products (0 = no limit)"})]})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"scrapingFieldRules",children:"Field Extraction Rules (JSON)"}),(0,l.jsx)("textarea",{required:!0,placeholder:'{\n "name": {\n "methods": [\n { "type": "regex", "pattern": "<meta property=\\"og:title\\" content=\\"([^\\"]+)\\"" }\n ],\n "transform": "decodeHtml"\n },\n "price": {\n "methods": [\n { "type": "regex", "pattern": "\\"price\\":\\\\s*\\"?(\\\\d+\\\\.?\\\\d*)\\"?" }\n ],\n "transform": "toFloat"\n },\n "sku": {\n "methods": [\n { "type": "urlPattern", "pattern": "/products/([^/]+)" }\n ]\n }\n}',id:"scrapingFieldRules",value:k.scrapingFieldRules,onChange:e=>ep("scrapingFieldRules",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm font-mono text-xs",rows:"16"}),(0,l.jsxs)("small",{className:"text-gray-500",children:["JSON config for field extraction. Methods: ",(0,l.jsx)("code",{children:"regex"})," (HTML pattern), ",(0,l.jsx)("code",{children:"urlPattern"})," (URL regex), ",(0,l.jsx)("code",{children:"regexAll"})," (multiple matches). Transforms: ",(0,l.jsx)("code",{children:"decodeHtml"}),", ",(0,l.jsx)("code",{children:"toFloat"}),", ",(0,l.jsx)("code",{children:"centsToCurrency"}),", ",(0,l.jsx)("code",{children:"trimArray"}),", ",(0,l.jsx)("code",{children:"boolToAvailability"})]})]})})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("label",{className:"text-sm font-medium",htmlFor:"collectionName",children:["Typesense Collection Name",a?(0,l.jsx)("span",{style:{marginLeft:"8px",fontSize:"11px",color:"#3b82f6"},children:"\uD83D\uDD12 (Locked)"}):(0,l.jsx)("span",{style:{marginLeft:"8px",fontSize:"11px",color:"#10b981"},children:"(Auto-generated)"})]}),(0,l.jsx)("input",{type:"text",required:!0,value:A,readOnly:!0,className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm bg-gray-100 cursor-not-allowed sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:a?"\uD83D\uDD12 Collection name is locked when editing":"⨠Automatically generated from index name"})]})}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("label",{className:"text-sm font-medium",htmlFor:"groupingField",children:["Group Results By Field",(0,l.jsx)("span",{style:{marginLeft:"8px",fontSize:"11px",color:"#6b7280"},children:"(Optional)"})]}),(0,l.jsx)("input",{type:"text",id:"groupingField",value:k.groupingField,onChange:e=>ep("groupingField",e.target.value),placeholder:"e.g., item_group_id",className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Field name to group search results by (e.g., item_group_id for product variants). Leave empty to show all items individually."})]})}),"scraping"!==k.feedFormat&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex text-left mt-4 space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"feed-auth-user",children:"Username"}),(0,l.jsx)("input",{type:"text",placeholder:"Enter username (optional)",id:"feed-auth-user",name:"feed-auth-user",autoComplete:"off","data-lpignore":"true","data-1p-ignore":!0,value:k.username,onChange:e=>ep("username",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]}),(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"feed-auth-pass",children:"Password"}),(0,l.jsx)("input",{type:"text",placeholder:"Enter password (optional)",id:"feed-auth-pass",name:"feed-auth-pass",autoComplete:"off","data-lpignore":"true","data-1p-ignore":!0,style:{WebkitTextSecurity:"disc"},value:k.password,onChange:e=>ep("password",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"headers",children:"Custom Headers"}),(0,l.jsx)("textarea",{placeholder:"Enter custom headers (one per line, e.g., KamuxApiKey=value)",id:"headers",value:k.headers,onChange:e=>ep("headers",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",rows:"3"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Add custom headers for API authentication. Format: HeaderName=value (one per line)"})]})})]}),"cars"===k.dataType&&(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("label",{className:"flex items-center",children:[(0,l.jsx)("input",{type:"checkbox",checked:k.useModelMakeAsTitle,onChange:e=>ep("useModelMakeAsTitle",e.target.checked),className:"mr-2"}),(0,l.jsx)("span",{className:"text-sm",children:"Use Brand Model as Title"})]}),(0,l.jsx)("small",{className:"text-gray-500",children:"When enabled, title will be Brand Model instead of full title with accessories"})]})}
1),("ecommerce"===k.dataType||"properties_ecommerce"===k.dataType)&&(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("label",{className:"flex items-center",children:[(0,l.jsx)("input",{type:"checkbox",checked:k.pricesInCents,onChange:e=>ep("pricesInCents",e.target.checked),className:"mr-2"}),(0,l.jsx)("span",{className:"text-sm",children:"Prices are already in cents (\xf6re)"})]}),(0,l.jsxs)("small",{className:"text-gray-500",children:["â
Check if feed prices are like: 10000 = â¬100 (already in cents)",(0,l.jsx)("br",{}),"â Uncheck if prices are like: 100 = â¬100 (needs conversion to cents)"]})]})}),("properties_rental"===k.dataType||"properties_ecommerce"===k.dataType)&&(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"defaultCountry",children:"Default country for search"}),(0,l.jsx)("input",{id:"defaultCountry",type:"text",className:"w-full p-2 border rounded",value:k.defaultCountry,onChange:e=>ep("defaultCountry",e.target.value),placeholder:"e.g., Finland, Spain, Germany..."}),(0,l.jsx)("small",{className:"text-gray-500",children:'When users search for a city that exists in multiple countries (e.g., "Salo" in Finland vs Italy), this country will be used as the default to avoid asking for clarification.'})]})}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"language",children:"Content language"}),(0,l.jsxs)("select",{id:"language",className:"w-full p-2 border rounded",value:k.language,onChange:e=>ep("language",e.target.value),children:[(0,l.jsx)("option",{value:"",children:"Not set"}),Y.map(e=>(0,l.jsxs)("option",{value:e.code,children:[e.flag," ",e.name]},e.code))]}),(0,l.jsx)("small",{className:"text-gray-500",children:"shopify_api"===k.feedFormat?"Leave empty to use the Shopify language above for routing. Only set this to override it.":"The language of this feed's product content. When a knowledgebase has multiple feeds enabled (e.g. one per language), Mira uses this to pick the feed matching the conversation's language."})]})}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"frequency",children:"Auto-Index Frequency"}),(0,l.jsx)(x.Ay,{id:"frequency",value:ei.find(e=>e.value===k.frequency),onChange:e=>ep("frequency",e.value),options:ei}),(0,l.jsx)("small",{className:"text-gray-500",children:"Set how often this index should be automatically refreshed with new data from the feed"})]})}),("ecommerce"===k.dataType||"properties_ecommerce"===k.dataType)&&(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"mainCategoryFilter",children:"Category filter (optional)"}),(0,l.jsx)("textarea",{id:"mainCategoryFilter",value:k.mainCategoryFilter,onChange:e=>ep("mainCategoryFilter",e.target.value),placeholder:"Fishing\nFly Fishing\nFly Rods\nReels\nClothing\nElectronics",rows:4,style:{width:"100%",padding:"8px 12px",border:"1px solid #d1d5db",borderRadius:"6px",fontSize:"13px",fontFamily:"monospace",resize:"vertical",marginTop:"4px"}}),(0,l.jsxs)("small",{className:"text-gray-500",children:["One category per line. Only products whose ",(0,l.jsx)("strong",{children:"main_category OR sub_category OR leaf_category"})," matches one of these will be indexed. Leave empty to index all products."]}),k.mainCategoryFilter&&(0,l.jsx)("div",{style:{marginTop:"6px",padding:"6px 10px",backgroundColor:"#FEF3C7",border:"1px solid #F59E0B",borderRadius:"6px"},children:(0,l.jsxs)("small",{style:{color:"#92400E"},children:["Filtering active: only ",k.mainCategoryFilter.split("\n").filter(e=>e.trim()).length," categories will be indexed"]})})]})}),"ecommerce"===k.dataType&&(0,l.jsx)("div",{className:"flex text-left mt-6 space-x-4",children:(0,l.jsxs)("div",{className:"w-full p-4 border rounded-lg",style:{backgroundColor:k.enableSemanticSearch?"#f0fdf4":"#f9fafb",borderColor:k.enableSemanticSearch?"#86efac":"#e5e7eb"},children:[(0,l.jsxs)("label",{className:"flex items-center cursor-pointer",children:[(0,l.jsx)("input",{type:"checkbox",checked:k.enableSemanticSearch,onChange:e=>ep("enableSemanticSearch",e.target.checked),className:"mr-3 h-5 w-5"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-sm font-semibold",children:"Enable semantic search (Beta)"}),(0,l.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"AI-powered search that understands meaning - handles slang, typos, and synonyms automatically"})]})]}),k.enableSemanticSearch&&(0,l.jsxs)("div",{className:"mt-3 p-3 bg-white rounded border border-green-200",children:[(0,l.jsxs)("p",{className:"text-xs text-gray-600",children:[(0,l.jsx)("strong",{children:"Hybrid search:"})," Combines keyword matching with vector similarity for better results."]}),(0,l.jsxs)("p",{className:"text-xs text-gray-600 mt-1",children:[(0,l.jsx)("strong",{children:"AI-guided:"})," For complex queries, AI selects relevant categories first, then ranks products."]}),(0,l.jsx)("p",{className:"text-xs text-green-600 mt-1",children:"Cost: Free (Gemini embeddings + Gemini Flash Lite for ranking)"})]})]})}
1),("ecommerce"===k.dataType||"properties_ecommerce"===k.dataType)&&(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full p-4 border rounded-lg",style:{backgroundColor:k.enableInfixSearch?"#eff6ff":"#f9fafb",borderColor:k.enableInfixSearch?"#93c5fd":"#e5e7eb"},children:[(0,l.jsxs)("label",{className:"flex items-center cursor-pointer",children:[(0,l.jsx)("input",{type:"checkbox",checked:k.enableInfixSearch,onChange:e=>ep("enableInfixSearch",e.target.checked),className:"mr-3 h-5 w-5"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-sm font-semibold",children:"Enable infix (substring) search"}),(0,l.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:"Matches words inside compound words. Essential for Finnish, German, and other languages with compound nouns."})]})]}),k.enableInfixSearch&&(0,l.jsxs)("div",{className:"mt-3 p-3 bg-white rounded border border-blue-200",children:[(0,l.jsxs)("p",{className:"text-xs text-gray-600",children:[(0,l.jsx)("strong",{children:"Example:"}),' Searching "kaapeli" will match "hitsauskaapeli" (welding cable).']}),(0,l.jsxs)("p",{className:"text-xs text-gray-600 mt-1",children:[(0,l.jsx)("strong",{children:"Fields:"})," Enabled on title, description, and SKU."]}),(0,l.jsx)("p",{className:"text-xs text-amber-600 mt-1",children:"Note: Increases index size. Re-indexing required after toggling."})]})]})})]}),"mapping"===L&&(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsx)("label",{className:"text-sm font-medium",children:"\uD83D\uDDFAï¸ Custom Field Mapping (Optional)"}),(0,l.jsx)(r.A,{type:"button",variant:"outline",small:!0,onClick:en,disabled:T,children:T?"Analyzing...":"\uD83E\uDD16 Gemini AI Auto-Map"})]}),_&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{style:{padding:"10px",backgroundColor:"#d1fae5",border:"1px solid #10b981",borderRadius:"4px",marginBottom:"10px"},children:(0,l.jsxs)("p",{style:{fontSize:"12px",color:"#065f46",display:"flex",alignItems:"center"},children:[(0,l.jsx)("span",{style:{marginRight:"4px"},children:"â"}),(0,l.jsxs)("span",{children:[_.aiPowered?"Gemini AI":"Auto"," Mapping Complete! Found ",Object.keys(_.fieldMapping||{}).length," field mappings",_.aiPowered&&(0,l.jsx)("span",{style:{marginLeft:"4px"},children:"\uD83E\uDDE0"})]})]})}),_.suggestedAttributeRules&&_.suggestedAttributeRules.length>0&&"ecommerce"===k.dataType&&(0,l.jsx)("div",{style:{padding:"10px",backgroundColor:"#EFF6FF",border:"1px solid #3B82F6",borderRadius:"4px",marginBottom:"10px"},children:(0,l.jsxs)("p",{style:{fontSize:"12px",color:"#1E40AF",display:"flex",alignItems:"center",margin:0},children:[(0,l.jsx)("span",{style:{marginRight:"4px"},children:"\uD83C\uDFF7ï¸"}),(0,l.jsxs)("span",{children:[(0,l.jsx)("strong",{children:"Bonus:"})," Auto-detected ",_.suggestedAttributeRules.length," attribute rules! Check the Attributes Builder tab to review."]})]})})]}),et.length>0&&(0,l.jsxs)("div",{style:{marginTop:"16px"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:[(0,l.jsx)("h4",{style:{fontSize:"13px",fontWeight:"600",margin:0,color:"#374151"},children:"\uD83D\uDCCB Field Mappings (Click to Edit)"}),(0,l.jsx)("button",{type:"button",onClick:()=>{ea([]),F(e=>({...e,fieldMapping:{}})),D(null)},style:{padding:"4px 8px",fontSize:"11px",color:"#DC2626",backgroundColor:"transparent",border:"1px solid #DC2626",borderRadius:"4px",cursor:"pointer"},children:"Clear All"})]}),(0,l.jsxs)("div",{style:{backgroundColor:"#F9FAFB",border:"1px solid #E5E7EB",borderRadius:"8px",padding:"12px",maxHeight:"400px",overflowY:"auto"},children:[et.map(e=>(0,l.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr auto 1fr auto",gap:"8px",alignItems:"center",marginBottom:"8px",padding:"8px",backgroundColor:"#FFFFFF",borderRadius:"6px",border:"1px solid #E5E7EB"}
1,children:[(0,l.jsx)("input",{type:"text",value:e.source,onChange:t=>{ea(a=>a.map(a=>a.id===e.id?{...a,source:t.target.value}:a))},placeholder:"Source field",style:{padding:"6px 10px",fontSize:"12px",fontFamily:"monospace",border:"1px solid #DBEAFE",borderRadius:"4px",backgroundColor:"#DBEAFE",color:"#1E40AF",fontWeight:"500"}}),(0,l.jsx)("div",{style:{textAlign:"center",color:"#6B7280",fontSize:"14px"},children:"â"}),(0,l.jsx)("input",{type:"text",value:e.target,onChange:t=>{ea(a=>a.map(a=>a.id===e.id?{...a,target:t.target.value}:a))},placeholder:"Target field",style:{padding:"6px 10px",fontSize:"12px",fontFamily:"monospace",border:"1px solid #D1FAE5",borderRadius:"4px",backgroundColor:"#D1FAE5",color:"#065F46",fontWeight:"500"}}),(0,l.jsx)("button",{type:"button",onClick:()=>{ea(t=>t.filter(t=>t.id!==e.id))},style:{color:"#EF4444",fontSize:"18px",cursor:"pointer",background:"transparent",border:"none",padding:"0 4px"},children:"\xd7"})]},e.id)),(0,l.jsx)("button",{type:"button",onClick:()=>{ea(e=>[...e,{id:(0,h.$)(10),source:"",target:""}])},style:{marginTop:"8px",padding:"6px 12px",fontSize:"12px",color:"#3B82F6",backgroundColor:"transparent",border:"1px dashed #3B82F6",borderRadius:"4px",cursor:"pointer",width:"100%"},children:"+ Add Custom Mapping"})]}),(0,l.jsx)("small",{style:{color:"#6B7280",fontSize:"11px",marginTop:"8px",display:"block"},children:"\uD83D\uDCA1 Edit field names or click â\xd7â to remove. Add custom mappings as needed."})]}),(0,l.jsx)("small",{className:"text-gray-500",children:"Map non-standard field names to standard fields. Leave empty for auto-detection."})]})}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsx)("label",{className:"text-sm font-medium",children:"â Extra Custom Fields"}),(0,l.jsx)(r.A,{type:"button",variant:"outline",small:!0,onClick:()=>{let e={sourceField:"",targetField:"",id:(0,h.$)(10),facet:!1,type:""};F(t=>({...t,extraFields:[...t.extraFields||[],e]}))},children:"+ Add Field"})]}),k.extraFields&&k.extraFields.length>0&&(0,l.jsx)("div",{style:{marginBottom:"10px"},children:k.extraFields.map(e=>{var t,a,s,r;return(0,l.jsxs)("div",{style:{display:"flex",gap:"8px",marginBottom:"8px",alignItems:"center"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Source field name",value:e.sourceField,onChange:t=>em(e.id,"sourceField",t.target.value),className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsx)("span",{style:{color:"#9ca3af"},children:"â"}),(0,l.jsx)("input",{type:"text",placeholder:"Target field (optional)",value:e.targetField,onChange:t=>em(e.id,"targetField",t.target.value),className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsxs)("label",{className:"flex items-center gap-1 text-xs text-gray-500 whitespace-nowrap",title:"Make this field facetable in Typesense",children:[(0,l.jsx)("input",{type:"checkbox",checked:null!=(t=e.facet)&&t,onChange:t=>em(e.id,"facet",t.target.checked)}),"Facet"]}),(0,l.jsxs)("select",{value:null!=(a=e.type)?a:"",onChange:t=>em(e.id,"type",t.target.value),disabled:null!=(s=e.isArray)&&s,title:"Dates and numbers are stored as numbers so shoppers can sort by them",className:"rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 text-xs",children:[(0,l.jsx)("option",{value:"",children:"Text"}),(0,l.jsx)("option",{value:"date",children:"Date"}),(0,l.jsx)("option",{value:"number",children:"Number"})]}),(0,l.jsxs)("label",{className:"flex items-center gap-1 text-xs text-gray-500 whitespace-nowrap",title:"Store as string[] instead of a joined string, so multi-value sources (e.g. repeated locations) keep each value distinct",children:[(0,l.jsx)("input",{type:"checkbox",checked:null!=(r=e.isArray)&&r,onChange:t=>em(e.id,"isArray",t.target.checked)}),"Array"]}),(0,l.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void F(e=>({...e,extraFields:(e.extraFields||[]).filter(e=>e.id!==t)}))},style:{color:"#ef4444",fontSize:"18px",padding:"4px 8px"},children:"\xd7"})]},e.id)})}),(0,l.jsx)("small",{className:"text-gray-500",children:"Add extra fields from your source data that aren't in the standard schema. These fields will be preserved in Typesense. Enable Facet to make the field facetable. Enable Array when the source repeats this field (e.g. multiple locations) s
1o each value is stored and faceted individually instead of joined into one string. Set Type to Date or Number to store the value as a number, which is what lets shoppers sort by it."}),(0,l.jsxs)("details",{className:"mt-3 group",children:[(0,l.jsxs)("summary",{className:"text-xs text-gray-400 cursor-pointer select-none hover:text-gray-600 list-none flex items-center gap-1",children:[(0,l.jsx)("span",{className:"transition-transform group-open:rotate-90",children:"â¶"}),"Source field syntax examples"]}),(0,l.jsx)("div",{className:"mt-2 rounded-lg border border-gray-200 bg-gray-50 overflow-hidden",children:(0,l.jsxs)("table",{className:"w-full text-xs",children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{className:"bg-gray-100 text-left text-gray-500 uppercase tracking-wide",children:[(0,l.jsx)("th",{className:"px-3 py-2 font-medium w-1/2",children:"Source field"}),(0,l.jsx)("th",{className:"px-3 py-2 font-medium",children:"What it does"})]})}),(0,l.jsx)("tbody",{className:"divide-y divide-gray-100",children:eF.map(e=>{let[t,a]=e;return(0,l.jsxs)("tr",{children:[(0,l.jsx)("td",{className:"px-3 py-2 font-mono text-blue-700 bg-blue-50/60",children:(0,l.jsx)("code",{children:t})}),(0,l.jsx)("td",{className:"px-3 py-2 text-gray-600",children:a})]},t)})})]})})]})]})})]}),"attributes"===L&&"ecommerce"===k.dataType&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{padding:"12px",backgroundColor:"#EFF6FF",border:"1px solid #3B82F6",borderRadius:"8px",marginBottom:"16px"},children:[(0,l.jsx)("p",{style:{fontSize:"13px",color:"#1E40AF",margin:"0 0 8px 0",fontWeight:"600"},children:"\uD83D\uDCA1 Universal Solution: Transform any product-specific fields into facets"}),(0,l.jsx)("p",{style:{fontSize:"12px",color:"#1E40AF",margin:0},children:"Works for computers (RAM, CPU), clothes (Fit, Style), furniture (Material), etc. without code changes!"})]}),!_&&(0,l.jsxs)("div",{style:{padding:"16px",backgroundColor:"#FEF3C7",border:"1px solid #F59E0B",borderRadius:"8px",marginBottom:"16px",textAlign:"center"},children:[(0,l.jsx)("p",{style:{fontSize:"13px",color:"#92400E",margin:"0 0 12px 0",fontWeight:"500"},children:"\uD83D\uDC46 First, analyze your feed to see available fields"}),(0,l.jsx)(r.A,{type:"button",variant:"primary",onClick:()=>M("mapping"),children:"Go to Field Mapping â Detect Fields"})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsx)("label",{className:"text-sm font-medium",children:"\uD83C\uDFF7ï¸ Attribute Transformation Rules"}),(0,l.jsx)(r.A,{type:"button",variant:"outline",small:!0,onClick:()=>{let e={sourceField:"",template:"",id:(0,h.$)(10)};F(t=>({...t,attributeRules:[...t.attributeRules||[],e]}))},children:"+ Add Rule"})]}),(0,l.jsx)("div",{style:{padding:"12px",backgroundColor:"#EFF6FF",border:"1px solid #3B82F6",borderRadius:"8px",marginBottom:"12px"},children:(0,l.jsxs)("p",{style:{fontSize:"12px",color:"#1E40AF",margin:0},children:["\uD83D\uDCA1 ",(0,l.jsx)("strong",{children:"Universal Solution:"})," Transform any product-specific fields into the ",(0,l.jsx)("code",{children:"attributes"})," array for faceting. This works for computers (RAM, CPU), clothes (Fit, Style), furniture (Material), etc. without code changes!",(null==_?void 0:_.suggestedAttributeRules)&&_.suggestedAttributeRules.length>0&&(0,l.jsx)("span",{style:{display:"block",marginTop:"8px",fontWeight:"600",color:"#3B82F6"},children:"\uD83E\uDD16 Rules below were auto-detected by AI! Review and customize as needed."})]})}),k.attributeRules&&k.attributeRules.length>0&&(0,l.jsx)("div",{style:{marginBottom:"10px"},children:k.attributeRules.map(e=>(0,l.jsxs)("div",{style:{display:"grid",gridTemplateColumns:J.length>0?"2fr 1fr 2fr 40px":"1fr 1fr 40px",gap:"8px",marginBottom:"12px",alignItems:"start",padding:"12px",backgroundColor:"#F9FAFB",borderRadius:"8px",border:"1px solid #E5E7EB"},children:[J.length>0?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{style:{fontSize:"11px",color:"#6B7280",display:"block",marginBottom:"4px"},children:"Source Field"}),(0,l.jsxs)("select",{value:e.sourceField,onChange:t=>eu(e.id,"sourceField",t.target.value),className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontFamily:"monospace",fontSize:"12px"},children:[(0,l.jsx)("option",{value:"",children:"-- Select a field --"}),J.map((e,t)=>(0,l.jsxs)("option",{value:e.path,children:[e.path,e.isArray?"[]":""," â ",e.sampleValue]},t))]})]}),(0,l.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",paddingTop:"24px"},children:(0,l.jsx)("span",{style:{color:"#9ca3af",fontSize:"18px"},children:"â"})})]}):(0,l.jsx)("input",{type:"text",placeholder:"Source field (e.g., ram, cpu, use_cases)",value:e.sourceField,onChange:t=>eu(e.id,"sourceField",t.target.value),className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{style:{fontSize:"11px",color:"#6B7280",display:"block",marginBottom:"4px"},children:"Display Template"}),(0,l.jsx)("input",{type:"text",placeholder:'e.g., "RAM: {value}GB"',value:e.template,onChange:t=>eu(e.id,"template",t.target.value),className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontFamily:"monospace",fontSize:"12px"}}),(0,l.jsxs)("small",{style:{fontSize:"10px",color:"#6B7280"},children:["Use ","{value}"," as placeholder"]})]}),(0,l.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void F(e=>({...e,attributeRules:(e.attributeRules||[]).filter(e=>e.id!==t)}))},style:{color:"#ef4444",fontSize:"20px",padding:"4px 8px",marginTop:"24px",background:"transparent",border:"none",cursor:"pointer"},children:"\xd7"})]},e.id))}),J.length>0&&(0,l.jsx)("div",{style:{padding:"12px",backgroundColor:"#D1FAE5",border:"1px solid #10B981",borderRadius:"8px",marginTop:"12px"},children:(0,l.jsxs)("p",{style:{fontSize:"12px",color:"#065F46",margin:0},children:["â
",(0,l.jsxs)("strong",{children:[J.length," fields detected"]})," from your feed! Use ",(0,l.jsx)("strong",{children:"âAdd a ruleâ"})," button above to see sample values."]})}),(0,l.jsxs)("small",{className:"text-gray-500",style:{display:"block",marginTop:"12px"}
1,children:[(0,l.jsx)("strong",{children:"Quick Examples:"}),(0,l.jsx)("br",{}),"⢠Field: ",(0,l.jsx)("code",{children:"ram"})," â Template: ",(0,l.jsxs)("code",{children:["RAM: ","{value}","GB"]}),(0,l.jsx)("br",{}),"⢠Field: ",(0,l.jsx)("code",{children:"use_cases"})," (array) â Template: ",(0,l.jsxs)("code",{children:["Use: ","{value}"]}),(0,l.jsx)("br",{}),"⢠Result: Values appear in the universal Features facet filter!"]})]})})]}),"advanced"===L&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:"8px",marginBottom:"12px",overflow:"hidden"},children:[(0,l.jsxs)("button",{type:"button",onClick:()=>{q(e=>({...e,filters:!e.filters})),W.filters||eS()},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",border:"none",backgroundColor:W.filters?"#f9fafb":"white",cursor:"pointer",fontSize:"14px",fontWeight:"600",color:"#374151"},children:[(0,l.jsxs)("span",{children:["Exclusion filters",(k.exclusionFilters||[]).filter(e=>e.field).length>0&&(0,l.jsx)("span",{style:{marginLeft:"8px",backgroundColor:"#ef4444",color:"white",borderRadius:"10px",padding:"1px 8px",fontSize:"11px",fontWeight:"700"},children:(k.exclusionFilters||[]).filter(e=>e.field).length})]}),(0,l.jsx)("span",{style:{fontSize:"18px",color:"#9ca3af",transition:"transform 0.2s",transform:W.filters?"rotate(180deg)":"rotate(0deg)"},children:"â¾"})]}),W.filters&&(0,l.jsxs)("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb"},children:[(0,l.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,l.jsxs)("p",{className:"text-sm text-gray-600",children:["Add rules to exclude items during indexing. An item is excluded if it matches ",(0,l.jsx)("strong",{children:"any"})," rule."]}),ej&&eg.length>0&&(0,l.jsxs)("p",{className:"text-xs text-green-600",style:{marginTop:"6px"},children:[eg.length," fields loaded. Pick a field to see available values."]}),ej&&0===eg.length&&(0,l.jsx)("p",{className:"text-xs text-gray-400",style:{marginTop:"6px"},children:"No indexed data yet. Run indexing first to enable suggestions, or type field names manually."})]}),(k.exclusionFilters||[]).map((e,t)=>{let a=eg.length>0?eg.map(e=>({value:e.name,label:"".concat(e.name).concat(e.type?" (".concat(e.type,")"):""),fieldType:e.type,facet:e.facet})):[],s=(e=>{let t=ef[e];return t&&0!==t.length?t.map(e=>({value:String(e.value),label:"".concat(e.value," (").concat(e.count,")")})):[]})(e.field),r=(e=>{let t=eg.find(t=>t.name===e);return(null==t?void 0:t.facet)===!0})(e.field),i=["greater_than","less_than"].includes(e.operator),n=r&&!i&&s.length>0;return(0,l.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-start",marginBottom:"10px",padding:"12px",backgroundColor:"#fef2f2",border:"1px solid #fecaca",borderRadius:"8px"},children:[(0,l.jsxs)("span",{style:{color:"#9ca3af",fontSize:"12px",marginTop:"10px",minWidth:"20px"},children:[t+1,"."]}),(0,l.jsxs)("div",{style:{flex:2},children:[(0,l.jsx)("label",{className:"text-xs text-gray-500",children:"Field"}),a.length>0?(0,l.jsx)(g.A,{value:e.field?{value:e.field,label:e.field}:null,onChange:t=>ek(e.id,"field",(null==t?void 0:t.value)||""),options:a,placeholder:"Select or type field...",isClearable:!0,formatCreateLabel:e=>"Custom: ".concat(e),styles:{container:e=>({...e,marginTop:"4px"}),control:e=>({...e,minHeight:"38px",fontSize:"13px"})}}):(0,l.jsx)("input",{type:"text",value:e.field||"",onChange:t=>ek(e.id,"field",t.target.value),placeholder:"e.g. price, category, brand",className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontSize:"13px"}})]}),(0,l.jsxs)("div",{style:{flex:2},children:[(0,l.jsx)("label",{className:"text-xs text-gray-500",children:"Operator"}),(0,l.jsx)(x.Ay,{value:ew.find(t=>t.value===e.operator),onChange:t=>ek(e.id,"operator",t.value),options:ew,styles:{container:e=>({...e,marginTop:"4px"}),control:e=>({...e,minHeight:"38px",fontSize:"13px"})}})]}),!["is_empty","is_not_empty","field_missing","field_exists"].includes(e.operator)&&(0,l.jsxs)("div",{style:{flex:2},children:[(0,l.jsxs)("label",{className:"text-xs text-gray-500",children:["Value",eb[e.field]&&(0,l.jsx)("span",{style:{marginLeft:"4px",color:"#9ca3af"},children:"loading..."})]}),n?(0,l.jsx)(g.A,{value:e.value?{value:e.value,label:e.value}:null,onChange:t=>ek(e.id,"value",(null==t?void 0:t.value)||""),options:s,placeholder:"Pick or type value...",isClearable:!0,formatCreateLabel:e=>"Custom: ".concat(e),styles:{container:e=>({...e,marginTop:"4px"}),control:e=>({...e,minHeight:"38px",fontSize:"13px"})}}):(0,l.jsx)("input",{type:"text",value:e.value||"",onChange:t=>ek(e.id,"value",t.target.value),placeholder:i?"e.g. 500":"e.g. Accessories",className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontSize:"13px"}})]}),(0,l.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void F(e=>({...e,exclusionFilters:(e.exclusionFilters||[]).filter(e=>e.id!==t)}))},style:{marginTop:"20px",padding:"6px 10px",border:"1px solid #fca5a5",borderRadius:"6px",backgroundColor:"white",color:"#dc2626",cursor:"pointer",fontSize:"13px",flexShrink:0},children:"Remove"})]},e.id)}),(0,l.jsx)("button",{type:"button",onClick:()=>{let e={field:"",operator:"equals",value:"",id:(0,h.$)(10)};F(t=>({...t,exclusionFilters:[...t.exclusionFilters||[],e]}))},style:{padding:"8px 16px",border:"2px dashed #d1d5db",borderRadius:"8px",backgroundColor:"transparent",color:"#6b7280",cursor:"pointer",fontSize:"13px",width:"100%"},children:"+ Add filter rule"}),(k.exclusionFilters||[]).filter(e=>e.field).length>0&&(0,l.jsx)("div",{style:{marginTop:"12px",padding:"10px",backgroundColor:"#fef3c7",border:"1px solid #f59e0b",borderRadius:"8px"},children:(0,l.jsx)("ul",{style:{margin:0,paddingLeft:"20px",fontSize:"12px",color:"#92400e"},children:(k.exclusionFilters||[]).filter(e=>e.field).map(e=>{var t;let a=(null==(t=ew.find(t=>t.value===e.operator))?void 0:t.label)||e.operator,s=["is_empty","is_not_empty","field_missing","field_exists"].includes(e.operator)?"":' "'.concat(e.value,'"');return(0,l.jsxs)("li",{children:["Exclude where ",(0,l.jsx)("strong",{children:e.field})," ",a,s]},e.id)})})})]})]}),(0,l.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:"8px",marginBottom:"12px",overflow:"hidden"},children:[(0,l.jsxs)("button",{type:"button",onClick:()=>q(e=>({...e,synonyms:!e.synonyms})),style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",border:"none",backgroundColor:W.synonyms?"#f9fafb":"white",cursor:"pointer",fontSize:"14px",fontWeight:"600",color:"#374151"},children:[(0,l.jsxs)("span",{children:["Search synonyms",(k.synonyms||[]).filter(e=>e.root).length>0&&(0,l.jsx)("span",{style:{marginLeft:"8px",backgroundColor:"#3b82f6",color:"white",borderRadius:"10px",padding:"1px 8px",fontSize:"11px",fontWeight:"700"},children:(k.synonyms||[]).filter(e=>e.root).length})]}),(0,l.jsx)("span",{style:{fontSize:"18px",color:"#9ca3af",transition:"transform 0.2s",transform:W.synonyms?"rotate(180deg)":"rotate(0deg)"},children:"â¾"})]}
1),W.synonyms&&(0,l.jsxs)("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb"},children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsxs)("div",{className:"text-xs text-gray-500",style:{margin:0},children:[(0,l.jsx)("p",{style:{margin:"0 0 8px 0"},children:"Define synonym groups so different terms return the same results."}),("properties_ecommerce"===k.dataType||"properties_rental"===k.dataType)&&(0,l.jsxs)("p",{style:{margin:0,padding:"8px",backgroundColor:"#eff6ff",borderRadius:"6px",color:"#1e40af",lineHeight:1.45},children:[(0,l.jsx)("strong",{children:"Mira property chat:"})," root = target filter â use a bedroom number (e.g. 0 for studio/yksi\xf6) or an exact type code from your index (e.g. 1h+kt). Put words users say (yksi\xf6, studio, â¦) in synonyms. Re-run indexing so the same rows sync to Typesense for classic search q; AI chat mainly reads these rules from the prompt, not from Typesense."]})]}),(0,l.jsx)(r.A,{type:"button",variant:"outline",small:!0,onClick:()=>{let e={root:"",synonyms:"",id:(0,h.$)(10)};F(t=>({...t,synonyms:[...t.synonyms||[],e]}))},children:"+ Add Synonym Group"})]}),k.synonyms&&k.synonyms.length>0&&(0,l.jsx)("div",{style:{marginTop:"10px"},children:k.synonyms.map(e=>(0,l.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr 40px",gap:"8px",marginBottom:"12px",alignItems:"start",padding:"12px",backgroundColor:"#F9FAFB",borderRadius:"8px",border:"1px solid #E5E7EB"},children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{style:{fontSize:"11px",color:"#6B7280",display:"block",marginBottom:"4px"},children:"Root Term"}),(0,l.jsx)("input",{type:"text",placeholder:"e.g., car",value:e.root,onChange:t=>ex(e.id,"root",t.target.value),className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontSize:"12px"}})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{style:{fontSize:"11px",color:"#6B7280",display:"block",marginBottom:"4px"},children:"Synonyms (comma-separated)"}),(0,l.jsx)("input",{type:"text",placeholder:"e.g., automobile, vehicle, auto",value:e.synonyms,onChange:t=>ex(e.id,"synonyms",t.target.value),className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontSize:"12px"}})]}),(0,l.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void F(e=>({...e,synonyms:(e.synonyms||[]).filter(e=>e.id!==t)}))},style:{color:"#ef4444",fontSize:"20px",padding:"4px 8px",marginTop:"16px",background:"transparent",border:"none",cursor:"pointer"},children:"\xd7"})]},e.id))})]})]}),"ecommerce"===k.dataType&&(0,l.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:"8px",marginBottom:"12px",overflow:"hidden"},children:[(0,l.jsxs)("button",{type:"button",onClick:()=>q(e=>({...e,categories:!e.categories})),style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",border:"none",backgroundColor:W.categories?"#f9fafb":"white",cursor:"pointer",fontSize:"14px",fontWeight:"600",color:"#374151"},children:[(0,l.jsx)("span",{children:"Category inference"}),(0,l.jsx)("span",{style:{fontSize:"18px",color:"#9ca3af",transition:"transform 0.2s",transform:W.categories?"rotate(180deg)":"rotate(0deg)"},children:"â¾"})]}),W.categories&&(0,l.jsxs)("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb"},children:[(0,l.jsx)("p",{className:"text-xs text-gray-500",style:{marginBottom:"12px"},children:"Paste category names (one per line). System searches product data for exact matches. Only triggers when feed has no categories (fallback)."}),(0,l.jsxs)("div",{className:"flex text-left space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"mainCategories",children:"Main categories (one per line)"}),(0,l.jsx)("textarea",{id:"mainCategories",placeholder:"Electronics Clothing Home & Garden",value:k.mainCategories,onChange:e=>ep("mainCategories",e.target.value),rows:6,className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontFamily:"monospace",fontSize:"13px"}})]}),(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"subCategories",children:"Sub categories (one per line)"}),(0,l.jsx)("textarea",{id:"subCategories",placeholder:"Smartphones Laptops Kitchen Appliances",value:k.subCategories,onChange:e=>ep("subCategories",e.target.value),rows:6,className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontFamily:"monospace",fontSize:"13px"}})]})]})]})]}),(0,l.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:"8px",marginBottom:"12px",overflow:"hidden"},children:[(0,l.jsxs)("button",{type:"button",onClick:()=>q(e=>({...e,urlTransform:!e.urlTransform})),style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",border:"none",backgroundColor:W.urlTransform?"#f9fafb":"white",cursor:"pointer",fontSize:"14px",fontWeight:"600",color:"#374151"},children:[(0,l.jsxs)("span",{children:["URL transformations",(k.linkStripPath||k.linkPrependUrl)&&(0,l.jsx)("span",{style:{marginLeft:"8px",backgroundColor:"#3b82f6",color:"white",borderRadius:"10px",padding:"1px 8px",fontSize:"11px",fontWeight:"700"},children:"active"})]}),(0,l.jsx)("span",{style:{fontSize:"18px",color:"#9ca3af",transition:"transform 0.2s",transform:W.urlTransform?"rotate(180deg)":"rotate(0deg)"},children:"â¾"})]}),W.urlTransform&&(0,l.jsxs)("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb"},children:[(0,l.jsx)("p",{className:"text-sm text-gray-600",style:{marginBottom:"12px"},children:"Fix product URLs from the feed before indexing. Useful when the feed adds unwanted path segments or returns relative paths."}),(0,l.jsxs)("div",{className:"flex text-left space-x-4",children:[(0,l.jsxs)("div",{className:"w-1/2",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"linkStripPath",children:"Strip from URLs"}),(0,l.jsx)("input",{id:"linkStripPath",type:"text",className:"w-full p-2 border rounded mt-1",value:k.linkStripPath,onChange:e=>ep("linkStripPath",e.target.value),placeholder:"e.g. /fi"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Removes this path segment from all product links (e.g. /fi strips the language prefix)"})]}),(0,l.jsxs)("div",{className:"w-1/2",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"linkPrependUrl",children:"Prepend to URLs"}),(0,l.jsx)("input",{id:"linkPrependUrl",type:"text",className:"w-full p-2 border rounded mt-1",value:k.linkPrependUrl,onChange:e=>ep("linkPrependUrl",e.target.value),placeholder:"e.g. https://example.com"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Prepends base URL when links are relative paths (e.g. /products/item)"})]})]})]})]}),(0,l.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:"8px",marginBottom:"12px",overflow:"hidden"},children:[(0,l.jsxs)("button",{type:"button",onClick:()=>q(e=>({...e,auth:!e.auth})),style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",border:"none",backgroundColor:W.auth?"#f9fafb":"white",cursor:"pointer",fontSize:"14px",fontWeight:"600",color:"#374151"},children:[(0,l.jsx)("span",{children:"Authentication & headers"}),(0,l.jsx)("span",{style:{fontSize:"18px",color:"#9ca3af",transition:"transform 0.2s",transform:W.auth?"rotate(180deg)":"rotate(0deg)"},children:"â¾"})]}),W.auth&&(0,l.jsxs)("div",{style:{padding:"16px",borderTop:"1px solid #e5e7eb"},children:[(0,l.jsxs)("div",{className:"flex text-left space-x-4",children:[(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"feed-auth-user-2",children:"Username"}),(0,l.jsx)("input",{type:"text",placeholder:"For password-protected feeds",id:"feed-auth-user-2",name:"feed-auth-user-2",autoComplete:"off","data-lpignore":"true","data-1p-ignore":!0,value:k.username,onChange:e=>ep("username",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]}),(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"feed-auth-pass-2",children:"Password"}),(0,l.jsx)("input",{type:"text",placeholder:"For password-protected feeds",id:"feed-auth-pass-2",name:"feed-auth-pass-2",autoComplete:"off","data-lpignore":"true","data-1p-ignore":!0,style:{WebkitTextSecurity:"disc"},value:k.password,onChange:e=>ep("password",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]})]}),(0,l.jsx)("div",{className:"flex text-left mt-4 space-x-4",children:(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",htmlFor:"headers",children:"Custom headers"}),(0,l.jsx)("textarea",{placeholder:"HeaderName=value (one per line)",id:"headers",value:k.headers,onChange:e=>ep("headers",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",rows:"3"}),(0,l.jsx)("small",{className:"text-gray-500",children:"For API authentication. Format: HeaderName=value (one per line)"})]})})]})]}),(0,l.jsxs)("div",{className:"border border-gray-200 rounded-lg mb-3",children:[(0,l.jsxs)("button",{type:"button",onClick:()=>q(e=>({...e,purchReq:!e.purchReq})),className:"w-full flex items-center justify-between px-4 py-3 border-none cursor-pointer text-sm font-semibold text-gray-700 rounded-lg ".concat(W.purchReq?"rounded-b-none bg-gray-50":"bg-white"),children:[(0,l.jsx)("span",{children:"Purchase Requirements"}),(0,l.jsx)("span",{className:"text-lg text-gray-400 transition-transform duration-200 ".concat(W.purchReq?"rotate-180":"rotate-0"),children:" â¾"})]}),W.purchReq&&(0,l.jsxs)("div",{className:"p-4 border-t border-gray-200",children:[(0,l.jsx)("p",{className:"text-xs text-gray-500 mb-3",children:"Add products that cannot be purchased alone, along with a message that should appear when a customer tries to add them with an empty cart."}),(0,l.jsxs)("div",{className:"w-full relative mt-4",children:[(0,l.jsx)("label",{className:"text-sm font-medium",children:"Add restricted products"}),(0,l.jsxs)("div",{className:"relative",children:[(0,l.jsx)("input",{type:"text",placeholder:k.collectionName||A?"Search products by nameâ¦":"Save the index first to enable search",disabled:!k.collectionName&&!A,value:G,autoComplete:"off","data-lpignore":"true","data-1p-ignore":!0,onChange:e=>{let t=e.target.value;V(t),clearTimeout(ee.current),ee.current=setTimeout(()=>ed(t),300)},className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),X&&(0,l.jsx)("span",{className:"absolute right-[10px] top-1/2 -translate-y-1/2 text-xs text-gray-400",children:"Loading..."})]}),Q.length>0&&(0,l.jsx)("div",{className:"absolute z-[100] w-full mt-0.5 max-h-[200px] overflow-y-auto rounded-md border border-gray-200 bg-white shadow-md",children:Q.map(e=>{let t=(k.purchaseRequiredProductIds||[]).some(t=>t.id===e.id);return(0,l.jsxs)("button",{type:"button",disabled:t,onClick:()=>{t||(ep("purchaseRequiredProductIds",[...k.purchaseRequiredProductIds||[],e]),V(""),$([]))},className:"block w-full text-left px-3 py-2 border-none border-b border-gray-100 text-[13px] ".concat(t?"bg-gray-50 cursor-default text-gray-400":"bg-white cursor-pointer text-gray-700"),children:[e.name,t?" (added)":""]},e.id)})})]}),(k.purchaseRequiredProductIds||[]).length>0&&(0,l.jsx)("div",{className:"flex gap-2 mb-3 mt-2 flex-wrap",children:(k.purchaseRequiredProductIds||[]).map(e=>(0,l.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-gray-200 bg-gray-100 px-2.5 py-1 text-xs text-gray-700",children:[e.name,(0,l.jsx)("button",{type:"button",onClick:()=>ep("purchaseRequiredProductIds",(k.purchaseRequiredProductIds||[]).filter(t=>t.id!==e.id)),className:"bg-transparent border-none cursor-pointer pl-0.5 p-0 text-gray-400 leading-none text-sm",children:"\xd7"})]},e.id))}),(0,l.jsxs)("div",{className:"w-full",children:[(0,l.jsx)("label",{className:"text-sm font-medium",children:"Message shown when cart is empty"}),(0,l.jsx)("textarea",{placeholder:"This product must be purchased with another item.",value:k.purchaseRequiredMessage||"",onChange:e=>ep("purchaseRequiredMessage",e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",rows:"2"}),(0,l.jsx)("small",{className:"text-gray-500",children:"Shown this message when a customer tries to add this product with an empty cart."})]})]})]})]}),(0,l.jsxs)("div",{className:o().buttonContainer,style:{justifyContent:"end",marginTop:"24px",paddingTop:"20px",borderTop:"2px solid #e5e7eb"},children:[(0,l.jsx)(r.A,{onClick:n,variant:"secondary",children:"Cancel"}),(0,l.jsx)(r.A,{type:"submit",disabled:m||"file_upload"===k.feedFormat&&!b,variant:"primary",children:m?"Processing...":"file_upload"===k.feedFormat?k.id?"Update & Index File":"Create & Index File":k.id?"Update Index":"Create Index"})]})]})})},$=e=>{let{onClose:t,onConfirm:a}=e;return(0,l.jsxs)(i.A,{title:"Confirm delete",onClose:t,children:[(0,l.jsx)("p",{children:"Are you sure you want to delete this index? This will also delete the Typesense collection."}),(0,l.jsxs)("div",{className:o().buttonContainer,style:{justifyContent:"end"},children:[(0,l.jsx)(r.A,{onClick:t,variant:"secondary",children:"Cancel"}),(0,l.jsx)(r.A,{onClick:a,variant:"primary",children:"Delete"})]})]})},X=e=>{let{index:t,previewData:a,onClose:s}=e;if(!a)return null;let n=(e,t)=>(0,l.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:[(0,l.jsx)("h3",{style:{fontSize:"14px",fontWeight:"600",marginBottom:"8px",color:"#374151"},children:t}),(0,l.jsx)("div",{style:{backgroundColor:"#1e1e1e",color:"#d4d4d4",padding:"16px",borderRadius:"8px",overflow:"auto",maxHeight:"500px",fontFamily:"monospace",fontSize:"12px",lineHeight:"1.5",border:"1px solid #e5e7eb"},children:(0,l.jsx)("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(e,null,2)})})]});return(0,l.jsxs)(i.A,{title:"Preview: ".concat((null==t?void 0:t.name)||"Index"),onClose:s,children:[a.loading?(0,l.jsx)("div",{style:{padding:"40px",textAlign:"center"},children:(0,l.jsx)("p",{children:"Loading preview..."})}):a.error?(0,l.jsx)("div",{style:{padding:"20px",textAlign:"center",color:"#ef4444"},children:(0,l.jsxs)("p",{children:["Error: ",a.error]})}):(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"20px",marginTop:"20px"},children:[(0,l.jsx)("div",{style:{padding:"12px",backgroundColor:"#f3f4f6",borderRadius:"8px"},children:(0,l.jsxs)("p",{style:{fontSize:"13px",color:"#6b7280",margin:0},children:["Compare the source data, transformed data, and indexed data to verify your field mappings.",!a.collectionExists&&(0,l.jsx)("span",{style:{color:"#f59e0b",marginLeft:"8px"},children:"â ï¸ Collection not indexed yet - showing preview of how data would be transformed."})]})}),(0,l.jsxs)("div",{style:{display:"flex",gap:"16px",flexWrap:"wrap"},children:[n(a.sourceItem,"\uD83D\uDCC4 Source (First Item from Feed)"),n(a.transformedItem,"\uD83D\uDD04 Transformed (After Mapping)")]}),a.typesenseItem&&(0,l.jsx)("div",{style:{display:"flex",gap:"16px"},children:n(a.typesenseItem,"\uD83D\uDCBE Indexed in Typesense (Current)")})]}),(0,l.jsx)("div",{className:o().buttonContainer,style:{justifyContent:"end",marginTop:"20px"},children:(0,l.jsx)(r.A,{onClick:s,variant:"primary",children:"Close"})})]})},Z=e=>{let{index:t,userTenantData:a,onClose:n}
1=e,[d,c]=(0,s.useState)("cross_sell"),[p,m]=(0,s.useState)(""),[u,g]=(0,s.useState)(null),[h,f]=(0,s.useState)(""),[y,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(4),[N,w]=(0,s.useState)(!1),[S,C]=(0,s.useState)(null),[k,F]=(0,s.useState)(null),[A,P]=(0,s.useState)(""),[T,R]=(0,s.useState)([]),[_,D]=(0,s.useState)(!1),[E,B]=(0,s.useState)(!1),[z,I]=(0,s.useState)(""),[U,O]=(0,s.useState)([]),[L,M]=(0,s.useState)(!1),[W,q]=(0,s.useState)(!1),[J,H]=(0,s.useState)(null),K=[{value:"upsell",label:"\uD83D\uDD1D Upsell (More Expensive)"},{value:"similar",label:"\uD83D\uDD04 Similar (Same Price)"},{value:"cross_sell",label:"\uD83D\uDED2 Cross-Sell (Cart Complementary)"}],G=async e=>{if(!e||e.length<2){R([]),B(!1);return}D(!0);try{let a=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:t.collectionName,query:e,limit:10})}),l=await a.json();l.success&&l.results&&(R(l.results),B(!0))}catch(e){console.error("Search error:",e)}finally{D(!1)}},V=async e=>{if(!e||e.length<2){O([]),q(!1);return}M(!0);try{let a=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:t.collectionName,query:e,limit:10})}),l=await a.json();l.success&&l.results&&(O(l.results),q(!0))}catch(e){console.error("JSON viewer search error:",e)}finally{M(!1)}},Y=async()=>{w(!0),F(null),C(null);try{let e={type:d,collectionName:t.collectionName,limit:parseInt(v)||4,indexId:t.id,master:null==a?void 0:a.master};if("cross_sell"===d&&(null==a?void 0:a.master)&&(e.uid=a.master,console.log('\uD83D\uDD0D Testing with "Often Bought Together" using uid:',a.master)),("upsell"===d||"similar"===d)&&p&&(e.productId=p.trim()),"cross_sell"===d){if(y.length>0)e.cartItems=y;else if(h)try{e.cartItems=JSON.parse(h)}catch(e){F("Invalid JSON format for cart items"),w(!1);return}}let l=await fetch("/api/recommend",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),s=await l.json();l.ok?C(s):F(s.error||"Failed to get recommendations")}catch(e){F(e.message||"Request failed")}finally{w(!1)}};return(0,l.jsxs)(i.A,{title:"Test Recommendations: ".concat((null==t?void 0:t.name)||"Index"),onClose:n,children:[(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"20px",marginTop:"20px"},children:[(0,l.jsxs)("div",{style:{padding:"16px",backgroundColor:"#F9FAFB",border:"1px solid #E5E7EB",borderRadius:"8px"},children:[(0,l.jsx)("h3",{style:{fontSize:"14px",fontWeight:"600",marginBottom:"12px",color:"#374151"},children:"\uD83D\uDD0D Product JSON Viewer"}),(0,l.jsxs)("div",{style:{position:"relative",marginBottom:"12px"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Search any product to view its JSON structure...",value:z,onChange:e=>{I(e.target.value),V(e.target.value)},className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),L&&(0,l.jsx)("span",{style:{position:"absolute",right:"12px",to
1p:"50%",transform:"translateY(-50%)",fontSize:"12px",color:"#6B7280"},children:"Searching..."}),W&&U.length>0&&(0,l.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,backgroundColor:"#fff",border:"1px solid #E5E7EB",borderRadius:"8px",marginTop:"4px",maxHeight:"300px",overflowY:"auto",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:10},children:U.map(e=>(0,l.jsxs)("div",{onClick:()=>{H(e),I(""),q(!1)},style:{padding:"12px",borderBottom:"1px solid #F3F4F6",cursor:"pointer",display:"flex",gap:"12px",alignItems:"center"},onMouseEnter:e=>e.currentTarget.style.backgroundColor="#F9FAFB",onMouseLeave:e=>e.currentTarget.style.backgroundColor="#fff",children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title,style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"4px"}}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontSize:"13px",fontWeight:"500"},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#6B7280"},children:["ID: ",e.id,e.price&&" ⢠â¬".concat((e.price/100).toFixed(2))]})]})]},e.id))})]}),J&&(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[(0,l.jsxs)("span",{style:{fontSize:"13px",fontWeight:"600",color:"#374151"},children:["\uD83D\uDCE6 ",J.title]}),(0,l.jsx)("button",{onClick:()=>H(null),style:{padding:"4px 12px",fontSize:"11px",backgroundColor:"#EF4444",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:"Clear"})]}),(0,l.jsx)("div",{style:{backgroundColor:"#1E1E1E",color:"#D4D4D4",padding:"16px",borderRadius:"8px",overflow:"auto",maxHeight:"400px",fontFamily:"monospace",fontSize:"12px",lineHeight:"1.5",border:"1px solid #374151"},children:(0,l.jsx)("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(J,null,2)})})]}),(0,l.jsx)("small",{style:{color:"#6B7280",fontSize:"12px",marginTop:"8px",display:"block"},children:"Search for any product to inspect its complete JSON structure from Typesense"})]}),(0,l.jsx)("div",{style:{borderTop:"2px solid #E5E7EB",paddingTop:"20px"},children:(0,l.jsx)("h3",{style:{fontSize:"14px",fontWeight:"600",marginBottom:"16px",color:"#374151"},children:"\uD83E\uDDEA Test Recommendations"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-sm font-medium",style:{display:"block",marginBottom:"8px"},children:"Recommendation Type"}),(0,l.jsx)(x.Ay,{value:K.find(e=>e.value===d),onChange:e=>{c(e.value),C(null),F(null)},options:K}),(0,l.jsxs)("small",{style:{color:"#6B7280",fontSize:"12px",marginTop:"4px",display:"block"},children:["upsell"===d&&"Find more expensive alternatives (20-50% higher price)","similar"===d&&"Find similar products at similar price (\xb120%)","cross_sell"===d&&(0,l.jsxs)("span",{children:["Find complementary products based on cart items",(null==a?void 0:a.master)&&(0,l.jsx)("span",{style:{color:"#10B981",fontWeight:"600",marginLeft:"8px"},children:'⨠Using "Often Bought Together" from Elastic'})]})]})]}),("upsell"===d||"similar"===d)&&(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-sm font-medium",style:{display:"block",marginBottom:"8px"},children:"Search Product"}),(0,l.jsxs)("div",{style:{position:"relative"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Type to search products...",value:A,onChange:e=>{P(e.target.value),G(e.target.value)},className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),_&&(0,l.jsx)("span",{style:{position:"absolute",right:"12px",to
1p:"50%",transform:"translateY(-50%)",fontSize:"12px",color:"#6B7280"},children:"Searching..."}),E&&T.length>0&&(0,l.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,backgroundColor:"#fff",border:"1px solid #E5E7EB",borderRadius:"8px",marginTop:"4px",maxHeight:"300px",overflowY:"auto",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:10},children:T.map(e=>(0,l.jsxs)("div",{onClick:()=>(e=>{g(e),m(e.id),P(""),B(!1)})(e),style:{padding:"12px",borderBottom:"1px solid #F3F4F6",cursor:"pointer",display:"flex",gap:"12px",alignItems:"center"},onMouseEnter:e=>e.currentTarget.style.backgroundColor="#F9FAFB",onMouseLeave:e=>e.currentTarget.style.backgroundColor="#fff",children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title,style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"4px"}}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontSize:"13px",fontWeight:"500"},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#6B7280",display:"flex",alignItems:"center",gap:"4px",flexWrap:"wrap"},children:[(0,l.jsxs)("span",{children:["ID: ",e.id]}),e.price&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("span",{children:"â¢"}),e.sale_price&&e.sale_price<e.price?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("span",{style:{fontWeight:"600",color:"#059669"},children:["â¬",(e.sale_price/100).toFixed(2)]}),(0,l.jsxs)("span",{style:{textDecoration:"line-through"},children:["â¬",(e.price/100).toFixed(2)]})]}):(0,l.jsxs)("span",{children:["â¬",(e.price/100).toFixed(2)]})]})]})]})]},e.id))})]}),u&&(0,l.jsx)("div",{style:{marginTop:"12px",padding:"12px",backgroundColor:"#F0FDF4",border:"1px solid #86EFAC",borderRadius:"8px"},children:(0,l.jsxs)("div",{style:{display:"flex",gap:"12px",alignItems:"center"},children:[u.image_link&&(0,l.jsx)("img",{src:u.image_link,alt:u.title,style:{width:"60px",height:"60px",objectFit:"cover",borderRadius:"6px"}}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontSize:"14px",fontWeight:"600",color:"#065F46"},children:"â Selected"}),(0,l.jsx)("div",{style:{fontSize:"13px",color:"#047857"},children:u.title}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#059669"},children:["ID: ",u.id]}),u.price&&(0,l.jsx)("div",{style:{fontSize:"11px",color:"#059669",marginTop:"4px",display:"flex",alignItems:"center",gap:"6px"},children:u.sale_price&&u.sale_price<u.price?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("span",{style:{fontWeight:"600"},children:["â¬",(u.sale_price/100).toFixed(2)]}),(0,l.jsxs)("span",{style:{textDecoration:"line-through",opacity:.7},children:["â¬",(u.price/100).toFixed(2)]}),(0,l.jsxs)("span",{style:{backgroundColor:"#DC2626",color:"white",padding:"2px 4px",borderRadius:"3px",fontSize:"10px"},children:["-",Math.round((u.price-u.sale_price)/u.price*100),"%"]})]}):(0,l.jsxs)("span",{style:{fontWeight:"600"},children:["â¬",(u.price/100).toFixed(2)]})})]}),(0,l.jsx)("button",{onClick:()=>{g(null),m("")},style:{padding:"4px 8px",fontSize:"11px",color:"#DC2626",cursor:"pointer",background:"transparent",border:"none"},children:"Clear"})]})}),(0,l.jsx)("small",{style:{color:"#6B7280",fontSize:"12px",marginTop:"4px",display:"block"},children:"Search by name, ID, or category"})]}),"cross_sell"===d&&(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-sm font-medium",style:{display:"block",marginBottom:"8px"},children:"Cart Items"}),(0,l.jsxs)("div",{style:{position:"relative",marginBottom:"12px"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Search products to add to cart...",value:A,onChange:e=>{P(e.target.value),G(e.target.value)},className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),_&&(0,l.jsx)("span",{style:{position:"absolute",right:"12px",to
1p:"50%",transform:"translateY(-50%)",fontSize:"12px",color:"#6B7280"},children:"Searching..."}),E&&T.length>0&&(0,l.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,backgroundColor:"#fff",border:"1px solid #E5E7EB",borderRadius:"8px",marginTop:"4px",maxHeight:"300px",overflowY:"auto",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:10},children:T.map(e=>(0,l.jsxs)("div",{onClick:()=>(e=>{if(!y.find(t=>t.id===e.id)){let t=[...y,{id:e.id,category:e.category||e.main_category||"uncategorized",brand:e.brand||"unknown"}];b(t),f(JSON.stringify(t,null,2))}P(""),B(!1)})(e),style:{padding:"12px",borderBottom:"1px solid #F3F4F6",cursor:"pointer",display:"flex",gap:"12px",alignItems:"center"},onMouseEnter:e=>e.currentTarget.style.backgroundColor="#F9FAFB",onMouseLeave:e=>e.currentTarget.style.backgroundColor="#fff",children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title,style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"4px"}}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontSize:"13px",fontWeight:"500"},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#6B7280",display:"flex",alignItems:"center",gap:"4px",flexWrap:"wrap"},children:[(0,l.jsx)("span",{children:e.category||e.main_category}),e.brand&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("span",{children:"â¢"}),(0,l.jsx)("span",{children:e.brand})]}),e.price&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("span",{children:"â¢"}),e.sale_price&&e.sale_price<e.price?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("span",{style:{fontWeight:"600",color:"#059669"},children:["â¬",(e.sale_price/100).toFixed(2)]}),(0,l.jsxs)("span",{style:{textDecoration:"line-through"},children:["â¬",(e.price/100).toFixed(2)]})]}):(0,l.jsxs)("span",{children:["â¬",(e.price/100).toFixed(2)]})]})]})]}),(0,l.jsx)("span",{style:{fontSize:"20px",color:"#10B981"},children:"+"})]},e.id))})]}),y.length>0&&(0,l.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,l.jsxs)("div",{style:{fontSize:"12px",fontWeight:"600",marginBottom:"8px",color:"#374151"},children:["Cart (",y.length," items):"]}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:y.map((e,t)=>(0,l.jsxs)("div",{style:{padding:"10px",backgroundColor:"#F0FDF4",border:"1px solid #86EFAC",borderRadius:"6px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{style:{fontSize:"13px",fontWeight:"500",color:"#065F46"},children:["Item ",t+1]}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#059669"},children:["ID: ",e.id," ⢠",e.category," ⢠",e.brand]})]}),(0,l.jsx)("button",{onClick:()=>(e=>{let t=y.filter(t=>t.id!==e);b(t),f(JSON.stringify(t,null,2))})(e.id),style:{padding:"4px 8px",fontSize:"11px",color:"#DC2626",cursor:"pointer",background:"transparent",border:"none"},children:"Remove"})]},e.id))})]}),(0,l.jsxs)("details",{style:{marginTop:"12px"},children:[(0,l.jsx)("summary",{style:{cursor:"pointer",fontSize:"12px",color:"#6B7280",marginBottom:"8px"},children:"Or paste JSON manually"}),(0,l.jsx)("textarea",{placeholder:JSON.stringify([{id:"123",category:"electronics",brand:"Sony"},{id:"456",category:"audio",brand:"Apple"}],null,2),value:h,onChange:e=>f(e.target.value),rows:6,className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm",style:{fontFamily:"monospace",fontSize:"12px"}})]}),(0,l.jsx)("small",{style:{color:"#6B7280",fontSize:"12px",marginTop:"4px",display:"block"},children:"Search and add products to build a test cart"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-sm font-medium",style:{display:"block",marginBottom:"8px"},children:"Number of Results"}),(0,l.jsx)("input",{type:"number",min:"1",max:"20",value:v,onChange:e=>j(e.target.value),className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"})]}),(0,l.jsx)(r.A,{variant:"primary",onClick:Y,disabled:N||("upsell"===d||"similar"===d)&&!p||"cross_sell"===d&&0===y.length&&!h,children:N?"Testing...":"\uD83E\uDDEA Run Test"}),k&&(0,l.jsx)("div",{style:{padding:"12px",backgroundColor:"#FEE2E2",border:"1px solid #EF4444",borderRadius:"8px"},children:(0,l.jsxs)("p",{style:{color:"#DC2626",margin:0,fontSize:"14px"},children:["â Error: ",k]})}),S&&(0,l.jsxs)("div",{style:{marginTop:"20px"},children:[(0,l.jsx)("div",{style:{padding:"12px",backgroundColor:"#D1FAE5",border:"1px solid #10B981",borderRadius:"8px",marginBottom:"12px"},children:(0,l.jsxs)("p",{style:{color:"#065F46",margin:0,fontSize:"14px"},children:["â
Success! Found ",S.count," recommendation",1!==S.
1count?"s":""]})}),S.recommendations&&S.recommendations.length>0&&(0,l.jsxs)("div",{children:[(0,l.jsx)("h4",{style:{fontSize:"14px",fontWeight:"600",marginBottom:"12px"},children:"Results:"}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:S.recommendations.map((e,t)=>(0,l.jsx)("div",{style:{padding:"12px",border:"1px solid #E5E7EB",borderRadius:"8px",backgroundColor:"#F9FAFB"},children:(0,l.jsxs)("div",{style:{display:"flex",gap:"12px",alignItems:"flex-start"},children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title,style:{width:"80px",height:"80px",objectFit:"cover",borderRadius:"6px",flexShrink:0}}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("h5",{style:{fontSize:"14px",fontWeight:"600",margin:"0 0 8px 0"},children:e.title||"Untitled"}),(0,l.jsxs)("div",{style:{fontSize:"12px",color:"#6B7280",display:"flex",flexWrap:"wrap",gap:"12px"},children:[(0,l.jsxs)("span",{children:["ID: ",e.id]}),e.price&&(0,l.jsxs)("span",{children:["Price: â¬",(e.price/100).toFixed(2)]}),e.category&&(0,l.jsxs)("span",{children:["Category: ",e.category]}),e.brand&&(0,l.jsxs)("span",{children:["Brand: ",e.brand]}),e._frequency&&(0,l.jsxs)("span",{style:{color:"#10B981",fontWeight:"600"},children:["\uD83D\uDD25 Bought together ",e._frequency," times"]}),e._isDefault&&(0,l.jsx)("span",{style:{color:e._isCategoryDefault?"#059669":"#3B82F6",fontWeight:"600",backgroundColor:e._isCategoryDefault?"#D1FAE5":"#DBEAFE",padding:"2px 6px",borderRadius:"4px",fontSize:"11px",border:e._isCategoryDefault?"1px solid #10B981":"1px solid #3B82F6"},children:e._isCategoryDefault?"\uD83D\uDCC2 Category Default":"\uD83C\uDF10 General Default"}),e._isFallback&&(0,l.jsx)("span",{style:{color:"#DC2626",fontWeight:"600",backgroundColor:"#FEE2E2",padding:"2px 6px",borderRadius:"4px",fontSize:"11px",border:"1px solid #DC2626"},children:"\uD83D\uDED2 Fallback Category"})]})]})]})},e.id||t))})]}),(0,l.jsxs)("details",{style:{marginTop:"16px"},children:[(0,l.jsx)("summary",{style:{cursor:"pointer",fontSize:"13px",color:"#6B7280"},children:"Show Raw JSON Response"}),(0,l.jsx)("div",{style:{backgroundColor:"#1E1E1E",color:"#D4D4D4",padding:"16px",borderRadius:"8px",overflow:"auto",maxHeight:"300px",fontFamily:"monospace",fontSize:"12px",marginTop:"8px"},children:(0,l.jsx)("pre",{style:{margin:0},children:JSON.stringify(S,null,2)})})]})]})]}),(0,l.jsx)("div",{className:o().buttonContainer,style:{justifyContent:"end",marginTop:"20px"},children:(0,l.jsx)(r.A,{onClick:n,variant:"secondary",children:"Close"})})]})},ee=e=>{let{index:t,onClose:a,onSave:n}=e,[d,c]=(0,s.useState)(!1),[p,m]=(0,s.useState)([]),[u,x]=(0,s.use
1State)({}),[g,h]=(0,s.useState)((null==t?void 0:t.fallbackCategory)||""),[f,y]=(0,s.useState)(""),[b,v]=(0,s.useState)(""),[j,N]=(0,s.useState)([]),[w,S]=(0,s.useState)(!1),[C,k]=(0,s.useState)(!1),[F,A]=(0,s.useState)(null),[P,T]=(0,s.useState)([]),[R,_]=(0,s.useState)(!1),[D,E]=(0,s.useState)(!1),[B,z]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=async()=>{_(!0);try{let e=await fetch("/api/indexes/facets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:t.collectionName,facetField:"category"})}),a=await e.json();a.success&&a.values&&T(a.values)}catch(e){console.error("Error fetching categories:",e)}finally{_(!1)}};(null==t?void 0:t.collectionName)&&e()},[null==t?void 0:t.collectionName]),(0,s.useEffect)(()=>{(async()=>{if(!(null==t?void 0:t.categoryUpsellProducts)||0===Object.keys(t.categoryUpsellProducts).length)return;let e={};for(let[a,l]of Object.entries(t.categoryUpsellProducts)){if(!Array.isArray(l)||0===l.length){e[a]=[];continue}try{let s=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:t.collectionName,query:l.join(" "),limit:l.length})}),r=await s.json();if(r.success&&r.results){let t={};r.results.forEach(e=>{t[e.id]=e}),e[a]=l.map(e=>t[e]).filter(Boolean)}else e[a]=[]}catch(t){console.error("Error fetching products for category ".concat(a,":"),t),e[a]=[]}}x(e)})()},[null==t?void 0:t.categoryUpsellProducts,null==t?void 0:t.collectionName]),(0,s.useEffect)(()=>{(async()=>{if((null==t?void 0:t.defaultUpsellProducts)&&0!==t.defaultUpsellProducts.length)try{let e=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:t.collectionName,query:t.defaultUpsellProducts.join(" "),limit:t.defaultUpsellProducts.length})}),a=await e.json();if(a.success&&a.results){let e={};a.results.forEach(t=>{e[t.id]=t});let l=t.defaultUpsellProducts.map(t=>e[t]).filter(Boolean);m(l)}}catch(e){console.error("Error fetching general default products:",e)}})()},[null==t?void 0:t.defaultUpsellProducts,null==t?void 0:t.collectionName]),(0,s.useEffect)(()=>{let e=()=>{D&&E(!1),B&&z(!1)};return(D||B)&&document.addEventListener("click",e),()=>{document.removeEventListener("click",e)}},[D,B]);let I=async e=>{if(!e||e.length<2){N([]),k(!1);return}S(!0);try{let a=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:t.collectionName,query:e,limit:10})}),l=await a.json();l.success&&l.results&&(N(l.results),k(!0))}catch(e){console.error("Search error:",e)}finally{S(!1)}},U=()=>{let e=f.trim();e&&!u[e]&&(x({...u,[e]:[]}),y(""),A(e))},O=async()=>{c(!0);try{let e=p.map(e=>e.id),t={};Object.entries(u).forEach(e=>{let[a,l]=e;t[a]=l.map(e=>e.id)}),await n({defaultUpsellProducts:e,categoryUpsellProducts:t,fallbackCategory:g.trim()||null})}catch(e){console.error("Error saving upsell config:",e),alert("Error saving upsell configuration")}finally{c(!1)}};return(0,l.jsxs)(i.A,{title:"\uD83C\uDFAF Train recommendations: ".concat((null==t?void 0:t.name)||"Index"),onClose:a,children:[(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"24px",marginTop:"20px"},children:[(0,l.jsx)("div",{style:{padding:"12px",backgroundColor:"#EFF6FF",border:"1px solid #3B82F6",borderRadius:"8px"},children:(0,l.jsxs)("p",{style:{fontSize:"13px",color:"#1E40AF",margin:0},children:["\uD83D\uDCA1 ",(0,l.jsx)("strong",{children:"How it works:"})," When recommendations return too few results (< 5 products), the system uses this priority:",(0,l.jsx)("br",{}),(0,l.jsx)("strong",{children:"1."})," Category-specific defaults (if product category matches)",(0,l.jsx)("br",{}),(0,l.jsx)("strong",{children:"2."})," General defaults (fallback)",(0,l.jsx)("br",{}),(0,l.jsx)("strong",{children:"3."}),' Fallback category (pulls products from a specific category like "Bestsellers")']})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-sm font-medium",style:{display:"block",marginBottom:"8px"},children:"\uD83D\uDD0D Search Products to Add"}),(0,l.jsxs)("div",{style:{position:"relative"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Search by name, ID, or category...",value:b,onChange:e=>{v(e.target.value),I(e.target.value)},className:"mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),w&&(0,l.jsx)("span",{style:{position:"absolute",right:"12px",to
1p:"50%",transform:"translateY(-50%)",fontSize:"12px",color:"#6B7280"},children:"Searching..."}),C&&j.length>0&&(0,l.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,backgroundColor:"#fff",border:"1px solid #E5E7EB",borderRadius:"8px",marginTop:"4px",maxHeight:"300px",overflowY:"auto",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:10},children:j.map(e=>(0,l.jsxs)("div",{style:{padding:"12px",borderBottom:"1px solid #F3F4F6",display:"flex",gap:"12px",alignItems:"center"},children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title,style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"4px"}}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontSize:"13px",fontWeight:"500"},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#6B7280"},children:["ID: ",e.id," ⢠",e.category||e.main_category]})]}),(0,l.jsxs)("div",{style:{display:"flex",gap:"4px"},children:[(0,l.jsx)("button",{onClick:()=>(e=>{p.find(t=>t.id===e.id)||m([...p,e]),v(""),k(!1)})(e),style:{padding:"4px 8px",fontSize:"11px",backgroundColor:"#3B82F6",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:"+ General"}),F&&(0,l.jsxs)("button",{onClick:()=>((e,t)=>{let a=u[e]||[];a.find(e=>e.id===t.id)||x({...u,[e]:[...a,t]}),v(""),k(!1)})(F,e),style:{padding:"4px 8px",fontSize:"11px",backgroundColor:"#10B981",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:["+ ",F]})]})]},e.id))})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{style:{fontSize:"14px",fontWeight:"600",marginBottom:"12px",color:"#374151"},children:"\uD83C\uDF10 General Defaults (All Products)"}),(0,l.jsx)("div",{style:{padding:"12px",backgroundColor:"#F9FAFB",border:"1px solid #E5E7EB",borderRadius:"8px",minHeight:"60px"},children:0===p.length?(0,l.jsx)("p",{style:{fontSize:"12px",color:"#9CA3AF",margin:0},children:'No general defaults configured. Search and click "+ General" to add.'}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:p.map((e,t)=>(0,l.jsxs)("div",{style:{padding:"10px",backgroundColor:"#FFFFFF",border:"1px solid #DBEAFE",borderRadius:"6px",display:"flex",gap:"12px",alignItems:"center"},children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title,style:{width:"50px",height:"50px",objectFit:"cover",borderRadius:"4px",flexShrink:0}}),(0,l.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,l.jsx)("div",{style:{fontSize:"13px",fontWeight:"500",color:"#1E40AF",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#3B82F6",marginTop:"2px"},children:["ID: ",e.id,e.price&&(0,l.jsxs)(l.Fragment,{children:[" ⢠",e.sale_price&&e.sale_price<e.price?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("span",{style:{fontWeight:"600"},children:["â¬",(e.sale_price/100).toFixed(2)]})," ",(0,l.jsxs)("span",{style:{textDecoration:"line-through",opacity:.7},children:["â¬",(e.price/100).toFixed(2)]})]}):(0,l.jsxs)("span",{style:{fontWeight:"600"},children:["â¬",(e.price/100).toFixed(2)]})]})]})]}),(0,l.jsx)("button",{type:"button",onClick:()=>{var t;return t=e.id,void m(p.filter(e=>e.id!==t))},style:{color:"#DC2626",fontSize:"18px",lineHeight:"1",cursor:"pointer",background:"transparent",border:"none",flexShrink:0,padding:"4px 8px"},children:"\xd7"})]},t))})}),(0,l.jsx)("small",{style:{color:"#6B7280",fontSize:"12px",marginTop:"4px",display:"block"},children:"These products will be shown for all categories when results are sparse."})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{style:{fontSize:"14px",fontWeight:"600",marginBottom:"12px",color:"#374151"},children:"\uD83D\uDED2 Fallback Category (Ultimate Backup)"}),(0,l.jsxs)("div",{style:{position:"relative"},children:[(0,l.jsx)("input",{type:"text",placeholder:R?"Loading categories...":"Select a category to use when no recommendations found",value:g,onChange:e=>h(e.target.value),onFocus:()=>z(!0),onClick:e=>{e.stopPropagation(),z(!0)},className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),B&&P.length>0&&(0,l.jsx)("div",{onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",maxHeight:"200px",overflowY:"auto",backgroundColor:"white",border:"1px solid #E5E7EB",borderRadius:"6px",boxShadow:"0 4px 6px rgba(0,0,0,0.1)",zIndex:1e3},children:P.filter(e=>e.value.toLowerCase().includes(g.toLowerCase())).map((e,t)=>(0,l.jsxs)("div",{onClick:()=>{h(e.value),z(!1)},style:{padding:"8px 12px",cursor:"pointer",fontSize:"13px",borderBottom:t<P.length-1?"1px solid #F3F4F6":"none",backgroundColor:"white",":hover":{backgroundColor:"#F9FAFB"}},onMouseEnter:e=>e.currentTarget.style.backgroundColor="#F9FAFB",onMouseLeave:e=>e.currentTarget.style.backgroundColor="white",children:[e.value," ",(0,l.jsxs)("span",{style:{color:"#9
1CA3AF",fontSize:"11px"},children:["(",e.count,")"]})]},t))})]}),(0,l.jsx)("small",{style:{color:"#6B7280",fontSize:"12px",marginTop:"4px",display:"block"},children:'\uD83D\uDCA1 When no products or defaults are found, show products from this category (e.g., "Bestsellers" or "Popular Items")'})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px"},children:(0,l.jsx)("h3",{style:{fontSize:"14px",fontWeight:"600",margin:0,color:"#374151"},children:"\uD83D\uDCC2 Category-Specific Defaults (Higher Priority)"})}),(0,l.jsxs)("div",{style:{display:"flex",gap:"8px",marginBottom:"16px",position:"relative"},children:[(0,l.jsxs)("div",{style:{flex:1,position:"relative"},children:[(0,l.jsx)("input",{type:"text",placeholder:R?"Loading categories...":"Select category from dropdown or type custom",value:f,onChange:e=>y(e.target.value),onFocus:()=>E(!0),onClick:e=>{e.stopPropagation(),E(!0)},onKeyPress:e=>{"Enter"===e.key&&(e.preventDefault(),U())},className:"block w-full rounded-md border-gray-300 shadow-sm focus:border-lightning-500 focus:ring-lightning-500 sm:text-sm"}),D&&P.length>0&&(0,l.jsx)("div",{onClick:e=>e.stopPropagation(),style:{position:"absolute",top:"100%",left:0,right:0,backgroundColor:"#fff",border:"1px solid #E5E7EB",borderRadius:"8px",marginTop:"4px",maxHeight:"200px",overflowY:"auto",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:P.filter(e=>!f||e.value.toLowerCase().includes(f.toLowerCase())).map(e=>(0,l.jsxs)("div",{onClick:()=>{y(e.value),E(!1)},style:{padding:"10px 12px",cursor:"pointer",borderBottom:"1px solid #F3F4F6",display:"flex",justifyContent:"space-between"},onMouseEnter:e=>e.currentTarget.style.backgroundColor="#F9FAFB",onMouseLeave:e=>e.currentTarget.style.backgroundColor="#fff",children:[(0,l.jsx)("span",{style:{fontSize:"13px"},children:e.value}),(0,l.jsxs)("span",{style:{fontSize:"11px",color:"#6B7280"},children:["(",e.count," products)"]})]},e.value))})]}),(0,l.jsx)(r.A,{type:"button",variant:"primary",small:!0,onClick:U,children:"+ Add Category"})]}),R&&(0,l.jsxs)("small",{style:{color:"#6B7280",fontSize:"12px",display:"block",marginBottom:"8px"},children:["â³ Loading ",P.length," categories from Typesense..."]}),0===Object.keys(u).length?(0,l.jsx)("div",{style:{padding:"20px",backgroundColor:"#F9FAFB",border:"1px solid #E5E7EB",borderRadius:"8px",textAlign:"center"},children:(0,l.jsx)("p",{style:{fontSize:"12px",color:"#9CA3AF",margin:0},children:"No category-specific defaults configured. Add a category above to start."})}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:Object.entries(u).map(e=>{let[t,a]=e;return(0,l.jsxs)("div",{style:{padding:"12px",backgroundColor:F===t?"#F0FDF4":"#F9FAFB",border:F===t?"2px solid #10B981":"1px solid #E5E7EB",borderRadius:"8px"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[(0,l.jsxs)("span",{style:{fontSize:"13px",fontWeight:"600",color:"#374151"},children:["\uD83D\uDCC1 ",t]}),(0,l.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[(0,l.jsx)("button",{type:"button",onClick:()=>A(F===t?null:t),style:{padding:"4px 8px",fontSize:"11px",backgroundColor:F===t?"#10B981":"#6B7280",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:F===t?"â Active":"Set Active"}),(0,l.jsx)("button",{type:"button",onClick:()=>(e=>{let t={...u};delete t[e],x(t),F===e&&A(null)})(t),style:{color:"#EF4444",fontSize:"18px",cursor:"pointer",background:"transparent",border:"none"},children:"\xd7"})]})]}),0===a.length?(0,l.jsx)("p",{style:{fontSize:"11px",color:"#9CA3AF",margin:0},children:"No products added yet. Set as active and search to add."}):(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map((e,a)=>(0,l.jsxs)("div",{style:{padding:"10px",backgroundColor:"#FFFFFF",border:"1px solid #D1FAE5",borderRadius:"6px",display:"flex",gap:"12px",alignItems:"center"},children:[e.image_link&&(0,l.jsx)("img",{src:e.image_link,alt:e.title,style:{width:"50px",height:"50px",objectFit:"cover",borderRadius:"4px",flexShrink:0}}),(0,l.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,l.jsx)("div",{style:{fontSize:"13px",fontWeight:"500",color:"#065F46",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.title}),(0,l.jsxs)("div",{style:{fontSize:"11px",color:"#059669",marginTop:"2px"},children:["ID: ",e.id,e.price&&(0,l.jsxs)(l.Fragment,{children:[" ⢠",e.sale_price&&e.sale_price<e.price?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("span",{style:{fontWeight:"600"},children:["â¬",(e.sale_price/100).toFixed(2)]})," ",(0,l.jsxs)("span",{style:{textDecoration:"line-through",opacity:.7},children:["â¬",(e.price/100).toFixed(2)]})]}):(0,l.jsxs)("span",{style:{fontWeight:"600"},children:["â¬",(e.price/100).toFixed(2)]})]})]})]}),(0,l.jsx)("button",{type:"button",onClick:()=>((e,t)=>{let a=(u[e]||[]).filter(e=>e.id!==t);if(0===a.length){let t={...u};delete t[e],x(t)}else x({...u,[e]:a})})(t,e.id),style:{color:"#DC2626",fontSize:"18px",lineHeight:"1",cursor:"pointer",background:"transparent",border:"none",flexShrink:0,padding:"4px 8px"},children:"\xd7"})]},a))})]},t)})}),(0,l.jsxs)("small",{style:{color:"#6B7280",fontSize:"12px",marginTop:"8px",display:"block"},children:["\uD83D\uDCA1 ",(0,l.jsx)("strong",{children:"Tip:"}),' Categories are auto-loaded from Typesense! Click the input to see all available categories with product counts. Set a category as "Active" to quickly add products from search results. Category-specific defaults are prioritized over general defaults.']})]})]}),(0,l.jsxs)("div",{className:o().buttonContainer,style:{justifyContent:"end",marginTop:"20px"},children:[(0,l.jsx)(r.A,{onClick:a,variant:"secondary",children:"Cancel"}),(0,l.jsx)(r.A,{onClick:O,disabled:d,variant:"primary",children:d?"Saving...":"Save Configuration"})]})]})}
1,et=function(){let[e,t]=(0,s.useState)(!1),[a,i]=(0,s.useState)(!1),[n,o]=(0,s.useState)(!1),[m,x]=(0,s.useState)(!1),[g,y]=(0,s.useState)(!1),[b,j]=(0,s.useState)(!1),[N,w]=(0,s.useState)(!1),[S,C]=(0,s.useState)([]),[k,F]=(0,s.useState)(null),[A,P]=(0,s.useState)({}),[R,_]=(0,s.useState)(null),{userTenantData:D}=p.default.getState(),[E,B]=(0,s.useState)(null),[z,I]=(0,s.useState)(!1),[U,O]=(0,s.useState)(""),L=(0,s.useRef)(null),M=()=>{if((null==D?void 0:D.master)&&d.firestore){w(!0);try{let e=(0,c.rJ)(d.firestore,"tenants/".concat(D.master,"/typesense_indexes"));return(0,c.aQ)(e,e=>{let t=[];e.forEach(e=>{let a=e.data();a.id=e.id,t.push(a)}),C(t),w(!1)},e=>{console.error("Error getting documents:",e),w(!1)})}catch(e){console.error("Error setting up listener:",e),w(!1)}}};(0,s.useEffect)(()=>{let e=M();return()=>{e&&e()}},[d.firestore,D]);let W=e=>{if(A[e.id])return A[e.id];switch(e.indexingStatus){case"queued":return{status:"indexing",message:"Queued..."};case"active":{let t=e.indexingProgress;if(t){if("pruning"===t.phase)return{status:"indexing",message:"Removing products no longer in the feed..."};let e="embedding"===t.phase?"Generating embeddings":"Indexing";if(t.skipped>0)return{status:"indexing",message:"Indexing... ".concat(t.processed.toLocaleString()," checked, ").concat(t.skipped.toLocaleString()," unchanged")};if(t.total>0)return{status:"indexing",message:"".concat(e,"... ").concat(t.processed,"/").concat(t.total)};if(t.processed>0)return{status:"indexing",message:"".concat(e,"... ").concat(t.processed.toLocaleString()," processed")}}return{status:"indexing",message:"Indexing..."}}case"completed":return{status:"success",message:null};case"failed":return{status:"error",message:e.indexingError};default:return null}},q=async function(e){let{rebuild:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!t||confirm('Rebuild "'.concat(e.name,'" from scratch? Every product is re-processed, which can take hours on a large catalogue. Search keeps serving the current data until the new one is ready.'))){P(t=>({...t,[e.id]:{status:"indexing",progress:0,message:"Starting..."}}));try{let a=await fetch("/api/indexes/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({indexId:e.id,master:D.master,source:"manual",rebuild:t})}),l=await a.json();l.success?P(t=>{let a={...t};return delete a[e.id],a}):(P(t=>({...t,[e.id]:{status:"error",progress:0,message:l.error||"Failed to start indexing"}})),console.error("Indexing enqueue error:",l))}catch(t){P(t=>({...t,[e.id]:{status:"error",progress:0,message:"Failed to start indexing"}}))}}},J=async e=>{F(e),_({loading:!0}),o(!0);try{let t=await fetch("/api/indexes/preview",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({indexId:e.id,master:D.master})}),a=await t.json();a.success?_(a):_({error:a.error||"Failed to fetch preview"})}catch(e){_({error:"Failed to fetch preview"}),console.error(e)}},K=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"*";L.current&&L.current.abort();let a=new AbortController;L.current=a,F(e),B({loading:!0}),I(!0);try{let l=await fetch("/api/indexes/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({collectionName:e.collectionName,query:t,limit:50}),signal:a.signal}),s=await l.json();s.success?B(s):B({error:s.error||"Failed to fetch search"})}catch(e){if("AbortError"===e.name)return;B({error:"Failed to fetch search"}),console.error(e)}},G=async e=>{if(confirm('Delete index "'.concat(e.name,'"? This will also delete the Typesense collection. This cannot be undone.')))try{await (0,c.kd)((0,c.H9)(d.firestore,"tenants/".concat(D.master,"/typesense_indexes/").concat(e.id))),C(S.filter(t=>t.id!==e.id)),i(!1)}catch(e){alert("Failed to delete index"),console.error(e)}},Y=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;F(e),t(!0)},et=async function(e){let a=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{var l,s,r;let i;Object.keys(e).forEach(t=>{void 0===e[t]&&delete e[t]});let n=(null==(l=e.username)?void 0:l.trim())||null,o=(null==(s=e.password)?void 0:s.trim())||null,p=(null==(r=e.headers)?void 0:r.trim())||null,m={...e,username:n,password:o,headers:p};
1if(Object.keys(m).forEach(e=>{(null===m[e]||void 0===m[e])&&delete m[e]}),e.id&&(n||(m.username=(0,c.CL)()),o||(m.password=(0,c.CL)()),p||(m.headers=(0,c.CL)())),e.id){let t=(0,c.H9)(d.firestore,"tenants/".concat(D.master,"/typesense_indexes/").concat(e.id));await (0,c.mZ)(t,m),i=e.id}else{let e=(0,h.$)(20),t=(0,c.H9)(d.firestore,"tenants/".concat(D.master,"/typesense_indexes"),e);await (0,c.BN)(t,{...m,id:e,createdAt:new Date().toISOString()}),i=e}return a||(t(!1),F(null)),M(),{...m,id:i}}catch(e){return console.error("Error saving document:",e),alert("Error saving index"),null}},ea=(0,l.jsx)("div",{className:"no-chosen-chat-wrapper",children:(0,l.jsxs)("div",{className:"no-tools-message-wrapper",children:[(0,l.jsx)("img",{src:"https://static-assets.serviceform.com/images/web-images/black-oop.svg",alt:""}),(0,l.jsx)("span",{className:"no-tools-message-title",children:"Create a Typesense index to get started"}),(0,l.jsx)("span",{className:"no-tools-message-description",children:"Index data from external feeds into Typesense for AI-powered search. Supports cars, properties, and e-commerce products."}),(0,l.jsx)("button",{type:"button",className:"sf-btn sf-btn-primary",onClick:()=>Y(),children:"+ Create your first index"})]})});return 0!==S.length&&(ea=(0,l.jsx)("div",{className:"overflow-x-auto overflow-y-hidden pb-1.5 [scrollbar-width:thin] [&::-webkit-scrollbar]:h-1.5 [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-gray-300 [&::-webkit-scrollbar-track]:bg-transparent",children:N?(0,l.jsx)("p",{children:"Loading..."}):(0,l.jsxs)("div",{className:"w-max min-w-full bg-white border border-gray-200 rounded-xl overflow-hidden",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 bg-gray-50 border-b border-gray-200 text-[12px] font-semibold text-gray-700",children:[(0,l.jsx)("div",{className:"flex items-center w-[105px]",children:(0,f.A)("Name")}),(0,l.jsx)("div",{className:"flex items-center w-[90px]",children:(0,f.A)("Type")}),(0,l.jsx)("div",{className:"flex items-center w-[160px]",children:(0,f.A)("Feed URL")}),(0,l.jsx)("div",{className:"flex items-center w-[120px]",children:(0,f.A)("Last indexed")}),(0,l.jsx)("div",{className:"flex items-center w-[80px]",children:(0,f.A)("Status")}),(0,l.jsx)("div",{className:"flex items-center w-[70px]",children:(0,f.A)("Documents")})]}),(0,l.jsx)("div",{className:"flex flex-col max-h-[700px] overflow-auto",children:S.map(e=>{var t,a,s;return(0,l.jsxs)("div",{className:"flex items-center flex-nowrap justify-between px-3 py-2 border-b border-gray-100 last:border-b-0 even:bg-gray-50/70 hover:bg-gray-50 transition-colors",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 flex-nowrap",children:[(0,l.jsx)("div",{className:"flex items-center w-[105px] overflow-x-auto whitespace-nowrap [scrollbar-width:thin] text-xs font-medium text-gray-900",title:e.name,children:e.name}),(0,l.jsx)("div",{className:"flex items-center w-[90px] overflow-hidden",children:(0,l.jsx)("span",{className:"block max-w-full truncate px-1.5 py-0.5 rounded text-[10px] leading-tight text-center text-white ".concat(V[e.dataType]||"bg-amber-500"),title:(null==(t=e.dataType)?void 0:t.replace(/_/g," "))||"ecommerce",children:(null==(a=e.dataType)?void 0:a.replace(/_/g," "))||"ecommerce"})}),(0,l.jsx)("div",{className:"flex items-center w-[160px] overflow-x-auto whitespace-nowrap [scrollbar-width:thin] text-xs",children:(null==(s=e.feedUrl)?void 0:s.includes(","))?(0,l.jsxs)("span",{className:"text-xs text-gray-600",title:e.feedUrl,children:[e.feedUrl.split(",").length," feeds combined"]}):(0,l.jsx)("a",{href:e.feedUrl,target:"_blank",rel:"noopener noreferrer",className:"text-blue-500",children:e.feedUrl})}),(0,l.jsx)("div",{className:"flex items-center w-[120px] text-xs text-gray-600",children:e.lastIndexed?(0,l.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,l.jsx)("span",{children:u()(e.lastIndexed).format("HH:mm, D MMM YY")}),e.lastIndexingSource&&(0,l.jsx)("span",{className:"text-[10px] font-medium ".concat("automatic"===e.lastIndexingSource?"text-emerald-500":"text-gray-500"),children:"automatic"===e.lastIndexingSource?"\uD83E\uDD16 Auto":"â Manual"})]}):"Never"}),(0,l.jsx)("div",{className:"flex items-center w-[80px] overflow-hidden text-xs",children:(()=>{let t=W(e);
1if(!t)return(0,l.jsx)("span",{className:"label label-status-campaigns label-sent-campaigns",children:"Ready"});let a=t.message||("indexing"===t.status?"Indexing...":"success"===t.status?"Success":"Error"),s="error"===t.status?"Error":a;return(0,l.jsx)("span",{className:"label label-status-campaigns block max-w-full truncate text-left ".concat("indexing"===t.status?"label-draft-campaigns":"success"===t.status?"label-sent-campaigns":"label-failed-campaigns"),title:a,children:s})})()}),(0,l.jsx)("div",{className:"flex items-center w-[70px] text-xs",children:e.documentCount||0})]}),(0,l.jsx)("div",{className:"flex items-center flex-shrink-0",children:(0,l.jsx)(T,{index:e,indexingStatus:W(e),onTestAI:()=>{F(e),x(!0)},onTrainUpsells:()=>{F(e),y(!0)},onRecommendations:()=>{F(e),j(!0)},onRunIndex:()=>q(e),onRebuildIndex:()=>q(e,{rebuild:!0}),onPreview:()=>J(e),onSearch:()=>K(e),onEdit:()=>Y(e),onDelete:()=>{F(e),i(!0)}})})]},e.id)})})]})})),N&&(ea="Loading..."),(0,l.jsxs)("div",{children:[e&&(0,l.jsx)(Q,{index:k,onClose:()=>{t(!1),F(null)},onSave:et,onSaveAndIndex:async(e,a,l)=>{let s=await et(e,!0);if(s){t(!1),F(null),P(e=>({...e,[s.id]:{status:"indexing",progress:0,message:"Processing file..."}}));try{let e=await fetch("/api/indexes/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({indexId:s.id,master:D.master,source:"manual",fileContent:a,fileFormat:l})}),t=await e.json();t.success?P(e=>{let t={...e};return delete t[s.id],t}):P(e=>({...e,[s.id]:{status:"error",progress:0,message:t.error||"Indexing failed"}}))}catch(e){P(e=>({...e,[s.id]:{status:"error",progress:0,message:"Failed to index file"}}))}}},userTenantData:D}),a&&(0,l.jsx)($,{onClose:()=>i(!1),onConfirm:()=>G(k)}),z&&(0,l.jsx)(v,{index:k,searchData:E,searchQuery:U,onSearch:e=>{O(e),K(k,e)},onClose:()=>{I(!1),B(null),O(""),F(null)}}),n&&(0,l.jsx)(X,{index:k,previewData:R,onClose:()=>{o(!1),_(null),F(null)}}),m&&(0,l.jsx)(Z,{index:k,userTenantData:D,onClose:()=>{x(!1),F(null)}}),g&&(0,l.jsx)(ee,{index:k,userTenantData:D,onClose:()=>{y(!1),F(null)},onSave:async e=>{try{let t=(0,c.H9)(d.firestore,"tenants/".concat(D.master,"/typesense_indexes/").concat(k.id));await (0,c.mZ)(t,{defaultUpsellProducts:e.defaultUpsellProducts,categoryUpsellProducts:e.categoryUpsellProducts,fallbackCategory:e.fallbackCategory,updatedAt:new Date().toISOString()}),y(!1),F(null),M()}catch(e){console.error("Error saving upsell config:",e),alert("Error saving upsell configuration")}}}),b&&k&&(0,l.jsx)(H,{index:k,userTenantData:D,onClose:()=>{j(!1),F(null)},onSave:()=>{j(!1),F(null)}}),(0,l.jsx)("div",{className:"sf-header",children:(0,l.jsx)("div",{className:"sf-header-right",children:(0,l.jsx)(r.A,{variant:"primary",onClick:()=>Y(),children:"+ Create index"})})}),ea]})}},41705:e=>{let t=[{code:"en",name:"English",flag:"\uD83C\uDDFA\uD83C\uDDF8"},{code:"fi",name:"Finnish",flag:"\uD83C\uDDEB\uD83C\uDDEE"},{code:"sv",name:"Swedish",flag:"\uD83C\uDDF8\uD83C\uDDEA"},{code:"es",name:"Spanish",flag:"\uD83C\uDDEA\uD83C\uDDF8"},{code:"ca",name:"Catalan",flag:"\uD83C\uDF10"},{code:"fr",name:"French",flag:"\uD83C\uDDEB\uD83C\uDDF7"},{code:"de",name:"German",flag:"\uD83C\uDDE9\uD83C\uDDEA"},{code:"ru",name:"Russian",flag:"\uD83C\uDDF7\uD83C\uDDFA"},{code:"lv",name:"Latvian",flag:"\uD83C\uDDF1\uD83C\uDDFB"},{code:"lt",name:"Lithuanian",flag:"\uD83C\uDDF1\uD83C\uDDF9"},{code:"pl",name:"Polish",flag:"\uD83C\uDDF5\uD83C\uDDF1"},{code:"no",name:"Norwegian",flag:"\uD83C\uDDF3\uD83C\uDDF4"},{code:"da",name:"Danish",flag:"\uD83C\uDDE9\uD83C\uDDF0"},{code:"pt",name:"Portuguese (Portugal)",flag:"\uD83C\uDDF5\uD83C\uDDF9"},{code:"it",name:"Italian",flag:"\uD83C\uDDEE\uD83C\uDDF9"},{code:"nl",name:"Dutch",flag:"\uD83C\uDDF3\uD83C\uDDF1"},{code:"cs",name:"Czech",flag:"\uD83C\uDDE8\uD83C\uDDFF"},{code:"zh",name:"Chinese",flag:"\uD83C\uDDE8\uD83C\uDDF3"},{code:"eu",name:"Basque",flag:"\uD83C\uDF10"},{code:"et",name:"Estonian",flag:"\uD83C\uDDEA\uD83C\uDDEA"},{code:"si",name:"Sinhala",flag:"\uD83C\uDDF1\uD83C\uDDF0"},{code:"ta",name:"Tamil",flag:"\uD83C\uDF10"},{code:"bn",name:"Bengali",flag:"\uD83C\uDDE7\uD83C\uDDE9"},{code:"hi",name:"Hindi",flag:"\uD83C\uDDEE\uD83C\uDDF3"},{code:"th",name:"Thai",flag:"\uD83C\uDDF9\uD83C\uDDED"},{code:"he",name:"Hebrew",flag:"\uD83C\uDDEE\uD83C\uDDF1"},{code:"ar",name:"Arabic",flag:"\uD83C\uDF10"},{code:"el",name:"Greek",flag:"\uD83C\uDDEC\uD83C\uDDF7"},{code:"ko",name:"Korean",flag:"\uD83C\uDDF0\uD83C\uDDF7"},{code:"ja",name:"Japanese",flag:"\uD83C\uDDEF\uD83C\uDDF5"}];function a(e){let a=t.find(t=>t.code===e);return a?a.name:e}e.exports={SUPPORTED_LANGUAGES:t,getLanguageName:a,getLanguageNames:function(e){return e.map(e=>a(e))}}},55578:(e,t,a)=>{a.d(t,{A:()=>r});var l=a(37876),s=a(90145);
1function r(e){let{content:t}=e;return(0,l.jsx)("div",{className:"tooltip ml-2 my-auto",style:{position:"relative"},children:(0,l.jsxs)("div",{className:"tooltip-hover",children:[(0,l.jsx)(s.A,{className:"h-5 w-5 text-gray-500 hover:text-gray-700 cursor-help","aria-hidden":"true"}),(0,l.jsx)("div",{className:"tooltip-text",style:{width:"280px"},children:(0,l.jsx)("div",{className:"p-2",children:t})})]})})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.