1import{j as e}from"./vendor-query-D1Mshrk-.js";import{u as k,r as P,L as G}from"./vendor-react-BfQMi0FG.js";import{B as l,q as V,x as $,r as N,J as X,t as m,a8 as p}from"./index-BrXTQpUj.js";import{C,a as b,b as v,d as I}from"./card-BPl9i0oB.js";import{P as W}from"./page-header-C7x1KRLA.js";import{f as H,c as K}from"./use-promotions-DO-aD3Qv.js";import{u as Q}from"./use-categories-BSxZIg5k.js";import{i as q}from"./use-products-C-d5SucD.js";import{d as J}from"./use-category-options-BODQxJzM.js";import{P as Z}from"./pencil-DXFkiqC-.js";import{C as ee}from"./check-DjZQULyt.js";import"./vendor-ui-87y9m6y2.js";const se=["20% off pizzas every Tuesday","Free delivery on orders over £20","Buy 1 get 1 free on burgers weekends","£5 off when you spend over £30","Spend £20 get a free garlic bread","Spend over £30 and get 5 wings for just £1.50",'3+ pizzas: 14" for £12.50 each, 12" for £11.50, 10" for £9.50',"Double loyalty points every Wednesday"],te={PERCENTAGE_OFF:"Percentage Off",FIXED_AMOUNT_OFF:"Fixed Amount Off",FREE_DELIVERY:"Free Delivery",BUY_X_GET_Y:"Buy X Get Y",MEAL_DEAL:"Meal Deal",MULTI_BUY_PRICE:"Multi-Buy Price",FREE_ITEM:"Free Item",POINTS_MULTIPLIER:"Points Multiplier",SPEND_AND_SAVE:"Spend & Save"},ae=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],re={ENTIRE_ORDER:"Entire Order",CATEGORY:"Specific Categories",PRODUCT:"Specific Products",DELIVERY_FEE:"Delivery Fee",SUBTOTAL_ONLY:"Subtotal Only"};function je(){const i=k(),[n,g]=P.useState(""),[s,x]=P.useState(null),c=H(),d=K(),{data:T}=Q({limit:100}),{data:O}=q(),L=T?.categories??[],A=O??[],u=s?.rules??[],S=Array.from(new Set(u.flatMap(t=>t.buyCategoryIds??[]))),{options:F}=J(S),_=t=>{const a=F.find(o=>o.id===t);return a?p(a.name):t},D=()=>{n.trim()&&(x(null),c.mutate(n,{onSuccess:t=>{x(t)},onError:()=>{m.error("Failed to generate promotion. Please try again.")}}))},M=()=>{s&&d.mutate(s,{onSuccess:()=>{m.success("Promotion created"),i("/dashboard/promotions")},onError:t=>{const a=t?.response?.data?.error?.message??"Failed to create promotion";m.error(a)}})},B=()=>{i("/dashboard/promotions/new",{state:{aiConfig:s}})},h=t=>{const a=L.find(o=>o.id===t);return a?p(a.name):t},j=t=>{const a=A.find(o=>o.id===t);return a?p(a.name):t},R=t=>!t||t.length===0||t.length===7?"Every day":t.map(a=>ae[a]).join(", "),w=t=>{if(!t||t.length===0)return"All types";const a={DELIVERY:"Delivery",COLLECTION:"Collection",DINE_IN:"Eat-In"};return t.map(o=>a[o]||o).join(", ")};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(W,{title:"Create Promotion with AI",description:"Describe your promotion in plain English and let AI set it up for you",action:e.jsx(l,{variant:"outline",asChild:!0,children:e.jsxs(G,{to:"/dashboard/promotions",children:[e.jsx(V,{className:"mr-2 h-4 w-4"}),"Back"]})})}),e.jsxs(C,{children:[e.jsx(b,{children:e.jsx(v,{children:"Describe Your Promotion"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsx($,{value:n,onChange:t=>g(t.target.value),placeholder:"e.g. 20% off all pizzas on Tuesdays",rows:3,className:"text-base"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:se.map(t=>e.jsx("button",{type:"button",onClick:()=>g(t),className:"text-xs bg-muted hover:bg-muted/80 px-3 py-1.5 rounded-full transition-colors",children:t},t))}),e.jsx(l,{onClick:D,disabled:!n.trim()||c.isPending,className:"w-full",size:"lg",children:c.isPending?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"mr-2 h-4 w-4 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"Generate Promotion"]})})]})]}),s&&e.jsxs(C,{children:[e.jsx(b,{children:e.jsx(v,{children:"Preview"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(r,{label:"Name",value:s.name}),e.jsx(r,{label:"Type",value:te[s.type]??s.type}),e.jsx(r,{label:s.type==="POINTS_MULTIPLIER"?"Multiplier":"Discount",value:s.type==="POINTS_MULTIPLIER"?`${s.discountValue}x points`:s.discountType==="PERCENTAGE"?`${s.discountValue}%`:`£${Number(s.discountValue).toFixed(2)}`}),e.jsx(r,{label:"Applies to",value:re[s.applicableTo]??s.applicableTo}),s.targetCategories?.length>0&&e.jsx(r,{label:"Categories",value:s.targetCategories.map(h).join(", ")}),s.targetProducts?.length>0&&e.jsx(r,{label:"Products",value:s.targetProducts.map(j).join(", ")}),s.minOrderValue!=null&&e.jsx(r,{label:"Min Order",value:`£${Number(s.minOrderValue).toFixed(2)}`}),e.jsx(r,{label:"Days",value:R(s.validDays)}),s.timeFrom&&s.timeTo?e.jsx(r,{label:"Time",value:`${s.timeFrom} - ${s.timeTo}`}):null,e.jsx(r,{label:"Order Types",value:w(s.orderTypes)}),e.jsx(r,{label:"Auto-apply",value:s.isAutoApply?"Yes":"No"}),e.jsx(r,{label:"Channels",value:(s.channels??["WEB","MOBILE","EPOS","KIOSK"]).join(", ")}),s.code?e.jsx(r,{label:"Promo Code",value:s.code}):null,s.displayBadge?e.jsx(r,{label:"Badge",value:s.displayBadge}):null]}),s.type==="MULTI_BUY_PRICE"&&u.length>0?e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Tiers"}),e.jsx("div",{className:"space-y-2",children:u.map((t,a)=>{const o=t.buyQuantity,Y=t.unitPriceOverride,y=t.buyCategoryIds??[],f=t.buyProductIds??[],E=t.buyCategoryOptionIds??[],U=y.length>0?y.map(h).join(", "):f.length>0?f.map(j).join(", "):"â",z=E.length>0?E.map(_).join(", "):"All sizes";return e.jsx("div",{className:"rounded-md border bg-muted/30 px-3 py-2 text-sm",children:e.jsxs("div",{className:"font-medium",children:["Buy ",o,"+ ",
1U," (",z,") â £",Number(Y??0).toFixed(2)," each"]})},a)})})]}):null,s.description?e.jsx("p",{className:"text-sm text-muted-foreground italic",children:s.description}):null,e.jsxs("div",{className:"flex gap-3 pt-2",children:[e.jsxs(l,{variant:"outline",onClick:B,className:"flex-1",children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),"Edit Manually"]}),e.jsx(l,{onClick:M,disabled:d.isPending,className:"flex-1",children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),"Create Promotion"]})})]})]})]})]})}function r({label:i,value:n}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:i}),e.jsx("p",{className:"text-sm font-medium",children:n})]})}export{je as AIPromotionCreatePage};
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.