1import{j as e,r,L as Ve,f as oa}from"./react-vendor-Cvme-g6x.js";import{c as Nt,j as E,t as C,u as wt,B as Q,X as nt,w as ze,m as Z,q as rt,a9 as it,r as Me,a3 as Pt,W as Vt,a6 as ca,z as ge,S as da,a7 as Ze,d as et,x as st,y as zt}from"./index-Dij6-G9-.js";import{u as ma}from"./usePageVisible-CtjPv3_L.js";import{C as tt}from"./card-DpjdXAlQ.js";import{g as ua,B as xa,T as Le,a as pa,b as ha,p as fa,c as ga,d as dt,w as ba,e as va,u as yt,f as ft,m as Ht,S as Ct,V as Gt,C as lt,h as _t,i as ja,j as mt,r as Na}from"./converterPostCopy-Dj-XFjZY.js";import{W as St}from"./WhatsAppConnectToolbar-Dlh7JFdA.js";import{T as Tt}from"./TelegramConnectStatus-tbl9ulgF.js";import{S as It,r as qt}from"./ScheduleCouponField--w_7HlB3.js";import{f as Ft}from"./minerOffers-D3myd5HH.js";import{a as Jt}from"./planCapabilities-BIPEQ99M.js";import{C as Ge}from"./calendar-clock-CqqcwrCT.js";import{C as kt}from"./chevron-right-cB9ixyqo.js";import{h as Kt,D as Xt,v as Zt,b as ea}from"./DestinationCategoryAssign-Cr6aEiMz.js";import{c as gt,S as bt,s as ta,a as aa,L as ut,r as wa,i as Pa,b as ya}from"./libraryScheduleHandoff-OVoUjfQR.js";import{i as Ca,f as Sa}from"./schedulePostCopy-T_RAiZwK.js";import{p as sa,b as na,r as ra}from"./scheduleHandoffCopy-BoTnzdyR.js";import{c as vt,r as Ta}from"./vitrineScheduleHandoff-BeYdTS_C.js";import{S as Ut}from"./shopping-bag-DJ0PtXCh.js";import{C as Lt}from"./circle-check-mjfUpuUy.js";import{T as Ia}from"./triangle-alert-CasIb3go.js";import{S as ka}from"./sliders-vertical-BTNmrxoZ.js";import{C as at}from"./chevron-up-jhO79PLr.js";import"./trpc-vendor-CcQiuHv2.js";import"./recharts-vendor-D3gx481F.js";import"./framer-vendor-vyqLUUua.js";import"./sliders-horizontal-CoW9Bi_d.js";import"./collapsible-BrXnpFzr.js";import"./checkbox-DjHpToDF.js";import"./index-DbRBuB-4.js";import"./index-BN74VVMI.js";import"./affiliateUrlCompact-CPGnhjyE.js";import"./mercadoLivreProductUrl-CLl3NzO_.js";import"./images-B6uRPvuA.js";import"./WhatsAppSingleBotWarning-Cp0527Cu.js";import"./external-link-gXljzYZa.js";import"./telegramChatIds-CagqvnyD.js";import"./marketplaceClosingPhrases-BSVOaX_g.js";import"./communityMinerCategories-BMyegEYz.js";import"./selectionButtonStyles-D5mS1pRJ.js";import"./constructNow-BiiAh-X8.js";import"./parseFlexibleMoney-B6RdYWM1.js";/** 2 * @license lucide-react v0.453.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ma=Nt("ArrowDownToLine",[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]]);/** 7 * @license lucide-react v0.453.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Mt=Nt("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/** 12 * @license lucide-react v0.453.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Aa=Nt("CirclePause",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"10",x2:"10",y1:"15",y2:"9",key:"c1nkhi"}],["line",{x1:"14",x2:"14",y1:"15",y2:"9",key:"h65svq"}]]);function Rt(a){const o=String(a||"").trim(),g=/^(\d{1,2}):(\d{2})$/.exec(o);if(!g)return null;const i=Number(g[1]),N=Number(g[2]);return!Number.isFinite(i)||!Number.isFinite(N)||i<0||i>23||N<0||N>59?null:`${String(i).padStart(2,"0")}:${String(N).padStart(2,"0")}`}function jt(a){const o=Math.round(Number(a));return Number.isFinite(o)?Math.min(720,Math.max(5,o)):30}function _e(a){const o=Rt(a.start),g=Rt(a.end);if(!o||!g)throw new Error("Horários inválidos. Use o formato HH:mm (ex.: 08:00).");return{start:o,end:g,intervalMinutes:jt(a.intervalMinutes??30)}}function Ea(a,o){return a.start===o.start&&a.end===o.end&&a.intervalMinutes===o.intervalMinutes}const Oa=["Prévia","Programação","Confirmar"];function At({step:a,labels:o=Oa}){const g=[{n:1,label:o[0]},{n:2,label:o[1]},{n:3,label:o[2]}];return e.jsx("nav",{"aria-label":"Passos do agendamento",className:"flex items-center gap-1 rounded-2xl border border-emerald-100 bg-white/90 p-1.5",children:g.map(({n:i,label:N},O)=>
16e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:[e.jsxs("div",{className:E("flex min-h-[36px] flex-1 touch-manipulation flex-col items-center justify-center rounded-xl px-1 py-1 text-center transition",a===i?"bg-emerald-600 text-white shadow-sm":a>i?"bg-emerald-50 text-emerald-800":"text-slate-400"),children:[e.jsx("span",{className:"text-[10px] font-black",children:i}),e.jsx("span",{className:"text-[9px] font-bold leading-tight",children:N})]}),O<g.length-1?e.jsx("div",{className:E("h-0.5 w-2 shrink-0 rounded-full sm:w-4",a>i?"bg-emerald-400":"bg-slate-200"),"aria-hidden":!0}):null]},i))})}function Et({banner:a,bannerTextOffsets:o,onBannerTextOffsetsChange:g,bannerPreviewRef:i,bannerCaptureRef:N,idPrefix:O,edit:f,className:j}){const F=a.templateId,G=ua(F),R=r.useMemo(()=>e.jsx(xa,{idPrefix:O,sheetMode:!0,bannerTextOffsets:o,onBannerTextOffsetsChange:g,titleEdit:f.productTitle,onTitleEditChange:f.onProductTitleChange,priceEdit:f.currentPrice,onPriceEditChange:f.onCurrentPriceChange,originalPriceEdit:f.originalPrice,onOriginalPriceEditChange:f.onOriginalPriceChange,ctaText:f.cta,onCtaTextChange:f.onCtaChange,bannerCopyEdit:"",onBannerCopyEditChange:()=>{},bannerCopySafeLimit:G,bannerCopyOverSafe:!1}),[O,o,g,f,G]),L=e.jsx("div",{className:"w-[4.75rem] shrink-0 overflow-hidden rounded-lg border border-violet-100 bg-slate-900/5 shadow-sm",children:e.jsx(Le,{displayMode:"panel",templateId:F,productTitle:a.productTitle,currentPrice:a.currentPrice,originalPrice:a.originalPrice,discountPercent:a.discountPercent,cta:a.cta,productImageUrl:a.productImageUrl,titleOffsetYPercent:o.title,priceOffsetYPercent:o.price,ctaOffsetYPercent:o.cta,fontScalePercent:o.fontScale})});return e.jsxs("div",{className:E("space-y-2",j),children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-slate-500",children:"Banner do post"}),e.jsxs("div",{className:"flex items-stretch gap-2",children:[e.jsx("div",{className:"relative flex min-w-0 flex-1 justify-center overflow-hidden rounded-xl border border-slate-200/90 bg-slate-900/5 shadow-sm",children:e.jsx("div",{ref:i,"data-banner-capture-root":!0,className:"w-full max-w-[min(100%,280px)]",children:e.jsx(Le,{displayMode:"panel",templateId:F,productTitle:a.productTitle,currentPrice:a.currentPrice,originalPrice:a.originalPrice,discountPercent:a.discountPercent,cta:a.cta,productImageUrl:a.productImageUrl,titleOffsetYPercent:o.title,priceOffsetYPercent:o.price,ctaOffsetYPercent:o.cta,fontScalePercent:o.fontScale})})}),e.jsx(pa,{preview:L,children:R})]}),e.jsx("div",{ref:N,className:"pointer-events-none fixed left-[-12000px] top-0 z-[-1] opacity-100","aria-hidden":!0,children:e.jsx(Le,{displayMode:"capture",templateId:F,productTitle:a.productTitle,currentPrice:a.currentPrice,originalPrice:a.originalPrice,discountPercent:a.discountPercent,cta:a.cta,productImageUrl:a.productImageUrl,titleOffsetYPercent:o.title,priceOffsetYPercent:o.price,ctaOffsetYPercent:o.cta,fontScalePercent:o.fontScale})}),e.jsxs("div",{className:"hidden md:block rounded-xl border border-violet-100/80 bg-violet-50/30 px-3 py-2",children:[e.jsx("p",{className:"mb-2 text-[10px] font-black uppercase tracking-widest text-violet-800",children:"Posição dos textos no banner"}),e.jsx(ha,{value:o,onChange:g,idPrefix:`${O}-desktop`,compact:!0})]})]})}function Re({productTitle:a,postContent:o,imageSrc:g,includeBanner:i=!0,channelLabel:N="WhatsApp",priceLabel:O,className:f,banner:j,bannerPreviewRef:F}){const G=j?.templateId?.trim()??"",R=i&&G.length>0,L=i&&!R&&g;return e.jsxs("div",{className:E("rounded-2xl border border-[#25D366]/25 bg-[#e7f8ef] p-3 shadow-inner",f),children:[e.jsxs("p",{className:"mb-2 text-[10px] font-black uppercase tracking-widest text-[#128C7E]",children:["Prévia do envio · ",N]}),e.jsxs("div",{className:"max-w-full rounded-xl rounded-tl-sm bg-white p-3 shadow-sm",children:[R&&j?e.jsx("div",{ref:F,className:"mb-2 overflow-hidden rounded-lg border border-slate-100 bg-slate-900/5",children:e.jsx(Le,{displayMode:"panel",templateId:G,productTitle:j.productTitle,currentPrice:j.currentPrice||"â",originalPrice
16:j.originalPrice,discountPercent:j.discountPercent,cta:j.cta,productImageUrl:j.productImageUrl,titleOffsetYPercent:j.titleOffsetYPercent,priceOffsetYPercent:j.priceOffsetYPercent,ctaOffsetYPercent:j.ctaOffsetYPercent,fontScalePercent:j.fontScalePercent})}):L?e.jsx("div",{className:"mb-2 overflow-hidden rounded-lg border border-slate-100 bg-slate-50",children:e.jsx("img",{src:g,alt:"",className:"max-h-[min(42vh,220px)] w-full object-contain"})}):i&&!g?e.jsx("div",{className:"mb-2 flex h-24 items-center justify-center rounded-lg border border-dashed border-slate-200 bg-slate-50 text-xs font-semibold text-slate-400",children:"Sem imagem â escolha um banner acima"}):null,e.jsx("p",{className:"text-[11px] font-bold text-slate-500 line-clamp-1",children:a}),O?e.jsx("p",{className:"text-xs font-semibold text-emerald-700",children:O}):null,e.jsx("pre",{className:"mt-2 max-h-[min(32vh,180px)] overflow-y-auto whitespace-pre-wrap break-words text-sm leading-relaxed text-slate-800 [overflow-wrap:anywhere]",children:o.trim()||"â"})]})]})}async function Ba(a,o){const g=Date.now();for(;Date.now()-g<o;){if(a())return!0;await new Promise(i=>setTimeout(i,80))}return a()}function Wt(a){return a?.startsWith("data:image/")?a.length>12e3:!1}async function Ot(a,o,g){if(!o.trim())return;const i=g?.compose;let N;if(i){const f=await fa(i.productImageUrl,g?.prefetchImage)||String(i.productImageUrl||"").trim()||null;N={templateId:i.templateId||o,productImageUrl:f,productTitle:i.productTitle||"Oferta",currentPrice:i.currentPrice||"",originalPrice:i.originalPrice,discountPercent:i.discountPercent,cta:i.cta,titleOffsetYPercent:i.titleOffsetYPercent,priceOffsetYPercent:i.priceOffsetYPercent,ctaOffsetYPercent:i.ctaOffsetYPercent,fontScalePercent:i.fontScalePercent};try{const j=await ga(N);if(Wt(j))return dt(j)}catch(j){console.warn("[schedule] Compose do banner falhou, a tentar DOM:",j)}}if(a)try{a.scrollIntoView({block:"nearest",inline:"nearest"}),await new Promise(f=>requestAnimationFrame(()=>requestAnimationFrame(()=>f()))),await ba(a);const O=await va(a,o,N);if(!Wt(O)){if(!N&&O?.startsWith("data:image/"))return dt(O);console.warn("[schedule] Banner capturado inválido ou sem foto do produto â não envia arte cega.");return}return dt(O)}catch(O){console.error("[schedule] Falha ao capturar banner:",O);return}}async function Bt(a,o=5e3){return await Ba(()=>a()!=null,o)?a():null}function Da({payload:a,onDismiss:o,onScheduled:g,setFeedback:i}){const N=C.useUtils(),{user:O}=wt(),f=C.access.me.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),j=O?.role==="admin",F=f.data?.planTier??1,G=f.data?.limits,R=j?Math.max(1,G?.maxWhatsAppGroups??4):Math.max(0,G?.maxWhatsAppGroups??0),L=j?Math.max(0,G?.maxTelegramChats??2):Math.max(0,G?.maxTelegramChats??0),J=j||Jt(F),[ee,ye]=r.useState(1),[te,Te]=r.useState(a.postContent),[W,be]=r.useState(""),[se,me]=r.useState(!0),[P,ne]=r.useState(a.productTitle),[y,$]=r.useState(a.currentPrice??""),[ue,B]=r.useState(a.originalPrice??""),[ve,w]=r.useState(a.cta??""),xe=r.useRef(null),Ce=r.useRef(null),{offsets:K,setOffsets:Ie}=yt(),[M,le]=r.useState(!1),[ae,ke]=r.useState(""),[S,oe]=r.useState(!0),[D,X]=r.useState(J&&L>0),[pe,_]=r.useState([]),[je,Y]=r.useState([]),re=r.useRef(!1),Ne=r.useRef(!1),ie=r.useMemo(()=>{const d=[];return S&&d.push("whatsapp"),D&&J&&d.push("telegram"),d},[S,D,J]),ce=C.miner.getAvailableDestinations.useQuery({channel:"whatsapp"},{enabled:S,staleTime:6e4,refetchOnWindowFocus:!0}),we=C.miner.getAvailableDestinations.useQuery({channel:"telegram"},{enabled:D&&J,staleTime:6e4,refetchOnWindowFocus:!0}),Ae=C.converter.scheduleCampaign.useMutation({onSuccess:async()=>{ft(),await N.miner.getQueue.invalidate(),N.miner.getScheduleOverview.invalidate(),i("â
Campanha enfileirada no agendamento."),setTimeout(()=>i(""),5e3),g()},onError:d=>{i(`â ${d.message}`),setTimeout(()=>i(""),6e3)}}),he=C.converter.fetchProductImageDataUrl.useMutation(),q=r.useMemo(()=>Ht(te,W),[te,W]);r.useEffect(()=>{Te(a.postContent),ne(a.productTitle),$(a.currentPrice??""),B(a.originalPrice??""),w(a.cta??"")},[a.postContent,a.productTitle,a.currentPrice,a.originalPrice,a.cta]),r.useEffect(()=>{const d=ce.data??[];!d.length||re.current||(re.current=!0,_(d.slice(0,R).map(v=>v.chatId)))},[ce.data,R]),r.useEffect(()=>{const d=we.data??[];!d.length||Ne.current||(Ne.current=!0,Y(d.slice(0,L).map(v=>v.chatId)))},[we.data,L]);const t=r.useMemo(()=>{const d=ae.trim();if(!d)return null;const v=new Date(d);return Number.isNaN(v.getTime())?null:{dateLabel:v.toLocaleDateString("pt-BR"),timeLabel:v.toLocaleTimeString("pt-BR",{hour:"2-digit",minute:"2-digit"})}},[ae]),m=r.useMemo(()=>a.includeBanner&&a.imageBase64?`data:image/png;base64,${a.imageBase64}`:a.imageUrl?.trim()||null,[a.includeBanner,a.imageBase64,a.imageUrl]),c=r.useMemo(()=>
16{if(!a.includeBanner||a.imageBase64)return null;const d=a.templateId?.trim();return d?{templateId:d,productTitle:P,currentPrice:y||"â",originalPrice:ue||void 0,cta:ve||void 0,productImageUrl:a.imageUrl,titleOffsetYPercent:K.title,priceOffsetYPercent:K.price,ctaOffsetYPercent:K.cta,fontScalePercent:K.fontScale}:null},[a,P,y,ue,ve,K]),V=a.source==="converter"?"Converter link":"Gerar banner";async function Se(){const d=Ht(te.trim(),W);if(d.length<3){i("â ï¸ O texto do post precisa ter pelo menos 3 caracteres."),setTimeout(()=>i(""),4500);return}if(ie.length===0){i("â ï¸ Marque WhatsApp e/ou Telegram para enfileirar."),setTimeout(()=>i(""),4500);return}let v=new Date;if(ae.trim()){const T=new Date(ae);if(Number.isNaN(T.getTime())){i("â ï¸ Data e hora inválidas."),setTimeout(()=>i(""),4500);return}v=T}if(S&&(ce.data??[]).length===0){i("â ï¸ Nenhum grupo WhatsApp configurado. Ajuste na Central do Afiliado."),setTimeout(()=>i(""),6e3);return}if(D&&J&&(we.data??[]).length===0){i("â ï¸ Nenhum destino Telegram configurado. Ajuste na Central do Afiliado."),setTimeout(()=>i(""),6e3);return}if(S&&pe.length===0){i("â ï¸ Selecione ao menos um grupo do WhatsApp."),setTimeout(()=>i(""),4500);return}if(D&&je.length===0){i("â ï¸ Selecione ao menos um destino do Telegram."),setTimeout(()=>i(""),4500);return}let u=a.includeBanner&&a.imageBase64?a.imageBase64:void 0;if(a.includeBanner&&!u&&c?.templateId){le(!0),i("Preparando arte do bannerâ¦");try{const T=await Bt(()=>Ce.current,6e3),fe=await Ot(T,c.templateId,{compose:c,prefetchImage:async z=>{try{const{dataUrl:Ee}=await he.mutateAsync({imageUrl:z});return Ee}catch{return null}}});if(!fe){i("â ï¸ Não foi possÃvel gerar o banner com a foto do produto. Ajuste a arte e tente de novo."),setTimeout(()=>i(""),5500);return}u=fe}finally{le(!1)}}try{for(const T of ie){const fe=T==="whatsapp"?pe:je;await Ae.mutateAsync({channel:T,platform:a.platform,originalUrl:a.originalUrl,convertedUrl:a.convertedUrl,productTitle:P.trim()||a.productTitle,imageUrl:a.imageUrl,currentPrice:y.trim()||a.currentPrice,originalPrice:ue.trim()||a.originalPrice,templateId:a.templateId,cta:ve.trim()||a.cta,description:a.description,postContent:d,executeAt:v.toISOString(),imageBase64:u,targetChatIds:fe.length>0?fe:void 0,compactMlLink:se})}}catch{}}const A=Ae.isPending||M;return e.jsxs("section",{className:"overflow-hidden rounded-[24px] border border-emerald-200/90 bg-gradient-to-br from-emerald-50/90 via-white to-violet-50/40 p-4 shadow-sm sm:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-emerald-100/80 pb-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-emerald-800",children:[V," â agenda"]}),e.jsxs("h2",{className:"flex items-center gap-2 text-lg font-black tracking-tight text-slate-900 sm:text-xl",children:[e.jsx(Ge,{className:"h-6 w-6 shrink-0 text-emerald-600"}),"Agendar esta oferta"]}),e.jsxs("p",{className:"max-w-2xl text-sm leading-relaxed text-slate-600",children:["Revise a prévia, ajuste o texto e defina data/hora."," ",a.includeBanner?"O disparo inclui a arte do banner.":"O disparo será só com texto (sem imagem do banner)."]})]}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",className:"h-10 min-h-[44px] shrink-0 touch-manipulation rounded-xl border-slate-200",onClick:()=>{ft(),o()},children:[e.jsx(nt,{className:"mr-1.5 h-4 w-4"}),"Fechar"]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(At,{step:ee})}),ee===1?e.jsxs("div",{className:"mt-4 grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-4",children:[c?e.jsx(Et,{banner:c,bannerTextOffsets:K,onBannerTextOffsetsChange:Ie,bannerPreviewRef:xe,bannerCaptureRef:Ce,idPrefix:"campaign-sched",edit:{productTitle:P,currentPrice:y,originalPrice:ue,cta:ve,onProductTitleChange:ne,onCurrentPriceChange:$,onOriginalPriceChange:B,onCtaChange:w}}):null,e.jsx(Re,{productTitle:P||a.productTitle,postContent:q,imageSrc:m,includeBanner:a.includeBanner,priceLabel:y||a.currentPrice,channelLabel:"WhatsApp / Telegram",banner:c})]}),e.jsxs("div",{children:[e.jsx(It,{id:"campaign-sched-coupon",value:W,onChange:be,platform:a.platform,className:"mb-3"}),e.jsx(Ct,{platform:a.platform,checked:se,onCheckedChange:me,className:"mb-3"}),e.jsx("label",{className:"mb-1.5 block text-[10px] font-black uppercase tracking-widest text-slate-500",children:"Texto do post"}),e.jsx(ze,{value:te,onChange:d=>Te(d.target.value),className:"min-h-[180px] rounded-2xl border-violet-100 text-sm"}),e.jsxs("p",{className:"mt-2 text-xs text-slate-500",children:[Ft(a.platform)," ·"," ",a.includeBanner?"Com banner":"Só texto"]})]})]}):null,ee===2?e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-4",children:[e.jsx("p",{className:"mb-3 text-[10px] font-black uppercase tracking-widest text-slate-500",children:"Data e hora do disparo"}),e.jsx(Z,{type:"datetime-local",value:ae,onChange:d=>ke(d.target.value),className:"h-12 min-h-[44px] touch-manipulation rounded-xl"}),t?e.jsxs("p",{className:"mt-2 text-xs font-semibold text-emerald-700",children:["Envio previsto em ",t.dateLabel," à s"," ",t.timeLabel,"."]}):e.jsx("p",{className:"mt-2 text-xs text-slate-500",children:"Deixe vazio para enfileirar com disparo imediato."})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>oe(d=>!d),className:E("flex min-h-[44px] touch-manipulation items-center gap-3 rounded-2xl border p-3 transition",S?"border-[#25D366] bg-[#25D366]/5 ring-2 ring-[#25D366]/20":"border-slate-200 bg-white"),children:[e.jsx(rt,{className:"h-5 w-5 text-[#25D366]"}),e.jsx("span",{className:"text-sm font-bold text-slate-900",children:"WhatsApp"})]}),J?e.jsxs("button",{type:"button",onClick:()=>X(d=>!d),className:E("flex min-h-[44px] touch-manipulation items-center gap-3 rounded-2xl border p-3 transition",D?"border-[#2AABEE] bg-[#2AABEE]/5 ring-2 ring-[#2AABEE]/20":"border-slate-200 bg-white"),children:[e.jsx(it,{className:"h-5 w-5 text-[#2AABEE]"}),e.jsx("span",{className:"text-sm font-bold text-slate-900",children:"Telegram"})]}):null]}),S&&e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-white p-3",children:[e.jsx(St,{}),(ce.data??[]).length>0?e.jsx("div",{className:"mt-3 max-h-[120px] space-y-2 overflow-y-auto",children:(ce.data??[]).map(d=>
16e.jsxs("label",{className:"flex min-h-[44px] cursor-pointer items-center gap-2 rounded-xl border border-slate-100 bg-slate-50 px-2.5 py-2 text-xs font-semibold text-slate-700",children:[e.jsx("input",{type:"checkbox",checked:pe.includes(d.chatId),onChange:v=>{v.target.checked?_(u=>u.includes(d.chatId)?u:u.length>=R?[...u.slice(1),d.chatId]:[...u,d.chatId]):_(u=>u.filter(T=>T!==d.chatId))},className:"h-4 w-4 rounded"}),e.jsx("span",{className:"line-clamp-1",children:d.chatName})]},d.chatId))}):null]}),D&&J&&e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-white p-3",children:[e.jsx(Tt,{}),(we.data??[]).length>0?e.jsx("div",{className:"mt-3 max-h-[120px] space-y-2 overflow-y-auto",children:(we.data??[]).map(d=>e.jsxs("label",{className:"flex min-h-[44px] cursor-pointer items-center gap-2 rounded-xl border border-slate-100 bg-slate-50 px-2.5 py-2 text-xs font-semibold text-slate-700",children:[e.jsx("input",{type:"checkbox",checked:je.includes(d.chatId),onChange:v=>{v.target.checked?Y(u=>u.includes(d.chatId)?u:u.length>=L?[...u.slice(1),d.chatId]:[...u,d.chatId]):Y(u=>u.filter(T=>T!==d.chatId))},className:"h-4 w-4 rounded"}),e.jsx("span",{className:"line-clamp-1",children:d.chatName})]},d.chatId))}):null]})]}):null,ee===3?e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx(Re,{productTitle:a.productTitle,postContent:te,imageSrc:m,includeBanner:a.includeBanner,priceLabel:a.currentPrice,banner:c}),e.jsxs("p",{className:"text-xs text-slate-600",children:[ie.length," canal(is) ·"," ",t?`envio em ${t.dateLabel} ${t.timeLabel}`:"disparo imediato na fila"]})]}):null,e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[ee>1?e.jsxs(Q,{type:"button",variant:"outline",className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl sm:flex-none",onClick:()=>ye(d=>d>1?d-1:d),children:[e.jsx(Mt,{className:"mr-1 h-4 w-4"}),"Voltar"]}):null,ee<3?e.jsxs(Q,{type:"button",className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl bg-emerald-600 font-bold sm:flex-none",onClick:()=>ye(d=>d<3?d+1:d),children:["Continuar",e.jsx(kt,{className:"ml-1 h-4 w-4"})]}):e.jsxs(Q,{type:"button",disabled:A||ie.length===0,onClick:()=>void Se(),className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl bg-gradient-to-r from-emerald-500 to-teal-500 font-black text-white sm:flex-none",children:[A?e.jsx(Me,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Pt,{className:"mr-2 h-4 w-4"}),"Confirmar agendamento"]})]})]})}function He(a,o){const g=a.currentPrice!=null?String(a.currentPrice):"",i=a.originalPrice!=null?String(a.originalPrice):"",N=lt[0]??"",O=_t()[0]?.id??"",f=String(a.selectedBannerTemplateKey??"").trim(),j=String(a.generatedCopy??"").trim(),F=!!j&&!Ca(j)&&j.length>80;return{productTitle:a.productTitle||"",currentPrice:g,originalPrice:i,aiHook:"",cta:"",postContent:F?j:"",templateId:f||(o?N:O),copyTemplateId:"",couponCode:"",compactMlLink:!0,includeBanner:!0}}function $t(a){const o=String(a||"").replace(/[^\d,.-]/g,"").replace(/\./g,"").replace(",","."),g=Number.parseFloat(o);return Number.isFinite(g)?g:Number.NaN}function xt(a,o){const g=$t(a),i=$t(o);if(!Number.isFinite(g)||!Number.isFinite(i)||i<=0)return;const N=Math.round((1-g/i)*100);if(!(!Number.isFinite(N)||N<0||N>99))return String(N)}function Ha({offerIds:a,onDismiss:o,onScheduled:g,setFeedback:i}){const N=C.useUtils(),{user:O}=wt(),f=C.access.me.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),j=O?.role==="admin",F=f.data?.planTier??1,G=f.data?.features??[],R=f.data?.limits,L=!j&&F===1,J=j||G.includes("operations.ai_copy"),ee=j||G.includes("tools.copy_page"),ye=j?Math.max(1,R?.maxWhatsAppGroups??4):Math.max(0,R?.maxWhatsAppGroups??0),te=j?Math.max(0,R?.maxTelegramChats??2):Math.max(0,R?.maxTelegramChats??0),Te=j||Jt(F),W=r.useMemo(()=>Array.from(new Set(a.map(n=>Number(n)).filter(n=>Number.isFinite(n)&&n>0))).slice(0,200),[a]),be=C.offers.listMine.useQuery({limit:500},{enabled:W.length>0,staleTime:3e4}),se=C.templates.list.useQuery(void 0,{enabled:ee,retry:!1,staleTime:6e4}),me=C.templates.getCopyPreferences.useQuery(void 0,{enabled:ee,retry:!1,staleTime:6e4}),P=r.useMemo(()=>{const n=new Set(W);return(be.data??[]).filter(x=>n.has(Number(x.id)))},[be.data,W]),[ne,y]=r.useState(1),[$,ue]=r.useState(null),[B,ve]=r.useState({}),[w,xe]=r.useState(null),Ce=r.useRef(null),K=r.useRef(null),Ie=r.useRef(null),{offsets:M,setOffsets:le}=yt(),[ae,ke]=r.useState(!1),[S,oe]=r.useState("whatsapp"),[D,X]=r.useState([]),[pe,_]=r.useState({}),[je,Y]=r.useState(()=>new Date().toISOString().slice(0,10)),[re,Ne]=r.useState("09:00"),[ie,ce]=r.useState("22:00"),[we,Ae]=r.useState(30),he=C.miner.getAvailableDestinations.useQuery({channel:S},{staleTime:6e4}),q=C.miner.getSchedulePreferences.useQuery(void 0,{staleTime:6e4}),t=S==="whatsapp"?ye:te;r.useEffect(()=>{P.length&&(ve(n=>{const x={...n};for(const p of P){const I=Number(p.id);x[I]||(x[I]=He(p,L))}return x}),ue(n=>n!=null&&P.some(x=>Number(x.id)===n)?n:Number(P[0].id)))},[P,L]),r.useEffect(()=>{const n=q.data;n&&(n.startHour&&Ne(n.startHour),n.endHour&&ce(n.endHour),n.intervalMinutes&&Ae(n.intervalMinutes))},[q.data]),r.useEffect(()=>{const n=he.data??[];X(x=>{const p=x.filter(I=>n.some(H=>H.chatId===I));return p.length>0?p.slice(0,t):n.slice(0,t).map(I=>I.chatId)})},[he.data,t]),r.useEffect(()=>{const n=q.data?.destinationCategories;n&&_(x=>{const p={...x},I=Kt(n,S,D);
16for(const[H,Pe]of Object.entries(I))(p[H]?.length??0)===0&&Pe.length&&(p[H]=Pe);return p})},[q.data?.destinationCategories,S,D]);const m=r.useMemo(()=>P.find(n=>Number(n.id)===$)??null,[P,$]),c=r.useMemo(()=>$==null||!m?null:B[$]??He(m,L),[$,m,B,L]),V=c?.includeBanner??!0,Se=r.useMemo(()=>{let n=0,x=0;for(const p of P)B[Number(p.id)]?.includeBanner===!1?x++:n++;return{with:n,without:x}},[P,B]);function A(n){$!=null&&ve(x=>{const p=P.find(H=>Number(H.id)===$),I=x[$]||(p?He(p,L):void 0);return I?{...x,[$]:{...I,...n}}:x})}const d=r.useMemo(()=>c?xt(c.currentPrice,c.originalPrice):void 0,[c]),v=r.useMemo(()=>{if(!c||!m)return null;const n=c.templateId.trim();return n?{templateId:n,productTitle:c.productTitle||m.productTitle||"Oferta",currentPrice:c.currentPrice||"â",originalPrice:c.originalPrice||void 0,discountPercent:d,cta:c.cta||void 0,productImageUrl:m.productImage||void 0,titleOffsetYPercent:M.title,priceOffsetYPercent:M.price,ctaOffsetYPercent:M.cta,fontScalePercent:M.fontScale}:null},[c,m,d,M]);function u(n){const x=P.find(H=>Number(H.id)===n);if(!x)return null;const p=B[n]||He(x,L),I=p.templateId.trim();return I?{templateId:I,productTitle:p.productTitle||x.productTitle||"Oferta",currentPrice:p.currentPrice||"â",originalPrice:p.originalPrice||void 0,discountPercent:xt(p.currentPrice,p.originalPrice),cta:p.cta||void 0,productImageUrl:x.productImage||void 0,titleOffsetYPercent:M.title,priceOffsetYPercent:M.price,ctaOffsetYPercent:M.cta,fontScalePercent:M.fontScale}:null}const T=r.useMemo(()=>w==null?null:u(w),[w,P,B,M,L]),fe=r.useMemo(()=>!c||!m?"":z(m,c),[c,m,d,se.data,me.data]);function z(n,x,p){const I=String(n.convertedUrl??"").trim(),H=qt(x.couponCode,n.platform),Pe=sa(x.copyTemplateId);return na({postContent:p?.ignorePostContent?null:x.postContent,copyTemplateId:Pe.copyTemplateId,skipAccountDefault:Pe.skipAccountDefault,forceSystemDefault:Pe.forceSystemDefault,templates:se.data??[],prefs:me.data??null,platform:n.platform,productTitle:x.productTitle||n.productTitle||"",currentPrice:x.currentPrice||n.currentPrice,originalPrice:x.originalPrice||n.originalPrice,discountPercent:xt(x.currentPrice,x.originalPrice),convertedUrl:I||"{{affiliateUrl}}",aiHook:x.aiHook,ctaLine:x.cta,couponCode:H,linkMode:"placeholder"})}function Ee(n,x){return z(n,x,{ignorePostContent:!0})}const Oe=C.converter.generateCopy.useMutation({onError:n=>{i(`â ${n.message}`),setTimeout(()=>i(""),6e3)}}),qe=C.converter.fetchProductImageDataUrl.useMutation(),de=C.offers.scheduleOffers.useMutation({onSuccess:async n=>{gt(),await Promise.all([N.miner.getQueue.invalidate(),N.miner.getScheduleOverview.invalidate(),N.offers.listMine.invalidate()]),i(`â
${n.createdCount} agendamento(s) criado(s).`),setTimeout(()=>i(""),6e3),g()},onError:n=>{i(`â ${n.message}`),setTimeout(()=>i(""),6e3)}}),Be=C.miner.updateScheduleWindow.useMutation();function We(n){X(x=>x.includes(n)?x.filter(p=>p!==n):x.length>=t?[...x.slice(1),n]:[...x,n])}function Fe(n,x={}){return n.map(p=>{const I=P.find(Ke=>Number(Ke.id)===p),H=B[p]||(I?He(I,L):void 0);if(!H||!I)return{offerId:p};const Pe=z(I,H);return{offerId:p,productTitle:H.productTitle.trim()||void 0,currentPrice:H.currentPrice.trim()||void 0,originalPrice:H.originalPrice.trim()||void 0,aiHook:H.aiHook.trim()||void 0,cta:H.cta.trim()||void 0,templateId:H.templateId.trim()||void 0,postContent:Pe.trim()||void 0,forceSystemDefaultCopy:H.copyTemplateId==="0",couponCode:H.couponCode.trim()||void 0,compactMlLink:H.compactMlLink,imageBase64:x[p],noBanner:H?.includeBanner===!1?!0:void 0}})}async function Je(n){const x={};for(const p of n){const I=P.find(h=>Number(h.id)===p),H=B[p]||(I?He(I,L):void 0),Pe=H?.templateId?.trim();if(!I||!H||!Pe||H.includeBanner===!1||!(!!String(I.productImage||"").trim()||!!String(I.generatedBannerUrl||"").trim()))continue;xe(p),await new Promise(h=>setTimeout(h,520));const Ye=await Bt(()=>Ie.current,6e3),s=u(p),l=await Ot(Ye,Pe,{compose:s,prefetchImage:async h=>{try{const{dataUrl:b}=await qe.mutateAsync({imageUrl:h});return b}catch{return null}}});l&&(x[p]=l)}return xe(null),x}async function $e(){if($==null||!c)return;const n=c.productTitle.trim()||m?.productTitle?.trim()||"";if(!n){i("â ï¸ Defina um tÃtulo para gerar o gancho."),setTimeout(()=>i(""),4500);return}try{const x=await Oe.mutateAsync({channel:"whatsapp",productTitle:n}),p=String(x.content??"").trim();p&&A({aiHook:p,postContent:""})}catch{}}async function ot(){const n=P.filter(p=>p.convertedUrl&&p.hasLinkReady!==!1).map(p=>Number(p.id));if(!n.length){i("â ï¸ Nenhuma oferta com link de afiliado pronto."),setTimeout(()=>i(""),5e3);return}if(!D.length){ta(),i(`â ï¸ ${aa}`),setTimeout(()=>i(""),7e3);return}if(S==="whatsapp"&&!Zt(S,D,pe)){i("â ï¸ Defina categoria de nicho para cada grupo WhatsApp."),setTimeout(()=>i(""),5e3);return}let x;try{x=_e({start:re,end:ie,intervalMinutes:we})}catch(p){i(p instanceof Error?`â ï¸ ${p.message}`:"Horários inválidos."),setTimeout(()=>i(""),5e3);return}try{ke(!0),i("Preparando artes do bannerâ¦");const p=await Je(n);await Be.mutateAsync(x),await de.mutateAsync({offerIds:n,channels:[S],targetChatIds:D,targetCategoryMap:ea(D,pe),intervalMinutes:x.intervalMinutes,anchorDate:je.trim()||void 0,anchorTime:x.start,offerOverrides:Fe(n,p)})}catch{}finally{ke(!1)}}const De=de.isPending||Be.isPending||Oe.isPending||ae;return W.length===0?null:e.jsxs("section",{className:"overflow-hidden rounded-[24px] border border-emerald-200/90 bg-gradient-to-br from-emerald-50/90 via-white to-violet-50/40 p-4 shadow-sm sm:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-emerald-100/80 pb-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-emerald-800",children:"Galeria â agenda"}),e.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-lg font-black text-slate-900",children:[e.jsx(Ge,{className:"h-6 w-6 text-emerald-600"}),"Agendar ",P.length," oferta(s)"]}),e.jsx("p",{className:"mt-1 text-sm text-slate-600",children:"Tudo nesta tela â prévia, horários e confirmação, sem voltar à Galeria."})]}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",className:"h-10 shrink-0 rounded-xl",onClick:()=>{gt(),o()},children:[e.jsx(nt,{className:"mr-1 h-4 w-4"}),"Fechar"]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(At,{step:ne})}),be.isLoading?e.jsxs("div",{className:"mt-4 flex items-center gap-2 text-sm text-slate-600",children:[e.jsx(Me,{className:"h-5 w-5 animate-spin text-emerald-600"}),"Carregando ofertasâ¦"]}):P.length===0?e.jsx("p",{className:"mt-4 text-sm text-rose-700",children:"Ofertas não encontradas na biblioteca. Volte à Galeria e tente de novo."}):e.jsxs(e.Fragment,{children:[ne===1?e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx("div",{className:"-mx-1 flex gap-2 overflow-x-auto pb-1 [scrollbar-width:thin]",children:P.map(n=>{const x=Number(n.id),p=$===x,I=n.generatedBannerUrl||n.productImage;return e.jsxs("button",{type:"button",onClick:()=>ue(x),className:E("w-[7.5rem] shrink-0 overflow-hidden rounded-2xl border bg-white text-left shadow-sm",p?"border-violet-500 ring-2 ring-violet-400/50":"border-slate-200"),children:[e.jsx("div",{className:"flex aspect-square items-center justify-center overflow-hidden bg-slate-50 p-1",children:I?e.jsx("img",{src:I,alt:"",className:"max-h-full max-w-full object-contain"}):e.jsx("div",{className:"flex h-full items-center justify-center text-[9px] font-bold text-slate-400",children:"Sem foto"})}),e.jsx("p",{className:"line-clamp-2 p-1.5 text-[10px] font-bold text-slate-800",children:n.productTitle})]},x)})}),m&&c?e.jsxs("div",{className:"space-y-4 rounded-2xl border border-violet-200/80 bg-gradient-to-b from-white to-violet-50/30 p-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["TÃtulo",e.jsx(Z,{value:c.productTitle,onChange:n=>A({productTitle:n.target.value}),className:"h-10 min-w-0 rounded-xl"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["CTA no banner",e.jsx(Z,{value:c.cta,onChange:n=>A({cta:n.target.value}),placeholder:"Ex.: Ver oferta",className:"h-10 min-w-0 rounded-xl"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["Preço atual (texto)",e.jsx(Z,{value:c.currentPrice,onChange:n=>A({currentPrice:n.target.value}),className:"h-10 min-w-0 rounded-xl font-mono text-sm"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["Preço original (texto)",e.jsx(Z,{value:c.originalPrice,onChange:n=>
16A({originalPrice:n.target.value}),className:"h-10 min-w-0 rounded-xl font-mono text-sm"})]})]}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 flex-col gap-1 text-xs font-bold text-slate-600",children:["Gancho (opcional â antes do ðï¸)",e.jsx(ze,{value:c.aiHook,onChange:n=>A({aiHook:n.target.value}),rows:2,className:"min-h-[72px] resize-y rounded-xl text-sm touch-manipulation"})]}),J?e.jsxs(Q,{type:"button",variant:"outline",className:"h-11 shrink-0 touch-manipulation gap-2 rounded-xl",disabled:De,onClick:()=>void $e(),children:[Oe.isPending?e.jsx(Me,{className:"h-4 w-4 shrink-0 animate-spin"}):e.jsx(Vt,{className:"h-4 w-4 shrink-0","aria-hidden":!0}),"Gerar com IA"]}):null]})}),e.jsxs("label",{className:"flex cursor-pointer touch-manipulation items-center gap-2 rounded-xl border border-slate-200 bg-white px-3 py-2.5",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 shrink-0 accent-emerald-600",checked:V,onChange:n=>A({includeBanner:n.target.checked})}),e.jsxs("span",{className:"min-w-0 flex-1 text-xs font-bold text-slate-700",children:["Usar banner (arte) nesta oferta",e.jsx("span",{className:"block text-[11px] font-medium text-slate-500",children:"Desligado: envia só a foto do produto, sem a arte do template."})]})]}),V?e.jsx("div",{className:"min-w-0 max-w-full overflow-x-hidden",children:e.jsx(Gt,{value:c.templateId,onChange:n=>A({templateId:n}),productTitle:c.productTitle||m.productTitle||"Oferta",currentPrice:c.currentPrice||"â",originalPrice:c.originalPrice||void 0,discountPercent:d,cta:c.cta||void 0,productImageUrl:m.productImage||void 0,restrictToTemplateIds:L?lt:void 0})}):null,V&&v?e.jsx(Et,{banner:v,bannerTextOffsets:M,onBannerTextOffsetsChange:le,bannerPreviewRef:Ce,bannerCaptureRef:K,idPrefix:"library-sched",edit:{productTitle:c.productTitle,currentPrice:c.currentPrice,originalPrice:c.originalPrice,cta:c.cta,onProductTitleChange:n=>A({productTitle:n}),onCurrentPriceChange:n=>A({currentPrice:n}),onOriginalPriceChange:n=>A({originalPrice:n}),onCtaChange:n=>A({cta:n})}}):null,e.jsx(Re,{productTitle:c.productTitle||m.productTitle||"Oferta",postContent:fe||"â",imageSrc:V&&m.generatedBannerUrl||m.productImage,includeBanner:V,priceLabel:c.currentPrice||void 0,channelLabel:S==="whatsapp"?"WhatsApp":"Telegram",banner:V?v:null}),e.jsx(It,{id:`library-sched-coupon-${$??"x"}`,value:c.couponCode,onChange:n=>A({couponCode:n}),platform:m.platform,className:"mb-3"}),e.jsx(Ct,{platform:m.platform,checked:c.compactMlLink,onCheckedChange:n=>A({compactMlLink:n}),className:"mb-3"}),e.jsxs("div",{className:"rounded-[18px] border border-slate-100 bg-slate-50 p-4 relative",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-900",children:"Texto do Post"}),ee?e.jsxs("select",{value:c.copyTemplateId,onChange:n=>{const x=n.target.value,p={...c,copyTemplateId:x,postContent:""};A({copyTemplateId:x,postContent:Ee(m,p)})},className:"h-8 max-w-[min(100%,16rem)] rounded-lg border border-slate-200 bg-white px-2 text-xs font-bold text-slate-600 outline-none focus:ring-1 focus:ring-violet-500",children:[e.jsxs("option",{value:"",children:["Preferência da conta",(()=>{const n=ra(me.data,m.platform);if(n==null)return" (sistema)";const x=(se.data??[]).find(p=>Number(p.id)===n)?.name;return x?` (${x})`:""})()]}),e.jsx("option",{value:"0",children:"Modelo padrão (sistema)"}),(se.data??[]).map(n=>e.jsx("option",{value:String(n.id),children:n.name},n.id))]}):null]}),e.jsx(ze,{value:c.postContent.trim()?c.postContent:fe,onChange:n=>A({postContent:n.target.value}),placeholder:"Texto que será enviado no agendamentoâ¦",className:"min-h-[160px] min-w-0 resize-y rounded-xl border border-slate-200 bg-white text-sm touch-manipulation"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:e.jsx(Q,{type:"button",variant:"ghost",size:"sm",className:"h-9 touch-manipulation rounded-lg text-xs font-semibold text-slate-700",onClick:()=>A({postContent:Ee(m,c)}),children:"Restaurar modelo"})}),e.jsxs("p",{className:"mt-2 text-xs text-slate-500",children:[Ft(m.platform)," ·"," ",m.convertedUrl?"Link OK":"Sem link"," ·"," ","{{affiliateUrl}}"," vira o link no envio"]})]})]}):null]}):null,ne===2?e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsxs("label",{className:"text-xs font-bold text-slate-600",children:["Data inicial",e.jsx(Z,{type:"date",value:je,onChange:n=>Y(n.target.value),className:"mt-1 h-11 rounded-xl"})]}),e.jsxs("label",{className:"text-xs font-bold text-slate-600",children:["Primeiro post",e.jsx(Z,{type:"time",value:re,onChange:n=>Ne(n.target.value),className:"mt-1 h-11 rounded-xl"})]}),e.jsxs("label",{className:"text-xs font-bold text-slate-600",children:["Até",e.jsx(Z,{type:"time",value:ie,onChange:n=>ce(n.target.value),className:"mt-1 h-11 rounded-xl"})]}),e.jsxs("label",{className:"text-xs font-bold text-slate-600",children:["Intervalo (min)",e.jsx(Z,{type:"number",min:5,max:720,value:we,onChange:n=>Ae(Number(n.target.value)||30),className:"mt-1 h-11 rounded-xl"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>oe("whatsapp"),className:E("flex min-h-[44px] items-center gap-2 rounded-2xl border p-3 font-bold",S==="whatsapp"?"border-[#25D366] bg-[#25D366]/10 ring-2 ring-[#25D366]/25":"border-slate-200"),children:[e.jsx(rt,{className:"h-5 w-5 text-[#25D366]"}),"WhatsApp"]}),Te?e.jsxs("button",{type:"button",onClick:()=>oe("telegram"),className:E("flex min-h-[44px] items-center gap-2 rounded-2xl border p-3 font-bold",S==="telegram"?"border-[#2AABEE] bg-[#2AABEE]/10 ring-2 ring-[#2AABEE]/25":"border-slate-200"),children:[e.jsx(it,{className:"h-5 w-5 text-[#2AABEE]"}),"Telegram"]}):null]}),S==="whatsapp"?e.jsx(St,{}):e.jsx(Tt,{compact:!0}),e.jsx("div",{className:"max-h-36 space-y-1 overflow-y-auto rounded-xl border bg-slate-50 p-2",children:(he.data??[]).map(n=>e.jsxs("label",{className:"flex min-h-[40px] cursor-pointer items-center gap-2 rounded-lg px-2 text-xs font-semibold",children:[e.jsx("input",{type:"checkbox",checked:D.includes(n.chatId),onChange:()=>We(n.chatId),className:"h-4 w-4"}),n.chatName]},n.chatId))}),e.jsx(Xt,{channel:S,destinations:(he.data??[]).map(n=>({chatId:n.chatId,chatName:n.chatName})),selectedChatIds:D,categoriesByChatId:pe,onCategoriesChange:(n,x)=>_(p=>({...p,[n]:x}))}),e.jsx(bt,{visible:!D.length})]}):null,ne===3?e.jsxs("div",{className:"mt-4 space-y-3 rounded-2xl border border-emerald-100 bg-white p-4",children:[e.jsx("p",{className:"text-sm font-bold text-slate-900",children:"Resumo"}),e.jsxs("ul",{className:"space-y-1 text-xs text-slate-600",children:[e.jsxs("li",{children:[e.jsx("strong",{children:P.length})," oferta(s) na fila"]}),e.jsxs("li",{children:[je," · ",re,"â",ie," · a cada ",we," ","min"]}),e.jsxs("li",{children:["Canal: ",e.jsx("strong",{children:S})," · ",D.length," ","destino(s)"]})]}),m&&c?e.jsx(Re,{productTitle:c.productTitle||m.productTitle||"Oferta",postContent:fe||"â",imageSrc:V&&m.generatedBannerUrl||m.productImage,includeBanner:V,banner:V?v:null}):null,e.jsx("p",{className:"text-[11px] font-semibold text-slate-500",children:Se.without===0?"Banner (arte) será enviado em todas as ofertas.":Se.with===0?"Sem banner â cada post leva só a foto do produto.":`${Se.with} oferta(s) com banner e ${Se.without} só com a foto do produto.`})]}):null,e.jsx("div",{ref:Ie,className:"pointer-events-none fixed left-[-12000px] top-0 z-[-1] opacity-100","aria-hidden":!0,
16children:T?e.jsx(Le,{displayMode:"capture",templateId:T.templateId,productTitle:T.productTitle,currentPrice:T.currentPrice,originalPrice:T.originalPrice,discountPercent:T.discountPercent,cta:T.cta,productImageUrl:T.productImageUrl,titleOffsetYPercent:T.titleOffsetYPercent,priceOffsetYPercent:T.priceOffsetYPercent,ctaOffsetYPercent:T.ctaOffsetYPercent,fontScalePercent:T.fontScalePercent}):null}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[ne>1?e.jsxs(Q,{type:"button",variant:"outline",className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl sm:flex-none",onClick:()=>y(n=>n>1?n-1:n),children:[e.jsx(Mt,{className:"mr-1 h-4 w-4"}),"Voltar"]}):null,ne<3?e.jsxs(Q,{type:"button",className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl bg-emerald-600 font-bold hover:bg-emerald-700 sm:flex-none",onClick:()=>y(n=>n<3?n+1:n),children:["Continuar",e.jsx(kt,{className:"ml-1 h-4 w-4"})]}):e.jsxs(Q,{type:"button",disabled:De,className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl bg-gradient-to-r from-emerald-500 to-teal-500 font-black text-white sm:flex-none",onClick:()=>void ot(),children:[De?e.jsx(Me,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Pt,{className:"mr-2 h-4 w-4"}),"Confirmar agendamento"]})]})]})]})}function Ue(a,o){const g=a.currentPrice!=null?String(a.currentPrice):"",i=a.originalPrice!=null?String(a.originalPrice):"",N=lt[0]??"",O=_t()[0]?.id??"";return{productTitle:a.productTitle||"",currentPrice:g,originalPrice:i,aiHook:"",cta:"",postContent:"",templateId:o?N:O,copyTemplateId:"",couponCode:"",compactMlLink:!0,includeBanner:!0}}function Yt(a){const o=String(a||"").replace(/[^\d,.-]/g,"").replace(/\./g,"").replace(",","."),g=Number.parseFloat(o);return Number.isFinite(g)?g:Number.NaN}function pt(a,o){const g=Yt(a),i=Yt(o);if(!Number.isFinite(g)||!Number.isFinite(i)||i<=0)return;const N=Math.round((1-g/i)*100);if(!(!Number.isFinite(N)||N<0||N>99))return String(N)}function ht(a){return{start:a.start.trim(),end:a.end.trim(),intervalMinutes:Math.min(720,Math.max(5,Math.round(Number(a.intervalMinutes))||30))}}function Ua({offerIds:a,windowDraft:o,windowHydrated:g=!1,onDismiss:i,onScheduled:N,onWindowPersisted:O,setFeedback:f}){const j=C.useUtils(),{user:F}=wt(),G=C.access.me.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),R=F?.role==="admin",L=G.data?.planTier??1,J=G.data?.features??[],ee=G.data?.limits,ye=R?Math.max(1,ee?.maxWhatsAppGroups??4):Math.max(0,ee?.maxWhatsAppGroups??0),te=R?Math.max(0,ee?.maxTelegramChats??2):Math.max(0,ee?.maxTelegramChats??0),Te=R||L>=3,W=!R&&L===1,be=R||J.includes("operations.ai_copy"),se=R||J.includes("tools.copy_page"),me=R||J.includes("operations.auto_schedule")&&J.includes("operations.basic"),P=r.useMemo(()=>Array.from(new Set(a.map(s=>Number(s)).filter(s=>Number.isFinite(s)&&s>0))).slice(0,200),[a]),ne=P.join(","),y=C.miner.getMinedOffersByIds.useQuery({ids:P},{enabled:P.length>0,staleTime:3e4}),$=C.templates.list.useQuery(void 0,{enabled:se,retry:!1,staleTime:6e4}),ue=C.templates.getCopyPreferences.useQuery(void 0,{enabled:se,retry:!1,staleTime:6e4}),[B,ve]=r.useState("whatsapp"),[w,xe]=r.useState([]),[Ce,K]=r.useState({}),[Ie,M]=r.useState(()=>new Date().toLocaleDateString("sv-SE")),[le,ae]=r.useState(""),[ke,S]=r.useState(new Set),[oe,D]=r.useState(()=>ht(o)),[X,pe]=r.useState({}),[_,je]=r.useState(1),[Y,re]=r.useState(null),[Ne,ie]=r.useState(null),ce=r.useRef(!1),we=r.useRef(null),Ae=r.useRef(null),he=r.useRef(null),{offsets:q,setOffsets:t}=yt(),[m,c]=r.useState(!1);r.useEffect(()=>{D(ht(o)),ce.current=!1},[ne,o]),r.useEffect(()=>{!g||ce.current||(ce.current=!0,D(ht(o)))},[g,o]);const V=C.miner.getAvailableDestinations.useQuery({channel:B},{staleTime:6e4,refetchOnWindowFocus:!0}),Se=C.miner.getSchedulePreferences.useQuery(void 0,{staleTime:6e4,refetchOnWindowFocus:!1}),A=B==="whatsapp"?ye:te;r.useEffect(()=>{const s=V.data??[];xe(l=>{const h=l.filter(b=>s.some(k=>k.chatId===b));return h.length>0?h.slice(0,A):s.slice(0,A).map(b=>b.chatId)})},[V.data,A]),r.useEffect(()=>{const s=Se.data?.destinationCategories;s&&K(l=>{const h={...l},b=Kt(s,B,w);for(const[k,U]of Object.entries(b))(h[k]?.length??0)===0&&U.length&&(h[k]=U);return h})},[Se.data?.destinationCategories,B,w]),r.useEffect(()=>{if(!y.data?.length)return;const s=y.data.filter(l=>l.hasConfig).map(l=>Number(l.id));S(new Set(s))},[y.data]),r.useEffect(()=>{y.data?.length&&pe(s=>{const l={...s};for(const h of y.data){const b=h,k=Number(b.id);l[k]||(l[k]=Ue(b,W))}return l})},[y.data,W]);const d=r.useMemo(()=>(y.data??[]).filter(l=>ke.has(Number(l.id))),[y.data,ke]);r.useEffect(()=>{const s=d.filter(l=>l.hasConfig).map(l=>Number(l.id));if(!s.length){re(null);return}re(l=>l!=null&&s.includes(l)?l:s[0])},[d]);const v=r.useMemo(()=>Y==null?null:(y.data??[]).find(s=>Number(s.id)===Y),[y.data,Y]),u=r.useMemo(()=>Y==null||!v?.hasConfig?null:X[Y]??Ue(v,W),[Y,v,X,W]),T=u?.includeBanner??!0,fe=r.useMemo(()=>{let s=0,l=0;for(const h of d)h.hasConfig&&(X[Number(h.id)]?.includeBanner===!1?l++:s++);return{with:s,without:l}},[d,X]);function z(s){Y!=null&&pe(l=>{const h=(y.data??[]).find(k=>
16Number(k.id)===Y),b=l[Y]||(h?Ue(h,W):void 0);return b?{...l,[Y]:{...b,...s}}:l})}const Ee=r.useMemo(()=>u?pt(u.currentPrice,u.originalPrice):void 0,[u]),Oe=r.useMemo(()=>{if(!u||!v)return null;const s=u.templateId.trim();return s?{templateId:s,productTitle:u.productTitle||v.productTitle||"Oferta",currentPrice:u.currentPrice||"â",originalPrice:u.originalPrice||void 0,discountPercent:Ee,cta:u.cta||void 0,productImageUrl:v.productImage||void 0,titleOffsetYPercent:q.title,priceOffsetYPercent:q.price,ctaOffsetYPercent:q.cta,fontScalePercent:q.fontScale}:null},[u,v,Ee,q]);function qe(s){const h=(y.data??[]).find(U=>Number(U.id)===s);if(!h)return null;const b=X[s]||Ue(h,W),k=b.templateId.trim();return k?{templateId:k,productTitle:b.productTitle||h.productTitle||"Oferta",currentPrice:b.currentPrice||"â",originalPrice:b.originalPrice||void 0,discountPercent:pt(b.currentPrice,b.originalPrice),cta:b.cta||void 0,productImageUrl:h.productImage||void 0,titleOffsetYPercent:q.title,priceOffsetYPercent:q.price,ctaOffsetYPercent:q.cta,fontScalePercent:q.fontScale}:null}const de=r.useMemo(()=>Ne==null?null:qe(Ne),[Ne,y.data,X,q,W]),Be=r.useMemo(()=>!u||!v?.hasConfig?"":We(v,u),[u,v,Ee,$.data,ue.data]);function We(s,l,h){const b=String(s.convertedUrl??"").trim(),k=qt(l.couponCode,s.platform),U=sa(l.copyTemplateId);return na({postContent:h?.ignorePostContent?null:l.postContent,copyTemplateId:U.copyTemplateId,skipAccountDefault:U.skipAccountDefault,forceSystemDefault:U.forceSystemDefault,templates:$.data??[],prefs:ue.data??null,platform:s.platform,productTitle:l.productTitle||s.productTitle||"",currentPrice:l.currentPrice||s.currentPrice,originalPrice:l.originalPrice||s.originalPrice,discountPercent:pt(l.currentPrice,l.originalPrice),convertedUrl:b||"{{affiliateUrl}}",aiHook:l.aiHook,ctaLine:l.cta,couponCode:k,linkMode:"placeholder"})}function Fe(s,l){return We(s,l,{ignorePostContent:!0})}const Je=C.miner.updateScheduleWindow.useMutation({onSuccess:s=>{if(!s.scheduleWindow)return;const l=s.scheduleWindow;D({start:l.start,end:l.end,intervalMinutes:l.intervalMinutes}),O?.(l)},onError:s=>{f(`â ${s.message}`),setTimeout(()=>f(""),6e3)}}),$e=C.converter.generateCopy.useMutation({onError:s=>{f(`â ${s.message}`),setTimeout(()=>f(""),6e3)}}),ot=C.converter.fetchProductImageDataUrl.useMutation(),De=C.miner.scheduleSelectedOffers.useMutation({onSuccess:async s=>{vt(),await Promise.all([j.miner.getQueue.invalidate(),j.miner.getScheduleOverview.invalidate(),j.miner.getSchedulePreferences.invalidate()]),f(`â
${s.createdCount} agendamento(s) criado(s) a partir da Vitrine.`),setTimeout(()=>f(""),6e3),N()},onError:s=>{f(`â ${s.message}`),setTimeout(()=>f(""),6e3)}});function n(s){S(l=>{const h=new Set(l);return h.has(s)?h.delete(s):h.add(s),h})}function x(s){xe(l=>l.includes(s)?l.filter(h=>h!==s):l.length>=A?[...l.slice(1),s]:[...l,s])}function p(){try{const s=_e({start:o.start,end:o.end,intervalMinutes:o.intervalMinutes});D(s),f(`â
Janela aplicada: ${s.start}â${s.end}, ${s.intervalMinutes} min entre posts.`)}catch(s){f(s instanceof Error?`â ï¸ ${s.message}`:"â ï¸ Horários inválidos (HH:mm).")}setTimeout(()=>f(""),4e3)}function I(s,l={}){const h=y.data??[];return s.map(b=>{const k=h.find(ct=>Number(ct.id)===b),U=X[b]||(k?Ue(k,W):void 0);if(!U||!k)return{offerId:b};const Xe=We(k,U);return{offerId:b,productTitle:U.productTitle.trim()||void 0,currentPrice:U.currentPrice.trim()||void 0,originalPrice:U.originalPrice.trim()||void 0,aiHook:U.aiHook.trim()||void 0,cta:U.cta.trim()||void 0,templateId:U.templateId.trim()||void 0,postContent:Xe.trim()||void 0,forceSystemDefaultCopy:U.copyTemplateId==="0",couponCode:U.couponCode.trim()||void 0,compactMlLink:U.compactMlLink,imageBase64:l[b]}})}async function H(s){const l=y.data??[],h={};for(const b of s){const k=l.find(Qe=>Number(Qe.id)===b),U=X[b]||(k?Ue(k,W):void 0),Xe=U?.templateId?.trim();if(!k||!U||!Xe||U.includeBanner===!1)continue;ie(b),await new Promise(Qe=>setTimeout(Qe,520));const ct=await Bt(()=>he.current,6e3),ia=qe(b),Dt=await Ot(ct,Xe,{compose:ia,prefetchImage:async Qe=>{try{const{dataUrl:la}=await ot.mutateAsync({imageUrl:Qe});return la}catch{return null}}});Dt&&(h[b]=Dt)}return ie(null),h}async function Pe(){if(Y==null||!u)return;const s=u.productTitle.trim()||v?.productTitle?.trim()||"";if(!s){f("â ï¸ Defina um tÃtulo para gerar o gancho."),setTimeout(()=>f(""),4500);return}try{const l=await $e.mutateAsync({channel:"whatsapp",productTitle:s}),h=ja(String(l.content??""));h&&(z({aiHook:Sa(h),postContent:""}),f("⨠Gancho IA em negrito gerado."),setTimeout(()=>f(""),4500))}catch{}}async function Ke(){if(!me){f("ð Agendar a partir da Vitrine requer Elite com agendamento automático ativo."),setTimeout(()=>f(""),6500);return}const s=d.filter(b=>b.hasConfig).map(b=>Number(b.id));if(!s.length){f("â ï¸ Nenhuma oferta apta: configure afiliado para as plataformas de
16stas ofertas."),setTimeout(()=>f(""),5e3);return}if(!w.length){ta(),f(`â ï¸ ${aa}`),setTimeout(()=>f(""),7e3);return}if(B==="whatsapp"&&!Zt(B,w,Ce)){f("â ï¸ Defina a categoria de nicho para cada grupo do WhatsApp selecionado."),setTimeout(()=>f(""),5e3);return}const l=oe;let h;try{h=_e({start:l.start,end:l.end,intervalMinutes:l.intervalMinutes})}catch(b){f(b instanceof Error?`â ï¸ ${b.message}`:"â ï¸ Use «Aplicar janela abaixo» após ajustar inÃcio/fim (HH:mm)."),setTimeout(()=>f(""),5500);return}D(h);try{c(!0),f("Preparando artes do bannerâ¦");const b=await H(s),U=(await Je.mutateAsync(h)).scheduleWindow??h;await De.mutateAsync({offerIds:s,channel:B,targetChatIds:w,targetCategoryMap:ea(w,Ce),intervalMinutes:U.intervalMinutes,anchorDate:Ie.trim()||void 0,anchorTime:le.trim()||void 0,offerOverrides:I(s,b)})}catch{}finally{c(!1)}}const Ye=De.isPending||Je.isPending||$e.isPending||y.isFetching||m;return P.length===0?null:e.jsxs("section",{className:"overflow-hidden rounded-[24px] border border-emerald-200/90 bg-gradient-to-br from-emerald-50/90 via-white to-violet-50/40 p-4 shadow-sm sm:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-emerald-100/80 pb-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-[0.18em] text-emerald-800",children:"Vitrine â agenda"}),e.jsxs("h2",{className:"flex items-center gap-2 text-lg font-black tracking-tight text-slate-900 sm:text-xl",children:[e.jsx(Ge,{className:"h-6 w-6 shrink-0 text-emerald-600"}),"Agendar ofertas selecionadas"]}),e.jsx("p",{className:"max-w-2xl text-sm leading-relaxed text-slate-600",children:"Prévia com foto, programação e confirmação nesta tela â sem voltar à Vitrine."})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:e.jsxs(Q,{type:"button",variant:"outline",size:"sm",className:"h-10 touch-manipulation rounded-xl border-slate-200",onClick:()=>{vt(),i()},children:[e.jsx(nt,{className:"mr-1.5 h-4 w-4"}),"Fechar"]})})]}),me?null:e.jsxs("p",{className:"mt-4 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm font-semibold text-amber-950",children:["Seu plano ainda não inclui agendamento a partir do pool da Vitrine."," ",e.jsx(Ve,{to:"/upgrade",className:"font-bold text-violet-800 underline underline-offset-2",children:"Ver planos"}),"."]}),y.isLoading?e.jsxs("div",{className:"mt-4 flex items-center gap-2 text-sm text-slate-600",children:[e.jsx(Me,{className:"h-5 w-5 animate-spin text-emerald-600"}),"Carregando ofertas da Vitrineâ¦"]}):y.isError?e.jsx("p",{className:"mt-4 text-sm text-rose-700",children:"Não foi possÃvel carregar as ofertas. Volte à Vitrine e tente de novo."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4",children:e.jsx(At,{step:_})}),_===1?e.jsxs("div",{className:"mt-4",children:[e.jsxs("p",{className:"mb-2 text-xs font-bold uppercase tracking-wide text-slate-500",children:["Ofertas (",y.data?.length??0,")"]}),e.jsx("div",{className:"-mx-1 flex gap-2 overflow-x-auto pb-2 pt-1 [scrollbar-width:thin]",children:(y.data??[]).map(s=>{const l=s,h=Number(l.id),b=ke.has(h),k=!l.hasConfig,U=Y===h;return e.jsxs("div",{className:E("flex w-[9.5rem] shrink-0 flex-col overflow-hidden rounded-2xl border bg-white text-left shadow-sm transition",b?"border-emerald-400 ring-1 ring-emerald-300/50":"border-slate-200 opacity-95",k&&"opacity-45",U&&"ring-2 ring-violet-500 ring-offset-1"),children:[e.jsx("div",{className:"flex items-center justify-between gap-1 px-1.5 pb-1 pt-1.5",children:e.jsxs("label",{className:E("flex min-h-[36px] cursor-pointer touch-manipulation select-none items-center gap-1 rounded-lg px-0.5 py-0.5 text-[9px] font-black uppercase tracking-wide text-slate-600",k&&"cursor-not-allowed opacity-60"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 shrink-0 accent-emerald-600",checked:b,disabled:k,onChange:()=>n(h),"aria-label":b?"Remover do lote":"Incluir no lote"}),"Lote"]})}),e.jsxs("button",{type:"button",disabled:k,onClick:()=>re(h),className:E("flex flex-1 flex-col text-left touch-manipulation outline-none focus-visible:ring-2 focus-visible:ring-violet-500/60",k&&"cursor-not-allowed"),children:[e.jsxs("div",{className:"relative flex aspect-square w-full items-center justify-center overflow-hidden rounded-xl bg-slate-50 p-1",children:[l.productImage?e.jsx("img",{src:l.productImage,alt:"",className:"max-h-full max-w-full object-contain",loading:"lazy"}):e.jsx("div",{className:"flex h-full items-center justify-center text-[10px] font-bold text-slate-400",children:"Sem imagem"}),b?e.jsx("span",{className:"pointer-events-none absolute right-1.5 top-1.5 flex h-7 w-7 items-center justify-center rounded-full border border-emerald-600 bg-emerald-600 text-white shadow-sm",children:e.jsx(Pt,{className:"h-4 w-4","aria-hidden":!0})}):null]}),e.jsxs("div",{className:"space-y-1 p-2",children:[e.jsx("p",{className:"line-clamp-2 text-[11px] font-bold leading-snug text-slate-900",children:l.productTitle||"â"}),e.jsx("p",{className:"text-[10px] font-semibold uppercase text-slate-500",children:String(l.platform||"")}),k?e.jsx("p",{className:"text-[10px] font-semibold text-amber-700",children:"Sem afiliado"}):null,k?null:e.jsx("p",{className:"text-[9px] font-semibold text-violet-600",children:U?"Editando":"Toque para editar"})]})]})]},h)})})]}):null,_===2?e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsx("p",{className:"mb-3 text-xs font-black uppercase tracking-wide text-slate-500",children:"Canal e destinos"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsxs("button",{type:"button","aria-pressed":B==="whatsapp",onClick:()=>ve("whatsapp"),className:E("flex min-h-[44px] touch-manipulation items-center gap-2 rounded-xl border px-3 py-2 text-left text-sm font-bold transition-all active:scale-[0.98]",B==="whatsapp"?"border-[#25D366] bg-[#25D366]/10 ring-2 ring-[#25D366]/30":"border-slate-200 hover:border-[#25D366]/40"),children:[e.jsx(rt,{className:"h-5 w-5 shrink-0 text-[#25D366]"}),"WhatsApp"]}),Te?e.jsxs("button",{type:"button","aria-pressed":B==="telegram",onClick:()=>ve("telegram"),className:E("flex min-h-[44px] touch-manipulation items-center gap-2 rounded-xl border px-3 py-2 text-left text-sm font-bold transition-all active:scale-[0.98]",B==="telegram"?"border-[#2AABEE] bg-[#2AABEE]/10 ring-2 ring-[#2AABEE]/30":"border-slate-200 hover:border-[#2AABEE]/40"),children:[e.jsx(it,{className:"h-5 w-5 shrink-0 text-[#2AABEE]"}),"Telegram"]}):null]}),B==="whatsapp"?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx(St,{}),e.jsxs("p",{className:"text-[11px] font-semibold text-slate-500",children:["Até ",ye," destino(s) neste disparo (seu plano)."]})]}):e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx(Tt,{compact:!0}),e.jsxs("p",{className:"text-[11px] font-semibold text-slate-500",children:["Até ",te," destino(s) neste disparo (seu plano)."]})]}),e.jsx("div",{className:"mt-3 max-h-48 space-y-1.5 overflow-y-auto rounded-xl border border-slate-100 bg-slate-50/80 p-2",children:(V.data??[]).length===0?e.jsx("p",{className:"px-1 py-2 text-xs text-slate-600",children:"Nenhum destino disponÃvel. Conecte o canal acima."}):(V.data??[]).map(s=>{const l=w.includes(s.chatId);return e.jsxs("label",{className:E("flex min-h-[40px] cursor-pointer touch-manipulation items-center gap-2 rounded-lg border px-2 py-1.5 transition-colors active:scale-[0.99]",l?"border-violet-300 bg-vi
16olet-50 ring-1 ring-violet-200":"border-transparent hover:bg-white"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 shrink-0 accent-emerald-600",checked:l,onChange:()=>x(s.chatId)}),e.jsx("span",{className:"min-w-0 flex-1 text-xs font-semibold leading-snug text-slate-800",children:s.chatName})]},s.chatId)})}),e.jsx(Xt,{channel:B,destinations:(V.data??[]).map(s=>({chatId:s.chatId,chatName:s.chatName})),selectedChatIds:w,categoriesByChatId:Ce,onCategoriesChange:(s,l)=>K(h=>({...h,[s]:l})),className:"mt-3"}),e.jsx(bt,{visible:!w.length,className:"mt-3"})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsx("p",{className:"mb-3 text-xs font-black uppercase tracking-wide text-slate-500",children:"Grade e data inicial"}),e.jsxs("p",{className:"mb-3 text-xs leading-relaxed text-slate-500",children:["Os horários usados no disparo são os da caixa"," ",e.jsx("strong",{children:"Janela aplicada"}),". Ajuste o bloco"," ",e.jsx("strong",{children:"Janela diária e intervalo"})," abaixo e traga os valores com o botão."]}),e.jsxs("label",{className:"mb-3 flex flex-col gap-1 text-xs font-bold text-slate-600",children:["Primeira data da sequência",e.jsx(Z,{type:"date",value:Ie,onChange:s=>M(s.target.value),className:"h-11 rounded-xl touch-manipulation"})]}),e.jsxs("label",{className:"mb-3 flex flex-col gap-1 text-xs font-bold text-slate-600",children:["Horário do primeiro post (opcional)",e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Z,{type:"time",value:le,onChange:s=>ae(s.target.value),className:"h-11 flex-1 rounded-xl touch-manipulation"}),le?e.jsx(Q,{type:"button",variant:"outline",className:"h-11 rounded-xl",onClick:()=>ae(""),children:"Limpar"}):null]}),e.jsx("span",{className:"text-[11px] font-medium text-slate-500",children:le?`O 1º post sai à s ${le} e os próximos a cada ${oe.intervalMinutes} min, dentro da janela.`:"Vazio: hoje começa agora; em dia futuro, no inÃcio da janela."})]}),e.jsxs("div",{className:"mb-3 rounded-xl border border-emerald-100 bg-emerald-50/50 px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wide text-emerald-900",children:"Janela aplicada ao disparo"}),e.jsxs("p",{className:"mt-1 font-mono text-sm font-semibold text-slate-800",children:[oe.start," â ",oe.end," ·"," ",oe.intervalMinutes," min"]})]}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",className:"h-10 w-full touch-manipulation gap-2 rounded-xl border-emerald-200 bg-white font-semibold text-emerald-950 hover:bg-emerald-50 sm:w-auto",onClick:p,children:[e.jsx(Ma,{className:"h-4 w-4 shrink-0","aria-hidden":!0}),"Aplicar janela abaixo"]})]})]}):null,_===1&&u&&v?e.jsxs("div",{className:"mt-5 space-y-4 rounded-2xl border border-violet-200/80 bg-gradient-to-b from-white to-violet-50/30 p-4 shadow-sm sm:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("h3",{className:"text-sm font-black text-slate-900",children:"Personalização (Converter link)"}),d.filter(s=>s.hasConfig).length>1?e.jsx("div",{className:"flex max-w-full flex-wrap gap-1.5",children:d.filter(s=>s.hasConfig).map(s=>{const l=Number(s.id),h=l===Y;return e.jsxs("button",{type:"button",onClick:()=>re(l),className:E("max-w-[10rem] touch-manipulation truncate rounded-full border px-2.5 py-1 text-[11px] font-bold transition",h?"border-violet-500 bg-violet-600 text-white":"border-slate-200 bg-white text-slate-700 hover:border-violet-300"),children:["#",l]},l)})}):null]}),e.jsxs("p",{className:"text-xs text-slate-500",children:["Editando:"," ",e.jsx("span",{className:"font-semibold text-slate-800",children:v.productTitle||`Oferta ${Y}`})]}),e.jsxs("label",{className:"flex cursor-pointer touch-manipulation items-center gap-2 rounded-xl border border-slate-200 bg-white px-3 py-2.5",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 shrink-0 accent-emerald-600",checked:T,onChange:s=>z({includeBanner:s.target.checked})}),e.jsxs("span",{className:"min-w-0 flex-1 text-xs font-bold text-slate-700",children:["Usar banner (arte) nesta oferta",e.jsx("span",{className:"block text-[11px] font-medium text-slate-500",children:"Desligado: envia só a foto do produto, sem a arte do template."})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["TÃtulo",e.jsx(Z,{value:u.productTitle,onChange:s=>
16z({productTitle:s.target.value}),className:"h-10 min-w-0 rounded-xl"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["CTA no banner",e.jsx(Z,{value:u.cta,onChange:s=>z({cta:s.target.value}),placeholder:"Ex.: Ver oferta",className:"h-10 min-w-0 rounded-xl"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["Preço atual (texto)",e.jsx(Z,{value:u.currentPrice,onChange:s=>z({currentPrice:s.target.value}),className:"h-10 min-w-0 rounded-xl font-mono text-sm"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs font-bold text-slate-600",children:["Preço original (texto)",e.jsx(Z,{value:u.originalPrice,onChange:s=>z({originalPrice:s.target.value}),className:"h-10 min-w-0 rounded-xl font-mono text-sm"})]})]}),e.jsxs("div",{className:"rounded-2xl border-2 border-fuchsia-200/90 bg-gradient-to-br from-fuchsia-50/80 via-white to-violet-50/50 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black tracking-tight text-slate-900",children:"Gancho em negrito (WhatsApp)"}),e.jsxs("p",{className:"mt-1 text-[11px] leading-relaxed text-slate-600 [overflow-wrap:anywhere]",children:["Abertura curta por oferta. No WhatsApp sai em"," ",e.jsx("strong",{className:"font-black text-slate-800",children:"negrito"})," ","(",e.jsx("span",{className:"font-mono text-[10px]",children:"*texto*"}),")."]})]}),be?e.jsxs(Q,{type:"button",className:"h-12 min-h-[44px] w-full shrink-0 touch-manipulation gap-2 rounded-2xl bg-gradient-to-r from-fuchsia-600 via-violet-600 to-purple-700 px-5 text-sm font-black text-white shadow-md hover:opacity-95 sm:w-auto",disabled:Ye,onClick:()=>void Pe(),children:[$e.isPending?e.jsx(Me,{className:"h-4 w-4 shrink-0 animate-spin"}):e.jsx(Vt,{className:"h-4 w-4 shrink-0","aria-hidden":!0}),"Gerar gancho IA (negrito)"]}):e.jsxs("div",{className:"flex h-12 min-h-[44px] w-full items-center justify-center rounded-2xl border border-slate-200 bg-slate-100 px-4 text-xs font-bold text-slate-500 sm:w-auto",children:[e.jsx(ca,{className:"mr-1.5 h-3.5 w-3.5"}),"Gancho IA no Elite"]})]}),e.jsxs("label",{className:"mt-3 flex flex-col gap-1 text-xs font-bold text-slate-600",children:["Texto do gancho",e.jsx(ze,{value:u.aiHook,onChange:s=>z({aiHook:s.target.value}),rows:3,placeholder:"Ex.: *ESSE SALVA QUEM MORA DE ALUGUEL* â ou clique em Gerar gancho IA (negrito).",className:E("min-h-[88px] resize-y rounded-xl text-sm touch-manipulation",u.aiHook.trim()&&"font-black text-slate-900")})]}),u.aiHook.trim()?e.jsx("p",{className:"mt-2 text-[11px] font-semibold text-fuchsia-800",children:"Prévia no WhatsApp: primeira linha em negrito no envio agendado."}):null,be?null:e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500",children:"Ganchos com IA estão disponÃveis no plano com texto assistido (operations.ai_copy)."})]}),T?e.jsx("div",{className:"min-w-0 max-w-full overflow-x-hidden",children:e.jsx(Gt,{value:u.templateId,onChange:s=>z({templateId:s}),productTitle:u.productTitle||v.productTitle||"Oferta",currentPrice:u.currentPrice||"â",originalPrice:u.originalPrice||void 0,discountPercent:Ee,cta:u.cta||void 0,productImageUrl:v.productImage||void 0,restrictToTemplateIds:W?lt:void 0})}):null,T&&Oe?e.jsx(Et,{banner:Oe,bannerTextOffsets:q,onBannerTextOffsetsChange:t,bannerPreviewRef:we,bannerCaptureRef:Ae,idPrefix:"vitrine-sched",edit:{productTitle:u.productTitle,currentPrice:u.currentPrice,originalPrice:u.originalPrice,cta:u.cta,onProductTitleChange:s=>
16z({productTitle:s}),onCurrentPriceChange:s=>z({currentPrice:s}),onOriginalPriceChange:s=>z({originalPrice:s}),onCtaChange:s=>z({cta:s})}}):null,e.jsx(Re,{productTitle:u.productTitle||v.productTitle||"Oferta",postContent:Be||"â",imageSrc:v.productImage,includeBanner:T,priceLabel:u.currentPrice||void 0,banner:T?Oe:null}),e.jsx(It,{id:`vitrine-sched-coupon-${Y??"x"}`,value:u.couponCode,onChange:s=>z({couponCode:s}),platform:v.platform,className:"mb-3"}),e.jsx(Ct,{platform:v.platform,checked:u.compactMlLink,onCheckedChange:s=>z({compactMlLink:s}),className:"mb-3"}),e.jsxs("div",{className:"rounded-[18px] border border-slate-100 bg-slate-50 p-4",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-900",children:"Texto do Post"}),se?e.jsxs("select",{value:u.copyTemplateId,onChange:s=>{const l=s.target.value,h={...u,copyTemplateId:l,postContent:""};z({copyTemplateId:l,postContent:Fe(v,h)})},className:"h-8 max-w-[min(100%,16rem)] rounded-lg border border-slate-200 bg-white px-2 text-xs font-bold text-slate-600 outline-none focus:ring-1 focus:ring-violet-500",children:[e.jsxs("option",{value:"",children:["Preferência da conta",(()=>{const s=ra(ue.data,v.platform);if(s==null)return" (sistema)";const l=($.data??[]).find(h=>Number(h.id)===s)?.name;return l?` (${l})`:""})()]}),e.jsx("option",{value:"0",children:"Modelo padrão (sistema)"}),($.data??[]).map(s=>e.jsx("option",{value:String(s.id),children:s.name},s.id))]}):null]}),e.jsx(ze,{value:u.postContent.trim()?u.postContent:Be,onChange:s=>z({postContent:s.target.value}),placeholder:"Texto que será enviado no agendamentoâ¦",className:"min-h-[160px] min-w-0 resize-y rounded-xl border border-slate-200 bg-white text-sm touch-manipulation"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:e.jsx(Q,{type:"button",variant:"ghost",size:"sm",className:"h-9 touch-manipulation rounded-lg text-xs font-semibold text-slate-700",onClick:()=>z({postContent:Fe(v,u)}),children:"Restaurar modelo"})}),e.jsxs("p",{className:"mt-2 text-xs text-slate-500",children:["Prefira «Modelo padrão (sistema)» para ver o texto completo.","{{affiliateUrl}}"," vira o link no envio."]})]})]}):null,_===3?e.jsxs("div",{className:"mt-4 space-y-3 rounded-2xl border border-emerald-100 bg-white p-4",children:[e.jsx("p",{className:"text-sm font-bold text-slate-900",children:"Resumo"}),e.jsxs("ul",{className:"text-xs text-slate-600 space-y-1",children:[e.jsxs("li",{children:[e.jsx("strong",{children:d.filter(s=>s.hasConfig).length})," ","oferta(s) no lote"]}),e.jsxs("li",{children:["Canal ",e.jsx("strong",{children:B})," · ",w.length," ","destino(s)"]}),e.jsxs("li",{children:["Janela ",oe.start,"â",oe.end," ·"," ",oe.intervalMinutes," min"]})]}),u&&v?e.jsx(Re,{productTitle:u.productTitle||v.productTitle||"Oferta",postContent:Be||"â",imageSrc:v.productImage,includeBanner:T,banner:T?Oe:null}):null,e.jsx("p",{className:"text-[11px] font-semibold text-slate-500",children:fe.without===0?"Banner (arte) será enviado em todas as ofertas.":fe.with===0?"Sem banner â cada post leva só a foto do produto.":`${fe.with} oferta(s) com banner e ${fe.without} só com a foto do produto.`})]}):null,e.jsx("div",{ref:he,className:"pointer-events-none fixed left-[-12000px] top-0 z-[-1] opacity-100","aria-hidden":!0,children:de?e.jsx(Le,{displayMode:"capture",templateId:de.templateId,productTitle:de.productTitle,currentPrice:de.currentPrice,originalPrice:de.originalPrice,discountPercent:de.discountPercent,cta:de.cta,productImageUrl:de.productImageUrl,titleOffsetYPercent:de.titleOffsetYPercent,priceOffsetYPercent:de.priceOffsetYPercent,ctaOffsetYPercent:de.ctaOffsetYPercent,fontScalePercent:de.fontScalePercent}):null}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[_>1?e.jsxs(Q,{type:"button",variant:"outline",className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl sm:flex-none",onClick:()=>je(s=>s>1?s-1:s),children:[e.jsx(Mt,{className:"mr-1 h-4 w-4"}),"Voltar"]}):e.jsx(Q,{type:"button",variant:"outline",className:"h-11 touch-manipulation rounded-xl sm:flex-none",asChild:!0,children:e.jsx(Ve,{to:"/miner-offers",children:"Vitrine"})}),_<3?e.jsxs(Q,{type:"button",className:"h-11 min-h-[44px] flex-1 touch-manipulation rounded-xl bg-emerald-600 font-bold text-white sm:flex-none",onClick:()=>je(s=>s<3?s+1:s),children:["Continuar",e.jsx(kt,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[e.jsx(bt,{visible:!w.length,className:"w-full"}),e.jsx(Q,{type:"button",className:"h-11 min-h-[44px] w-full touch-manipulation rounded-xl bg-emerald-600 font-bold text-white hover:bg-emerald-700 disabled:opacity-50 sm:w-auto",disabled:Ye||!me||!d.filter(s=>s.hasConfig).length,onClick:()=>void Ke(),children:Ye?e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"mr-2 h-4 w-4 animate-spin"}),"Agendandoâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Confirmar agendamento"]})})]})]})]})]})}const La=[{value:5,label:"5 min"},{value:10,label:"10 min"},{value:15,label:"15 min"},{value:30,label:"30 min",recommended:!0},{value:45,label:"45 min"},{value:60,label:"1 hora"}
16,{value:90,label:"1h 30m"},{value:120,label:"2 horas"}],Ra={shopee:{label:"Shopee",bg:"bg-[#ee4d2d]",text:"text-white"},mercadolivre:{label:"Mercado Livre",bg:"bg-[#ffe600]",text:"text-slate-900"},amazon:{label:"Amazon",bg:"bg-[#232f3e]",text:"text-white"},magalu:{label:"Magalu",bg:"bg-[#0086ff]",text:"text-white"},shein:{label:"Shein",bg:"bg-[#7928ca]",text:"text-white"},tiktokshop:{label:"TikTok",bg:"bg-black",text:"text-white"}};function Qt(a){if(!a)return"â";const o=a instanceof Date?a:new Date(a);return Number.isNaN(o.getTime())?"â":Pa(o)?`Hoje à s ${st(o,"HH:mm")}`:ya(o)?`Amanhã à s ${st(o,"HH:mm")}`:st(o,"dd/MM 'à s' HH:mm",{locale:zt})}function Wa(a){if(!a)return"â";const o=a instanceof Date?a:new Date(a);return Number.isNaN(o.getTime())?"â":st(o,"dd/MM HH:mm",{locale:zt})}function Is(){const a=C.useUtils(),o=ma(),[g,i]=oa(),N=g.get("vitrineSchedule")==="1",O=g.get(mt)==="1",f=g.get(ut)==="1",[j,F]=r.useState([]),[G,R]=r.useState([]),[L,J]=r.useState(null),[ee,ye]=r.useState(null),[te,Te]=r.useState("all"),[W,be]=r.useState(!0),[se,me]=r.useState(!0),[P,ne]=r.useState(!0),[y,$]=r.useState(!0);r.useEffect(()=>{if(!N){F([]);return}const t=Ta();F(t),t.length===0&&i(m=>{const c=new URLSearchParams(m);return c.delete("vitrineSchedule"),c},{replace:!0})},[N,i]),r.useEffect(()=>{if(!O){J(null);return}const t=Na();J(t),t||i(m=>{const c=new URLSearchParams(m);return c.delete(mt),c},{replace:!0})},[O,i]);function ue(){ft(),J(null),i(t=>{const m=new URLSearchParams(t);return m.delete(mt),m},{replace:!0})}r.useEffect(()=>{if(!f){R([]);return}const t=wa();R(t),t.length===0&&i(m=>{const c=new URLSearchParams(m);return c.delete(ut),c},{replace:!0})},[f,i]);function B(){gt(),R([]),i(t=>{const m=new URLSearchParams(t);return m.delete(ut),m},{replace:!0})}function ve(){vt(),F([]),i(t=>{const m=new URLSearchParams(t);return m.delete("vitrineSchedule"),m},{replace:!0})}L||j.length>0||G.length>0;const w=C.miner.getScheduleOverview.useQuery(void 0,{staleTime:15e3,refetchOnWindowFocus:!1,refetchInterval:t=>o?Number(t.state.data?.queuePending??0)>0?12e3:25e3:!1}),[xe,Ce]=r.useState("08:00"),[K,Ie]=r.useState("22:30"),[M,le]=r.useState(30),[ae,ke]=r.useState(!1),[S,oe]=r.useState(null);function D(t){Ce(t.start),Ie(t.end),le(t.intervalMinutes),oe(t)}r.useEffect(()=>{const t=w.data?.scheduleWindow;if(!t)return;const m={start:t.start,end:t.end,intervalMinutes:jt(t.intervalMinutes??30)};ae||(D(m),ke(!0))},[w.data?.scheduleWindow,ae]);const X=r.useMemo(()=>{if(!S)return!0;try{const t=_e({start:xe,end:K,intervalMinutes:M});return!Ea(t,S)}catch{return!0}},[xe,K,M,S]),pe=C.miner.updateScheduleWindow.useMutation({onSuccess:async t=>{t.scheduleWindow&&(D(t.scheduleWindow),a.miner.getScheduleOverview.setData(void 0,m=>m&&{...m,scheduleWindow:{...m.scheduleWindow,start:t.scheduleWindow.start,end:t.scheduleWindow.end,intervalMinutes:t.scheduleWindow.intervalMinutes}})),await Promise.all([a.miner.getSchedulePreferences.invalidate(),a.miner.getQueue.invalidate()]),ge.success(`Janela salva: ${t.scheduleWindow?.start??xe} à s ${t.scheduleWindow?.end??K}, a cada ${t.scheduleWindow?.intervalMinutes??M} min.`)},onError:t=>ge.error(`Erro ao salvar: ${t.message}`)}),_=C.miner.setScheduleDispatchPaused.useMutation({onSuccess:async(t,m)=>{await Promise.all([w.refetch(),a.miner.getSchedulePreferences.invalidate()]),m.paused?ge.info("â¸ï¸ Disparos pausados. Nenhum agendamento pendente sairá até retomar."):ge.success("â¶ï¸ Disparos da agenda retomados com sucesso!")},onError:t=>ge.error(`Erro: ${t.message}`)}),je=C.miner.cancelPendingScheduledCampaign.useMutation({onSuccess:async()=>{ye(null),ge.success("Oferta removida da fila de agendamento."),await Promise.all([w.refetch(),a.miner.getQueue.invalidate()])},onError:t=>{ye(null),ge.error(`Erro: ${t.message}`)}}),Y=C.miner.abortAllSchedules.useMutation({onSuccess:async()=>{await Promise.all([w.refetch(),a.miner.getQueue.invalidate()]),ge.success("Todos os envios pendentes foram cancelados.")},onError:t=>ge.error(`Erro: ${t.message}`)}),re=r.useMemo(()=>(w.data?.upcoming||[]).slice(),[w.data?.upcoming]),Ne=w.data?.queuePending??0,ie=w.data?.scheduleWindow?.dispatchPaused??!1;w.data?.dispatchHealth?.overall;async function ce(t){const m=t??M;let c;try{c=_e({start:xe,end:K,intervalMinutes:m})}catch(V){ge.error(V instanceof Error?V.message:"Use horários válidos no formato HH:mm (ex.: 08:00).");return}D(c),await pe.mutateAsync(c)}function we(){if(Ne===0){ge.info("Não há envios pendentes para cancelar.");return}window.confirm(`Cancelar todos os ${Ne} envio(s) pendente(s)? Esta ação removerá os agendamentos da fila.`)&&Y.mutateAsync()}async function Ae(t){window.confirm("Remover esta oferta da fila de agendamento?")&&(ye(t),await je.mutateAsync({id:t}))}const he=w.data?.recentDispatches??[],q=r.useMemo(()=>te==="sent"?he.filter(t=>t.status==="sent"):te==="failed"?he.filter(t=>t.status==="failed"):he,[he,te]);
16return e.jsxs("div",{className:"min-w-0 w-full space-y-5 pb-28 md:pb-16",children:[e.jsxs("section",{className:"relative overflow-hidden rounded-3xl border border-violet-100 bg-gradient-to-br from-violet-700 via-purple-700 to-indigo-800 p-5 text-white shadow-xl shadow-violet-500/10 sm:p-7",children:[e.jsx("div",{className:"pointer-events-none absolute -right-16 -top-16 h-64 w-64 rounded-full bg-white/10 blur-3xl"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-16 left-12 h-48 w-48 rounded-full bg-black/20 blur-2xl"}),e.jsxs("div",{className:"relative flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"max-w-2xl space-y-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-white/20 bg-white/10 px-3 py-1 text-xs font-semibold text-white/90 backdrop-blur-md",children:[e.jsx(Ge,{className:"h-3.5 w-3.5 text-amber-300"}),e.jsx("span",{children:"Central de Agendamento & Fila Automática"})]}),e.jsx("h1",{className:"text-2xl font-black tracking-tight sm:text-3xl lg:text-4xl",children:"Agendamento de Ofertas"}),e.jsx("p",{className:"text-xs sm:text-sm text-white/80 leading-relaxed max-w-xl",children:"Monitore os próximos disparos nos seus grupos, configure a janela de horário e ajuste o intervalo entre cada envio automático."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsxs(Ve,{to:"/offers",className:"inline-flex items-center gap-1.5 rounded-2xl border border-white/25 bg-white/10 px-4 py-2.5 text-xs font-bold text-white shadow-sm backdrop-blur hover:bg-white/20 transition",children:[e.jsx(Ut,{className:"h-4 w-4 text-violet-200"}),e.jsx("span",{children:"Galeria de Ofertas"})]}),e.jsxs(Ve,{to:"/vitrine",className:"inline-flex items-center gap-1.5 rounded-2xl border border-white/25 bg-white/10 px-4 py-2.5 text-xs font-bold text-white shadow-sm backdrop-blur hover:bg-white/20 transition",children:[e.jsx(da,{className:"h-4 w-4 text-amber-300"}),e.jsx("span",{children:"Vitrine"})]})]})]}),e.jsxs("div",{className:"mt-5 grid grid-cols-2 gap-2 border-t border-white/15 pt-4 sm:grid-cols-4 sm:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-xl bg-violet-400/20 text-white shadow-inner",children:e.jsx(Ze,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] text-white/70",children:"Fila Pendente"}),e.jsxs("p",{className:"text-base font-black text-white",children:[Ne," oferta(s)"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-xl bg-emerald-400/20 text-emerald-300 shadow-inner",children:e.jsx(Lt,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] text-white/70",children:"Enviados (24h)"}),e.jsx("p",{className:"text-base font-black text-white",children:w.data?.last24h.sent??0})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-xl bg-rose-400/20 text-rose-300 shadow-inner",children:e.jsx(Ia,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] text-white/70",children:"Falhas (24h)"}),e.jsx("p",{className:"text-base font-black text-white",children:w.data?.last24h.failed??0})]})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-xl bg-amber-400/20 text-amber-300 shadow-inner",children:e.jsx(ka,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] text-white/70",children:"Intervalo Ativo"}),e.jsxs("p",{className:"text-base font-black text-white",children:[S?.intervalMinutes??M," min"]})]})]})]})]}),L?e.jsx(Da,{payload:L,onDismiss:ue,onScheduled:()=>{ue(),w.refetch()},setFeedback:t=>t?ge.info(t):null}):null,G.length>0?e.jsx(Ha,{offerIds:G,onDismiss:B,onScheduled:()=>{B(),w.refetch()},setFeedback:t=>t?ge.info(t):null}):null,j.length>0?e.jsx(Ua,{offerIds:j,windowDraft:{start:xe,end:K,intervalMinutes:M},windowHydrated:ae,onDismiss:ve,onWindowPersisted:t=>D(t),onScheduled:()=>{ve(),w.refetch()},setFeedback:t=>t?ge.info(t):null}):null,w.isLoading?e.jsxs("div",{className:"flex items-center justify-center gap-3 rounded-3xl border border-slate-200 bg-white p-12 text-sm text-slate-600 shadow-sm",children:[e.jsx(Me,{className:"h-6 w-6 animate-spin text-violet-600"}),e.jsx("span",{children:"Carregando painel de agendamento e fila..."})]}):w.isError?e.jsx("div",{className:"rounded-3xl border border-rose-200 bg-rose-50 p-6 text-sm text-rose-900 shadow-sm",children:"Não foi possÃvel carregar os dados de agendamento. Atualize a página ou tente novamente."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex sm:hidden items-center justify-between px-1 text-xs text-slate-500",children:[e.jsx("span",{className:"font-semibold text-slate-600",children:"Visualização dos cards:"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{be(!0),me(!0),ne(!0),$(!0)},className:"text-violet-700 font-bold hover:underline",children:"Expandir todos"}),e.jsx("span",{className:"text-slate-300",children:"â¢"}),e.jsx("button",{type:"button",onClick:()=>{be(!1),me(!1),ne(!1),$(!1)},className:"text-slate-600 font-bold hover:underline",children:"Recolher todos"})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[1.3fr_0.9fr]
16items-start",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs(tt,{className:"overflow-hidden rounded-3xl border-slate-200/80 bg-white shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-100 bg-slate-50/70 p-4 sm:px-6 sm:py-4 cursor-pointer select-none transition hover:bg-slate-100/50",onClick:()=>be(t=>!t),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-xl bg-violet-100 text-violet-700 shrink-0",children:e.jsx(Ze,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-extrabold text-slate-900",children:"Próximos Envios na Fila"}),e.jsx("p",{className:"text-xs text-slate-500 hidden sm:block",children:"Disparos automáticos programados por ordem de horário"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",onClick:t=>t.stopPropagation(),children:[e.jsxs("span",{className:"inline-flex items-center rounded-full bg-violet-100 px-2.5 sm:px-3 py-1 text-xs font-bold text-violet-800",children:[re.length," agendada(s)"]}),re.length>0?e.jsx(Q,{type:"button",variant:"outline",size:"sm",disabled:Y.isPending,onClick:we,className:"h-8 rounded-xl border-rose-200 text-xs font-bold text-rose-700 hover:bg-rose-50",title:"Cancelar todas as ofertas pendentes",children:Y.isPending?e.jsx(Me,{className:"h-3 w-3 animate-spin"}):"Limpar Fila"}):null,e.jsx("button",{type:"button",onClick:()=>be(t=>!t),className:"p-1.5 rounded-xl text-slate-500 hover:text-slate-800 hover:bg-slate-200/70 transition touch-manipulation",title:W?"Recolher card":"Expandir card","aria-label":W?"Recolher card":"Expandir card",children:W?e.jsx(at,{className:"h-5 w-5"}):e.jsx(et,{className:"h-5 w-5"})})]})]}),W&&e.jsx("div",{className:"p-4 sm:p-6",children:re.length===0?e.jsxs("div",{className:"rounded-2xl border border-dashed border-slate-200 p-8 text-center space-y-3",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-2xl bg-slate-100 text-slate-400",children:e.jsx(Ze,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-slate-800",children:"Sua fila está vazia"}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Selecione ofertas para agendar diretamente pela Galeria ou Vitrine."})]}),e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-2 pt-1",children:e.jsx(Ve,{to:"/offers",children:e.jsx(Q,{size:"sm",className:"rounded-xl bg-violet-600 font-bold hover:bg-violet-700 text-xs",children:"Ir para Galeria de Ofertas"})})})]}):e.jsx("div",{className:"space-y-3",children:re.map((t,m)=>{const c=Number(t.id),V=je.isPending&&ee===c,Se=String(t.platform||"").toLowerCase(),A=Ra[Se],d=String(t.channel||"").toLowerCase();return e.jsxs("div",{className:"group relative flex flex-col sm:flex-row sm:items-center justify-between gap-3.5 rounded-2xl border border-slate-200/90 bg-white p-3.5 sm:p-4 shadow-2xs hover:border-violet-300 hover:shadow-sm transition",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"relative flex h-14 w-14 sm:h-16 sm:w-16 shrink-0 items-center justify-center overflow-hidden rounded-xl border border-slate-100 bg-slate-50 p-1",children:t.imageUrl?e.jsx("img",{src:t.imageUrl,alt:"",className:"max-h-full max-w-full object-contain",loading:"lazy"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center text-slate-300",children:e.jsx(Ut,{className:"h-6 w-6"})})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[A?e.jsx("span",{className:E("inline-flex items-center rounded-md px-2 py-0.5 text-[10px] font-extrabold uppercase tracking-wide",A.bg,A.text),children:A.label}):null,e.jsxs("span",{className:E("inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[10px] font-bold uppercase",d==="whatsapp"?"bg-emerald-100 text-emerald-900":d==="telegram"?"bg-sky-100 text-sky-900":"bg-purple-100 text-purple-900"),children:[d==="whatsapp"?e.jsx(rt,{className:"h-3 w-3"}):e.jsx(it,{className:"h-3 w-3"}),e.jsx("span",{children:t.channel})]}),t.targetChatName?e.jsxs("span",{className:"truncate max-w-[140px] text-[10px] font-semibold text-slate-500",children:["â ",t.targetChatName]}):null]}),e.jsx("p",{className:"line-clamp-2 text-xs sm:text-sm font-bold text-slate-900 leading-snug",children:t.productTitle||"Produto
16sem tÃtulo"}),t.currentPrice?e.jsx("p",{className:"text-xs font-black text-emerald-600",children:t.currentPrice.startsWith("R$")?t.currentPrice:`R$ ${t.currentPrice}`}):null]})]}),e.jsxs("div",{className:"flex items-center justify-between sm:flex-col sm:items-end gap-2 border-t sm:border-t-0 border-slate-100 pt-2 sm:pt-0",children:[e.jsx("div",{className:"text-left sm:text-right",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-black text-violet-700 bg-violet-50 px-2.5 py-1 rounded-lg",children:[e.jsx(Ze,{className:"h-3.5 w-3.5"}),Qt(t.executeAt)]})}),e.jsx(Q,{type:"button",variant:"ghost",size:"sm",disabled:!Number.isFinite(c)||c<=0||V,onClick:()=>void Ae(c),className:"h-8 rounded-xl px-2 text-xs font-semibold text-slate-400 hover:bg-rose-50 hover:text-rose-600 transition",title:"Cancelar este agendamento",children:V?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(nt,{className:"mr-1 h-3.5 w-3.5"}),e.jsx("span",{children:"Cancelar"})]})})]})]},String(t.id||m))})})})]}),e.jsxs(tt,{className:"overflow-hidden rounded-3xl border-slate-200/80 bg-white shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-100 bg-slate-50/70 p-4 sm:px-6 sm:py-4 cursor-pointer select-none transition hover:bg-slate-100/50",onClick:()=>me(t=>!t),children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-extrabold text-slate-900",children:"Histórico Recente de Disparos"}),e.jsx("p",{className:"text-xs text-slate-500 hidden sm:block",children:"Ãltimos envios processados pelo sistema"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 rounded-xl bg-slate-200/60 p-1",children:[e.jsx("button",{type:"button",onClick:()=>Te("all"),className:E("px-2 sm:px-2.5 py-1 text-xs font-bold rounded-lg transition",te==="all"?"bg-white text-slate-900 shadow-xs":"text-slate-600"),children:"Todos"}),e.jsx("button",{type:"button",onClick:()=>Te("sent"),className:E("px-2 sm:px-2.5 py-1 text-xs font-bold rounded-lg transition",te==="sent"?"bg-white text-emerald-700 shadow-xs":"text-slate-600"),children:"Enviados"}),e.jsx("button",{type:"button",onClick:()=>Te("failed"),className:E("px-2 sm:px-2.5 py-1 text-xs font-bold rounded-lg transition",te==="failed"?"bg-white text-rose-700 shadow-xs":"text-slate-600"),children:"Falhas"})]}),e.jsx("button",{type:"button",onClick:()=>me(t=>!t),className:"p-1.5 rounded-xl text-slate-500 hover:text-slate-800 hover:bg-slate-200/70 transition touch-manipulation",title:se?"Recolher card":"Expandir card","aria-label":se?"Recolher card":"Expandir card",children:se?e.jsx(at,{className:"h-5 w-5"}):e.jsx(et,{className:"h-5 w-5"})})]})]}),se&&e.jsx("div",{className:"p-4 sm:p-6",children:q.length===0?e.jsx("p",{className:"text-center py-6 text-xs text-slate-400",children:"Nenhum registro no histórico recente com o filtro selecionado."}):e.jsx("div",{className:"divide-y divide-slate-100",children:q.slice(0,10).map(t=>e.jsxs("div",{className:"py-3 first:pt-0 last:pb-0 space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:E("rounded-full px-2 py-0.5 text-[10px] font-black uppercase tracking-wide",t.status==="sent"?"bg-emerald-100 text-emerald-900":t.status==="failed"?"bg-rose-100 text-rose-900":t.status==="cancelled"?"bg-slate-200 text-slate-700":"bg-amber-100 text-amber-900"),children:t.status==="sent"?"Enviado â":t.status==="failed"?"Falha â":t.status==="cancelled"?"Cancelado":t.status}),e.jsx("span",{className:"text-xs font-bold text-slate-800 truncate max-w-[200px] sm:max-w-md",children:t.productTitle||"â"})]}),e.jsx("span",{className:"text-[11px] font-medium text-slate-400",children:Wa(t.updatedAt)})]}),e.jsxs("p",{className:"text-[11px] text-slate-500",children:["Canal: ",e.jsx("strong",{children:String(t.channel).toUpperCase()})," · Destino:"," ",t.targetChatName||"Padrão"," · Previsto para: ",Qt(t.executeAt)]}),t.lastError?e.jsxs("p",{className:"text-[11px] text-rose-700 bg-rose-50 p-2 rounded-xl mt-1",children:["Motivo: ",t.lastError]}):null]},t.id))})})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(tt,{className:"overflow-hidden rounded-3xl border-slate-200/80 bg-white shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-slate-100 bg-slate-50/70 p-4 sm:px-6 sm:py-4 cursor-pointer select-none transition hover:bg-slate-100/50",onClick:()=>ne(t=>!t),children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-violet-600",children:"Cockpit de Operação"}),e.jsx("h3",{className:"text-base sm:text-lg font-black text-slate-900 mt-0.5",children:"Saúde dos Disparos"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:E("inline-flex items-center gap-1.5 rounded-full px-2.5 sm:px-3 py-1 text-xs font-extrabold shadow-xs",ie?"bg-amber-100 text-amber-900 border border-amber-300":"bg-emerald-100 text-emerald-900 border border-emerald-300"),children:[e.jsx("span",{className:E("h-2 w-2 rounded-full",ie?"bg-amber-500":"bg-emerald-500 animate-pulse")}),e.jsx("span",{children:ie?"Pausado":"Disparos Ativos"})]}),e.jsx("button",{type:"button",onClick:()=>ne(t=>!t),className:"p-1.5 rounded-xl text-slate-500 hover:text-slate-800 hover:bg-slate-200/70 transition touch-manipulation",title:P?"Recolher card":"Expandir card","aria-label":P?"Recolher card":"Expandir card",children:P?e.jsx(at,{className:"h-5 w-5"}):e.jsx(et,{className:"h-5 w-5"})})]})]}),P&&e.jsxs("div",{className:"p-5 sm:p-6 space-y-4",children:[ie?e.jsxs("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 p-3.5 text-xs text-amber-900 leading-relaxed space-y-2",children:[e.jsxs("p",{className:"font-bold flex items-center gap-1.5",children:[e.jsx(Aa,{className:"h-4 w-4 text-amber-600 shrink-0"}
16),"Sua agenda está pausada"]}),e.jsx("p",{children:"As ofertas agendadas continuarão na fila, mas não serão disparadas até você retomar a operação."}),e.jsx(Q,{type:"button",size:"sm",disabled:_.isPending,onClick:()=>void _.mutateAsync({paused:!1}),className:"w-full rounded-xl bg-amber-600 hover:bg-amber-700 text-white font-bold text-xs h-9",children:_.isPending?"Retomandoâ¦":"â¶ï¸ Retomar Disparos Agora"})]}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"O despachante roda em segundo plano a cada ~30s checando novos envios na janela permitida."}),e.jsx(Q,{type:"button",variant:"outline",size:"sm",disabled:_.isPending,onClick:()=>void _.mutateAsync({paused:!0}),className:"rounded-xl border-amber-200 text-amber-900 hover:bg-amber-50 font-bold text-xs h-9",children:_.isPending?"Pausandoâ¦":"â¸ï¸ Pausar Todos os Disparos"})]}),w.data?.dispatchHealth?.cards&&w.data.dispatchHealth.cards.length>0?e.jsxs("div",{className:"border-t border-slate-100 pt-3 space-y-2",children:[e.jsx("p",{className:"text-[11px] font-bold uppercase text-slate-500",children:"Status de Conexão dos Canais"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-1.5",children:w.data.dispatchHealth.cards.map(t=>e.jsxs("div",{className:E("flex items-center justify-between rounded-xl border px-3 py-2 text-xs font-semibold",t.status==="ok"&&"border-emerald-100 bg-emerald-50/50 text-emerald-950",t.status==="warn"&&"border-amber-100 bg-amber-50/50 text-amber-950",t.status==="bad"&&"border-rose-100 bg-rose-50/50 text-rose-950"),children:[e.jsx("span",{className:"truncate",children:t.label}),e.jsx("span",{className:E("h-2 w-2 rounded-full shrink-0 ml-2",t.status==="ok"&&"bg-emerald-500",t.status==="warn"&&"bg-amber-500",t.status==="bad"&&"bg-rose-500")})]},t.key))})]}):null]})]}),e.jsxs(tt,{className:"overflow-hidden rounded-3xl border-slate-200/80 bg-white shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-slate-100 bg-slate-50/70 p-4 sm:px-6 sm:py-4 cursor-pointer select-none transition hover:bg-slate-100/50",onClick:()=>$(t=>!t),children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-violet-600",children:"Frequência & Horários"}),e.jsx("h3",{className:"text-base sm:text-lg font-black text-slate-900 mt-0.5",children:"Janela de Disparo"})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",onClick:t=>t.stopPropagation(),children:[e.jsx(Q,{type:"button",size:"sm",disabled:pe.isPending,onClick:()=>void ce(),className:E("h-8 sm:h-9 rounded-xl px-3 sm:px-4 text-xs font-bold transition",ae&&!X?"bg-emerald-100 text-emerald-900 hover:bg-emerald-200 border border-emerald-300":"bg-violet-600 text-white hover:bg-violet-700 shadow-sm"),children:pe.isPending?"Salvandoâ¦":ae&&!X?"Salvo â":"Salvar Horários"}),e.jsx("button",{type:"button",onClick:()=>$(t=>!t),className:"p-1.5 rounded-xl text-slate-500 hover:text-slate-800 hover:bg-slate-200/70 transition touch-manipulation",title:y?"Recolher card":"Expandir card","aria-label":y?"Recolher card":"Expandir card",children:y?e.jsx(at,{className:"h-5 w-5"}):e.jsx(et,{className:"h-5 w-5"})})]})]}),y&&e.jsxs("div",{className:"p-5 sm:p-6 space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"text-xs font-bold text-slate-700 flex items-center justify-between",children:[e.jsx("span",{children:"Espaço de tempo entre cada oferta"}),e.jsxs("span",{className:"font-extrabold text-violet-700",children:[M," minutos"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2",children:La.map(t=>{const m=M===t.value;return e.jsxs("button",{type:"button",onClick:()=>{le(t.value),ce(t.value)},className:E("flex flex-col items-center justify-center p-2.5 rounded-xl border text-xs font-bold transition touch-manipulation",m?"border-violet-600 bg-violet-50 text-violet-900 ring-2 ring-violet-400/40 shadow-xs":"border-slate-200 hover:border-violet-300 hover:bg-slate-50 text-slate-700"),children:[e.jsx("span",{children:t.label}),t.recommended?e.jsx("span",{className:"text-[9px] font-normal text-violet-600",children:"Recomendado"}):null]},t.value)})}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50/70 p-3 sm:p-3.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs font-bold text-slate-700",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-slate-500 font-extrabold",children:"Intervalo entre envios (Arrastar)"}),e.jsxs("span",{className:"rounded-lg bg-violet-100 px-2.5 py-0.5 text-xs font-black text-violet-900",children:[M," min"]})]}),e.jsx("input",{type:"range",min:5,max:60,step:1,className:"h-2 w-full cursor-pointer accent-violet-600 touch-manipulation",value:Math.min(60,Math.max(5,M)),onChange:t=>le(Number(t.target.value))}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] font-semibold text-slate-400 px-0.5",children:[e.jsx("span",{children:"5 min"}),e.jsxs("span",{className:"text-xs font-black text-slate-800",children:[M," min"]}),e.jsx("span",{children:"60 min"})]}),M>60?e.jsxs("p",{className:"text-center text-[11px] font-semibold text-amber-800",children:["Intervalo longo ativo (",M," min)"]}):null,e.jsxs("details",{className:"mt-1 rounded-xl border border-dashed border-slate-300 bg-white px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] font-bold text-violet-800 touch-manipulation",children:"Outro intervalo (61â720 min) â digitar"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx(Z,{type:"number",min:5,max:720,value:M,onChange:t=>{const m=Number(t.target.value);Number.isFinite(m)&&le(jt(m))},className:"h-9 w-28 text-sm font-bold text-slate-900"}),e.jsx("span",{className:"text-xs text-slate-500",children:"minutos (qualquer valor até 720)"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 pt-1",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-bold text-slate-700",children:"InÃcio dos envios"}),e.jsx(Z,{type:"time",value:xe,onChange:t=>Ce(t.target.value),className:"h-11 rounded-xl text-center font-bold text-slate-800"}),e.jsx("p",{className:"text-[10px] text-slate-400 text-center",children:"Horário de BrasÃlia"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-bold text-slate-700",children:"Fim dos envios"}),e.jsx(Z,{type:"time",value:K,onChange:t=>Ie(t.target.value),className:"h-11 rounded-xl text-center font-bold text-slate-800"}),e.jsx("p",{className:"text-[10px] text-slate-400 text-center",children:"Horário de BrasÃlia"})]})]}
16),S&&ae?e.jsx("div",{className:E("rounded-2xl border p-3 text-xs leading-relaxed",X?"border-amber-200 bg-amber-50 text-amber-950 font-semibold":"border-emerald-200 bg-emerald-50 text-emerald-900 font-medium"),children:X?e.jsxs("p",{children:["â ï¸ Há alterações não salvas. Toque em"," ",e.jsx("strong",{children:"Salvar Horários"})," para aplicar na sua fila."]}):e.jsxs("p",{className:"flex items-center gap-1.5",children:[e.jsx(Lt,{className:"h-4 w-4 text-emerald-600 shrink-0"}),e.jsxs("span",{children:["Envios permitidos entre ",e.jsx("strong",{children:S.start})," e"," ",e.jsx("strong",{children:S.end})," a cada"," ",e.jsxs("strong",{children:[S.intervalMinutes," minutos"]}),"."]})]})}):null]})]})]})]})]})]})}export{Is 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.