PageSourceSearch

https://possibleapp.lovable.app/assets/AutomationSettings-A91v3oFW.js

js possibleapp.lovable.app collected 2026-10-03 03:40:17 UTC 87,107 bytes, 1 lines download raw bytes

1import{j as e,p as _s,r as f,m as ze,q as xs,x as Pe,y as ye,s as _e,E as qe,B as Is}from"./storefront-core-DOZzotQO.js";import{D as Ms}from"./AnnouncementPopup-Dt0woof_.js";import{a as Rs,s as Ge}from"./useErrorToast-C69wq04o.js";import{c as ee,u as ms,as as Ce,B as O,s as he,e as Fs}from"./index-BHuFdqen.js";import{S as ve}from"./switch-DfAzmSgb.js";import{Z as Be}from"./r2Upload-EC_kstLn.js";import Os from"./zap-off-DQXkDHx0.js";import{A as $s}from"./AiCallBalanceCard-CFoz358c.js";import{C as P,c as D,a as q,b as V,d as Z}from"./card-BIX9QUaW.js";import{T as os,a as is,b as ie,c as ce}from"./tabs-Ce37yzGx.js";import{toast as Q}from"./sonner-srvUwDud.js";import{L as T}from"./label-9cEArPld.js";import{I as oe}from"./input-DjBZVanG.js";import{T as de}from"./textarea-MPRkPtUR.js";import{S as Ls,a as Us,b as qs,c as Vs,d as Bs}from"./select-BOX4_TX3.js";import vs from"./bot-DThn0s75.js";import{T as Es}from"./RawHtmlShadow-BWbIc2pI.js";import{P as Ks}from"./useWebsitePages-DQRyoD0i.js";import Ns from"./phone-outgoing-DPZ5rPS4.js";import{L as ge}from"./useCrmUserMap-X1iOOPOr.js";import Xs from"./clock-3-BENJHZIS.js";import ys from"./save-CoRF33vm.js";import zs from"./phone-incoming-XqFCK19D.js";import{C as $e}from"./paymentLinkUtils-BwurDBCq.js";import Le from"./circle-x-Dt7doAEz.js";import Gs from"./circle-pause-Cp0uTgR2.js";import{S as Hs}from"./smsSegments-DfGvwWV2.js";import Qs from"./package-plus-Da2-vHKv.js";import{D as Ws,a as Ys,b as Zs,c as Js,f as et}from"./dialog-e0eRAmQv.js";import st from"./music-pCvA3ky6.js";import{C as He}from"./variationCombinationFilter-CFLG8JBn.js";import ws from"./square-q_Rsf_wR.js";import Cs from"./volume-2-ayBuDWTK.js";import{C as ks,B as ue}from"./badge-CDC6fr5s.js";import{T as Qe,a as We,b as pe,c as k,d as Ye,e as C}from"./table-Du_lE-Rt.js";import{P as tt,a as at,b as rt}from"./popover-B1C-gQgc.js";import{L as nt}from"./lazy-calendar-C6FcXQb9.js";import Je from"./list-ordered-mWUiDveX.js";import es from"./hourglass-Bo1qNCIe.js";import{C as Ee}from"./orderItemImageResolver-CeNCg4Qv.js";import Ke from"./phone-off-CuYA14po.js";import Xe from"./phone-forwarded-h_-ybYry.js";import us from"./trending-up-D4QdntOz.js";import lt from"./layers-DO5G5aOt.js";import hs from"./timer-DCGU_BjC.js";import ps from"./dollar-sign-CzXVe4Iy.js";import{P as Ie}from"./lpOfferUtils-ixcqdNYv.js";import we from"./phone-call-Djl3J_8W.js";import ot from"./activity-CedH2D3H.js";import it from"./calendar-BjE5c0YJ.js";import{C as ct}from"./activityLogger-DN-Z3uB6.js";import{F as Ze}from"./BodyCleansingSections-BCzoCCOW.js";import Ve from"./triangle-alert-Bfu1kif9.js";import ss from"./monitor-B05uxPqp.js";import gs from"./settings-BhGB0RQb.js";import{M as dt}from"./friendlyError-BbpPwT42.js";import{S as mt}from"./useBottomCtaOffset-Mb1GpiEk.js";import{T as xt}from"./leadFormSchema-CKIyE_QT.js";import{P as cs}from"./lpCachePurge-br7-uXaG.js";import ut from"./upload-nmM-a_3N.js";import ht from"./circle-stop-BFejoeB8.js";import pt from"./mic-Cs5hrRon.js";import gt from"./refresh-cw-CXT1Rx9l.js";import"./sheet-nUXeLRPb.js";import"./vendor-ui-core-tug0qXYz.js";import"./dialFromApp-Bn9AP7uw.js";import"./orderDeviceSignals-B_tQ9AGC.js";import"./bell-DxoPe46g.js";import"./vendor-ui-extra-nnXCMECZ.js";import"./vendor-tiptap-BDuU78d0.js";import"./capiTrigger-DofKQ2Mu.js";import"./useActiveAnnouncements-B-L4CirJ.js";import"./users-BdSwQ2ny.js";import"./send-DYWQiQ1_.js";import"./ProductPromoBadge-CVYcZ-GU.js";import"./list-todo-BFJHioTO.js";import"./lightbulb-BodVdVPs.js";import"./layout-dashboard-CcaFBICT.js";import"./wallet-BKzD5PAP.js";import"./database-BVKWqTia.js";import"./globe-DRgv8neH.js";import"./sparkles-sp6gYSIp.js";import"./panel-left-open-BZA_0at1.js";import"./panel-left-close-CPpmtJtq.js";import"./flask-conical-CGW01FZ2.js";import"./gift-B1Ka2Exu.js";import"./contact-D12DIqJC.js";import"./rocket-pEYypunS.js";import"./credit-card-D87HjB_A.js";import"./users-round-D9ltevlA.js";import"./ChulkaniOilSections-DEgMN6g0.js";import"./building-2-Cykl3ym8.js";import"./book-open-wf-y8_Qo.js";import"./log-out-B-U-ly6C.js";import"./menu-gHKeoCWf.js";import"./headphones-PlhEqF8q.js";import"./eye-CEzdSD9U.js";import"./type-BtHm8e1h.js";import"./image-CUFOAiCf.js";import"./square-pen-DmIsXHzz.js";import"./panels-top-left-C6cW-5X9.js";import"./grid-3x3-DkkF86q0.js";import"./heart-DBgDsk_d.js";import"./circle-play-C0YyJJsc.js";import"./sun-Uq38S3Zz.js";import"./orderSmsTrigger-B7aXpIRK.js";import"./creator-badge-Co4Fvi7t.js";import"./storefrontCachePurge-DKByiKhQ.js";
1import"./ShasthoGoriSections-DbSMUn__.js";import"./use-mobile-DKdRrv-D.js";function ft({label:m,enabled:x,onToggle:r,isUpdating:s,description:v}){return e.jsxs("div",{className:ee("flex items-center gap-3 rounded-xl border px-4 py-3 transition-all duration-200",x?"border-emerald-500/30 bg-emerald-500/5":"border-border bg-muted/30"),children:[e.jsx("div",{className:ee("flex h-8 w-8 items-center justify-center rounded-lg",x?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:x?e.jsx(Be,{className:"h-4 w-4"}):e.jsx(Os,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold",children:m}),e.jsx("span",{className:ee("rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider",x?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:x?"Auto":"Manual"})]}),v&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:v})]}),e.jsx(ve,{checked:x,onCheckedChange:r,disabled:s})]})}const fs={enabled:!1,agent_name:"AI Agent",answer_inbound_calls:!1,outbound_order_calls:!1,can_confirm_order:!0,can_cancel_order:!0,can_hold_order:!0,can_add_item:!1,can_lookup_product:!0,persona_tone:"friendly",inbound_greeting:"আসসালামু আলাইকুম, আমি {agent}। কীভাবে সাহায্য করতে পারি?",inbound_instructions:"কাস্টমার নিজে কল দিলে: প্রথমে শুনবে সে কী চায়। দাম/স্টক/ডেলিভারি জিজ্ঞেস করলে দোকানের তথ্য থেকে বলবে। অর্ডার করতে চাইলে নাম, ঠিকানা ও পণ্য জেনে নেবে।",order_call_greeting:"আসসালামু আলাইকুম, {agent} বলছি। আপনার অর্ডারটি নিশ্চিত করার জন্য কল দিয়েছি।",order_call_instructions:"অর্ডার কনফার্মেশন কলে: অর্ডারের পণ্য ও মোট টাকা বলে নিশ্চিত করতে বলবে। কাস্টমার রাজি হলে অর্ডার কনফার্ম করবে, না চাইলে কারণ জেনে বাতিল বা হোল্ড করবে।",extra_instructions:"",voice_faqs:[],max_call_seconds:300},jt=[{value:"friendly",label:"বন্ধুত্বপূর্ণ"},{value:"formal",label:"আনুষ্ঠানিক / ভদ্র"},{value:"energetic",label:"উদ্যমী / বিক্রয়মুখী"},{value:"calm",label:"শান্ত ও ধীর"}],bt=[{key:"answer_inbound_calls",label:"কাস্টমারের কল রিসিভ করবে",desc:"কেউ দোকানের নম্বরে কল দিলে AI নিজে ধরে কথা বলবে",icon:zs},{key:"outbound_order_calls",label:"নতুন অর্ডারে কল দেবে",desc:"অর্ডার এলে AI নিজে কল দিয়ে কনফার্ম করবে",icon:Ns},{key:"can_confirm_order",label:"অর্ডার কনফার্ম করতে পারবে",desc:"কাস্টমার মুখে হ্যাঁ বললে অর্ডার কনফার্ম হবে",icon:$e},{key:"can_cancel_order",label:"অর্ডার বাতিল করতে পারবে",desc:"কাস্টমার না করলে অর্ডার বাতিল হবে (আগে মুখে নিশ্চিত করবে)",icon:Le},{key:"can_hold_order",label:"অর্ডার হোল্ড করতে পারবে",desc:"পরে জানাবে বললে অর্ডার হোল্ডে যাবে",icon:Gs},{key:"can_lookup_product",label:"পণ্যের দাম/স্টক বলতে পারবে",de
1sc:"নাম শুনে পণ্যের দাম ও স্টক জানাবে",icon:Hs},{key:"can_add_item",label:"অর্ডারে নতুন পণ্য যোগ করতে পারবে",desc:"কাস্টমার চাইলে চলতি অর্ডারে পণ্য যোগ হবে",icon:Qs}];function _t(){const{currentBusinessId:m}=ms(),x=_s(),[r,s]=f.useState(null),[v,u]=f.useState(""),{data:g=[]}=ze({queryKey:["ai-agent-test-calls",m],enabled:!!m,refetchInterval:5e3,queryFn:async()=>{const{data:a,error:i}=await he.from("ai_call_logs").select("id, customer_phone, status, duration, created_at, summary, transcript, ai_actions").eq("business_id",m).eq("purpose","ai_agent_test").order("created_at",{ascending:!1}).limit(5);if(i)throw i;return a||[]}}),o=xs({mutationFn:async()=>{if(!m)throw new Error("কোনো ব্যবসা নির্বাচন করা হয়নি");const{data:a,error:i}=await he.functions.invoke("ai-agent-test-call",{body:{business_id:m,phone:v}});if(i)throw i;if(a?.error)throw new Error(a.message||a.error);return a},onSuccess:a=>{Q.success(`কল যাচ্ছে ${a?.from||""} নম্বর থেকে`),x.invalidateQueries({queryKey:["ai-agent-test-calls",m]})},onError:a=>Q.error(a?.message||"কল দেওয়া যায়নি")}),{data:b,isLoading:j}=ze({queryKey:["ai-agent-settings",m],enabled:!!m,queryFn:async()=>{const{data:a,error:i}=await he.from("ai_agent_settings").select("*").eq("business_id",m).maybeSingle();if(i)throw i;const d=a||{business_id:m,...fs};return{...fs,...d,voice_faqs:Array.isArray(d.voice_faqs)?d.voice_faqs:[]}}});f.useEffect(()=>{b&&s(b)},[b]);const h=xs({mutationFn:async a=>{if(!m)throw new Error("কোনো ব্যবসা নির্বাচন করা হয়নি");const{error:i}=await he.from("ai_agent_settings").upsert({...a,business_id:m,updated_at:new Date().toISOString()},{onConflict:"business_id"});if(i)throw i},onSuccess:()=>{Q.success("AI Agent সেটিংস সেভ হয়েছে"),x.invalidateQueries({queryKey:["ai-agent-settings",m]})},onError:a=>Q.error(a?.message||"সেভ করা যায়নি")});if(j||!r)return e.jsx("div",{className:"space-y-4",children:[1,2,3].map(a=>e.jsx(Ce,{className:"h-32 w-full rounded-xl"},a))});const c=a=>s({...r,...a}),M=r.voice_faqs||[],X=(a,i)=>c({voice_faqs:M.map((d,A)=>A===a?{...d,...i}:d)}),R=a=>{const i=String(a||"").toLowerCase();return["completed","confirmed"].includes(i)?{label:"সম্পন্ন",className:"text-emerald-600"}:["queued","initiated","ringing","in-progress"].includes(i)?{label:"চলছে",className:"text-primary"}:["no-answer","no_answer","busy"].includes(i)?{label:"ধরা হয়নি",className:"text-amber-600"}:{label:"ব্যর্থ",className:"text-destructive"}};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(P,{children:e.jsx(D,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-xl bg-primary/10",children:e.jsx(vs,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-bold",children:"AI Agent"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"কাস্টমারের সাথে সরাসরি কথা বলে অর্ডার কনফার্ম/বাতিল করবে ও প্রশ্নের উত্তর দেবে"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider ${r.enabled?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"}`,children:r.enabled?"ON":"OFF"}),e.jsx(ve,{checked:r.enabled,onCheckedChange:a=>c({enabled:a})})]})]})})}),e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"পরিচয় ও ধরন"}),e.jsx(Z,{children:"এজেন্ট নিজেকে কী নামে পরিচয় দেবে এবং কেমন সুরে কথা বলবে"})]}),e.jsxs(D,{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-1",children:[e.jsx(T,{className:"text-xs",children:"এজেন্টের নাম"}),e.jsx(oe,{value:r.agent_name,onChange:a=>c({agent_name:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{className:"text-xs",children:"কথার ধরন"}),e.jsxs(Ls,{value:r.persona_tone,onValueChange:a=>c({persona_tone:a}),children:[e.jsx(Us,{children:e.jsx(qs,{})}),e.jsx(Vs,{children:jt.map(a=>e.jsx(Bs,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{className:"text-xs",children:"সর্বোচ্চ কল দৈর্ঘ্য (সেকেন্ড)"}),e.jsx(oe,{type:"number",min:60,max:900,value:r.max_call_seconds,onChange:a=>c({max_call_seconds:Number(a.target.value)||300})})]})]})]}),e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"এজেন্ট কী কী কাজ করবে"}),e.jsx(Z,{children:"যেগুলো বন্ধ থাকবে, সেগুলো এজেন্ট কখনো করবে না"})]}),e.jsx(D,{className:"grid gap-2",children:bt.map(a=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(a.icon,{className:"mt-0.5 h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.desc})]})]}),e.jsx(ve,{checked:!!r[a.key],onCheckedChange:i=>c({[a.key]:i}),disabled:!r.enabled})]},String(a.key)))})]}),e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"কাস্টমার কল দিলে কীভাবে কথা বলবে"}),e.jsxs(Z,{children:["প্রথম বাক্য ও আচরণের নির্দেশনা। ",e.jsx("code",{className:"text-[11px]",children:"{agent}"})," লিখলে এজেন্টের নাম বসবে।"]})]}),e.jsxs(D,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{className:"text-xs",children:"শুরুর কথা"}
1),e.jsx(de,{rows:2,value:r.inbound_greeting||"",onChange:a=>c({inbound_greeting:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{className:"text-xs",children:"নির্দেশনা"}),e.jsx(de,{rows:4,value:r.inbound_instructions||"",onChange:a=>c({inbound_instructions:a.target.value})})]})]})]}),e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"অর্ডারের কল দিলে কীভাবে কথা বলবে"}),e.jsx(Z,{children:"অর্ডার কনফার্মেশন কলের শুরুর কথা ও নিয়ম"})]}),e.jsxs(D,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{className:"text-xs",children:"শুরুর কথা"}),e.jsx(de,{rows:2,value:r.order_call_greeting||"",onChange:a=>c({order_call_greeting:a.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(T,{className:"text-xs",children:"নির্দেশনা"}),e.jsx(de,{rows:4,value:r.order_call_instructions||"",onChange:a=>c({order_call_instructions:a.target.value})})]})]})]}),e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"প্রশ্ন-উত্তর শেখানো"}),e.jsx(Z,{children:"কাস্টমার যা প্রায়ই জিজ্ঞেস করে, তার নির্দিষ্ট উত্তর এখানে লিখে দিন"})]}),e.jsxs(D,{className:"space-y-3",children:[M.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"এখনো কিছু শেখানো হয়নি।"}),M.map((a,i)=>e.jsxs("div",{className:"grid gap-2 rounded-lg border p-3 sm:grid-cols-[1fr_1.4fr_auto]",children:[e.jsx(oe,{placeholder:"প্রশ্ন",value:a.question,onChange:d=>X(i,{question:d.target.value})}),e.jsx(oe,{placeholder:"উত্তর",value:a.answer,onChange:d=>X(i,{answer:d.target.value})}),e.jsx(O,{variant:"ghost",size:"icon",onClick:()=>c({voice_faqs:M.filter((d,A)=>A!==i)}),children:e.jsx(Es,{className:"h-4 w-4 text-destructive"})})]},i)),e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>c({voice_faqs:[...M,{question:"",answer:""}]}),children:[e.jsx(Ks,{className:"mr-1.5 h-4 w-4"})," নতুন প্রশ্ন যোগ করুন"]})]})]}),e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"টেস্ট কল"}),e.jsx(Z,{children:"একটি নম্বর দিন — এই ব্যবসার জন্য সেট করা নম্বর থেকেই AI Agent কল দেবে। আগে সেটিংস সেভ করে নিন।"})]}),e.jsxs(D,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(T,{className:"text-xs",children:"মোবাইল নম্বর"}),e.jsx(oe,{inputMode:"numeric",placeholder:"01XXXXXXXXX",value:v,onChange:a=>u(a.target.value)})]}),e.jsxs(O,{onClick:()=>o.mutate(),disabled:o.isPending||!r.enabled||v.replace(/\D/g,"").length<11,children:[e.jsx(Ns,{className:"mr-1.5 h-4 w-4"}),o.isPending?"কল যাচ্ছে...":"টেস্ট কল দিন"]})]}),e.jsxs("div",{className:"border-t pt-3",children:[e.jsx("p",{className:"mb-2 text-xs font-semibold",children:"সাম্প্রতিক টেস্ট কল"}),g.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"এখনো কোনো টেস্ট কলের ফলাফল নেই।"}):e.jsx("div",{className:"space-y-2",children:g.map(a=>{const i=R(a.status),d=["queued","initiated","ringing","in-progress"].includes(String(a.status||"").toLowerCase());return e.jsxs("div",{className:"rounded-md border px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d?e.jsx(ge,{className:"h-3.5 w-3.5 animate-spin text-primary"}):e.jsx(Xs,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:a.customer_phone}),e.jsx("span",{className:i.className,children:i.label}),Number(a.duration||0)>0&&e.jsxs("span",{className:"text-muted-foreground",children:[a.duration," সেকেন্ড"]})]}),e.jsx("span",{className:"text-muted-foreground",children:new Date(a.created_at).toLocaleStr
1ing("bn-BD",{timeZone:"Asia/Dhaka",dateStyle:"short",timeStyle:"short"})})]}),e.jsx("p",{className:"mt-1.5 text-xs text-muted-foreground",children:a.summary||(a.transcript?"কথোপকথন সংরক্ষিত হয়েছে।":d?"কলের ফলাফলের অপেক্ষায়…":"কথোপকথনের সারাংশ পাওয়া যায়নি।")})]},a.id)})})]})]})]}),e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"অতিরিক্ত নির্দেশনা"}),e.jsx(Z,{children:"যেকোনো বাড়তি নিয়ম — যেমন কোন কথা কখনো বলবে না"})]}),e.jsx(D,{children:e.jsx(de,{rows:3,value:r.extra_instructions||"",onChange:a=>c({extra_instructions:a.target.value})})})]}),e.jsx("div",{className:"sticky bottom-3 flex justify-end",children:e.jsxs(O,{onClick:()=>h.mutate(r),disabled:h.isPending,children:[e.jsx(ys,{className:"mr-1.5 h-4 w-4"}),h.isPending?"সেভ হচ্ছে...":"সেভ করুন"]})})]})}const vt=[{key:"classic",label:"ক্লাসিক রিং",desc:"Traditional phone ring"},{key:"soft",label:"সফট টোন",desc:"Gentle & soft"},{key:"digital",label:"ডিজিটাল রিং",desc:"Sharp digital tone"},{key:"melody",label:"মেলোডি",desc:"Musical arpeggio"},{key:"vibration",label:"ভাইব্রেশন রিং",desc:"Low pulse tone"}];function Nt(m){const x=new AudioContext;x.state==="suspended"&&x.resume().catch(()=>{});const r=x.createGain();r.connect(x.destination);const s=x.currentTime;if(m==="classic"){const u=x.createOscillator();u.type="sine",u.connect(r),u.start();for(let g=0;g<3;g++){const o=s+g*1.2;r.gain.setValueAtTime(.3,o),u.frequency.setValueAtTime(440,o),u.frequency.setValueAtTime(480,o+.4),r.gain.setValueAtTime(0,o+.8)}return u.stop(s+3.6),{stop:()=>{try{u.stop(),x.close()}catch{}}}}if(m==="soft"){const u=x.createOscillator();u.type="sine",u.frequency.value=523,u.connect(r),u.start();for(let g=0;g<4;g++){const o=s+g*.8;r.gain.setValueAtTime(.15,o),r.gain.linearRampToValueAtTime(0,o+.5)}return u.stop(s+3.2),{stop:()=>{try{u.stop(),x.close()}catch{}}}}if(m==="digital"){const u=x.createOscillator();u.type="square",u.connect(r),r.gain.value=.15,u.start();for(let g=0;g<6;g++){const o=s+g*.3;u.frequency.setValueAtTime(g%2===0?800:1e3,o),r.gain.setValueAtTime(.15,o),r.gain.setValueAtTime(0,o+.2)}return u.stop(s+2),{stop:()=>{try{u.stop(),x.close()}catch{}}}}if(m==="melody"){const u=[523,659,784,659,523],g=x.createOscillator();return g.type="sine",g.connect(r),g.start(),u.forEach((o,b)=>{const j=s+b*.35;g.frequency.setValueAtTime(o,j),r.gain.setValueAtTime(.25,j),r.gain.linearRampToValueAtTime(0,j+.3)}),g.stop(s+u.length*.35),{stop:()=>{try{g.stop(),x.close()}catch{}}}}const v=x.createOscillator();v.type="sine",v.frequency.value=300,v.connect(r),v.start();for(let u=0;u<5;u++){const g=s+u*.5;r.gain.setValueAtTime(.3,g),r.gain.setValueAtTime(0,g+.15)}return v.stop(s+2.5),{stop:()=>{try{v.stop(),x.close()}catch{}}}}function yt({selectedRingtone:m,onSelect:x,isUpdating:r}){const[s,v]=f.useState(null),u=f.useRef(null),g=f.useCallback(o=>{if(u.current&&(u.current(),u.current=null),s===o){v(null);return}const{stop:b}=Nt(o);u.current=b,v(o),setTimeout(()=>{v(j=>j===o?null:j)},4e3)},[s]);return e.jsxs(P,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(st,{className:"h-4.5 w-4.5 text-primary"})}),e.jsxs("div",{children:[e.jsx(V,{className:"text-base",children:"🔔 রিংটোন সিলেক্ট করুন"}),e.jsx(Z,{children:"কাস্টমারের স্ক্রিনে কল আসলে যে শব্দ বাজবে"})]})]})}),e.jsx(D,{children:e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2",children:vt.map(o=>{const b=m===o.key,j=s===o.key;return e.jsxs("div",{onClick:()=>!r&&x(o.key),className:`relative flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-all ${b?"border-primary bg-primary/5 ring-1 ring-primary/20":"border-border bg-card hover:border-primary/40"}`,children:[b&&e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(He,{className:"h-4 w-4 text-primary"})}),e.jsx(O,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 shrink-0",onClick:h=>{h.stopPropagation(),g(o.key)},children:j?e.jsx(ws,{className:"h-3.5 w-3.5 text-primary"}):e.jsx(Cs,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium leading-tight",children:o.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o.desc})]})]},o.key)})})})]})}const wt=[{label:"Today",getValue:()=>({from:Pe(new Date),to:ye(new Date)})},{label:"Yesterday",getValue:()=>({from:Pe(qe(new Date,1)),to:ye(qe(new Date,1))})},{label:"Last 7 Days",getValue:()=>({from:Pe(qe(new Date,6)),to:ye(new Date)})},{label:"Last 30 Days",getValue:()=>({from:Pe(qe(new Date,29)),to:ye(new Date)})},{label:"This Month",getValue:()=>({from:Is(new Date),to:ye(new Date)})}],ds=m=>String(m||"").toLowerCase();function Ct(m,x){const r=ds(x);return["failed","busy","no-answer"].includes(r)?{label:"Failed",color:"bg-destructive/15 text-destructive border-destructive/20",icon:Ke}:m==="1"?{label:"Confirmed",color:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400 border-emerald-500/20",icon:$e}
1:m==="2"?{label:"Hold/Cancel",color:"bg-amber-500/15 text-amber-700 dark:text-amber-400 border-amber-500/20",icon:Le}:m==="0"?{label:"Forwarded",color:"bg-blue-500/15 text-blue-700 dark:text-blue-400 border-blue-500/20",icon:Xe}:(r==="completed"||r==="disconnected")&&!m?{label:"No Response",color:"bg-muted text-muted-foreground border-border",icon:Ee}:["ringing"].includes(r)?{label:"Ringing",color:"bg-blue-500/15 text-blue-700 dark:text-blue-400 border-blue-500/20",icon:we}:["in-progress"].includes(r)?{label:"In Progress",color:"bg-blue-500/15 text-blue-700 dark:text-blue-400 border-blue-500/20",icon:ge}:["initiated","queued"].includes(r)?{label:"Initiated",color:"bg-blue-500/15 text-blue-700 dark:text-blue-400 border-blue-500/20",icon:Ie}:{label:x||"Unknown",color:"bg-muted text-muted-foreground border-border",icon:Ie}}const De=m=>{if(!m)return"0s";const x=Math.floor(m/60),r=m%60;return x>0?`${x}m ${r}s`:`${r}s`};function js({cards:m,isLoading:x}){return x?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 gap-3",children:Array.from({length:10}).map((r,s)=>e.jsx(Ce,{className:"h-20 rounded-lg"},s))}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 gap-3",children:m.map(r=>e.jsx(P,{className:"border-border/40",children:e.jsxs(D,{className:"p-3 flex items-center gap-3",children:[e.jsx("div",{className:ee("flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-muted/60",r.color),children:e.jsx(r.icon,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground truncate",children:r.label}),e.jsx("p",{className:ee("text-lg font-bold leading-tight truncate",r.color),children:r.value})]})]})},r.label))})}function kt({businessId:m,currency:x="৳"}){const[r,s]=f.useState({from:Pe(new Date),to:ye(new Date)}),[v,u]=f.useState("Today"),[g,o]=f.useState(!1),[b,j]=f.useState(r),[h,c]=f.useState(!1),[M,X]=f.useState("orders"),{data:R=[],isLoading:a}=ze({queryKey:["call-activity-logs",m,r?.from?.toISOString(),r?.to?.toISOString()],queryFn:async()=>{if(!r?.from||!r?.to)return[];const{data:l,error:p}=await he.from("ai_call_logs").select("*, orders!twilio_call_logs_order_id_fkey(order_number)").eq("business_id",m).gte("created_at",r.from.toISOString()).lte("created_at",r.to.toISOString()).order("created_at",{ascending:!1});if(p)throw p;return l||[]},enabled:!!m&&!!r?.from}),{data:i=[],isLoading:d}=ze({queryKey:["ai-call-queue-pending",m],queryFn:async()=>{const{data:l,error:p}=await he.from("ai_call_queue").select("id, kind, status, enqueued_at, payload").eq("business_id",m).in("status",["pending","in_flight"]).order("enqueued_at",{ascending:!0});if(p)throw p;return l||[]},enabled:!!m,refetchInterval:3e4}),A=f.useMemo(()=>{const l=R.length;let p=0,y=0,$=0,W=0,se=0,H=0,te=0,ae=0,L=0,re=0,E=0;for(const je of R){const _=ds(je.status),S=je.dtmf_input;re+=je.call_cost||0,E+=je.duration||0,S==="1"?(p++,L++):S==="2"?(y++,L++):S==="0"&&($++,L++),["failed","busy","no-answer"].includes(_)?W++:(_==="completed"||_==="disconnected")&&!S?se++:_==="ringing"?H++:_==="in-progress"?te++:["initiated","queued"].includes(_)&&ae++}const U=l>0?E/l:0,G=l>0?(p/l*100).toFixed(1):"0",Y=l>0?(L/l*100).toFixed(1):"0";return{total:l,confirmed:p,holdCancel:y,forwarded:$,failed:W,noResponse:se,ringing:H,inProgress:te,initiated:ae,answered:L,totalCost:re,totalDuration:E,avgDuration:U,successRate:G,answerRate:Y}},[R]),F=f.useMemo(()=>{const l=new Map;for(const _ of R){if(!_.order_id)continue;const S=l.get(_.order_id)||[];S.push(_),l.set(_.order_id,S)}const p=Array.from(l.entries()).map(([_,S])=>{S.sort((N,w)=>new Date(N.created_at).getTime()-new Date(w.created_at).getTime());const be=S[S.length-1],Ae=S.map(N=>N.dtmf_input).filter(Boolean),Se=S.map(N=>ds(N.status));let t;Se.some(N=>["ringing","in-progress","initiated","queued"].includes(N))?t="in_progress":Ae.includes("1")?t="confirmed":Ae.includes("0")?t="forwarded":be.dtmf_input==="2"?t="hold_cancel":Se.every(N=>["failed","busy","no-answer"].includes(N))?t="failed":(Se.some(N=>["completed","disconnected"].includes(N))&&Ae.length,t="no_response");const n=S.reduce((N,w)=>N+(w.duration||0),0),I=S.reduce((N,w)=>N+(w.call_cost||0),0);return{orderId:_,orderNumber:be.orders?.order_number,phone:be.customer_phone,attempts:S.length,maxAttempts:be.max_attempts,outcome:t,totalDuration:n,totalCost:I,lastAt:be.created_at}}),y=p.length,$=p.filter(_=>_.outcome==="confirmed").length,W=p.filter(_=>_.outcome==="hold_cancel").length,se=p.filter(_=>_.outcome==="forwarded").length,H=p.filter(_=>_.outcome==="failed").length,te=p.filter(_=>_.outcome==="no_response").length,ae=p.filter(_=>_.outcome==="in_progress").length,L=p.reduce((_,S)=>_+S.attempts,0),re=p.reduce((_,S)=>_+S.totalDuration,0),E=p.reduce((_,S)=>_+S.totalCost,0),U=y>0?($/y*100).toFixed(1):"0",G=y>0?(L/y).toFixed(1):"0",Y=y>0?re/y:0,je=y>0?E/y:0;return p.sort((_,S)=>new Date(S.lastAt).getTime()-new Date(_.lastAt).getTime()),{rows:p,total:y,confirmed:$,holdCancel:W,forwarded:se,failed:H,noResponse:te,inProgress:ae,totalAttempts:L,successRate:U,avgAttempts:G,avgDuration:Y,avgCost:je,totalCost:E,totalDur:re}},[R]),ke=l=>{const p=l.getValue();s(p),u(l.label),o(!1),c(!1)},Ne=()=>{b?.from&&(s({from:Pe(b.from),to:ye(b.to||b.from)}),u("Custom"),o(!1),c(!1))},Me=[{label:"মোট Order (Called)",value:F.total,icon:Je,color:"text-foreground"},{label:"Queue-এ Pending",value:d?"…":i.length,icon:es,color:"text-amber-600 dar
1k:text-amber-400"},{label:"Confirmed",value:F.confirmed,icon:$e,color:"text-emerald-600 dark:text-emerald-400"},{label:"Hold/Cancel",value:F.holdCancel,icon:Le,color:"text-amber-600 dark:text-amber-400"},{label:"No Response",value:F.noResponse,icon:Ee,color:"text-muted-foreground"},{label:"Failed",value:F.failed,icon:Ke,color:"text-destructive"},{label:"Forwarded",value:F.forwarded,icon:Xe,color:"text-blue-600 dark:text-blue-400"},{label:"In Progress",value:F.inProgress,icon:ge,color:"text-blue-600 dark:text-blue-400"},{label:"Order Success Rate",value:`${F.successRate}%`,icon:us,color:"text-emerald-600 dark:text-emerald-400"},{label:"Avg Attempts/Order",value:F.avgAttempts,icon:lt,color:"text-foreground"},{label:"Avg Duration/Order",value:De(Math.round(F.avgDuration)),icon:hs,color:"text-foreground"},{label:"Avg Cost/Order",value:`${x}${F.avgCost.toFixed(2)}`,icon:ps,color:"text-foreground"}],z=[{label:"মোট Call",value:A.total,icon:Ie,color:"text-foreground"},{label:"Confirmed",value:A.confirmed,icon:$e,color:"text-emerald-600 dark:text-emerald-400"},{label:"Hold/Cancel",value:A.holdCancel,icon:Le,color:"text-amber-600 dark:text-amber-400"},{label:"Forwarded",value:A.forwarded,icon:Xe,color:"text-blue-600 dark:text-blue-400"},{label:"No Response",value:A.noResponse,icon:Ee,color:"text-muted-foreground"},{label:"Failed",value:A.failed,icon:Ke,color:"text-destructive"},{label:"Ringing",value:A.ringing,icon:we,color:"text-blue-600 dark:text-blue-400"},{label:"In Progress",value:A.inProgress,icon:ge,color:"text-blue-600 dark:text-blue-400"},{label:"Initiated/Queued",value:A.initiated,icon:Ie,color:"text-blue-600 dark:text-blue-400"},{label:"Call Success Rate",value:`${A.successRate}%`,icon:us,color:"text-emerald-600 dark:text-emerald-400"},{label:"Answer Rate",value:`${A.answerRate}%`,icon:ot,color:"text-emerald-600 dark:text-emerald-400"},{label:"Avg Duration",value:De(Math.round(A.avgDuration)),icon:hs,color:"text-foreground"},{label:"মোট সময়",value:De(A.totalDuration),icon:ks,color:"text-foreground"},{label:"মোট খরচ",value:`${x}${A.totalCost.toFixed(2)}`,icon:ps,color:"text-foreground"}],fe=l=>{switch(l){case"confirmed":return{label:"Confirmed",color:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400 border-emerald-500/20",icon:$e};case"hold_cancel":return{label:"Hold/Cancel",color:"bg-amber-500/15 text-amber-700 dark:text-amber-400 border-amber-500/20",icon:Le};case"forwarded":return{label:"Forwarded",color:"bg-blue-500/15 text-blue-700 dark:text-blue-400 border-blue-500/20",icon:Xe};case"failed":return{label:"Failed",color:"bg-destructive/15 text-destructive border-destructive/20",icon:Ke};case"in_progress":return{label:"In Progress",color:"bg-blue-500/15 text-blue-700 dark:text-blue-400 border-blue-500/20",icon:ge};default:return{label:"No Response",color:"bg-muted text-muted-foreground border-border",icon:Ee}}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs(tt,{open:h,onOpenChange:c,children:[e.jsx(at,{asChild:!0,children:e.jsxs(O,{variant:"outline",size:"sm",className:ee("h-9 gap-1.5 text-xs",v?"font-medium":"text-muted-foreground"),children:[e.jsx(it,{className:"h-3.5 w-3.5"}),v==="Custom"&&r?.from?`${_e(r.from,"dd MMM")}${r.to?` – ${_e(r.to,"dd MMM")}`:""}`:v,e.jsx(ct,{className:"h-3 w-3 opacity-50"})]})}),e.jsx(rt,{className:"w-auto p-0",align:"start",children:e.jsxs("div",{className:"flex",children:[e.jsxs("div",{className:"border-r border-border/40 p-2 min-w-[150px]",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground px-2 py-1.5",children:"Quick Select"}),wt.map(l=>e.jsxs("button",{onClick:()=>ke(l),className:ee("w-full flex items-center justify-between rounded-md px-2 py-1.5 text-sm transition-colors",v===l.label?"bg-primary/10 text-primary font-medium":"hover:bg-muted text-foreground"),children:[l.label,v===l.label&&e.jsx(He,{className:"h-3.5 w-3.5"})]},l.label)),e.jsx("div",{className:"border-t border-border/30 my-1.5"}),e.jsxs("button",{onClick:()=>o(!0),className:ee("w-full flex items-center justify-between rounded-md px-2 py-1.5 text-sm transition-colors",g||v==="Custom"?"bg-primary/10 text-primary font-medium":"hover:bg-muted text-foreground"),children:["Custom Range",v==="Custom"&&e.jsx(He,{className:"h-3.5 w-3.5"})]})]}),g&&e.jsxs("div",{className:"p-2",children:[e.jsx(nt,{initialFocus:!0,mode:"range",defaultMonth:b?.from,selected:b,onSelect:j,numberOfMonths:2,className:ee("p-2 pointer-events-auto")}),e.jsxs("div",{className:"flex items-center justify-between px-2 pt-1 pb-1 border-t border-border/30",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:b?.from?`${_e(b.from,"dd MMM yyyy")}${b.to?` – ${_e(b.to,"dd MMM yyyy")}`:""}`:"Select dates"}),e.jsx(O,{size:"sm",className:"h-7 text-xs",onClick:Ne,disabled:!b?.from,children:"Apply"})]})]})]})})]}),i.length>0&&e.jsxs(ue,{variant:"outline",className:"text-xs gap-1.5 border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-400",children:[e.jsx(es,{className:"h-3 w-3"}),i.length," order Queue-এ অপেক্ষমান"]})]}),e.jsxs(os,{value:M,onValueChange:X,className:"space-y-4",children:[e.jsxs(is,{className:"grid w-full grid-cols-3 max-w-xl",children:[e.jsxs(ie,{value:"orders",className:"gap-1.5 text-xs sm:text-sm",children:[e.jsx(Je,{className:"h-3.5 w-3.5"}),"Orders"]}),e.jsxs(ie,{value:"calls",className:"gap-1.5 text-xs sm:text-sm",children:[e.jsx(we,{className:"h-3.5 w-3.5"}),"Call Activities"]}),e.jsxs(ie,{value:"logs",className:"gap-1.5 text-xs sm:text-sm",children:[e.jsx(Ze,{className:"h-3.5 w-3.5"}
1),"Activity Logs"]})]}),e.jsxs(ce,{value:"orders",className:"space-y-4 mt-4",children:[e.jsx(js,{cards:Me,isLoading:a}),e.jsxs(P,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(V,{className:"text-base flex items-center gap-2",children:[e.jsx(es,{className:"h-4 w-4 text-amber-600"}),"Pending Queue (",i.length,")"]})}),e.jsx(D,{className:"p-0",children:d?e.jsx("div",{className:"p-4 space-y-2",children:Array.from({length:3}).map((l,p)=>e.jsx(Ce,{className:"h-8"},p))}):i.length===0?e.jsx("div",{className:"p-6 text-center text-muted-foreground text-sm",children:"Queue-এ কোনো order অপেক্ষমান নেই"}):e.jsxs(Qe,{children:[e.jsx(We,{children:e.jsxs(pe,{children:[e.jsx(k,{className:"text-xs",children:"Enqueued"}),e.jsx(k,{className:"text-xs",children:"Kind"}),e.jsx(k,{className:"text-xs",children:"Status"}),e.jsx(k,{className:"text-xs",children:"Order/Payload"})]})}),e.jsx(Ye,{children:i.slice(0,50).map(l=>e.jsxs(pe,{children:[e.jsx(C,{className:"text-xs whitespace-nowrap",children:_e(new Date(l.enqueued_at),"dd MMM, hh:mm a")}),e.jsx(C,{className:"text-xs",children:e.jsx(ue,{variant:"outline",className:"text-[10px]",children:l.kind})}),e.jsx(C,{className:"text-xs",children:e.jsx(ue,{variant:"outline",className:ee("text-[10px]",l.status==="in_flight"?"bg-blue-500/15 text-blue-700 border-blue-500/20":"bg-amber-500/15 text-amber-700 border-amber-500/20"),children:l.status==="in_flight"?"চলমান":"অপেক্ষমান"})}),e.jsx(C,{className:"text-xs font-mono truncate max-w-[200px]",children:l.payload?.order_id?`#${String(l.payload.order_id).slice(0,8)}`:l.payload?.phone||"—"})]},l.id))})]})})]}),e.jsxs(P,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(V,{className:"text-base flex items-center gap-2",children:[e.jsx(Je,{className:"h-4 w-4"}),"Order Summary (",F.total,")"]})}),e.jsx(D,{className:"p-0",children:a?e.jsx("div",{className:"p-4 space-y-2",children:Array.from({length:5}).map((l,p)=>e.jsx(Ce,{className:"h-10"},p))}):F.rows.length===0?e.jsx("div",{className:"p-8 text-center text-muted-foreground text-sm",children:"এই তারিখে কোনো call দেওয়া order নেই"}):e.jsxs(Qe,{children:[e.jsx(We,{children:e.jsxs(pe,{children:[e.jsx(k,{className:"text-xs",children:"Order"}),e.jsx(k,{className:"text-xs",children:"Phone"}),e.jsx(k,{className:"text-xs",children:"Attempts"}),e.jsx(k,{className:"text-xs",children:"Final Result"}),e.jsx(k,{className:"text-xs",children:"Total Duration"}),e.jsx(k,{className:"text-xs text-right",children:"মোট খরচ"}),e.jsx(k,{className:"text-xs",children:"Last Attempt"})]})}),e.jsx(Ye,{children:F.rows.slice(0,100).map(l=>{const p=fe(l.outcome),y=p.icon;return e.jsxs(pe,{children:[e.jsx(C,{className:"text-xs font-medium",children:l.orderNumber?`#${l.orderNumber}`:"—"}),e.jsx(C,{className:"text-xs font-mono",children:l.phone}),e.jsx(C,{className:"text-xs",children:e.jsxs(ue,{variant:"outline",className:"text-[10px] px-1 py-0 h-5",children:[l.attempts,l.maxAttempts?`/${l.maxAttempts}`:""]})}),e.jsx(C,{children:e.jsxs(ue,{variant:"outline",className:ee("text-[10px] gap-1 border",p.color),children:[e.jsx(y,{className:"h-3 w-3"}),p.label]})}),e.jsx(C,{className:"text-xs",children:De(l.totalDuration)}),e.jsxs(C,{className:"text-xs text-right",children:[x,l.totalCost.toFixed(2)]}),e.jsx(C,{className:"text-xs whitespace-nowrap",children:_e(new Date(l.lastAt),"dd MMM, hh:mm a")})]},l.orderId)})})]})})]})]}),e.jsxs(ce,{value:"calls",className:"space-y-4 mt-4",children:[e.jsx(js,{cards:z,isLoading:a}),e.jsx(At,{logs:R,isLoading:a,currency:x})]}),e.jsx(ce,{value:"logs",className:"space-y-4 mt-4",children:e.jsx(St,{logs:R,isLoading:a,currency:x})})]})]})}function At({logs:m,isLoading:x,currency:r}){const[s,v]=f.useState(0),[u,g]=f.useState(null),o=20,b=f.useMemo(()=>m.slice(s*o,(s+1)*o),[m,s]),j=Math.ceil(m.length/o);return e.jsxs(P,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(V,{className:"text-base flex items-center gap-2",children:[e.jsx(we,{className:"h-4 w-4"}),"কল লগ (",m.length,")"]})}),e.jsx(D,{className:"p-0",children:x?e.jsx("div",{className:"p-4 space-y-2",children:Array.from({length:5}).map((h,c)=>e.jsx(Ce,{className:"h-10"},c))}):m.length===0?e.jsx("div",{className:"p-8 text-center text-muted-foreground text-sm",children:"এই তারিখে কোনো কল লগ নেই"}):e.jsxs(e.Fragment,{children:[e.jsxs(Qe,{children:[e.jsx(We,{children:e.jsxs(pe,{children:[e.jsx(k,{className:"text-xs",children:"তারিখ/সময়"}),e.jsx(k,{className:"text-xs",children:"অর্ডার"}),e.jsx(k,{className:"text-xs",children:"ফোন"}),e.jsx(k,{className:"text-xs",children:"রেজাল্ট"}),e.jsx(k,{className:"text-xs",children:"DTMF"}),e.jsx(k,{className:"text-xs",children:"Duration"}),e.jsx(k,{className:"text-xs text-right",children:"খরচ"})]})}),e.jsx(Ye,{children:b.map(h=>{const c=Ct(h.dtmf_input,h.status),M=c.icon,X=h.orders?.order_number,R=!!(h.summary||h.transcript||Array.isArray(h.ai_actions)&&h.ai_actions.length),a=u===h.id;return e.jsxs(f.Fragment,{children:[e.jsxs(pe,{children:[e.jsx(C,{className:"text-xs whitespace-nowrap",children:_e(new Date(h.created_at),"dd MMM, hh:mm a")}),e.jsx(C,{className:"text-xs font-medium",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:X?`#${X}`:"—"}),h.attempt_number&&h.max_attempts&&e.jsxs(ue,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 font-normal",children:[h.attempt_number,"/",h.max_attempts]}),R&&e.jsxs(O,{variant:"ghost",size:"sm",className:"h-5 px-1.5 text-[10px] gap-1",onClick:()=>g(a?null:h.id),children:[e.jsx(Ze,{className:"h-3 w-3"}),"সারাংশ"]})]})}),e.jsx(C,{className:"text-xs font-mono",children:h.customer_phone}),e.jsx(C,{children:e.jsxs(ue,{variant:"outline",className:ee("text-[10px] gap-1 border",c.color),children:[e.jsx(M,{className:"h-3 w-3"}),c.label]})}),e.jsx(C,{className:"text-xs text-center font-mono",children:h.dtmf_input||"—"}),e.jsx(C,{className:"text-xs",children:h.duration?De(h.duration):"—"}),e.jsx(C,{className:"text-xs text-right",children:h.call_cost?`${r}${h.call_cost.toFixed(2)}`:"—"})]}),R&&a&&e.jsx(pe,{className:"bg-muted/30",children:e.jsxs(C,{colSpan:7,className:"text-xs space-y-2 py-3",children:[h.summary&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium mb-1",children:"কল সারাংশ"}),e.jsx("p",{className:"whitespace-pre-line text-muted-foreground",children:h.summary})]}),Array.isArray(h.ai_actions)&&h.ai_actions.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.ai_actions.map((i,d)=>e.jsxs(ue,{variant:"outline",className:"text-[10px]",children:[i.action,i?.result?.ok===!1?" (ব্যর্থ)":""]},d))}),h.transcript&&e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground",children:"সম্পূর্ণ কথোপকথন"}),e.jsx("pre",{className:"mt-1 whitespace-pre-wrap font-sans text-[11px] leading-5",children:h.transcript})]})]})},`${h.id}-conv`)]},h.id)})})]}),j>1&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-t border-border/40",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["পেজ ",s+1,"/",j]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>v(h=>Math.max(0,h-1)),disabled:s===0,children:"আগে"}),e.jsx(O,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>v(h=>Math.min(j-1,h+1)),disabled:s>=j-1,children:"পরে"})]})]})]})})]})}function St({logs:m,isLoading:x,currency:r}){const[s,v]=f.useState(""),[u,g]=f.useState(0),o=30,b=f.useMemo(()=>{const c=s.trim().toLowerCase();return c?m.filter(M=>(M.customer_phone||"").toLowerCase().includes(c)||(M.orders?.order_number||"").toString().toLowerCase().includes(c)||(M.call_sid||"").toLowerCase().includes(c)):m},[m,s]),j=f.useMemo(()=>b.slice(u*o,(u+1)*o),[b,u]),h=Math.ceil(b.length/o);return e.jsxs(P,{children:[e.jsxs(q,{className:"pb-2 flex-row items-center justify-between gap-2 space-y-0",children:[e.jsxs(V,{className:"text-base flex items-center gap-2",children:[e.jsx(Ze,{className:"h-4 w-4"}
1),"Activity Logs (",b.length,")"]}),e.jsx("input",{type:"text",value:s,onChange:c=>{v(c.target.value),g(0)},placeholder:"Phone/Order/SID search…",className:"h-8 px-2 text-xs rounded-md border border-border bg-background w-48"})]}),e.jsx(D,{className:"p-0",children:x?e.jsx("div",{className:"p-4 space-y-2",children:Array.from({length:6}).map((c,M)=>e.jsx(Ce,{className:"h-8"},M))}):b.length===0?e.jsx("div",{className:"p-8 text-center text-muted-foreground text-sm",children:"কোনো log পাওয়া যায়নি"}):e.jsxs(e.Fragment,{children:[e.jsxs(Qe,{children:[e.jsx(We,{children:e.jsxs(pe,{children:[e.jsx(k,{className:"text-xs",children:"Timestamp"}),e.jsx(k,{className:"text-xs",children:"Phone"}),e.jsx(k,{className:"text-xs",children:"Order"}),e.jsx(k,{className:"text-xs",children:"Attempt"}),e.jsx(k,{className:"text-xs",children:"Status"}),e.jsx(k,{className:"text-xs",children:"DTMF"}),e.jsx(k,{className:"text-xs",children:"Duration"}),e.jsx(k,{className:"text-xs",children:"Cost"}),e.jsx(k,{className:"text-xs",children:"Call SID"}),e.jsx(k,{className:"text-xs",children:"Error"})]})}),e.jsx(Ye,{children:j.map(c=>e.jsxs(pe,{children:[e.jsx(C,{className:"text-[11px] whitespace-nowrap font-mono",children:_e(new Date(c.created_at),"dd MMM yyyy, HH:mm:ss")}),e.jsx(C,{className:"text-[11px] font-mono",children:c.customer_phone}),e.jsx(C,{className:"text-[11px] font-medium",children:c.orders?.order_number?`#${c.orders.order_number}`:"—"}),e.jsx(C,{className:"text-[11px]",children:c.attempt_number?`${c.attempt_number}${c.max_attempts?`/${c.max_attempts}`:""}`:"—"}),e.jsx(C,{className:"text-[11px]",children:e.jsx(ue,{variant:"outline",className:"text-[10px]",children:c.status||"—"})}),e.jsx(C,{className:"text-[11px] text-center font-mono",children:c.dtmf_input||"—"}),e.jsx(C,{className:"text-[11px]",children:c.duration?De(c.duration):"—"}),e.jsx(C,{className:"text-[11px]",children:c.call_cost?`${r}${c.call_cost.toFixed(2)}`:"—"}),e.jsx(C,{className:"text-[10px] font-mono text-muted-foreground truncate max-w-[140px]",title:c.call_sid||"",children:c.call_sid?c.call_sid.slice(0,14)+"…":"—"}),e.jsx(C,{className:"text-[10px] text-destructive truncate max-w-[180px]",title:c.error_message||"",children:c.error_message||"—"})]},c.id))})]}),h>1&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-t border-border/40",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["পেজ ",u+1,"/",h]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>g(c=>Math.max(0,c-1)),disabled:u===0,children:"আগে"}),e.jsx(O,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>g(c=>Math.min(h-1,c+1)),disabled:u>=h-1,children:"পরে"})]})]})]})})]})}const bs=[{key:"ads_automation",label:"Ads Automation",icon:dt,description:"Automatically fetch ad spend from Meta Ads and track spend by product, campaign, and date.",manualNote:"When OFF, ad spend and product-wise costs must be entered manually in Reports."},{key:"orders_automation",label:"Orders Automation",icon:mt,description:"Automatically track orders per product, cancellations, and shipments from existing order data.",manualNote:"When OFF, order quantities and statuses must be entered manually in Reports."},{key:"courier_automation",label:"Courier Automation",icon:xt,description:"Automatically sync delivery, return, and lost data from the courier integration.",manualNote:"When OFF, delivered/returned/lost quantities and courier costs must be entered manually."},{key:"reports_automation",label:"Reports & Analytics Automation",icon:Ze,description:"Auto-generate daily reports and profit calculations from connected data sources.",manualNote:"When OFF, reports must be created manually with manual data entry."}],Tt=[{value:"natalie-promo",label:"Natalie",style:"প্রমো স্টাইল",tag:"Gen2"},{value:"natalie-conversational-bn",label:"Natalie",style:"বাংলা কথোপকথন",tag:"Gen2 · bn-IN"},{value:"miles-angry-bn",label:"Miles",style:"বাংলা পুরুষ (জোরালো)",tag:"Gen2 · bn-IN"},{value:"anwesha-conversational",label:"Anwesha",style:"কথোপকথন মহিলা",tag:"Gen2"},{value:"natalie-angry-hi",label:"Natalie",style:"হিন্দি (জোরালো)",tag:"Gen2 · hi-IN"},{value:"Abhik",label:"Abhik",style:"পুরুষ",tag:"লেগাসি"},{value:"Lia",label:"Lia",style:"মহিলা",tag:"লেগাসি"},{value:"Zion",label:"Zion",style:"পুরুষ",tag:"লেগাসি"}],ts="ধন্যবাদ আপনার অর্ডারের জন্য। আপনার অর্ডারটি সফলভাবে গ্রহণ করা হয়েছে। অনুগ্রহ করে অর্ডারটি নিশ্চিত করতে কনফার্ম বাটনে ক্লিক করুন।",as="ধন্যবাদ! আপনার অর্ডারটি সফলভাবে নিশ্চিত করা হয়েছে। শীঘ্রই আপনার পণ্য ডেলিভারি করা হবে।",rs="আপনার অর্ডারটি হোল্ডে রাখা হয়েছে। আমাদের টিম শীঘ্রই আপনার সাথে যোগাযোগ করবে।",ns="আপনাকে আমাদের কাস্টমার সার্ভিসে কানেক্ট করা হচ্ছে। অনুগ্রহ করে অপেক্ষা করুন।",ls="দুঃখিত, এই মুহূর্তে আমাদের কাস্টমার সার্ভিস ব্যস্ত আছে। অনুগ্রহ করে কিছুক্ষণ পর আবার চেষ্টা করুন।";function Te({label:m,audioUrl:x,fieldKey:r,businessId:s,storagePath:v,onUploaded:u,isUpdating:g}){const{hasRole:o}=ms(),b=o("super_admin"),[j,h]=f.useState(!1),[c,M]=f.useState(!1),[X,R]=f.useState(!1),a=f.useRef(null),i=f.useRef([]),d=f.useRef(null),A=f.useRef(null),F=async(l,p)=>{h(!0);try{const y=`${v}/${r}.${p}`,{error:$}=await he.storage.from("ai-call-audio").upload(y,l,{contentType:l.type,upsert:!0});if($)throw $;const{data:W}=he.storage.from("ai-call-audio").getPublicUrl(y);u(W.publicUrl),Q.success(`${m} আপলোড সফল`)}catch(y){Ge(b,"আপলোড ব্যর্থ",y.message)}finally{h(!1)}},ke=async l=>{window.lamejs||await new Promise((U,G)=>{const Y=document.createElement("script");Y.src="https://cdn.jsdelivr.net/npm/[email protected]/lame.min.js",Y.onload=()=>U(),Y.onerror=()=>G(new Error("lamejs লোড করা যায়নি")),document.head.appendChild(Y)});const p=window.lamejs,y=l.sampleRate,$=1,W=128,se=l.getChannelData(0),H=se.length,te=new Int16Array(H);for(let U=0;U<H;U++){const G=Math.max(-1,Math.min(1,se[U]));te[U]=G<0?G*32768:G*32767}const ae=new p.Mp3Encoder($,y,W),L=[],re=1152;for(let U=0;U<te.length;U+=re){const G=te.subarray(U,U+re),Y=ae.encodeBuffer(G);Y.length>0&&L.push(new Uint8Array(Y))}const E=ae.flush();return E.length>0&&L.push(new Uint8Array(E)),new Blob(L,{type:"audio/mpeg"})},Ne=async l=>{const p=l.target.files?.[0];if(!p)return;
1if((p.name.split(".").pop()?.toLowerCase()||"")==="mp3"||p.type==="audio/mpeg"){await F(p,"mp3"),A.current&&(A.current.value="");return}Q.error("শুধু MP3 ফাইল আপলোড করুন। অন্য ফরম্যাট সাপোর্টেড নয়।"),A.current&&(A.current.value="")},Me=async()=>{try{const l=await navigator.mediaDevices.getUserMedia({audio:!0}),p=new MediaRecorder(l);i.current=[],p.ondataavailable=y=>{y.data.size>0&&i.current.push(y.data)},p.onstop=async()=>{l.getTracks().forEach($=>$.stop());const y=new Blob(i.current,{type:"audio/webm"});try{Q.info("MP3 তে কনভার্ট হচ্ছে...");const $=await y.arrayBuffer(),W=new AudioContext,se=await W.decodeAudioData($),H=await ke(se);await W.close(),await F(H,"mp3")}catch($){console.error("MP3 conversion failed:",$),Ge(b,"MP3 কনভার্সন ব্যর্থ")}},a.current=p,p.start(),M(!0)}catch{Q.error("মাইক্রোফোন অ্যাক্সেস করা যায়নি")}},z=()=>{a.current?.stop(),M(!1)},fe=()=>{if(!x)return;if(X&&d.current){d.current.pause(),R(!1);return}const l=new Audio(x+"?t="+Date.now());l.onended=()=>R(!1),d.current=l,R(!0),l.play().catch(()=>R(!1))};return e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-lg bg-muted/50 border",children:[e.jsx("span",{className:"text-sm font-medium min-w-0 flex-1",children:m}),x&&e.jsx(O,{variant:"ghost",size:"sm",onClick:fe,className:"h-8 w-8 p-0 shrink-0",children:e.jsx(cs,{className:`h-3.5 w-3.5 ${X?"text-primary animate-pulse":""}`})}),x&&e.jsx("span",{className:"text-[10px] text-emerald-600 shrink-0",children:"✓"}),e.jsx("input",{ref:A,type:"file",accept:"audio/mpeg,.mp3",className:"hidden",onChange:Ne}),e.jsx(O,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs shrink-0",disabled:j||c||g,onClick:()=>A.current?.click(),children:j?e.jsx(ge,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ut,{className:"h-3.5 w-3.5"})}),e.jsx(O,{variant:c?"destructive":"outline",size:"sm",className:"h-8 px-2 text-xs shrink-0",disabled:j||g,onClick:c?z:Me,children:c?e.jsx(ht,{className:"h-3.5 w-3.5"}):e.jsx(pt,{className:"h-3.5 w-3.5"})})]})}function Ir({defaultTab:m="automation"}){const[x,r]=f.useState(m),{settings:s,isLoading:v,toggleSetting:u,updateSetting:g,isUpdating:o}=Rs(),{hasRole:b,currentBusinessId:j}=ms();f.useEffect(()=>{r(m)},[m]);const h=_s(),c=b("super_admin"),M=[s.ads_automation,s.orders_automation,s.courier_automation,s.reports_automation].filter(Boolean).length;f.useState(null);const[X,R]=f.useState({}),a=Object.keys(X).length>0,i=t=>{R(n=>({...n,...t}))},d=(t,n)=>t in X?X[t]:n,A=()=>{a&&(g(X),R({}),Q.success("সেটিংস সেভ করা হয়েছে ✅"))},[F,ke]=f.useState(null),[Ne,Me]=f.useState(!1),z=f.useRef(null),[fe,l]=f.useState(null),[p,y]=f.useState(null),[$,W]=f.useState({}),[se,H]=f.useState(!1),te=new Date().toISOString().slice(0,10),ae=s.audio_gen_date===te?s.audio_gen_count:0,L=s.audio_gen_locked,re=Math.max(0,3-ae),E=d("call_mode",s.call_mode),U=E==="browser"||E==="both",G=E==="phone"||E==="both",Y=async(t,n,I)=>{if(!j)return;if(L){H(!0);return}if(!Ne&&ae>=3){H(!0);return}const N=t==="phone",w=`${t}-${n}`;ke(w);try{const K=N?d("phone_murf_voice_id",s.phone_murf_voice_id||"natalie-promo"):d("murf_voice_id",s.murf_voice_id||"natalie-promo"),{data:J,error:ne}=await Fs("murf-tts",{body:{mode:"generateSingle",target:t,businessId:j,voiceId:K,audioKey:n,text:I}});if(ne)throw ne;if(J?.error)throw new Error(J.error);if(!Ne){const me=ae+1;await he.from("automation_settings").update({audio_gen_count:me,audio_gen_date:te}).eq("business_id",j),Me(!0)}h.invalidateQueries({queryKey:["automation-settings",j]}),Q.success(`${n} অডিও সফলভাবে জেনারেট হয়েছে!`)}catch(K){Ge(c,"অডিও জেনারেট হতে সমস্যা হচ্ছে",K.message||"Unknown error")}finally{ke(null)}},je=async t=>{if(fe===`preview-${t}`){z.current&&z.current.pause(),l(null);return}if($[t]){z.current&&z.current.pause();const n=new Audio($[t]);n.onended=()=>l(null),n.onerror=()=>{l(null),Q.error("অডিও প্লে করতে সমস্যা")},z.current=n,l(`preview-${t}`),n.play().catch(()=>l(null));return}y(t);try{const n=await fetch("https://ijnixydejuebjihtvjix.supabase.co/functions/v1/murf-tts",{method:"POST",headers:{"Content-Type":"application/json",apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imlqbml4eWRlanVlYmppaHR2aml4Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzA3MDgyMDUsImV4cCI6MjA4NjI4NDIwNX0.ujoWAX_0SWFi0rpjN0N4pQniLfdGxKyv1oYi5zN_bUY"},body:JSON.stringify({text:"আসসালামু আলাইকুম, আপনার অর্ডারের জন্য ধন্যবাদ।",voiceId:t})});if(!n.ok)throw new Error("Preview generation failed");const I=await n.blob(),N=URL.createObjectURL(I);W(K=>({...K,[t]:N})),z.current&&z.current.pause();const w=new Audio(N);w.onended=()=>l(null),w.onerror=()=>{l(null),Q.error("অডিও প্লে করতে সমস্যা")},z.current=w,l(`preview-${t}`),w.play().catch(()=>l(null))}catch(n){Ge(c,"প্রিভিউ জেনারেট হতে সমস্যা হচ্ছে",n.message||"Unknown")}finally{y(null)}},_=(t,n)=>{if(!t){Q.error("অডিও এখনো জেনারেট হয়নি");return}if(z.current&&z.current.pause(),fe===n){l(null);return}
1const I=new Audio(t+"?t="+Date.now());I.onended=()=>l(null),I.onerror=()=>{l(null),Q.error("অডিও প্লে করতে সমস্যা")},z.current=I,l(n),I.play().catch(()=>l(null))},S=t=>{const n=t==="phone",I=n?"phone_murf_voice_id":"murf_voice_id",N=d(I,n?s.phone_murf_voice_id:s.murf_voice_id);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(T,{children:"🎙️ ভয়েস সিলেক্ট করুন"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:Tt.map(w=>{const K=(N||"natalie-promo")===w.value,J=fe===`preview-${w.value}`,ne=p===w.value;return e.jsxs("div",{onClick:()=>i({[I]:w.value}),className:`relative flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-all ${K?"border-primary bg-primary/5 ring-1 ring-primary/20":"border-border bg-card hover:border-primary/40"}`,children:[K&&e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(He,{className:"h-4 w-4 text-primary"})}),e.jsx(O,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 shrink-0",disabled:ne,onClick:me=>{me.stopPropagation(),je(w.value)},children:ne?e.jsx(ge,{className:"h-4 w-4 animate-spin"}):J?e.jsx(ws,{className:"h-3.5 w-3.5 text-primary"}):e.jsx(Cs,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium leading-tight",children:w.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:w.style})]}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0",children:w.tag})]},w.value)})})]})},be=t=>{const n=t==="phone",I=n?"phone_voice_script":"voice_script",N=n?"phone_voice_confirm_text":"voice_confirm_text",w=n?"phone_voice_cancel_text":"voice_cancel_text",K=n?"phone_voice_connecting_text":"voice_connecting_text",J=n?"phone_voice_forward_miss_text":"voice_forward_miss_text",ne=d(I,n?s.phone_voice_script:s.voice_script),me=d(N,n?s.phone_voice_confirm_text:s.voice_confirm_text),Re=d(w,n?s.phone_voice_cancel_text:s.voice_cancel_text),Fe=d(K,n?s.phone_voice_connecting_text:s.voice_connecting_text),Oe=d(J,n?s.phone_voice_forward_miss_text:s.voice_forward_miss_text);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"📢 মূল স্ক্রিপ্ট (অর্ডারের পর শুনবে)"}),e.jsx(de,{value:ne??ts,onChange:B=>i({[I]:B.target.value}),placeholder:ts,rows:3,disabled:o,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"✅ কনফার্ম করলে শুনবে"}),e.jsx(de,{value:me??as,onChange:B=>i({[N]:B.target.value}),placeholder:as,rows:2,disabled:o,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"❌ ক্যান্সেল / রেসপন্স না করলে শুনবে"}),e.jsx(de,{value:Re??rs,onChange:B=>i({[w]:B.target.value}),placeholder:rs,rows:2,disabled:o,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"🤝 কাস্টমার প্রতিনিধির সাথে কথা বলতে চাইলে শুনবে"}),e.jsx(de,{value:Fe??ns,onChange:B=>i({[K]:B.target.value}),placeholder:ns,rows:2,disabled:o,className:"text-sm"})]}),n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"📞 ফরওয়ার্ড কল মিস (সাপোর্ট কল না ধরলে শুনবে)"}),e.jsx(de,{value:Oe??ls,onChange:B=>i({[J]:B.target.value}),placeholder:ls,rows:2,disabled:o,className:"text-sm"})]})]})},Ae=t=>{const n=t==="phone",I=n?"phone_voice_main_audio_url":"voice_main_audio_url",N=n?"phone_voice_confirm_audio_url":"voice_confirm_audio_url",w=n?"phone_voice_cancel_audio_url":"voice_cancel_audio_url",K=n?"phone_voice_connecting_audio_url":"voice_connecting_audio_url",J=n?"phone_voice_forward_miss_audio_url":"voice_forward_miss_audio_url",ne=d(I,n?s.phone_voice_main_audio_url:s.voice_main_audio_url),me=d(N,n?s.phone_voice_confirm_audio_url:s.voice_confirm_audio_url),Re=d(w,n?s.phone_voice_cancel_audio_url:s.voice_cancel_audio_url),Fe=d(K,n?s.phone_voice_connecting_audio_url:s.voice_connecting_audio_url),Oe=d(J,n?s.phone_voice_forward_miss_audio_url:s.voice_forward_miss_audio_url),B=n?"phone_voice_script":"voice_script",le=n?"phone_voice_confirm_text":"voice_confirm_text",As=n?"phone_voice_cancel_text":"voice_cancel_text",Ss=n?"phone_voice_connecting_text":"voice_connecting_text",Ts=n?"phone_voice_forward_miss_text":"voice_forward_miss_text",Ps=[{audioKey:"main",label:"📢 মূল স্ক্রিপ্ট",url:ne,text:d(B,n?s.phone_voice_script:s.voice_script)||ts},{audioKey:"confirm",label:"✅ কনফার্ম",url:me,text:d(le,n?s.phone_voice_confirm_text:s.voice_confirm_text)||as},{audioKey:"cancel",label:"❌ ক্যান্সেল",url:Re,text:d(As,n?s.phone_voice_cancel_text:s.voice_cancel_text)||rs},{audioKey:"connecting",label:n?"🔗 কানেক্টিং (০ প্রেসে)":"🤝 কাস্টমার প্রতিনিধি",url:Fe,text:d(Ss,n?s.phone_voice_connecting_text:s.voice_connecting_text)||ns},...n?[{audioKey:"forward_miss",label:"📞 ফরওয়ার্ড কল মিস",url:Oe,text:d(Ts,n?s.phone_voice_forward_miss_text:s.voice_forward_miss_text)||ls}]:[]];return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`flex items-center gap-2 rounded-lg px-3 py-2 text-xs ${L?"bg-destructive/10 border border-destructive/20 text-destructive":re<=1?"bg-amber-500/10 border border-amber-500/20 text-amber-700 dark:text-amber-400":"bg-muted border text-muted-foreground"}`,children:[e.jsx(Ve,{className:"h-3.5 w-3.5 shrink-0"}),L?e.jsx("span",{children:"অডিও জেনারেশন লক করা আছে।"}):Ne?e.jsx("span",{children:"এই সেশনে আর জেনারেট করতে পারবেন"}):e.jsxs("span",{children:["আজ আর ",re," বার জেনারেট করতে পারবেন (দৈনিক সর্বোচ্চ ৩ বার)"]})]}),e.jsx("div",{className:"grid gap-2",children:Ps.map(xe=>{const Ue=`${t}-${xe.audioKey}`,Ds=F===Ue;return e.jsxs("div",{className:"flex items-center gap-2 p-2.5 rounded-lg bg-muted/50 border",children:[xe.url&&e.jsx(O,{variant:"ghost",size:"sm",onClick:()=>_(xe.url||null,Ue),className:"h-8 w-8 p-0 shrink-0",children:e.jsx(cs,{className:`h-3.5 w-3.5 ${fe===Ue?"text-primary animate-pulse":""}`})}),e.jsx("span",{className:"text-sm flex-1 min-w-0",children:xe.label}),xe.url&&e.jsx("span",{className:"text-[10px] text-emerald-600 shrink-0",children:"✓ Ready"}),e.jsx(O,{variant:xe.url?"outline":"default",size:"sm",className:"h-8 px-3 text-xs shrink-0",disabled:F!==null||o||L,onClick:()=>Y(t,xe.audioKey,xe.text),children:Ds?e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"h-3.5 w-3.5 mr-1 animate-spin"}),"জেনারেট হচ্ছে..."]}):xe.url?e.jsxs(e.Fragment,{children:[e.jsx(gt,{className:"h-3.5 w-3.5 mr-1"}),"রি-জেনারেট"]}):e.jsxs(e.Fragment,{children:[e.jsx(cs,{className:"h-3.5 w-3.5 mr-1"}),"জেনারেট"]})})]},Ue)})})]})},Se=t=>{const n=t==="phone",I=n?"phone_voice_main_audio_url":"voice_main_audio_url",N=n?"phone_voice_confirm_audio_url":"voice_confirm_audio_url",w=n?"phone_voice_cancel_audio_url":"voice_cancel_audio_url",K=n?"phone_voice_connecting_audio_url":"voice_connecting_audio_url",J=n?"phone_voice_forward_miss_audio_url":"voice_forward_miss_audio_url",ne=d(I,n?s.phone_voice_main_audio_url:s.voice_main_audio_url),me=d(N,n?s.phone_voice_confirm_audio_url:s.voice_confirm_audio_url),Re=d(w,n?s.phone_voice_cancel_audio_url:s.voice_cancel_audio_url),Fe=d(K,n?s.phone_voice_connecting_audio_url:s.voice_connecting_audio_url),Oe=d(J,n?s.phone_voice_forward_miss_audio_url:s.voice_forward_miss_audio_url),B=`${j}/${n?"phone-custom":"browser-custom"}`;return e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"📁 অডিও আপলোড বা রেকর্ড করুন"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"প্রতিটি অডিও আলাদাভাবে আপলোড বা রেকর্ড করুন"}
1),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mb-2",children:"⚠️ অডিও অবশ্যই MP3 ফরম্যাটে হতে হবে। রেকর্ড করলে অটোমেটিক MP3 হবে।"}),e.jsx(Te,{label:"📢 মূল স্ক্রিপ্ট",audioUrl:ne,fieldKey:"main",businessId:j,storagePath:B,onUploaded:le=>i({[I]:le}),isUpdating:o}),e.jsx(Te,{label:"✅ কনফার্ম",audioUrl:me,fieldKey:"confirm",businessId:j,storagePath:B,onUploaded:le=>i({[N]:le}),isUpdating:o}),e.jsx(Te,{label:"❌ ক্যান্সেল",audioUrl:Re,fieldKey:"cancel",businessId:j,storagePath:B,onUploaded:le=>i({[w]:le}),isUpdating:o}),e.jsx(Te,{label:n?"🔗 কানেক্টিং (০ প্রেসে বাজবে)":"🤝 কাস্টমার প্রতিনিধি (কথা বলতে চাইলে বাজবে)",audioUrl:Fe,fieldKey:"connecting",businessId:j,storagePath:B,onUploaded:le=>i({[K]:le}),isUpdating:o}),n&&e.jsx(Te,{label:"📞 ফরওয়ার্ড কল মিস (সাপোর্ট না ধরলে বাজবে)",audioUrl:Oe,fieldKey:"forward_miss",businessId:j,storagePath:B,onUploaded:le=>i({[J]:le}),isUpdating:o})]})};return e.jsxs(Ms,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10",children:e.jsx(Be,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:x==="ai-call"?"AI Calling":x==="ai-agent"?"AI Agent":"Profit Automation"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x==="ai-call"?"অর্ডারের পর কাস্টমারকে AI ভয়েসে কনফার্ম করুন":x==="ai-agent"?"AI Agent-এর ক্ষমতা, কথার ধরন ও ট্রেনিং ম্যানেজ করুন":"Control which modules use automated data vs manual entry"})]})]}),e.jsxs(os,{value:x,onValueChange:r,className:"w-full",children:[e.jsxs(is,{className:"hidden",children:[e.jsxs(ie,{value:"automation",children:[e.jsx(Be,{className:"h-4 w-4 mr-1.5"}),"Automation"]}),e.jsxs(ie,{value:"ai-call",children:[e.jsx(Ie,{className:"h-4 w-4 mr-1.5"}),"AI Call"]}),e.jsxs(ie,{value:"ai-agent",children:[e.jsx(vs,{className:"h-4 w-4 mr-1.5"}),"AI Agent"]})]}),e.jsxs(ce,{value:"automation",className:"space-y-4 mt-4",children:[e.jsxs(P,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsx(V,{className:"text-base",children:"Automation Status"}),e.jsx(Z,{children:M===0?"All modules are running in manual mode":M===4?"Full automation is enabled across all modules":`${M} of 4 modules are automated`})]}),e.jsx(D,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:bs.map(t=>{const n=s[t.key];return e.jsxs("div",{className:`flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium ${n?"bg-emerald-500/10 text-emerald-600":"bg-muted text-muted-foreground"}`,children:[e.jsx(t.icon,{className:"h-3.5 w-3.5"}),t.label.replace(" Automation","")]},t.key)})})})]}),v?e.jsx("div",{className:"space-y-4",children:[1,2,3,4].map(t=>e.jsx(Ce,{className:"h-24 w-full rounded-xl"},t))}):e.jsx("div",{className:"grid gap-4",children:bs.map(t=>e.jsx(P,{children:e.jsxs(D,{className:"p-4",children:[e.jsx(ft,{label:t.label,enabled:s[t.key],onToggle:n=>u(t.key,n),isUpdating:o,description:s[t.key]?t.description:t.manualNote}),!s[t.key]&&e.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-lg bg-amber-500/5 border border-amber-500/20 px-3 py-2",children:[e.jsx(Ve,{className:"h-4 w-4 text-amber-500 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:t.manualNote})]})]})},t.key))}),e.jsx(P,{children:e.jsxs(D,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`flex h-10 w-10 items-center justify-center rounded-xl ${s.finance_automation?"bg-primary/15 text-primary":"bg-muted text-muted-foreground"}`,children:e.jsx(Be,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-bold",children:"Finance Automation"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Courier withdraw → bank balance-এ auto-add, Salary → bank balance থেকে auto-deduct"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider ${s.finance_automation?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"}`,children:s.finance_automation?"ON":"OFF"}),e.jsx(ve,{checked:s.finance_automation,onCheckedChange:t=>u("finance_automation",t),disabled:o})]})]}),!s.finance_automation&&e.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-lg bg-amber-500/5 border border-amber-500/20 px-3 py-2",children:[e.jsx(Ve,{className:"h-4 w-4 text-amber-500 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:"Finance Automation বন্ধ থাকলে Salary ও Courier Withdraw শুধু রেকর্ড হবে, bank balance affect হবে না।"})]})]})}),e.jsxs(P,{children:[e.jsx(q,{className:"pb-3",children:e.jsx(V,{className:"text-base",children:"Automation Depen
1dencies"})}),e.jsxs(D,{className:"text-sm text-muted-foreground space-y-2",children:[e.jsxs("p",{children:["• ",e.jsx("strong",{children:"Reports Automation"})," works best when Ads, Orders, and Courier are also automated."]}),e.jsxs("p",{children:["• ",e.jsx("strong",{children:"Estimated Profit"})," requires Ads + Orders data (auto or manual)."]}),e.jsxs("p",{children:["• ",e.jsx("strong",{children:"Final Profit"})," requires Courier delivery data (auto or manual)."]}),e.jsxs("p",{children:["• ",e.jsx("strong",{children:"Finance Automation"})," controls whether Salary & Courier Withdraw affect bank balance."]}),e.jsxs("p",{children:["• Values are clearly labeled as ",e.jsx("span",{className:"text-emerald-600 font-medium",children:"Auto"})," or ",e.jsx("span",{className:"text-muted-foreground font-medium",children:"Manual"})," throughout the app."]})]})]})]}),e.jsxs(ce,{value:"ai-call",className:"space-y-4 mt-4",children:[e.jsx("div",{className:"flex justify-end sticky top-0 z-10",children:e.jsxs(O,{onClick:A,disabled:o,size:"lg",className:"shadow-lg shadow-primary/25 px-8",children:[o?e.jsx(ge,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ys,{className:"h-4 w-4 mr-2"}),"সব সেটিংস সেভ করুন"]})}),e.jsx(P,{className:s.order_voice_confirm?"border-primary/30 bg-primary/[0.02]":"",children:e.jsx(D,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`flex h-10 w-10 items-center justify-center rounded-xl ${s.order_voice_confirm?"bg-primary/15 text-primary":"bg-muted text-muted-foreground"}`,children:e.jsx(Ie,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-bold",children:"AI Call"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"অর্ডারের পর কাস্টমারকে AI ভয়েসে কনফার্ম করাবে"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider ${s.order_voice_confirm?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"}`,children:s.order_voice_confirm?"ON":"OFF"}),e.jsx(ve,{checked:s.order_voice_confirm,onCheckedChange:t=>u("order_voice_confirm",t),disabled:o})]})]})})}),e.jsxs(os,{defaultValue:"phone",className:"w-full",children:[e.jsxs(is,{className:"w-full grid grid-cols-4 h-auto p-1",children:[e.jsxs(ie,{value:"phone",className:"text-xs gap-1.5 py-2 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-sm data-[state=active]:font-semibold",children:[e.jsx(we,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Real Phone Call"}),e.jsx("span",{className:"sm:hidden",children:"Phone"})]}),e.jsxs(ie,{value:"browser",className:"text-xs gap-1.5 py-2 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-sm data-[state=active]:font-semibold",children:[e.jsx(ss,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Browser Popup"}),e.jsx("span",{className:"sm:hidden",children:"Browser"})]}),e.jsxs(ie,{value:"activities",className:"text-xs gap-1.5 py-2 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-sm data-[state=active]:font-semibold",children:[e.jsx(ks,{className:"h-3.5 w-3.5"}),"Activities"]}),e.jsxs(ie,{value:"settings",className:"text-xs gap-1.5 py-2 data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=active]:shadow-sm data-[state=active]:font-semibold",children:[e.jsx(gs,{className:"h-3.5 w-3.5"}),"Settings"]})]}),e.jsx(ce,{value:"browser",className:"space-y-4 mt-4",children:e.jsxs(P,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-blue-500/10",children:e.jsx(ss,{className:"h-4.5 w-4.5 text-blue-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(V,{className:"text-base",children:"🔊 Browser Popup সেটিংস"}),e.jsx(Z,{children:"Browser popup-এর ভয়েস, স্ক্রিপ্ট ও অডিও কনফিগার করুন"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"text-xs",children:"সক্রিয়"}),e.jsx(ve,{checked:U,onCheckedChange:t=>{i(t?{call_mode:G?"both":"browser"}:{call_mode:G?"phone":"off"})},disabled:o})]})]})}),e.jsxs(D,{className:"space-y-5 pt-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{className:"text-sm",children:"অডিও সোর্স:"}),e.jsxs("div",{className:"flex rounded-lg border overflow-hidden",children:[e.jsx("button",{className:`px-3 py-1.5 text-xs font-medium transition-colors ${d("browser_voice_source",s.browser_voice_source)==="ai"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"}`,onClick:()=>i({browser_voice_source:"ai"}),children:"🤖 AI Voice"}),e.jsx("button",{className:`px-3 py-1.5 text-xs font-medium transition-colors ${d("browser_voice_source",s.browser_voice_source)==="custom"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"}`,onClick:()=>i({browser_voice_source:"custom"}),children:"📁 Custom Upload"})]})]}),d("browser_voice_source",s.browser_voice_source)==="ai"?e.jsxs(e.Fragment,{children:[S("browser"),be("browser"),Ae("browser")]}):Se("browser"),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"সাপোর্ট নম্বর (কল স্ক্রিনে দেখাবে)"}),e.jsx(oe,{placeholder:"01XXXXXXXXX",value:d("voice_support_phone",s.voice_support_phone)||"",onChange:t=>i({voice_support_phone:t.target.value||null}),disabled:o,className:"max-w-xs"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"না দিলে ওয়েবসাইটের কন্ট্যাক্ট নম্বর ব্যবহার হবে"})]}),e.jsx(yt,{selectedRingtone:d("call_ringtone",s.call_ringtone)||"classic",onSelect:t=>i({call_ringtone:t}),isUpdating:o})]})]})}
1),e.jsxs(ce,{value:"phone",className:"space-y-4 mt-4",children:[e.jsxs(P,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-emerald-500/10",children:e.jsx(we,{className:"h-4.5 w-4.5 text-emerald-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(V,{className:"text-base",children:"📞 Real Phone Call সেটিংস"}),e.jsx(Z,{children:"Real phone call-এর ভয়েস, স্ক্রিপ্ট ও অডিও কনফিগার করুন"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"text-xs",children:"সক্রিয়"}),e.jsx(ve,{checked:G,onCheckedChange:t=>{i(t?{call_mode:U?"both":"phone"}:{call_mode:U?"browser":"off"})},disabled:o})]})]})}),e.jsxs(D,{className:"space-y-5 pt-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(T,{className:"text-sm",children:"অডিও সোর্স:"}),e.jsxs("div",{className:"flex rounded-lg border overflow-hidden",children:[e.jsx("button",{className:`px-3 py-1.5 text-xs font-medium transition-colors ${d("phone_voice_source",s.phone_voice_source)==="ai"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"}`,onClick:()=>i({phone_voice_source:"ai"}),children:"🤖 AI Voice"}),e.jsx("button",{className:`px-3 py-1.5 text-xs font-medium transition-colors ${d("phone_voice_source",s.phone_voice_source)==="custom"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-accent"}`,onClick:()=>i({phone_voice_source:"custom"}),children:"📁 Custom Upload"})]})]}),d("phone_voice_source",s.phone_voice_source)==="ai"?e.jsxs(e.Fragment,{children:[S("phone"),be("phone"),Ae("phone")]}):Se("phone"),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"সাপোর্ট নম্বর (0 চাপলে এই নম্বরে ফরোয়ার্ড হবে)"}),e.jsx(oe,{placeholder:"01XXXXXXXXX",value:d("voice_support_phone",s.voice_support_phone)||"",onChange:t=>i({voice_support_phone:t.target.value||null}),disabled:o,className:"max-w-xs"})]})]})]}),e.jsxs(P,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-indigo-500/10",children:e.jsx(we,{className:"h-4 w-4 text-indigo-600"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(V,{className:"text-base",children:"🙏 Thank You পেজ কল কনফার্মেশন"}),e.jsx(Z,{children:'কাস্টমার Thank You পেজে "কলে কনফার্ম" চাপলে এই ভয়েসে কল যাবে (১ = কনফার্ম, ২ = হোল্ড, ০ = প্রতিনিধি)'})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"text-xs",children:"সক্রিয়"}),e.jsx(ve,{checked:!!d("ty_call_enabled",s.ty_call_enabled),onCheckedChange:t=>i({ty_call_enabled:t}),disabled:o})]})]})}),e.jsxs(D,{className:"space-y-2 pt-0",children:[e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:"⚠️ অডিও অবশ্যই MP3 হতে হবে। কোনো স্লট খালি রাখলে Real Phone Call-এর ঐ অডিওটাই ব্যবহার হবে।"}),[["ty_voice_main_audio_url","📢 মূল ভয়েস (কল ধরার সাথে সাথে)","ty-main"],["ty_voice_confirm_audio_url","✅ ১ চাপলে (কনফার্ম)","ty-confirm"],["ty_voice_hold_audio_url","⏸️ ২ চাপলে (হোল্ড)","ty-hold"],["ty_voice_connecting_audio_url","🔗 ০ চাপলে (প্রতিনিধির সাথে কানেক্ট)","ty-connecting"],["ty_voice_forward_miss_audio_url","📞 প্রতিনিধি না ধরলে","ty-miss"]].map(([t,n,I])=>e.jsx(Te,{label:n,audioUrl:d(t,s[t]),fieldKey:I,businessId:j,storagePath:`${j}/thankyou-confirm`,onUploaded:N=>i({[t]:N}),isUpdating:o},t))]})]}),e.jsx($s,{hasRole:b,currentBusinessId:j})]}
1),e.jsx(ce,{value:"activities",className:"space-y-4 mt-4",children:j&&e.jsx(kt,{businessId:j})}),e.jsxs(ce,{value:"settings",className:"space-y-4 mt-4",children:[e.jsxs(P,{children:[e.jsx(q,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-muted",children:e.jsx(gs,{className:"h-4.5 w-4.5 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(V,{className:"text-base",children:"⚙️ কল সেটিংস"}),e.jsx(Z,{children:"কল ডিলে, রিট্রাই এবং Both মোডের আচরণ কনফিগার করুন"})]})]})}),e.jsxs(D,{className:"space-y-5 pt-0",children:[E==="both"&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-blue-500/5 border border-blue-500/20 px-3 py-2",children:[e.jsx(ss,{className:"h-4 w-4 text-blue-500 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-blue-700 dark:text-blue-400",children:[e.jsx("strong",{children:"Both মোড:"})," প্রথমে Browser Popup কাজ করবে। Browser-এ confirm হলে Real Call আর যাবে না। Hold/no response হলে Browser Timeout-এর পর Real Call trigger হবে।"]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"অর্ডারের পর কত মিনিট পর কল দিবে"}),e.jsx(oe,{type:"number",min:0,max:120,value:d("call_delay_minutes",s.call_delay_minutes),onChange:t=>i({call_delay_minutes:parseInt(t.target.value)||0}),disabled:o,className:"max-w-[120px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"০ = তাৎক্ষণিক"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"কল না ধরলে কতক্ষণ পর আবার কল"}),e.jsx(oe,{type:"number",min:1,max:60,value:d("call_retry_interval_minutes",s.call_retry_interval_minutes),onChange:t=>i({call_retry_interval_minutes:parseInt(t.target.value)||5}),disabled:o,className:"max-w-[120px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"মিনিট"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"সর্বোচ্চ কতবার কল করবে"}),e.jsx(oe,{type:"number",min:1,max:10,value:d("call_max_retries",s.call_max_retries),onChange:t=>
1i({call_max_retries:parseInt(t.target.value)||2}),disabled:o,className:"max-w-[120px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"বার"})]}),E==="both"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"Browser Timeout (Both মোডে)"}),e.jsx(oe,{type:"number",min:15,max:300,value:d("browser_timeout_seconds",s.browser_timeout_seconds),onChange:t=>i({browser_timeout_seconds:parseInt(t.target.value)||60}),disabled:o,className:"max-w-[120px]"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"সেকেন্ড — Browser-এ response না পেলে এর পর Real Call"})]})]})]})]}),e.jsx(P,{children:e.jsxs(D,{className:"p-4 text-sm text-muted-foreground space-y-2",children:[e.jsxs("p",{children:["• ",e.jsx("strong",{children:"Browser Popup:"})," Thank You পেজে voice + button দিয়ে অর্ডার confirm করাবে।"]}),e.jsxs("p",{children:["• ",e.jsx("strong",{children:"Real Phone Call:"})," কাস্টমারের আসল ফোনে কল যাবে এবং কীপ্যাড দিয়ে Confirm/Hold করতে পারবে।"]}),e.jsxs("p",{children:["• ",e.jsx("strong",{children:"Both মোড:"})," Browser আগে চলবে, confirm না হলে Real Call যাবে।"]})]})})]})]})]}),e.jsx(ce,{value:"ai-agent",className:"space-y-4 mt-4",children:e.jsx(_t,{})})]})]}),e.jsx(Ws,{open:se,onOpenChange:H,children:e.jsxs(Ys,{className:"max-w-[95vw] sm:max-w-sm max-h-[90vh] overflow-y-auto",children:[e.jsxs(Zs,{children:[e.jsxs(Js,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(Ve,{className:"h-5 w-5"}),L?"জেনারেশন লক করা আছে":"দৈনিক লিমিট শেষ"]}),e.jsx(et,{children:L?"আপনার অডিও জেনারেশন লক করা হয়েছে। আনলক করতে সাপোর্ট-এ যোগাযোগ করুন।":"আপনি আজ ৩ বার অডিও জেনারেট করেছেন। আগামীকাল আবার জেনারেট করতে পারবেন। বাড়তি প্রয়োজন হলে সাপোর্ট-এ যোগাযোগ করুন।"})]}),e.jsx(O,{variant:"outline",onClick:()=>H(!1),className:"w-full",children:"বুঝেছি"})]})})]})}export{Ir as default};

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.