PageSourceSearch

https://boombam.app/assets/offer-creator-B_HpyAzJ.js

js boombam.app collected 2026-10-04 13:33:36 UTC 87,974 bytes, 19 lines download raw bytes

1import{K as Xs,r as l,_ as Ps,a5 as Is,j as e,bd as Ke,af as Rs,ag as Bs,B as m,bJ as ft,ah as qs,bK as pt,aj as bs,bL as gt,ai as Re,aC as yt,au as as,ar as jt,C as de,e as ve,T as zs,aD as us,E as As,s as M,J as vt,Y as Nt,bM as bt,bN as wt,bO as Ms,bP as Zs,bQ as St,bR as Ks,ak as ae,al as re,am as ie,an as ne,bT as Gs,ao as me,ab as p,aF as ss,bU as Ct,D as et,bC as Tt,aK as At,N as st,a as Ge,a6 as D,a7 as w,bD as ws,b as Fs,d as Os,o as ks,aE as Es,$ as Qe,a0 as Ve,a1 as Ye,a2 as Je,a3 as O,a4 as Oe,aH as Qs,aq as ke,c as Ss,w as Ft,f as Ot,i as kt,bt as Et,u as Dt,ct as Pt,bo as It,bi as Vs,S as Lt,L as Cs,aO as Fe,z as Ys,bm as es,F as Ts,aY as Js,bB as $t,br as Ut,y as Rt,bq as Bt}from"./index-CuSEeJFb.js";import{D as Ds,u as qt,P as zt}from"./pdf-generator-BNB8T3ue.js";import{u as Mt,a as Hs,s as Kt,K as Gt,P as Qt,D as Vt,c as Yt,S as Jt,h as Ht,d as Wt,C as _t,f as Xt}from"./sortable.esm-CaaY9462.js";import{G as tt}from"./grip-vertical-DtmmqDbO.js";import{F as hs}from"./folder-open-nDEnLPQX.js";import{a as He,F as ts}from"./folder-XQRCjIoi.js";import{F as Zt}from"./filter-DIYm3mPi.js";import{P as rs}from"./pen-line-Ys7SVokk.js";import{H as ea}from"./hash-jasa6rMo.js";import{E as sa}from"./ellipsis-vertical-04pZ3iRl.js";import{C as ta}from"./copy-Ctw93tQ7.js";import{C as aa}from"./chevrons-up-down-BZ7u-cRr.js";import{f as Ws}from"./formatDistanceToNow-JmSQUCLK.js";import{S as ra}from"./save-DMqvNvzo.js";import"./typeof-QjJsDpFa.js";import"./constructNow-CAQUuh76.js";import"./en-US-BOoww7nS.js";import"./differenceInCalendarMonths-CdYt3YUn.js";import"./endOfDay-CTvcx9iE.js";import"./endOfMonth-DMtDxPW7.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 ia=Xs("BookMarked",[["path",{d:"M10 2v8l3-3 3 3V2",key:"sqw3rj"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);/**
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 _s=Xs("FolderCog",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["path",{d:"M10.3 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v3.3",key:"1k8050"}],["path",{d:"m21.7 19.4-.9-.3",key:"1qgwi9"}],["path",{d:"m15.2 16.9-.9-.3",key:"1t7mvx"}],["path",{d:"m16.6 21.7.3-.9",key:"1j67ps"}],["path",{d:"m19.1 15.2.3-.9",key:"18r7jp"}],["path",{d:"m19.6 21.7-.4-1",key:"z2vh2"}],["path",{d:"m16.8 15.3-.4-1",key:"1ei7r6"}],["path",{d:"m14.3 19.6 1-.4",key:"11sv9r"}],["path",{d:"m20.7 16.8 1-.4",key:"19m87a"}]]),Me=[{id:"deployment",label:"Deployment",visible:!0,width:150,minWidth:130},{id:"name",label:"Offer Name",visible:!0,width:250,minWidth:150},{id:"type",label:"Type",visible:!0,width:120,minWidth:80},{id:"price",label:"Price",visible:!0,width:120,minWidth:80},{id:"service",label:"Target Service",visible:!0,width:180,minWidth:120},{id:"tags",label:"Tags",visible:!0,width:180,minWidth:100},{id:"folder",label:"Folder",visible:!0,width:150,minWidth:100},{id:"created",label:"Date Created",visible:!0,width:150,minWidth:100},{id:"actions",label:"Action Items",visible:!0,width:120,minWidth:100}];function na({column:i,isSelected:g,sortColumn:ue,sortDirection:Ne,onSort:x,onResize:be}){const{attributes:V,listeners:Ee,setNodeRef:he,transform:xe,transition:we,isDragging:De}=Wt({id:i.id}),[q,Y]=l.useState(!1),z=l.useRef(0),S=l.useRef(0),v={transform:_t.Transform.toString(xe),transition:q?"none":we,opacity:De?.5:1,width:`${i.width}px`,minWidth:`${i.minWidth||80}px`,position:"relative"},C=ue===i.id,k=i.id!=="actions"&&x,L=()=>k?C?Ne==="asc"?e.jsx(Tt,{className:"h-3 w-3 text-orange-500"}):e.jsx(At,{className:"h-3 w-3 text-orange-500"}):e.jsx(aa,{className:"h-3 w-3 text-gray-400"}):null,$=()=>{k&&!q&&x(i.id)},J=P=>{P.preventDefault(),P.stopPropagation(),Y(!0),z.current=P.clientX,S.current=i.width;const H=K=>{const ee=K.clientX-z.current,G=Math.max(i.minWidth||80,S.current+ee);be&&be(i.id,G)},W=()=>{Y(!1),document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",W)};document.addEventListener("mousemove",H),document.addEventListener("mouseup",W)};return e.jsx(Zs,{ref:he,style:v,className:`${De?"bg-gray-100":""} ${g?"ring-2 ring-orange-200":""} px-2`,...V,children:e.jsxs("div",{className:"flex items-center justify-between h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[e.jsx("div",{className:"cursor-grab active:cursor-grabbing flex items-center gap-2 hover:text-orange-600",...Ee,children:e.jsx(tt,{className:"h-4 w-4 text-gray-400"})}),e.jsxs("div",{className:`flex items-center gap-1 flex-1 ${k?"cursor-pointer hover:text-orange-600":""} ${C?"text-orange-600 font-medium":""}`,onClick:$,children:[e.jsx("span",{className:"truncate",children:i.label}),L()]})]}),e.jsx("div",{onMouseDown:J,className:"absolute right-0 top-0 h-full w-1 cursor-col-resize hover:bg-orange-400 bg-transparent group",children:e.jsx("div",{className:"absolute right-0 top-0 h-full w-3 -translate-x-1/2"})})]})})}function la({offers:i,loading:g,onViewOffer:ue,onEditOffer:Ne,onUseAsTemplate:x,onDeleteOffer:be,onBulkDelete:V,onCreateOffer:Ee,onMoveToFolder:he,sortColumn:xe="created",sortDirection:we="desc",onSort:De,onUpdateTags:q,selectedFolderId:Y,onAddOffersToFolder:z}){const[S,v]=l.useState(new Set),[C,k]=l.useState(Me),[L,$]=l.useState(Me.map(a=>a.id)),[J,P]=l.useState(!1),[H,W]=l.useState(null),[K,ee]=l.useState(""),{toast:G}=Ps(),T=Is();l.useEffect(()=>{const a=localStorage.getItem("offerTableColumns"),c=localStorage.getItem("offerTableColumnOrder");if(a)try{k(JSON.parse(a))}catch{k(Me)}if(c)try{$(JSON.parse(c))}catch{$(Me.map(n=>n.id))}},[]);const fe=(a,c)=>{localStorage.setItem("offerTableColumns",JSON.stringify(a)),c&&localStorage.setItem("offerTableColumnOrder",JSON.stringify(c))},Be=a=>{const c=C.map(n=>n.id===a?{...n,visible:!n.visible}:n);k(c),fe(c)},pe=()=>{k(Me),$(Me.map(a=>a.id)),localStorage.removeItem("offerTableColumns"),localStorage.removeItem("offerTableColumnOrder")},se=(a,c)=>{const n=C.map(A=>A.id===a?{...A,width:c}:A);k(n),fe(n,L)},Se=Mt(Hs(Qt),Hs(Gt,{coordinateGetter:Kt})),is=a=>{const{active:c,over:n}
11=a;if(n&&c.id!==n.id){const A=L.indexOf(c.id),I=L.indexOf(n.id),R=Xt(L,A,I);$(R),fe(C,R)}},_=L.map(a=>C.find(c=>c.id===a)).filter(a=>!!a&&a.visible),E=(a,c)=>{switch(c){case"deployment":return e.jsx(Ds,{status:a.deploymentStatus||"draft",entityId:a.id,entityType:"offer",compact:!0,onStatusChange:()=>{T.invalidateQueries({queryKey:["/api/offers"]})}});case"name":return e.jsx("div",{className:"font-medium text-gray-900",children:a.name});case"type":return e.jsx(M,{variant:"outline",children:a.type});case"price":return e.jsx("div",{className:"text-sm text-gray-900 font-medium",children:a.offerPrice||"-"});case"service":return e.jsx("div",{className:"text-sm text-gray-600",children:a.targetService||"-"});case"tags":return e.jsxs("div",{className:"flex flex-wrap gap-1",children:[(a.tags||[]).length>0?a.tags.slice(0,2).map((n,A)=>e.jsx(M,{variant:"outline",className:"text-xs",children:n},A)):e.jsx("span",{className:"text-xs text-gray-400",children:"No tags"}),(a.tags||[]).length>2&&e.jsxs(M,{variant:"outline",className:"text-xs bg-gray-100",children:["+",a.tags.length-2]})]});case"folder":return Ce(a);case"created":return e.jsx("div",{className:"text-sm text-gray-600",children:Ws(new Date(a.createdAt),{addSuffix:!0})});case"actions":return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>ue(a),className:"h-8 w-8 p-0",title:"Preview offer","data-testid":"button-preview-offer",children:e.jsx(As,{className:"h-4 w-4"})}),e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>x(a),className:"h-8 w-8 p-0",title:"Use offer as template (create new)","data-testid":"button-use-as-template",children:e.jsx(Ct,{className:"h-4 w-4 text-orange-600"})}),e.jsxs(Rs,{children:[e.jsx(Bs,{asChild:!0,children:e.jsx(m,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0",title:"More actions",children:e.jsx(sa,{className:"h-4 w-4"})})}),e.jsxs(qs,{align:"end",className:"w-48",children:[e.jsxs(Re,{onClick:()=>Ne(a),children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Edit Offer"]}),he&&e.jsxs(Re,{onClick:()=>he(a),"data-testid":`menu-move-to-folder-${a.id}`,children:[e.jsx(He,{className:"h-4 w-4 mr-2"}),"Add to Folder"]}),e.jsxs(Re,{onClick:()=>ye(a),children:[e.jsx(Gs,{className:"h-4 w-4 mr-2"}),"Add Tags"]}),e.jsxs(Re,{children:[e.jsx(ta,{className:"h-4 w-4 mr-2"}),"Duplicate"]}),e.jsxs(Re,{children:[e.jsx(et,{className:"h-4 w-4 mr-2"}),"Add to Favorites"]}),e.jsx(bs,{}),e.jsxs(Re,{onClick:()=>be(a),className:"text-red-600 focus:text-red-600",children:[e.jsx(as,{className:"h-4 w-4 mr-2"}),"Delete"]})]})]})]});default:return null}},j=(a=>xe?[...a].sort((c,n)=>{let A,I;switch(xe){case"name":A=c.name||"",I=n.name||"";break;case"type":A=c.type||"",I=n.type||"";break;case"price":A=parseFloat((c.offerPrice||"0").replace(/[^0-9.]/g,""))||0,I=parseFloat((n.offerPrice||"0").replace(/[^0-9.]/g,""))||0;break;case"service":A=c.targetService||"",I=n.targetService||"";break;case"tags":A=(c.tags||[]).length,I=(n.tags||[]).length;break;case"folder":A=c.folderName||"",I=n.folderName||"";break;case"created":A=new Date(c.createdAt).getTime(),I=new Date(n.createdAt).getTime();break;default:return 0}if(typeof A=="string"&&typeof I=="string"){const R=A.localeCompare(I);return we==="asc"?R:-R}return typeof A=="number"&&typeof I=="number"?we==="asc"?A-I:I-A:0}):a)(i),le=(a,c)=>{console.log("☑️ [SELECTION] handleSelectOffer called:",{offerId:a,checked:c});const n=new Set(S);c?n.add(a):n.delete(a),console.log("☑️ [SELECTION] New selection state:",Array.from(n)),v(n)},X=a=>{if(console.log("☑️ [SELECTION] handleSelectAll called:",{checked:a,offerCount:j.length}),a){const c=new Set(j.map(n=>n.id));console.log("☑️ [SELECTION] Selecting all offer IDs:",Array.from(c)),v(c)}else console.log("☑️ [SELECTION] Clearing all selections"),v(new Set)},ge=()=>{v(new Set)},ye=a=>{W(a),ee((a.tags||[]).join(", ")),P(!0)},qe=()=>{if(!H||!q)return;const a=K.split(",").map(c=>c.trim()).filter(c=>c.length>0);q(H.id,a),P(!1),W(null),ee(""),G({title:"Tags Updated",description:`Updated tags for "${H.name}"`})},Pe=()=>{if(console.log("🗑️ [TABLE] handleBulkDelete called"),console.log("🗑️ [TABLE] selectedOffers.size:",S.size),console.log("🗑️ [TABLE] onBulkDelete exists:",!!V),S.size===0||!V){console.log("❌ [TABLE] Early return - no offers selected or no handler");return}const a=Array.from(S),c=S.size;console.log("🗑️ [TABLE] Calling onBulkDelete with IDs:",a),v(new Set),V(a),G({title:"Offers Deleted",description:`Successfully deleted ${c} offer${c>1?"s":""}`})},Ce=a=>!a.folderId||!a.folderName?e.jsxs("div",{className:"flex items-center gap-1 text-gray-400",children:[e.jsx(ts,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"No folder"})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(hs,{className:"h-4 w-4",style:{color:a.folderColor||"#6366f1"}}),e.jsx("span",{className:"text-sm font-medium",children:a.folderName})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[j.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{id:"select-all",checked:S.size===j.length&&j.length>0,onCheckedChange:X,className:"h-4 w-4 shrink-0"}),e.jsx("label",{htmlFor:"select-all",className:"text-sm cursor-pointer",children:"Select All"})]}),j.length>0&&e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:e.jsxs("span",{className:"font-medium",children:[j.length," offers"]})}),e.jsx("div",{className:"text-xs text-gray-500 hidden md:block",children:"Drag column headers to reorder"})]}),e.jsxs(Rs,{children:[e.jsx(Bs,{asChild:!0,children:e.jsxs(m,{variant:"outline",size:"sm",className:"flex items-center gap-2",children:[e.jsx(ft,{className:"h-4 w-4"}),"Columns"]})}),e.jsxs(qs,{align:"end",className:"w-64",children:[e.jsx(pt,{children:"Table Columns"}),e.jsx(bs,{}),e.jsx("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:C.map(a=>e.jsx(gt,{checked:a.visible,onCheckedChange:()=>Be(a.id),disabled:a.id==="name",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tt,{className:"h-3 w-3 text-gray-400"}),a.label]})},a.id))}),e.jsx(bs,{}),e.jsx(Re,{onClick:pe,children:"Reset to Default"})]})]})]}),S.size>0&&e.jsx("div",{className:"bg-orange-50 border border-orange-200 rounded-lg p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(yt,{className:"h-5 w-5 text-orange-600"}),e.jsxs("span",{className:"text-sm font-medium text-orange-900",children:[S.size," offer",S.size>1?"s":""," selected"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(m,{variant:"ghost",size:"sm",onClick:()=>Pe(),className:"flex items-center gap-2 text-red-600 hover:text-red-700","data-testid":"button-bulk-delete",children:[e.jsx(as,{className:"h-4 w-4"}),"Delete Selected"]}),e.jsxs(m,{variant:"ghost",size:"sm",onClick:ge,className:"flex items-center gap-2 text-gray-600 hover:text-gray-800","data-testid":"button-clear-selection",children:[e.jsx(jt,{className:"h-4 w-4"}),"Clear"]})]})]})}),e.jsx(de,{children:e.jsx(ve,{className:"p-0",children:g?e.jsx("div",{className:"p-6 space-y-4",children:e.jsx("div",{className:"animate-pulse space-y-3",children:[1,2,3].map(a=>e.jsxs("div",{className:"flex items-center space-x-4 p-4 border rounded-lg",children:[e.jsx("div",{className:"h-4 w-4 bg-gray-200 rounded"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded w-1/4"}),e.jsx("div",{className:"h-3 bg-gray-200 rounded w-1/2"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"h-8 w-8 bg-gray-200 rounded"}),e.jsx("div",{className:"h-8 w-8 bg-gray-200 rounded"}),e.jsx("div",{className:"h-8 w-8 bg-gray-200 rounded"})]})]},a))})}):j.length===0?e.jsx("div",{className:"text-center py-12 sm:py-16",children:Y&&z?e.jsxs("div",{children:[e.jsx(hs,{className:"h-12 w-12 sm:h-16 sm:w-16 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-base sm:text-lg font-medium text-gray-700 mb-2",children:"This folder is empty"}),e.jsx("p",{className:"text-sm sm:text-base text-gray-500 mb-4 sm:mb-6",children:"Add existing offers to organize them in this folder"}),e.jsxs(m,{className:"bg-orange-500 hover:bg-orange-600 w-full sm:w-auto",onClick:z,"data-testid":"button-add-offers-to-folder",children:[e.jsx(He,{className:"h-4 w-4 mr-2"}),"Add Offers to Folder"]})]}):i.length===0?e.jsxs("div",{children:[e.jsx(zs,{className:"h-12 w-12 sm:h-16 sm:w-16 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-base sm:text-lg font-medium text-gray-700 mb-2",children:"No offers yet"}),e.jsx("p",{className:"text-sm sm:text-base text-gray-500 mb-4 sm:mb-6",children:"Create your first offer to get started"}),e.jsxs(m,{className:"bg-orange-500 hover:bg-orange-600 w-full sm:w-auto",onClick:()=>Ee==null?void 0:Ee(),"data-testid":"button-create-first-offer",children:[e.jsx(us,{className:"h-4 w-4 mr-2"}),"Create First Offer"]})]}):e.jsxs("div",{children:[e.jsx(Zt,{className:"h-10 w-10 sm:h-12 sm:w-12 text-gray-300 mx-auto mb-4"}),e.jsx("h3",{className:"text-base sm:text-lg font-medium text-gray-700 mb-2",children:"No matching offers"}),e.jsx("p",{className:"text-sm sm:text-base text-gray-500",children:"Try adjusting your search or filters"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"block lg:hidden space-y-3 p-3",children:j.map(a=>e.jsx(de,{className:`hover:shadow-md transition-shadow ${S.has(a.id)?"ring-2 ring-orange-200 bg-orange-50":""}`,children:e.jsx(ve,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ke,{checked:S.has(a.id),onCheckedChange:c=>le(a.id,c),className:"h-4 w-4 shrink-0"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>ue(a),className:"h-8 w-8 p-0",children:e.jsx(As,{className:"h-3 w-3"})}),e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>Ne(a),className:"h-8 w-8 p-0",children:e.jsx(rs,{className:"h-3 w-3"})}),e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>be(a),className:"h-8 w-8 p-0 text-red-500 hover:text-red-700",children:e.jsx(as,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"font-medium text-gray-900 text-sm leading-tight break-words",children:a.name||a.title||"Untitled Offer"}),e.jsx("div",{className:"text-xs text-gray-500 line-clamp-2",children:a.headline||a.description||"No description available"})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap text-xs",children:[e.jsx(M,{variant:"outline",className:"text-xs capitalize",children:a.type}),e.jsx("span",{className:"font-medium text-green-600",children:a.offerPrice||"FREE"}),e.jsx(Ds,{status:a.deploymentStatus||"draft",entityId:a.id,entityType:"offer",compact:!0,onStatusChange:()=>
11{T.invalidateQueries({queryKey:["/api/offers"]})}})]}),e.jsxs("div",{className:"flex flex-col gap-2 text-xs",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[Ce(a),a.targetService&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(zs,{className:"h-3 w-3 text-blue-500"}),e.jsx("span",{children:a.targetService})]}),(a.tags||[]).length>0&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ea,{className:"h-3 w-3 text-purple-500"}),e.jsxs("span",{className:"text-xs",children:[a.tags.slice(0,2).join(", "),a.tags.length>2&&` +${a.tags.length-2}`]})]})]})}),e.jsxs("div",{className:"flex items-center justify-between text-gray-500",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(vt,{className:"h-3 w-3"}),e.jsxs("span",{children:[Ws(new Date(a.createdAt))," ago"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Nt,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[100px]",children:a.creatorName||a.creatorEmail||"Unknown"})]})]})]})]})})},a.id))}),e.jsx("div",{className:"hidden lg:block overflow-x-auto",children:e.jsx(Vt,{sensors:Se,collisionDetection:Yt,onDragEnd:is,children:e.jsxs(bt,{children:[e.jsx(wt,{children:e.jsxs(Ms,{children:[e.jsx(Zs,{className:"w-12",children:e.jsx(Ke,{checked:S.size===j.length&&j.length>0,onCheckedChange:X,className:"h-4 w-4"})}),e.jsx(Jt,{items:_.map(a=>a.id),strategy:Ht,children:_.map(a=>e.jsx(na,{column:a,isSelected:!1,sortColumn:xe,sortDirection:we,onSort:De,onResize:se},a.id))})]})}),e.jsx(St,{children:j.map(a=>e.jsxs(Ms,{className:`hover:bg-gray-50 ${S.has(a.id)?"bg-orange-50":""}`,children:[e.jsx(Ks,{className:"w-12",children:e.jsx(Ke,{checked:S.has(a.id),onCheckedChange:c=>le(a.id,c),className:"h-4 w-4"})}),_.map(c=>e.jsx(Ks,{style:{width:`${c.width}px`,minWidth:`${c.minWidth||80}px`},className:"px-2",children:E(a,c.id)},`${a.id}-${c.id}`))]},a.id))})]})})})]})})}),e.jsx(ae,{open:J,onOpenChange:P,children:e.jsxs(re,{className:"sm:max-w-[425px]",children:[e.jsxs(ie,{children:[e.jsxs(ne,{className:"flex items-center gap-2",children:[e.jsx(Gs,{className:"h-4 w-4"}),"Add Tags"]}),e.jsxs(me,{children:['Add comma-separated tags to organize "',H==null?void 0:H.name,'"']})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(p,{htmlFor:"tags-input",children:"Tags"}),e.jsx(ss,{id:"tags-input",value:K,onChange:a=>ee(a.target.value),placeholder:"e.g., premium, seasonal, limited-time",className:"mt-1"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Separate multiple tags with commas"})]}),K&&e.jsxs("div",{children:[e.jsx(p,{className:"text-xs text-gray-600",children:"Preview:"}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:K.split(",").map((a,c)=>{const n=a.trim();return n?e.jsx(M,{variant:"outline",className:"text-xs",children:n},c):null})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(m,{type:"button",variant:"outline",onClick:()=>P(!1),children:"Cancel"}),e.jsx(m,{type:"button",onClick:qe,disabled:!K.trim(),children:"Save Tags"})]})]})})]})}function oa({offers:i,isLoading:g,selectedOffers:ue,onToggleOfferSelection:Ne,onSelectAllOffers:x,onDeselectAllOffers:be,onStarOffer:V,onShareOffer:Ee,onDownloadPDF:he,onDeleteOffer:xe,onBatchDeleteOffers:we,onBatchUpdateStatus:De,onEditLibraryOffer:q,onUseAsTemplate:Y,onCreateFirstTemplate:z,onCreateOffer:S,templateMode:v=!1}){var os,cs;const{toast:C}=Ps(),k=Is(),{activeCompanyId:L}=st(),[$,J]=l.useState(""),[P,H]=l.useState("all"),[W,K]=l.useState("all"),[ee,G]=l.useState("newest"),[T,fe]=l.useState(null),[Be,pe]=l.useState(!1),[se,Se]=l.useState(""),[is,_]=l.useState(!1),[E,We]=l.useState(null),[j,le]=l.useState(null),[X,ge]=l.useState(""),[ye,qe]=l.useState(!1),[Pe,Ce]=l.useState(!1),[a,c]=l.useState(new Set),[n,A]=l.useState(null),[I,R]=l.useState(!1),{data:h=[],isLoading:U}=Ge({queryKey:["/api/offer-folders",{companyId:L}],enabled:!v}),{data:_e=[]}=Ge({queryKey:["/api/offer-folder-items",{companyId:L}],enabled:!v}),oe=D({mutationFn:async r=>{console.log("[FOLDER DEBUG] Creating folder with name:",r);const o=await w("/api/offer-folders",{method:"POST",body:JSON.stringify({name:r})});return console.log("[FOLDER DEBUG] Response received:",o.status),o.json()},onSuccess:()=>{k.invalidateQueries({queryKey:["/api/offer-folders"]}),pe(!1),Se(""),C({title:"Folder created successfully"})},onError:r=>{C({title:"Failed to create folder",description:r.message,variant:"destructive"})}}),b=D({mutationFn:async({id:r,name:o})=>(await w(`/api/offer-folders/${r}`,{method:"PUT",body:JSON.stringify({name:o})})).json(),onSuccess:()=>{k.invalidateQueries({queryKey:["/api/offer-folders"]}),le(null),ge(""),C({title:"Folder updated successfully"})},onError:r=>{C({title:"Failed to update folder",description:r.message,variant:"destructive"})}}),Te=D({mutationFn:async r=>{await w(`/api/offer-folders/${r}`,{method:"DELETE"})},onSuccess:()=>{k.invalidateQueries({queryKey:["/api/offer-folders"]}),k.invalidateQueries({queryKey:["/api/offer-folder-items"]}),T&&fe(null),C({title:"Folder deleted successfully"})},onError:r=>{C({title:"Failed to delete folder",description:r.message,variant:"destructive"})}}),Ae=D({mutationFn:async({offerId:r,folderId:o})=>(await w(`/api/offer-folders/${o}/offers/${r}`,{method:"POST",body:JSON.stringify({})})).json(),onSuccess:()=>{k.invalidateQueries({queryKey:["/api/offer-folder-items"]}),k.invalidateQueries({queryKey:["/api/offer-folders"]}),_(!1),We(null),C({title:"Offer added to folder"})},onError:r=>{C({title:"Failed to add offer to folder",description:r.message,variant:"destructive"})}}),Ie=D({mutationFn:async({offerId:r,folderId:o})=>{await w(`/api/offer-folders/${o}/offers/${r}`,{method:"DELETE"})},onSuccess:()=>{k.invalidateQueries({queryKey:["/api/offer-folder-items"]}),k.invalidateQueries({queryKey:["/api/offer-folders"]}),C({title:"Offer removed from folder"})},onError:r=>{C({title:"Failed to remove offer from folder",description:r.message,variant:"destructive"})}}),Le=r=>_e.filter(o=>o.folderId===r).map(o=>o.offerId),B=l.useMemo(()=>
11{if(T===null)return i;const r=Le(T);return i.filter(o=>o.id&&!r.includes(o.id))},[i,T,_e]),xs=async()=>{if(!T||a.size===0)return;const r=Array.from(a);for(const o of r)try{await w(`/api/offer-folders/${T}/offers/${o}`,{method:"POST",body:JSON.stringify({})})}catch(Z){console.error(`Failed to add offer ${o} to folder:`,Z)}k.invalidateQueries({queryKey:["/api/offer-folder-items"]}),k.invalidateQueries({queryKey:["/api/offer-folders"]}),Ce(!1),c(new Set),C({title:"Offers added to folder",description:`Added ${r.length} offer${r.length>1?"s":""} to folder`})},ns=l.useMemo(()=>{let r=i.filter(o=>{var $e,Xe,ds;const Z=(($e=o.name)==null?void 0:$e.toLowerCase().includes($.toLowerCase()))||("description"in o?(Xe=o.description)==null?void 0:Xe.toLowerCase().includes($.toLowerCase()):!1)||((ds=o.headline)==null?void 0:ds.toLowerCase().includes($.toLowerCase())),gs=P==="all"||P==="active"&&("isActive"in o?o.isActive:!0)||P==="draft"&&("isActive"in o?!o.isActive:!1),ys=W==="all"||o.type===W;let y=!0;return T!==null&&o.id&&(y=Le(T).includes(o.id)),Z&&gs&&ys&&y});return r.sort((o,Z)=>{switch(ee){case"newest":return new Date(Z.createdAt||"").getTime()-new Date(o.createdAt||"").getTime();case"oldest":return new Date(o.createdAt||"").getTime()-new Date(Z.createdAt||"").getTime();case"name":return(o.name||"").localeCompare(Z.name||"");case"type":return(o.type||"").localeCompare(Z.type||"");default:return 0}}),r},[i,$,P,W,ee,T,_e]),ze=()=>{se.trim()&&oe.mutate(se.trim())},ls=()=>{!j||!X.trim()||b.mutate({id:j.id,name:X.trim()})},fs=r=>{E!=null&&E.id&&Ae.mutate({offerId:E.id,folderId:r})},ps=r=>{We(r),_(!0)};return v&&(!i.length||g)?e.jsx(de,{children:e.jsx(ve,{className:"p-6",children:e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"mx-auto w-12 h-12 bg-gray-100 rounded-full flex items-center justify-center",children:e.jsx(ws,{className:"h-6 w-6 text-gray-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-gray-900",children:"No templates yet"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Create your first offer template to save time on future offers"})]}),e.jsxs(m,{onClick:z,className:"bg-orange-600 hover:bg-orange-700",children:[e.jsx(us,{className:"h-4 w-4 mr-2"}),"Create First Template"]})]})})}):e.jsxs(e.Fragment,{children:[e.jsxs(de,{children:[e.jsxs(Fs,{className:"pb-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(Os,{className:"flex items-center gap-2",children:[e.jsx(ws,{className:"h-5 w-5 text-orange-600"}),v?"Template Library":"Offer Library"]}),e.jsx(ks,{children:v?"Browse and manage your offer templates":`${ns.length} offers${T!==null?` in "${((os=h.find(r=>r.id===T))==null?void 0:os.name)||"folder"}"`:""}`})]}),v&&e.jsxs(m,{onClick:z,size:"sm",children:[e.jsx(us,{className:"h-4 w-4 mr-2"}),"New Template"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-4",children:[e.jsx("div",{className:"flex-1 min-w-[200px]",children:e.jsxs("div",{className:"relative",children:[e.jsx(Es,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),e.jsx(ss,{placeholder:v?"Search templates...":"Search offers...",value:$,onChange:r=>J(r.target.value),className:"pl-9 h-9","data-testid":"input-search-offers"})]})}),!v&&e.jsxs(Qe,{value:(T==null?void 0:T.toString())||"all",onValueChange:r=>fe(r==="all"?null:parseInt(r)),children:[e.jsxs(Ve,{className:"w-[160px] h-9","data-testid":"select-folder-filter",children:[e.jsx(ts,{className:"h-4 w-4 mr-2 text-orange-600"}),e.jsx(Ye,{placeholder:"All Folders"})]}),e.jsxs(Je,{children:[e.jsxs(O,{value:"all",children:["All Folders (",i.length,")"]}),h.map(r=>{const o=Le(r.id).length;return e.jsxs(O,{value:r.id.toString(),children:[r.name," (",o,")"]},r.id)})]})]}),!v&&e.jsxs(m,{variant:"outline",size:"sm",className:"h-9",onClick:()=>qe(!0),"data-testid":"button-manage-folders",children:[e.jsx(_s,{className:"h-4 w-4 mr-2"}),"Manage"]}),e.jsxs(Qe,{value:P,onValueChange:H,children:[e.jsx(Ve,{className:"w-[140px] h-9","data-testid":"select-status-filter",children:e.jsx(Ye,{placeholder:"Status"})}),e.jsxs(Je,{children:[e.jsx(O,{value:"all",children:"All Status"}),e.jsx(O,{value:"active",children:"Active"}),e.jsx(O,{value:"draft",children:"Draft"})]})]}),e.jsxs(Qe,{value:W,onValueChange:K,children:[e.jsx(Ve,{className:"w-[140px] h-9","data-testid":"select-type-filter",children:e.jsx(Ye,{placeholder:"Type"})}),e.jsxs(Je,{children:[e.jsx(O,{value:"all",children:"All Types"}),e.jsx(O,{value:"discount",children:"Discount"}),e.jsx(O,{value:"bundle",children:"Bundle"}),e.jsx(O,{value:"trial",children:"Trial"}),e.jsx(O,{value:"bogo",children:"BOGO"}),e.jsx(O,{value:"loyalty",children:"Loyalty"}),e.jsx(O,{value:"seasonal",children:"Seasonal"})]})]}),e.jsxs(Qe,{value:ee,onValueChange:G,children:[e.jsx(Ve,{className:"h-9","data-testid":"select-sort",children:e.jsx(Ye,{placeholder:"Sort by"})}),e.jsxs(Je,{children:[e.jsx(O,{value:"newest",children:"Newest First"}),e.jsx(O,{value:"oldest",children:"Oldest First"}),e.jsx(O,{value:"name",children:"Name A-Z"}),e.jsx(O,{value:"type",children:"Type"})]})]})]})]}),e.jsx(ve,{children:e.jsx(la,{offers:ns.map(r=>({...r,targetService:("targetService"in r?r.targetService:"")||"",creatorId:r.userId||0,status:r.isActive?"published":"draft"})),loading:g,onViewOffer:r=>{A(r),R(!0)},onEditOffer:q,onUseAsTemplate:Y,onDeleteOffer:r=>xe(r.id),onBulkDelete:we,onCreateOffer:S,onMoveToFolder:v?void 0:ps,sortColumn:"created",sortDirection:"desc",onSort:r=>{r==="name"?G("name"):r==="type"?G("type"):r==="created"&&G("newest")},selectedFolderId:v?void 0:T,onAddOffersToFolder:v?void 0:()=>Ce(!0)})})]}),e.jsx(ae,{open:ye,onOpenChange:qe,children:e.jsxs(re,{className:"sm:max-w-[500px]",children:[e.jsxs(ie,{children:[e.jsxs(ne,{className:"flex items-center gap-2",children:[e.jsx(_s,{className:"h-5 w-5 text-orange-600"}),"Manage Folders"]}),e.jsx(me,{children:"Create, rename, or delete folders to organize your offers"})]}),e.jsxs("div",{className:"py-4 space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ss,{value:se,onChange:r=>Se(r.target.value),placeholder:"New folder name...",className:"flex-1","data-testid":"input-new-folder-manage",onKeyDown:r=>{r.key==="Enter"&&ze()}}),e.jsx(m,{onClick:ze,disabled:!se.trim()||oe.isPending,className:"bg-orange-600 hover:bg-orange-700","data-testid":"button-create-folder-manage",children:oe.isPending?e.jsx(Oe,{className:"h-4 w-4 animate-spin"}):e.jsx(He,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"border rounded-lg",children:U?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(Oe,{className:"h-5 w-5 animate-spin text-gray-400"})}):h.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ts,{className:"h-10 w-10 mx-auto text-gray-300 mb-2"}),e.jsx("p",{className:"text-sm text-gray-500",children:"No folders yet"}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"Create one above to get started"})]}):e.jsx(Qs,{className:"max-h-[300px]",children:e.jsx("div",{className:"divide-y",children:h.map(r=>{const o=Le(r.id).length;return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 hover:bg-gray-50",children:[e.jsx(hs,{className:"h-5 w-5 text-orange-500 flex-shrink-0"}),e.jsx("span",{className:"flex-1 font-medium truncate",children:r.name}),e.jsxs(M,{variant:"secondary",className:"text-xs",children:[o," ",o===1?"offer":"offers"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(m,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0",onClick:()=>{le(r),ge(r.name)},"data-testid":`button-edit-folder-manage-${r.id}`,children:e.jsx(rs,{className:"h-4 w-4"})}),e.jsx(m,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 text-red-500 hover:text-red-600 hover:bg-red-50",onClick:()=>{confirm(`Delete folder "${r.name}"? Offers will not be deleted.`)&&Te.mutate(r.id)},disabled:Te.isPending,"data-testid":`button-delete-folder-manage-${r.id}`,children:Te.isPending?e.jsx(Oe,{className:"h-4 w-4 animate-spin"}):e.jsx(as,{className:"h-4 w-4"})})]})]},r.id)})})})})]}),e.jsx(ke,{children:e.jsx(m,{variant:"outline",onClick:()=>qe(!1),children:"Close"})})]})}),e.jsx(ae,{open:Be,onOpenChange:pe,children:e.jsxs(re,{className:"sm:max-w-[400px]",children:[e.jsxs(ie,{children:[e.jsxs(ne,{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-5 w-5"}),"Create New Folder"]}),e.jsx(me,{children:"Create a folder to organize your offers"})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(p,{htmlFor:"folder-name",children:"Folder Name"}),e.jsx(ss,{id:"folder-name",value:se,onChange:r=>Se(r.target.value),placeholder:"Enter folder name...",className:"mt-2","data-testid":"input-folder-name",onKeyDown:r=>{r.key==="Enter"&&ze()}})]}),e.jsxs(ke,{children:[e.jsx(m,{variant:"outline",onClick:()=>pe(!1),children:"Cancel"}),e.jsxs(m,{onClick:ze,disabled:!se.trim()||oe.isPending,className:"bg-orange-600 hover:bg-orange-700","data-testid":"button-confirm-create-folder",children:[oe.isPending?e.jsx(Oe,{className:"h-4 w-4 animate-spin mr-2"}):null,"Create Folder"]})]})]})}),e.jsx(ae,{open:!!j,onOpenChange:r=>!r&&le(null),children:e.jsxs(re,{className:"sm:max-w-[400px]",children:[e.jsx(ie,{children:e.jsxs(ne,{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"h-5 w-5"}),"Rename Folder"]})}),e.jsxs("div",{className:"py-4",children:[e.jsx(p,{htmlFor:"edit-folder-name",children:"Folder Name"}),e.jsx(ss,{id:"edit-folder-name",value:X,onChange:r=>ge(r.target.value),placeholder:"Enter folder name...",className:"mt-2","data-testid":"input-edit-folder-name",onKeyDown:r=>{r.key==="Enter"&&ls()}})]}),e.jsxs(ke,{children:[e.jsx(m,{variant:"outline",onClick:()=>le(null),children:"Cancel"}),e.jsxs(m,{onClick:ls,disabled:!X.trim()||b.isPending,className:"bg-orange-600 hover:bg-orange-700","data-testid":"button-confirm-rename-folder",children:[b.isPending?e.jsx(Oe,{className:"h-4 w-4 animate-spin mr-2"}):null,"Save"]})]})]})}),e.jsx(ae,{open:is,onOpenChange:_,children:e.jsxs(re,{className:"sm:max-w-[400px]",children:[e.jsxs(ie,{children:[e.jsxs(ne,{className:"flex items-center gap-2",children:[e.jsx(ts,{className:"h-5 w-5"}),"Add to Folder"]}),e.jsx(me,{children:E!=null&&E.name?`Select a folder for "${E.name}"`:"Select a folder"})]}),e.jsx("div",{className:"py-4",children:h.length===0?e.jsxs("div",{className:"text-center py-6",children:[e.jsx(ts,{className:"h-10 w-10 mx-auto text-gray-300 mb-3"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"No folders yet"}),e.jsxs(m,{size:"sm",onClick:()=>{_(!1),pe(!0)},children:[e.jsx(He,{className:"h-4 w-4 mr-2"}),"Create First Folder"]})]}):e.jsx("div",{className:"space-y-2",children:h.map(r=>{const o=E!=null&&E.id?Le(r.id).includes(E.id):!1;return e.jsxs("button",{onClick:()=>{o&&(E!=null&&E.id)?Ie.mutate({offerId:E.id,folderId:r.id}):fs(r.id)},disabled:Ae.isPending||Ie.isPending,className:Ss("w-full flex items-center gap-3 px-4 py-3 rounded-lg text-left transition-colors",o?"bg-orange-100 border-2 border-orange-300":"bg-gray-50 hover:bg-gray-100 border-2 border-transparent"),"data-testid":`folder-option-${r.id}`,children:[e.jsx(hs,{className:Ss("h-5 w-5",o?"text-orange-600":"text-gray-400")}),e.jsx("span",{className:"flex-1 font-medium",children:r.name}),o&&e.jsx(M,{variant:"secondary",className:"bg-orange-200 text-orange-800",children:"In folder"}),e.jsx(Ft,{className:"h-4 w-4 text-gray-400"})]},r.id)})})}),e.jsx(ke,{children:e.jsx(m,{variant:"outline",onClick:()=>_(!1),children:"Close"})})]})}),e.jsx(ae,{open:I,onOpenChange:R,children:e.jsxs(re,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ie,{children:[e.jsxs(ne,{className:"flex items-center gap-2",children:[e.jsx(As,{className:"h-5 w-5"}),"Preview: ",(n==null?void 0:n.name)||"Offer Details"]}
11),e.jsxs(me,{children:[v?"Template preview":"Offer preview"," - View all details"]})]}),n&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Name"}),e.jsx("p",{className:"text-lg font-semibold",children:n.name})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Type"}),e.jsx(M,{variant:"outline",className:"mt-1",children:n.type||"Not specified"})]})]}),n.description&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Description"}),e.jsx("p",{className:"mt-1 text-gray-600",children:n.description})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[n.originalPrice&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Original Price"}),e.jsx("p",{className:"text-lg font-semibold text-gray-900",children:n.originalPrice})]}),n.offerPrice&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Offer Price"}),e.jsx("p",{className:"text-lg font-semibold text-green-600",children:n.offerPrice})]})]}),n.benefits&&n.benefits.length>0&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Benefits"}),e.jsx("ul",{className:"mt-2 space-y-1",children:n.benefits.map((r,o)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Ot,{className:"h-4 w-4 text-green-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-gray-700",children:r})]},o))})]}),n.features&&n.features.length>0&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Features"}),e.jsx("ul",{className:"mt-2 space-y-1",children:n.features.map((r,o)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(et,{className:"h-4 w-4 text-orange-500 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-gray-700",children:r})]},o))})]}),n.bonuses&&n.bonuses.length>0&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Bonuses"}),e.jsx("ul",{className:"mt-2 space-y-1",children:(Array.isArray(n.bonuses)?n.bonuses:[n.bonuses]).map((r,o)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(kt,{className:"h-4 w-4 text-purple-500 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-gray-700",children:r})]},o))})]}),n.guarantees&&n.guarantees.length>0&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Guarantees"}),e.jsx("ul",{className:"mt-2 space-y-1",children:(Array.isArray(n.guarantees)?n.guarantees:[n.guarantees]).map((r,o)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(Et,{className:"h-4 w-4 text-blue-500 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-gray-700",children:r})]},o))})]}),n.terms&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Terms & Conditions"}),e.jsx("p",{className:"mt-1 text-sm text-gray-600",children:n.terms})]}),e.jsx("div",{className:"flex items-center justify-between pt-4 border-t",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Status"}),e.jsx("p",{className:"text-sm",children:e.jsx(M,{variant:n.isActive?"default":"secondary",children:n.isActive?"Active":"Inactive"})})]}),n.validUntil&&e.jsxs("div",{children:[e.jsx(p,{className:"text-sm font-medium text-gray-700",children:"Valid Until"}),e.jsx("p",{className:"text-sm text-gray-600",children:n.validUntil})]})]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-4 border-t mt-4",children:[e.jsx(m,{variant:"outline",onClick:()=>R(!1),children:"Close"}),e.jsxs(m,{onClick:()=>{R(!1),q(n)},className:"bg-orange-600 hover:bg-orange-700","data-testid":"button-edit-offer-preview",children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Edit Offer"]})]})]})]})}),e.jsx(ae,{open:Pe,onOpenChange:r=>{Ce(r),r||c(new Set)},children:e.jsxs(re,{className:"sm:max-w-[500px]",children:[e.jsxs(ie,{children:[e.jsxs(ne,{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-5 w-5 text-orange-600"}),"Add Offers to Folder"]}),e.jsxs(me,{children:['Select offers to add to "',((cs=h.find(r=>r.id===T))==null?void 0:cs.name)||"folder",'"']})]}),e.jsx("div",{className:"py-4",children:B.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ws,{className:"h-10 w-10 mx-auto text-gray-300 mb-3"}),e.jsx("p",{className:"text-sm text-gray-500",children:"All offers are already in this folder"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 pb-3 border-b mb-3",children:[e.jsx(Ke,{id:"select-all-offers",checked:a.size===B.length&&B.length>0,onCheckedChange:r=>{c(r?new Set(B.map(o=>o.id)):new Set)}}),e.jsxs("label",{htmlFor:"select-all-offers",className:"text-sm font-medium cursor-pointer",children:["Select All (",B.length," offers)"]})]}),e.jsx(Qs,{className:"max-h-[300px]",children:e.jsx("div",{className:"space-y-2",children:B.map(r=>e.jsxs("div",{className:Ss("flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors",a.has(r.id)?"bg-orange-50 border-orange-300":"hover:bg-gray-50 border-gray-200"),onClick:()=>
11{const o=new Set(a);o.has(r.id)?o.delete(r.id):o.add(r.id),c(o)},children:[e.jsx(Ke,{checked:a.has(r.id),onCheckedChange:()=>{},className:"pointer-events-none"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:r.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(M,{variant:"outline",className:"text-xs",children:r.type||"offer"}),r.offerPrice&&e.jsx("span",{className:"text-xs text-gray-500",children:r.offerPrice})]})]})]},r.id))})})]})}),e.jsxs(ke,{children:[e.jsx(m,{variant:"outline",onClick:()=>{Ce(!1),c(new Set)},children:"Cancel"}),e.jsxs(m,{onClick:xs,disabled:a.size===0,className:"bg-orange-600 hover:bg-orange-700","data-testid":"button-confirm-add-offers-to-folder",children:["Add ",a.size>0?`(${a.size})`:""," to Folder"]})]})]})})]})}function Oa(){const{toast:i}=Ps(),g=Is();qt();const{subscriptionInfo:ue,aiPowerLevel:Ne}=Dt();Pt();const{activeCompanyId:x}=st(),[be,V]=It(),he=new URLSearchParams(be.split("?")[1]||"").get("mode"),{data:xe=[]}=Ge({queryKey:["/api/avatars",{companyId:x}],enabled:!!x}),[we,De]=l.useState(null),[q,Y]=l.useState(0),[z,S]=l.useState(""),[v,C]=l.useState(!1);l.useState([]);const[k,L]=l.useState(""),[$,J]=l.useState(0),[P,H]=l.useState(null);l.useState(!1);const[W,K]=l.useState(!1),[ee,G]=l.useState(!1),[T,fe]=l.useState(""),[Be,pe]=l.useState(""),[se,Se]=l.useState(!1),[is,_]=l.useState(null),[E,We]=l.useState(""),[j,le]=l.useState(null);l.useState(null);const[X,ge]=l.useState(""),[ye,qe]=l.useState(""),[Pe,Ce]=l.useState("all"),[a,c]=l.useState("date-newest"),[n,A]=l.useState(!1),[I,R]=l.useState(new Set),[h,U]=l.useState(null),[_e,oe]=l.useState(!1),[b,Te]=l.useState(null);l.useState("basic"),l.useState(new Set);const Ae=l.useRef(null);l.useEffect(()=>{he==="manual"?(De(null),_(null)):he==="templates"&&V("/offer-templates")}
11,[he,V]);const{data:Ie=[],isLoading:Le}=Ge({queryKey:["/api/offers",{companyId:x}],enabled:!!x,queryFn:async()=>(await w("/api/offers")).json()}),{data:B}=Ge({queryKey:["/api/business-profile",{companyId:x}],enabled:!!x,queryFn:async()=>(await w("/api/business-profile")).json()});l.useMemo(()=>ye,[ye]);const xs=s=>{R(t=>{const d=new Set(t);return d.has(s)?d.delete(s):d.add(s),d})},ns=()=>{R(new Set(ys.map(s=>s.id)))},ze=()=>{R(new Set)},ls=(s,t)=>{rt.mutate({id:s,isStarred:t})},fs=s=>{Te(s),oe(!0)},ps=async s=>{if(!B){i({title:"Error",description:"Business profile is required for PDF generation. Please complete your business profile first.",variant:"destructive"});return}try{let t={};try{t=JSON.parse(s.notes||"{}")}catch{console.warn("Failed to parse offer notes")}const d={id:s.id,name:s.title||s.name||"Untitled Offer",type:s.offerType||"discount",headline:t.headline||s.title||"",subheadline:t.subheadline||"",description:s.description||"",value:s.incentiveValue||"",originalPrice:t.originalPrice||"",offerPrice:t.offerPrice||s.pricePoint||"",savings:t.savings||"",conditions:t.conditions||s.termsConditions||"",urgency:s.urgency||"",callToAction:t.callToAction||"",benefits:Array.isArray(t.benefits)?t.benefits:[],features:Array.isArray(t.features)?t.features:[],bonuses:Array.isArray(t.bonuses)?t.bonuses:[],guarantees:Array.isArray(t.guarantees)?t.guarantees:[],status:s.isActive?"active":"inactive",createdAt:s.createdAt?new Date(s.createdAt).toLocaleDateString():new Date().toLocaleDateString()},N=new zt().generateOfferPDF(d,B),Q=document.createElement("a");Q.href=N,Q.download=`${d.name.replace(/[^a-z0-9]/gi,"_").toLowerCase()}_offer.pdf`,document.body.appendChild(Q),Q.click(),document.body.removeChild(Q),i({title:"Success",description:"Offer PDF downloaded successfully"})}catch(t){console.error("PDF generation error:",t),i({title:"Error",description:"Failed to generate PDF. Please try again.",variant:"destructive"})}},os=s=>{at.mutate(s)},cs=s=>{console.log("🗑️ [FRONTEND] handleBatchDeleteOffers called with IDs:",s),console.log("🗑️ [FRONTEND] Number of offers to delete:",s.length),console.log("🗑️ [FRONTEND] Selected offers before delete:",Array.from(I)),it.mutate(s)},r=(s,t)=>{nt.mutate({ids:s,isActive:t})},o=s=>{console.log("=== EDITING LIBRARY OFFER - COMPLETELY REWRITTEN ==="),console.log("Offer to edit:",s);let t={};try{t=JSON.parse(s.notes||"{}"),console.log("Parsed notes:",t)}catch{console.warn("Failed to parse offer notes, using basic data")}U(s),le(s),$e({id:s.id,name:s.title||s.name||"",type:s.offerType||"discount",headline:t.headline||s.title||"",subheadline:t.subheadline||"",value:s.incentiveValue||"",originalPrice:t.originalPrice||"",offerPrice:t.offerPrice||s.pricePoint||"",savings:t.savings||"",description:s.description||"",conditions:t.conditions||s.termsConditions||"",urgency:s.urgency||"",callToAction:t.callToAction||"",benefits:Array.isArray(t.benefits)?t.benefits:[],features:Array.isArray(t.features)?t.features:[],bonuses:Array.isArray(t.bonuses)?t.bonuses:[],guarantees:Array.isArray(t.guarantees)?t.guarantees:[],targetAvatarId:s.targetAvatarId||null,isArchived:s.isArchived||!1}),console.log("=== FULL EDITING STATE SET ==="),console.log("editingOffer:",s),console.log("formData populated with all fields")},Z=s=>{console.log("=== USING OFFER AS TEMPLATE ==="),console.log("Template offer:",s),navigate(`/manual-offer-creator?templateId=${s.id}`)},gs=s=>{lt.mutate({id:h.id,...s})},ys=l.useMemo(()=>Ie?Ie.filter(s=>{var t,d,u,N;if(ye){const Q=ye.toLowerCase();if(!(((t=s.name)==null?void 0:t.toLowerCase().includes(Q))||((d=s.headline)==null?void 0:d.toLowerCase().includes(Q))||((u=s.description)==null?void 0:u.toLowerCase().includes(Q))||((N=s.type)==null?void 0:N.toLowerCase().includes(Q))))return!1}return!(Pe==="active"&&s.isArchived||Pe==="draft"&&!s.isArchived||n&&!s.isStarred)}).sort((s,t)=>{switch(a){case"name":return(s.name||s.headline||"").localeCompare(t.name||t.headline||"");case"type":return(s.type||"").localeCompare(t.type||"");case"date-newest":return new Date(t.createdAt||0).getTime()-new Date(s.createdAt||0).getTime();case"date-oldest":return new Date(s.createdAt||0).getTime()-new Date(t.createdAt||0).getTime();default:return 0}}):[],[Ie,ye,Pe,a,n]),[y,$e]=l.useState({name:"",type:"discount",headline:"",subheadline:"",value:"",originalPrice
11:"",offerPrice:"",savings:"",description:"",conditions:"",urgency:"",callToAction:"",benefits:[],features:[],bonuses:[],guarantees:[],targetAvatarId:null,isArchived:!1});l.useEffect(()=>{(!Array.isArray(y.benefits)||!Array.isArray(y.features)||!Array.isArray(y.bonuses)||!Array.isArray(y.guarantees))&&$e(t=>({...t,benefits:Array.isArray(t.benefits)?t.benefits:[],features:Array.isArray(t.features)?t.features:[],bonuses:Array.isArray(t.bonuses)?t.bonuses:[],guarantees:Array.isArray(t.guarantees)?t.guarantees:[]}))},[y.benefits,y.features,y.bonuses,y.guarantees]);const{data:Xe=[],isLoading:ds}=Ge({queryKey:["/api/offer-templates",{companyId:x}],enabled:!!x,queryFn:async()=>{const s=await fetch("/api/offer-templates");if(!s.ok)throw new Error("Failed to fetch templates");return s.json()}});D({mutationFn:async s=>await(await w("/api/offers",{method:"POST",body:JSON.stringify(s)})).json(),onSuccess:s=>{console.log("=== OFFER CREATED SUCCESSFULLY ==="),console.log("Created offer data:",s),Bt("create_offer","content_creation","offer_creator"),g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]}),g.invalidateQueries({queryKey:["/api/generated-offers",{companyId:x}]}),g.invalidateQueries({queryKey:["/api/item-counts"]}),le(s),i({title:"Offer Saved!",description:"Your offer has been created successfully. You can continue editing it."})},onError:s=>{if(console.error("Create offer failed:",s),s.name==="SessionExpiredError"){i({title:"🔒 Session Expired",description:"Your session has expired. Refreshing the page to log you back in...",variant:"destructive"}),setTimeout(()=>window.location.reload(),2e3);return}if(s.name==="CompanyAccessError"){i({title:"🏢 Access Denied",description:"You don't have permission to create offers for this company. Please switch companies or contact your administrator.",variant:"destructive"});return}if(s.name==="NetworkError"){i({title:"🌐 Connection Issue",description:"Network connection failed. Please check your internet and try again.",variant:"destructive"});return}i({title:"Error",description:s.message||"Failed to create offer",variant:"destructive"})}}),D({mutationFn:async({id:s,...t})=>(console.log("=== UPDATE OFFER MUTATION ==="),console.log("Updating offer ID:",s),console.log("Updates:",t),await(await w(`/api/offers/${s}`,{method:"PATCH",body:JSON.stringify(t)})).json()),onSuccess:s=>{console.log("Offer update successful:",s),g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]}),g.invalidateQueries({queryKey:["/api/generated-offers",{companyId:x}]}),i({title:"Success!",description:"Offer updated successfully."})},onError:s=>{if(console.error("Offer update failed:",s),s.name==="SessionExpiredError"){i({title:"🔒 Session Expired",description:"Your session has expired. Refreshing the page to log you back in...",variant:"destructive"}),setTimeout(()=>window.location.reload(),2e3);return}if(s.name==="CompanyAccessError"){i({title:"🏢 Access Denied",description:"You don't have permission to update offers for this company. Please switch companies or contact your administrator.",variant:"destructive"});return}if(s.name==="NetworkError"){i({title:"🌐 Connection Issue",description:"Network connection failed. Your changes weren't saved. Please check your internet and try again.",variant:"destructive"});return}i({title:"Error",description:s.message||"Failed to update offer",variant:"destructive"})}});const js=D({mutationFn:async({id:s,...t})=>(console.log("=== AUTO-SAVE ==="),console.log("Auto-saving offer ID:",s),console.log("Field updates:",t),await(await w(`/api/offers/${s}`,{method:"PATCH",body:JSON.stringify(t)})).json()),onSuccess:s=>{console.log("Auto-save successful for offer:",s.id),g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]}),g.invalidateQueries({queryKey:["/api/generated-offers",{companyId:x}]})},onError:s=>{console.warn("Auto-save failed:",s),s.name==="SessionExpiredError"&&(i({title:"🔒 Session Expired",description:"Your session expired. Auto-save failed. Please refresh to continue.",variant:"destructive"}),setTimeout(()=>window.location.reload(),3e3))}}),at=D({mutationFn:async s=>await(await w(`/api/offers/${s}`,{method:"DELETE"})).json(),onSuccess:async()=>{await g.invalidateQueries({queryKey:["/api/offers"]}),await g.refetchQueries({queryKey:["/api/offers"]}),await g.invalidateQueries({queryKey:["/api/generated-offers"]}),i({title:"Success!",description:"Offer deleted successfully."})},onError:s=>{if(console.error("Delete offer failed:",s),s.name==="SessionExpiredError"){i({title:"
11🔒 Session Expired",description:"Your session has expired. Refreshing the page to log you back in...",variant:"destructive"}),setTimeout(()=>window.location.reload(),2e3);return}if(s.name==="CompanyAccessError"){i({title:"🏢 Access Denied",description:"You don't have permission to delete offers for this company. Please switch companies or contact your administrator.",variant:"destructive"});return}if(s.name==="NetworkError"){i({title:"🌐 Connection Issue",description:"Network connection failed. The offer was not deleted. Please check your internet and try again.",variant:"destructive"});return}i({title:"Delete Failed",description:s.message||"Failed to delete offer",variant:"destructive"})}}),rt=D({mutationFn:async({id:s,isStarred:t})=>(console.log("=== STAR OFFER MUTATION ==="),console.log("ID:",s,"isStarred:",t),await(await w(`/api/offers/${s}/star`,{method:"PUT",body:JSON.stringify({isStarred:t})})).json()),onSuccess:(s,{isStarred:t})=>{console.log("Star mutation successful:",s),g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]}),i({title:t?"Offer Starred":"Offer Unstarred",description:t?"Offer added to favorites":"Offer removed from favorites"})},onError:s=>{if(console.error("Star mutation failed:",s),s.name==="SessionExpiredError"){i({title:"🔒 Session Expired",description:"Your session has expired. Refreshing the page to log you back in...",variant:"destructive"}),setTimeout(()=>window.location.reload(),2e3);return}if(s.name==="CompanyAccessError"){i({title:"🏢 Access Denied",description:"You don't have permission to modify offers for this company. Please switch companies or contact your administrator.",variant:"destructive"});return}if(s.name==="NetworkError"){i({title:"🌐 Connection Issue",description:"Network connection failed. Please check your internet and try again.",variant:"destructive"});return}i({title:"Error",description:s.message||"Failed to update offer star status",variant:"destructive"})}});D({mutationFn:async({id:s,isActive:t})=>(console.log("=== UPDATE OFFER STATUS MUTATION ==="),console.log("ID:",s,"isActive:",t),await(await w(`/api/offers/${s}/status`,{method:"PUT",body:JSON.stringify({isActive:t})})).json()),onSuccess:(s,{isActive:t})=>{console.log("Status mutation successful:",s),g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]}),i({title:"Status Updated",description:`Offer ${t?"published":"set to draft"} successfully`})},onError:s=>{if(console.error("Status mutation failed:",s),s.name==="SessionExpiredError"){i({title:"🔒 Session Expired",description:"Your session has expired. Refreshing the page to log you back in...",variant:"destructive"}),setTimeout(()=>window.location.reload(),2e3);return}if(s.name==="CompanyAccessError"){i({title:"🏢 Access Denied",description:"You don't have permission to update offer status for this company. Please switch companies or contact your administrator.",variant:"destructive"});return}if(s.name==="NetworkError"){i({title:"🌐 Connection Issue",description:"Network connection failed. Status was not updated. Please check your internet and try again.",variant:"destructive"});return}i({title:"Error",description:s.message||"Failed to update offer status",variant:"destructive"})}});const it=D({mutationFn:async s=>{console.log("🗑️ [FRONTEND] batchDeleteOffersMutation called with IDs:",s),console.log("🗑️ [FRONTEND] activeCompanyId:",x);const d=await(await w("/api/offers/batch-delete",{method:"POST",body:JSON.stringify({ids:s})})).json();return console.log("✅ [FRONTEND] Batch delete response:",d),d},onSuccess:async s=>{console.log("✅ [FRONTEND] Batch delete onSuccess called with data:",s),console.log("🔄 [FRONTEND] Refetching offers for companyId:",x),await g.refetchQueries({queryKey:["/api/offers",{companyId:x}],exact:!1}),console.log("✅ [FRONTEND] Refetch complete, clearing selected offers"),R(new Set),i({title:"Offers Deleted",description:`Successfully deleted ${s.totalDeleted||0} offer(s)`})},onError:s=>{if(console.error("Batch delete failed:",s),s.name==="SessionExpiredError"){i({title:"🔒 Session Expired",description:"Your session has expired. Refreshing the page to log you back in...",variant:"destructive"}),setTimeout(()=>window.location.reload(),2e3);return}
11if(s.name==="CompanyAccessError"){i({title:"🏢 Access Denied",description:"You don't have permission to delete offers for this company. Please switch companies or contact your administrator.",variant:"destructive"});return}if(s.name==="NetworkError"){i({title:"🌐 Connection Issue",description:"Network connection failed. Offers were not deleted. Please check your internet and try again.",variant:"destructive"});return}i({title:"Batch Delete Failed",description:s.message||"Failed to delete selected offers",variant:"destructive"})}}),nt=D({mutationFn:async({ids:s,isActive:t})=>await(await w("/api/offers/batch-update-status",{method:"POST",body:JSON.stringify({ids:s,isActive:t})})).json(),onSuccess:()=>{g.invalidateQueries({queryKey:["/api/offers",{companyId:x}],exact:!1}),R(new Set),i({title:"Status Updated",description:"Selected offers status updated successfully"})},onError:s=>{if(console.error("Batch status update failed:",s),s.name==="SessionExpiredError"){i({title:"🔒 Session Expired",description:"Your session has expired. Refreshing the page to log you back in...",variant:"destructive"}),setTimeout(()=>window.location.reload(),2e3);return}if(s.name==="CompanyAccessError"){i({title:"🏢 Access Denied",description:"You don't have permission to update offer status for this company. Please switch companies or contact your administrator.",variant:"destructive"});return}if(s.name==="NetworkError"){i({title:"🌐 Connection Issue",description:"Network connection failed. Status was not updated. Please check your internet and try again.",variant:"destructive"});return}i({title:"Batch Update Failed",description:s.message||"Failed to update selected offers status",variant:"destructive"})}}),lt=D({mutationFn:async({id:s,...t})=>(console.log("=== UPDATE LIBRARY OFFER MUTATION ==="),console.log("ID:",s,"Data:",t),await(await w(`/api/offers/${s}`,{method:"PATCH",body:JSON.stringify(t)})).json()),onSuccess:s=>{console.log("Library offer update successful:",s),g.invalidateQueries({queryKey:["/api/offers",{companyId:x}],exact:!1}),U(null),i({title:"Offer Updated",description:"Successfully updated offer"})},onError:s=>{console.error("Library offer update failed:",s),i({title:"Error",description:s.message||"Failed to update offer",variant:"destructive"})}}),ot=D({mutationFn:async({id:s,sharingState:t})=>await(await w(`/api/offers/${s}/sharing`,{method:"PUT",body:JSON.stringify({sharingState:t})})).json(),onSuccess:()=>{g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]}),oe(!1),i({title:"Sharing Settings Updated",description:"The offer sharing settings have been updated successfully"})},onError:s=>{i({title:"Error",description:s.message||"Failed to update sharing settings",variant:"destructive"})}});D({mutationFn:async({id:s,...t})=>(console.log("=== QUICK SAVE MUTATION ==="),console.log("Quick saving offer ID:",s),console.log("Updates:",t),await(await w(`/api/offers/${s}`,{method:"PATCH",body:JSON.stringify(t)})).json()),onSuccess:s=>{console.log("Quick save successful:",s),g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]}),g.invalidateQueries({queryKey:["/api/generated-offers",{companyId:x}]}),i({title:"Saved!",description:"Tab changes saved successfully."})},onError:s=>{console.error("Quick save failed:",s),i({title:"Save Error",description:s.message||"Failed to save changes",variant:"destructive"})}});const vs=D({mutationFn:async s=>await(await w("/api/offer-templates",{method:"POST",body:JSON.stringify(s)})).json(),onSuccess:()=>{g.invalidateQueries({queryKey:["/api/offer-templates",{companyId:x}]}),i({title:"Template Saved!",description:"Your offer template has been saved successfully."}),G(!1),fe(""),pe(""),Se(!1)},onError:s=>{i({title:"Error",description:s.message||"Failed to save template",variant:"destructive"})}}),ct=D({mutationFn:async s=>w(`/api/offer-templates/${s}`,{method:"DELETE"}),onSuccess:()=>{g.invalidateQueries({queryKey:["/api/offer-templates",{companyId:x}]}),i({title:"Template Deleted",description:"The template has been removed."})},onError:s=>{i({title:"Cannot Delete Template",description:s.message||"System templates cannot be deleted",variant:"destructive"})}});D({mutationFn:async s=>await(await w(`/api/offer-templates/${s}/copy`,{method:"POST"})).json(),onSuccess:()=>{g.invalidateQueries({queryKey:["/api/offer-templates",{companyId:x}]}),i({title:"Template Copied!",description:"A copy has been created in your templates."})},onError:s=>{i({title:"Error",description:s.message||"Failed to copy template",variant:"destructive"})}}),D({mutationFn:async({id:s,...t})=>await(await w(`/api/offer-templates/${s}`,{method:"PATCH",body:JSON.stringify(t)})).json(),onSuccess:()=>{g.invalidateQueries({queryKey:["/api/offer-templates",{companyId:x}]}),i({title:"Template Updated",description:"Your changes have been saved."})},onError:s=>{i({title:"Cannot Edit Template",description:s.message||"This template cannot be edited",variant:"destructive"})}}),l.useCallback((s,t)=>{if(!(j!=null&&j.id)){console.log("No editingOffer ID, skipping auto-save");return}Ae.current&&clearTimeout(Ae.current),Ae.current=setTimeout(()=>{console.log(`Auto-saving field: ${s} =`,t);const d={id:j.id,...y,[s]:t};js.mutate(d)},800)},[j==null?void 0:j.id,y,js]),l.useEffect(()=>()=>{Ae.current&&clearTimeout(Ae.current)},[]);const dt=async s=>{try{await w(`/api/offer-templates/${s}/use`,{method:"POST"})}catch{}},Ls=async s=>{var ms,Us;const t=document.querySelector('textarea[placeholder*="Create a summer discount"]'),d=(t==null?void 0:t.value)||"",u=s||d.trim()||localAiPrompt.trim()||z.trim();console.log("=== AI PROMPT DEBUG ==="),console.log("overridePrompt:",s),console.log("textareaValue:",d),console.log("localAiPrompt:",localAiPrompt),console.log("aiPrompt:",z),console.log("currentPrompt:",u);const N=X||((ms=te==null?void 0:te[0])==null?void 0:ms.name)||"General Service";if(!u||u.length<10){i({title:"Prompt Required",description:"Please provide a detailed description of your offer (at least 10 characters)",variant:"destructive"});return}const Q=u;localAiPrompt.trim()&&localAiPrompt!==z&&S(localAiPrompt),!X&&(te==null?void 0:te.length)>0&&ge(te[0].name),C(!0),L("Analyzing your business context..."),J(10);try{const ce=P?xe.find(Ns=>Ns.id===P):null;setTimeout(()=>{L("Applying marketing psychology frameworks..."),J(30)},500),setTimeout(()=>{L("Crafting compelling copy with Claude Sonnet 4..."),J(60)},1500),setTimeout(()=>{L("Optimizing for conversions..."),J(85)},3e3),console.log("=== SENDING TO API ==="),console.log("Prompt being sent:",Q),console.log("Service:",N),console.log("Avatar:",ce);const je=await w("/api/offers/generate-ai",{method:"POST",body:JSON.stringify({prompt:Q,targetAvatar:ce,selectedService:N,aiPowerLevel:Ne})});if(!je.ok){const Ns=await je.json();throw new Error(Ns.message||"Failed to generate AI offer")}const f=await je.json();L("Finalizing your AI-generated offer..."),J(100);let Ue="";
11typeof f.description=="string"&&f.description.trim()?Ue=f.description:typeof f.description=="object"&&((Us=f.description)!=null&&Us.primary_benefit)?Ue=f.description.primary_benefit:f.hook?Ue=f.hook:f.value_proposition?Ue=f.value_proposition:f.headline?Ue=`${f.headline}${f.subheadline?" - "+f.subheadline:""}`:Ue="Professional marketing offer designed to attract and convert your ideal customers";const F={...f,targetAvatarId:P,name:f.name||f.headline||"AI Generated Offer",type:f.type||"custom",value:f.value||f.savings||"Special Offer",description:Ue,originalPrice:f.originalPrice||"",offerPrice:f.offerPrice||"",savings:f.savings||"",benefits:f.benefits||[],features:f.features||[],bonuses:f.bonuses||[],guarantees:f.guarantees||[],isArchived:!1};console.log("AI Generated Response:",f),console.log("Processed Offer Data:",F),console.log("Benefits:",F.benefits),console.log("Features:",F.features),console.log("Bonuses:",F.bonuses),console.log("Guarantees:",F.guarantees);const Ze={...y,name:F.name,type:F.type,headline:F.headline,subheadline:F.subheadline,value:F.value,description:F.description,conditions:F.conditions,urgency:F.urgency,callToAction:F.callToAction,originalPrice:F.originalPrice,offerPrice:F.offerPrice,savings:F.savings,benefits:F.benefits||[],features:F.features||[],bonuses:F.bonuses||[],guarantees:F.guarantees||[],targetAvatarId:F.targetAvatarId,isActive:F.isActive};console.log("=== FIXED DATA FLOW DEBUG ==="),console.log("Final preservedData benefits:",Ze.benefits),console.log("Final preservedData features:",Ze.features),console.log("Final preservedData bonuses:",Ze.bonuses),console.log("Final preservedData guarantees:",Ze.guarantees),console.log("=== END DEBUG ==="),$e(Ze),i({title:"🎉 AI Generation Complete!",description:"Your professional-grade offer is ready for review and customization"})}catch(ce){console.error("AI Generation Error:",ce);let je="Generation Failed",f="Failed to generate offer. Please try again.";ce.message&&(ce.message.includes("temporarily busy")?(je="🤖 AI Service Busy",f="The AI is experiencing high demand. Please wait a moment and click 'Generate AI Offer' to retry."):ce.message.includes("wait a moment")?(je="⏱️ Rate Limited",f="Too many requests. Please wait 30 seconds before trying again."):ce.message.includes("authentication")?(je="🔧 Service Issue",f="There's a temporary issue with the AI service. Please try again or contact support."):ce.message.includes("clearer prompt")?(je="📝 Improve Your Prompt",f="Please provide more details about your offer (pricing, target audience, value proposition) and try again."):f=ce.message),i({title:je,description:f,variant:"destructive"})}finally{C(!1),L(""),J(0)}},mt=async s=>{_(s),$e({name:s.name,type:s.type,headline:s.headline,subheadline:s.subheadline||"",value:s.value,originalPrice:s.originalPrice||"",offerPrice:s.offerPrice||"",savings:s.savings||"",description:s.description_template||"",conditions:s.conditions||"",urgency:s.urgency||"",callToAction:s.callToAction,benefits:s.benefits||[],features:s.features||[],bonuses:s.bonuses||[],guarantees:s.guarantees||[],targetAvatarId:P}),s.id&&await dt(s.id)},ut=()=>{if(!T.trim()){i({title:"Template name required",description:"Please enter a name for your template",variant:"destructive"});return}const s={name:T,description:Be,category:"custom",isPublic:se,type:y.type==="custom"&&E?E:y.type||"custom",headline:y.headline,subheadline:y.subheadline,value:y.value,originalPrice:y.originalPrice,offerPrice:y.offerPrice,savings:y.savings,description_template:y.description,conditions:y.conditions,urgency:y.urgency,callToAction:y.callToAction,benefits:y.benefits,features:y.features,bonuses:y.bonuses,guarantees:y.guarantees};vs.mutate(s)},te=l.useMemo(()=>(B==null?void 0:B.services)||[],[B==null?void 0:B.services]),$s=l.useMemo(()=>te.length>0,[te]);l.useCallback(()=>e.jsxs(de,{children:[e.jsxs(Fs,{children:[e.jsx(Os,{children:"AI Offer Generation"}),e.jsx(ks,{children:"Select a service to promote and describe your ideal offer"})]}),e.jsxs(ve,{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4 sm:justify-between mb-6 pb-4 border-b border-gray-200",children:[e.jsxs(m,{variant:"outline",onClick:()=>Y(1),className:"w-full sm:w-auto order-2 sm:order-1",children:[e.jsx(Vs,{className:"h-4 w-4 mr-2"}),"Back"]}),e.jsx(m,{onClick:()=>{const s=document.querySelector('textarea[placeholder*="Create a summer discount"]'),t=(s==null?void 0:s.value)||localAiPrompt||"";console.log("=== BUTTON CLICK DEBUG ==="),console.log("Current textarea value:",t),console.log("localAiPrompt state:",localAiPrompt),localAiPrompt!==z&&S(localAiPrompt),localCustomOfferType!==E&&We(localCustomOfferType),Ls(t)}
11,disabled:v,className:`w-full sm:w-auto order-1 sm:order-2 ${v?"bg-gradient-to-r from-orange-500 to-orange-600 text-white":""} transition-all duration-300`,children:v?e.jsxs(e.Fragment,{children:[e.jsx(Oe,{className:"h-4 w-4 mr-2 animate-spin"}),"AI Working..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Lt,{className:"h-4 w-4 mr-2"}),"Generate with AI"]})})]}),v&&e.jsxs("div",{className:"mb-6 p-3 sm:p-4 bg-gradient-to-r from-orange-50 to-orange-100 dark:from-orange-900/20 dark:to-orange-800/10 border border-orange-200 dark:border-orange-700 rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 sm:mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 bg-orange-500 rounded-full animate-pulse"}),e.jsx("span",{className:"text-sm font-medium text-orange-700 dark:text-orange-300",children:k})]}),e.jsxs("span",{className:"text-xs text-orange-600 dark:text-orange-400",children:[$,"%"]})]}),e.jsx("div",{className:"w-full bg-orange-100 dark:bg-orange-900/50 rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-orange-400 to-orange-600 h-2 rounded-full transition-all duration-700 ease-out",style:{width:`${$}%`,boxShadow:$>0?"0 0 8px rgba(249, 115, 22, 0.4)":"none"}})}),$>0&&e.jsxs("div",{className:"mt-2 flex items-center text-xs text-orange-600 dark:text-orange-400",children:[e.jsx("div",{className:"animate-pulse mr-1",children:"●●●"}),"AI is creating your personalized offer..."]})]}),e.jsxs("div",{children:[e.jsxs(p,{className:"text-sm font-medium",children:["Service to Promote ",e.jsx("span",{className:"text-red-500",children:"*"})]}),$s?e.jsxs(Qe,{value:X,onValueChange:ge,children:[e.jsx(Ve,{className:"mt-2",children:e.jsx(Ye,{placeholder:"Select a service to create an offer for..."})}),e.jsx(Je,{children:te.map((s,t)=>e.jsx(O,{value:s,children:s},t))})]}):e.jsx("div",{className:"mt-2 p-3 border rounded-md bg-yellow-50 border-yellow-200",children:e.jsxs("p",{className:"text-sm text-yellow-800",children:[e.jsx("strong",{children:"Services not configured:"})," Please add your services in your"," ",e.jsx(Cs,{href:"/business-setup-new",className:"underline font-medium",children:"business profile"})," ","before generating AI offers."]})}),e.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"Choose the specific service you want to create a promotional offer for"})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-sm md:text-base",children:"Describe Your Offer"}),e.jsx(Fe,{placeholder:"e.g., Create a summer discount offer targeting homeowners who haven't had maintenance in over a year. Include urgency and value proposition.",value:localAiPrompt,onChange:s=>setLocalAiPrompt(s.target.value),onBlur:handleAiPromptBlur,rows:4,className:"mt-1 resize-none transition-all",style:{minHeight:"100px",maxHeight:"300px"}}),e.jsx("p",{className:"text-xs sm:text-sm text-gray-500 mt-1 sm:mt-2",children:"Be specific about your target audience, discount type, and desired outcome"})]}),e.jsxs("div",{className:"p-4 bg-blue-50 rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-2 text-blue-900",children:"💡 Pro Tips for Better Results:"}),e.jsxs("ul",{className:"space-y-1 text-sm text-blue-800",children:[e.jsx("li",{children:"• Mention your industry and services"}),e.jsx("li",{children:"• Specify the type of offer (discount, bundle, trial, etc.)"}),e.jsx("li",{children:"• Include any specific value or percentage"}),e.jsx("li",{children:"• Mention urgency or time constraints"}),e.jsx("li",{children:"• Describe your ideal customer"})]})]})]})]}),[te,$s,X,ge,z,S,Ls,v,Ne,ue==null?void 0:ue.creditsRemaining]);const ht=()=>e.jsxs(de,{children:[e.jsx(Fs,{children:e.jsx("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-start gap-4",children:e.jsxs("div",{className:"flex-1",children:[e.jsx(Os,{className:"text-xl sm:text-2xl",children:"Choose Your Creation Method"}),e.jsx(ks,{className:"mt-1 text-sm sm:text-base",children:"Select how you'd like to create your offer"})]})})}),e.jsxs(ve,{children:[e.jsx("div",{className:"flex justify-start mb-6 pb-4 border-b border-gray-200",children:e.jsxs(m,{variant:"outline",onClick:()=>Y(0),className:"w-full sm:w-auto","data-testid":"button-back-to-library",children:[e.jsx(Vs,{className:"h-4 w-4 mr-2"}),"Back to Library"]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 sm:gap-6",children:[e.jsx(de,{className:"cursor-pointer hover:shadow-lg transition-all duration-200 border-2 hover:border-purple-300",onClick:()=>V("/offer-guide-interactive"),"data-testid":"card-method-guided",children:e.jsxs(ve,{className:"p-6 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(Ys,{className:"h-8 w-8 text-purple-600"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2 text-purple-900",children:"Guided Creation"}),e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"Step-by-step wizard walks you through creating a complete offer"}),e.jsx(M,{variant:"secondary",className:"bg-purple-100 text-purple-800",children:"Recommended for beginners"})]})}),e.jsx(de,{className:"cursor-pointer hover:shadow-lg transition-all duration-200 border-2 hover:border-blue-300",onClick:()=>V("/manual-offer-creator"),"data-testid":"card-method-manual",children:e.jsxs(ve,{className:"p-6 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(Ts,{className:"h-8 w-8 text-blue-600"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2 text-blue-900",children:"Manual Creation"}),e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"Create offers from scratch with full control over every detail"}),e.jsx(M,{variant:"secondary",className:"bg-blue-100 text-blue-800",children:"For experienced users"})]})}),e.jsx(de,{className:"cursor-pointer hover:shadow-lg transition-all duration-200 border-2 hover:border-orange-300",onClick:()=>V("/offer-templates"),"data-testid":"card-method-templates",children:e.jsxs(ve,{className:"p-6 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-orange-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(ia,{className:"h-8 w-8 text-orange-600"})}),e.jsx("h3",{className:"text-lg font-semibold mb-2 text-orange-900",children:"Use Templates"}),e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"Start with proven templates and customize to your needs"}),e.jsx(M,{variant:"secondary",className:"bg-orange-100 text-orange-800",children:"Fastest option"})]})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-200",children:e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 justify-center",children:[e.jsxs(m,{variant:"outline",onClick:()=>{i({title:"Coming Soon",description:"Competitor research will be available in a future update. We're integrating SpyFu to help you discover what your competitors are offering."})},className:"w-full sm:w-auto","data-testid":"button-research-ideas",children:[e.jsx(Es,{className:"h-4 w-4 mr-2"}),"Research Ideas First"]}),e.jsx(Cs,{href:"/offer-guide-introduction",children:e.jsxs(m,{variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(Rt,{className:"h-4 w-4 mr-2"}),"Read Offer Guide"]})})]})})]})]}),xt=()=>e.jsx(oa,{offers:Ie,isLoading:Le,selectedOffers:I,onToggleOfferSelection:xs,onSelectAllOffers:ns,onDeselectAllOffers:ze,onStarOffer:ls,onShareOffer:fs,onDownloadPDF:ps,onDeleteOffer:os,onBatchDeleteOffers:cs,onBatchUpdateStatus:r,onEditLibraryOffer:o,onUseAsTemplate:Z,onCreateFirstTemplate:()=>Y(2),onCreateOffer:()=>Y(1)});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container mx-auto p-4 md:p-6 max-w-6xl",children:[e.jsx("div",{className:"mb-6 md:mb-8",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold mb-2",children:j&&q!==0?"Edit Template":"Offer Creator & Generator"}),e.jsx("p",{className:"text-sm md:text-base text-gray-600 dark:text-gray-400",children:j&&q!==0?`Editing template: ${j.name||"Unnamed Template"}`:"Create compelling offers that convert prospects into customers"})]}),(q===0||!j)&&e.jsxs(m,{onClick:()=>Y(1),className:"bg-orange-600 hover:bg-orange-700 text-white w-full sm:w-auto px-4 sm:px-6 py-2 text-sm sm:text-base font-medium shadow-lg hover:shadow-xl transition-all","data-testid":"button-create-offer",children:[e.jsx(us,{className:"h-4 w-4 sm:h-5 sm:w-5 mr-2"}),"Create Offer"]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 w-full sm:w-auto",children:[e.jsxs(m,{variant:"outline",className:"flex items-center justify-center gap-1 sm:gap-2 w-full sm:w-auto px-2 sm:px-4 py-2 text-xs sm:text-sm",onClick:()=>i({title:"Coming Soon",description:"Competitor research will be available in a future update. We're integrating SpyFu to help you discover what your competitors are offering."}),children:[e.jsx(Es,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Research"}),e.jsx("span",{className:"sm:hidden",children:"Search"})]}),e.jsx(Cs,{href:"/offer-guide-introduction",children:e.jsxs(m,{variant:"outline",className:"flex items-center justify-center gap-1 sm:gap-2 w-full sm:w-auto px-2 sm:px-4 py-2 text-xs sm:text-sm",children:[e.jsx(Ys,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Offer Guide"}),e.jsx("span",{className:"sm:hidden",children:"Guide"})]})})]})]})}),e.jsxs("div",{className:"mt-8",children:[q===0&&xt(),q===1&&ht(
11)]})]}),e.jsx(ae,{open:ee,onOpenChange:G,children:e.jsxs(re,{className:"sm:max-w-[425px]",children:[e.jsxs(ie,{children:[e.jsx(ne,{children:"Save as Template"}),e.jsx(me,{children:"Save your current offer as a template for future use"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(p,{htmlFor:"templateName",children:"Template Name"}),e.jsx(es,{id:"templateName",value:T,onChange:s=>fe(s),placeholder:"e.g., Holiday Sale Template",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"templateDescription",children:"Description (Optional)"}),e.jsx(Fe,{id:"templateDescription",value:Be,onChange:s=>pe(s),placeholder:"Describe when to use this template...",rows:3,className:"mt-1"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"templatePublic",checked:se,onChange:s=>Se(s.target.checked),className:"rounded border-gray-300"}),e.jsx(p,{htmlFor:"templatePublic",className:"text-sm font-normal",children:"Make this template public (share with other users)"})]})]}),e.jsxs(ke,{children:[e.jsx(m,{variant:"outline",onClick:()=>G(!1),children:"Cancel"}),e.jsx(m,{onClick:ut,disabled:vs.isPending,children:vs.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Oe,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ra,{className:"h-4 w-4 mr-2"}),"Save Template"]})})]})]})}),e.jsx(ae,{open:W,onOpenChange:K,children:e.jsxs(re,{className:"sm:max-w-[600px]",children:[e.jsxs(ie,{children:[e.jsx(ne,{children:"Manage Templates"}),e.jsx(me,{children:"View and manage your custom offer templates"})]}),e.jsx("div",{className:"py-4",children:ds?e.jsx("div",{className:"flex justify-center p-8",children:e.jsx(Oe,{className:"h-8 w-8 animate-spin text-orange-500"})}):Xe.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(Ts,{className:"h-12 w-12 text-gray-400 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-600",children:"No custom templates yet"})]}):e.jsx("div",{className:"space-y-3 max-h-[400px] overflow-y-auto",children:Xe.map(s=>e.jsx(de,{className:"p-3",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:"font-semibold",children:s.name}),e.jsx(M,{variant:"secondary",className:"text-xs",children:s.type}),s.isPublic&&e.jsx(Js,{className:"h-3 w-3 text-blue-500"})]}),s.description&&e.jsx("p",{className:"text-sm text-gray-600 mb-2",children:s.description}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-gray-500",children:[e.jsxs("span",{children:["Used ",s.usageCount||0," times"]}),e.jsxs("span",{children:["Created ",new Date(s.createdAt).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>{mt(s),K(!1)},children:e.jsx(Ts,{className:"h-4 w-4"})}),e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>{confirm("Delete this template?")&&ct.mutate(s.id)},children:e.jsx(as,{className:"h-4 w-4 text-red-500"})})]})]})},s.id))})}),e.jsx(ke,{children:e.jsx(m,{variant:"outline",onClick:()=>K(!1),children:"Close"})})]})}),e.jsx(ae,{open:_e,onOpenChange:oe,children:e.jsxs(re,{className:"max-w-md",children:[e.jsxs(ie,{children:[e.jsx(ne,{children:"Sharing Settings"}),e.jsx(me,{children:"Control who can access and use this offer template"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-sm font-medium",children:"Sharing State"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-3 p-3 border rounded-lg cursor-pointer hover:bg-gray-50",children:[e.jsx("input",{type:"radio",name:"sharingState",value:"private",checked:(b==null?void 0:b.sharingState)==="private"||!(b!=null&&b.sharingState),onChange:()=>Te({...b,sharingState:"private"}),className:"h-4 w-4"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($t,{className:"h-4 w-4 text-gray-500"}),e.jsx("span",{className:"font-medium",children:"Private"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Only you can access this offer"})]})]}),e.jsxs("label",{className:"flex items-center gap-3 p-3 border rounded-lg cursor-pointer hover:bg-gray-50",children:[e.jsx("input",{type:"radio",name:"sharingState",value:"organization",checked:(b==null?void 0:b.sharingState)==="organization",onChange:()=>Te({...b,sharingState:"organization"}),className:"h-4 w-4"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"font-medium",children:"Organization"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Share with your team members"})]})]}),e.jsxs("label",{className:"flex items-center gap-3 p-3 border rounded-lg cursor-pointer hover:bg-gray-50",children:[e.jsx("input",{type:"radio",name:"sharingState",value:"public",checked:(b==null?void 0:b.sharingState)==="public",onChange:()=>Te({...b,sharingState:"public"}),className:"h-4 w-4"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Js,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"font-medium",children:"Public"})]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Share globally with all Boom Bam users"})]})]})]})]}),(b==null?void 0:b.sharingState)==="public"&&e.jsx("div",{className:"p-3 bg-purple-50 rounded-lg",children:e.jsxs("p",{className:"text-sm text-purple-700",children:[e.jsx("strong",{children:"Note:"})," Public templates will be available in the global template marketplace for all users to discover and use."]})})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4 border-t",children:[e.jsx(m,{variant:"outline",onClick:()=>oe(!1),children:"Cancel"}),e.jsx(m,{onClick:()=>{b&&ot.mutate({id:b.id,sharingState:b.sharingState||"private"})},children:"Save Settings"})]})]})}),h&&e.jsx(ae,{open:!!h,onOpenChange:()=>U(null),children:e.jsxs(re,{className:"sm:max-w-[700px] max-h-[90vh] overflow-y-auto",children:[e.jsx(ie,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(ne,{children:"Edit Offer"}),e.jsx(me,{children:"Make changes to your offer details"})]}),e.jsx("div",{className:"ml-4",children:e.jsx(Ds,{status:h.deploymentStatus||"draft",entityId:h.id,entityType:"offer",onStatusChange:()=>{g.invalidateQueries({queryKey:["/api/offers",{companyId:x}]})}})})]})}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-name",children:"Offer Name"}),e.jsx(es,{id:"edit-name",defaultValue:h.name||"",onChange:s=>{var d;const t=((d=s.target)==null?void 0:d.value)??"";U(u=>u?{...u,name:t}:null)}},`name-${h.id}`)]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-type",children:"Type"}),e.jsxs(Qe,{defaultValue:(()=>{const s=["discount","bogo","bundle","trial","seasonal","loyalty"],t=h.type||"";return s.includes(t)?t:"discount"})(),onValueChange:s=>U(t=>t?{...t,type:s}:null),children:[e.jsx(Ve,{children:e.jsx(Ye,{placeholder:"Select type"})}),e.jsxs(Je,{children:[e.jsx(O,{value:"discount",children:"Discount"}),e.jsx(O,{value:"bogo",children:"Buy One Get One"}),e.jsx(O,{value:"bundle",children:"Bundle Deal"}),e.jsx(O,{value:"trial",children:"Free Trial"}),e.jsx(O,{value:"seasonal",children:"Seasonal"}),e.jsx(O,{value:"loyalty",children:"Loyalty Reward"})]})]},`type-${h.id}`)]})]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-headline",children:"Headline"}),e.jsx(es,{id:"edit-headline",defaultValue:h.headline||"",onChange:s=>{var d;const t=((d=s.target)==null?void 0:d.value)??"";U(u=>u?{...u,headline:t}:null)}},`headline-${h.id}`)]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-description",children:"Description"}),e.jsx(Fe,{id:"edit-description",defaultValue:h.description||"",onChange:s=>{var d;const t=((d=s.target)==null?void 0:d.value)??"";U(u=>u?{...u,description:t}:null)},rows:3},`description-${h.id}`)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-original-price",children:"Original Price"}),e.jsx(es,{id:"edit-original-price",defaultValue:h.originalPrice||"",onChange:s=>{var d;const t=((d=s.target)==null?void 0:d.value)??"";U(u=>
11u?{...u,originalPrice:t}:null)}},`originalPrice-${h.id}`)]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-offer-price",children:"Offer Price"}),e.jsx(es,{id:"edit-offer-price",defaultValue:h.offerPrice||"",onChange:s=>{var d;const t=((d=s.target)==null?void 0:d.value)??"";U(u=>u?{...u,offerPrice:t}:null)}},`offerPrice-${h.id}`)]})]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-benefits",children:"Benefits (one per line)"}),e.jsx(Fe,{id:"edit-benefits",defaultValue:(h.benefits||[]).join(`
12`),onChange:s=>{var u;const d=(((u=s.target)==null?void 0:u.value)??"").split(`
13`).filter(N=>N.trim());U(N=>N?{...N,benefits:d}:null)},rows:4,placeholder:"Enter benefits, one per line"},`benefits-${h.id}`)]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-features",children:"Features (one per line)"}),e.jsx(Fe,{id:"edit-features",defaultValue:(h.features||[]).join(`
14`),onChange:s=>{var u;const d=(((u=s.target)==null?void 0:u.value)??"").split(`
15`).filter(N=>N.trim());U(N=>N?{...N,features:d}:null)},rows:4,placeholder:"Enter features, one per line"},`features-${h.id}`)]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-bonuses",children:"Bonuses (one per line)"}),e.jsx(Fe,{id:"edit-bonuses",defaultValue:(h.bonuses||[]).join(`
16`),onChange:s=>{var u;const d=(((u=s.target)==null?void 0:u.value)??"").split(`
17`).filter(N=>N.trim());U(N=>N?{...N,bonuses:d}:null)},rows:3,placeholder:"Enter bonuses, one per line"},`bonuses-${h.id}`)]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-guarantees",children:"Guarantees (one per line)"}),e.jsx(Fe,{id:"edit-guarantees",defaultValue:(h.guarantees||[]).join(`
18`),onChange:s=>{var u;const d=(((u=s.target)==null?void 0:u.value)??"").split(`
19`).filter(N=>N.trim());U(N=>N?{...N,guarantees:d}:null)},rows:3,placeholder:"Enter guarantees, one per line"},`guarantees-${h.id}`)]}),e.jsxs("div",{children:[e.jsx(p,{htmlFor:"edit-conditions",children:"Terms & Conditions"}),e.jsx(Fe,{id:"edit-conditions",defaultValue:h.conditions||"",onChange:s=>{var d;const t=((d=s.target)==null?void 0:d.value)??"";U(u=>u?{...u,conditions:t}:null)},rows:2,placeholder:"Enter any terms or conditions"},`conditions-${h.id}`)]})]}),e.jsxs(ke,{children:[e.jsx(m,{variant:"outline",onClick:()=>U(null),children:"Cancel"}),e.jsx(m,{onClick:()=>gs(h),className:"bg-orange-600 hover:bg-orange-700",children:"Save Changes"})]})]},`edit-offer-${h.id}`)})]})}export{Oa 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.