PageSourceSearch

https://chpeptides.com/js/PromotionForm-Dr3riOAA.js

js chpeptides.com collected 2026-10-04 06:36:08 UTC 28,869 bytes, 1 lines download raw bytes

1import{j as e}from"./admin-vendor-B_1xywrZ.js";import{u as t,f as s,r as a}from"./react-vendor-DOiMLSFB.js";import{s as r,G as i,t as o,P as l,S as n,I as c}from"./index-BwhXW8eI.js";import{z as d,N as u,G as m,o as p,ah as x}from"./ui-vendor-CtHzwLAQ.js";import"./data-vendor-CIxtln5N.js";const b=({label:t,placeholder:s,selected:r,onChange:i,fetchOptions:o})=>{const[l,n]=a.useState(""),[c,d]=a.useState([]),[u,m]=a.useState(!1);a.useEffect(()=>{let e=!0;const t=setTimeout(async()=>{if(!l||l.trim().length<2)d([]);else{m(!0);try{const t=await o(l.trim());e&&d(t)}catch{e&&d([])}finally{e&&m(!1)}}},200);return()=>{e=!1,clearTimeout(t)}},[l,o]);return e.jsxs("div",{className:"col-span-1 lg:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:t}),e.jsxs("div",{className:"w-full",children:[e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:r.map(t=>e.jsxs("span",{className:"inline-flex items-center px-2 py-1 rounded-full bg-blue-100 text-blue-800 text-xs",children:[t.label,e.jsx("button",{type:"button",onClick:()=>{return e=t.id,i(r.filter(t=>t.id!==e));var e},className:"ml-1 text-blue-700 hover:text-blue-900",children:"×"})]},t.id))}),e.jsx("input",{type:"text",value:l,onChange:e=>n(e.target.value),className:"w-full px-3 py-2 text-gray-900 bg-white border border-clay-border rounded-lg focus:border-blue-500 focus:ring-2 focus:ring-blue-200 transition-all duration-200",placeholder:s||"Search... (type at least 2 characters)"}),u&&e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:"Searching…"}),!u&&c.length>0&&e.jsx("div",{className:"mt-1 border border-clay-border rounded-md max-h-48 overflow-auto bg-white shadow-clay",children:c.map(t=>e.jsx("button",{type:"button",onClick:()=>(e=>{r.some(t=>t.id===e.id)||(i([...r,e]),n(""),d([]))})(t),className:"w-full text-left px-3 py-2 text-gray-900 hover:bg-blue-50",children:t.label},t.id))})]})]})},g=()=>{const g=t(),{id:h}=s(),y=!!h,[_,f]=a.useState(y),[j,v]=a.useState(!1),[w,N]=a.useState([]),[k,q]=a.useState([]),[C,S]=a.useState({name:"",description:"",show_popup:!0,activation_type:"automatic",discount_code_id:"",promotion_type:"bogo_same",qualifying_min_quantity:2,qualifying_min_amount:"",reward_quantity:1,reward_discount_type:"percentage",reward_discount_value:100,reward_max_discount:"",discount_cheapest_item:!0,buy_quantity:1,max_discounted_items:"",usage_limit:"",per_customer_limit:"",starts_at:"",expires_at:"",is_active:!0,is_stackable:!1,stack_priority:0,excludes_discount_codes:!1}),[O,P]=a.useState([]),[B,G]=a.useState([]),[$,D]=a.useState([]),[M,I]=a.useState([]),[A,F]=a.useState([]),[T,E]=a.useState([]),R=a.useCallback(async()=>{try{const{data:e,error:t}=await r.from("discount_codes").select("id, code").eq("is_active",!0).order("code");if(t)throw t;N(e||[])}catch(e){}},[]),L=a.useCallback(async()=>{try{const{data:e,error:t}=await r.from("products").select("category").not("category","is",null);if(t)throw t;const s=(e||[]).map(e=>e.category).filter(Boolean).flatMap(e=>e.split(",").map(e=>e.trim())).filter(e=>e.length>0),a=[...new Set(s)].sort();q(a)}catch(e){}},[]),Q=a.useCallback(async()=>{if(h)try{const{data:e,error:t}=await r.from("promotions").select("*").eq("id",h).single();if(t)throw t;const s=e;if(S({name:s.name,description:s.description||"",show_popup:s.show_popup??!0,activation_type:s.activation_type,discount_code_id:s.discount_code_id||"",promotion_type:s.promotion_type,qualifying_min_quantity:s.qualifying_min_quantity,qualifying_min_amount:s.qualifying_min_amount?.toString()||"",reward_quantity:s.reward_quantity,reward_discount_type:s.reward_discount_type,reward_discount_value:s.reward_discount_value,reward_max_discount:s.reward_max_discount?.toString()||"",discount_cheapest_item:s.discount_cheapest_item??!0,buy_quantity:s.buy_quantity||1,max_discounted_items:s.max_discounted_items?.toString()||"",usage_limit:s.usage_limit?.toString()||"",per_customer_limit:s.per_customer_limit?.toString()||"",starts_at:i(s.starts_at),expires_at:i(s.expires_at),is_active:s.is_active,is_stackable:s.is_stackable,stack_priority:s.stack_priority,excludes_discount_codes:s.excludes_discount_codes}),s.qualifying_product_ids?.length){const{data:e}=await r.from("products").select("id, name, sku").in("id",s.qualifying_product_ids);P((e||[]).map(e=>({id:e.id,label:e.name})))}if(s.qualifying_category_ids?.length&&G(s.qualifying_category_ids.map(e=>({id:e,label:e}))),s.reward_product_ids?.length){const{data:e}=await r.from("products").select("id, name, sku").in("id",s.reward_product_ids);D((e||[]).map(e=>({id:e.id,label:e.name})))}if(s.reward_category_ids?.length&&I(s.reward_category_ids.map(e=>({id:e,label:e}))),s.excluded_product_ids?.length){const{data:e}=await r.from("products").select("id, name, sku").in("id",s.excluded_product_ids);F((e||[]).map(e=>({id:e.id,label:e.name})))}s.excluded_category_ids?.length&&E(s.excluded_category_ids.map(e=>({id:e,label:e})))}catch(e){o.error("Failed to load promotion"),g("/admin/promotions")}finally{f(!1)}},[h,g]),U=a.useCallback(async e=>{const{data:t}=await r.from("products").select("id, name, sku").or(`name.ilike.%${e}%,sku.ilike.%${e}%`).limit(20);return(t||[]).map(e=>({id:e.id,label:`${e.name}${e.sku?` (${e.sku})`:""}`}))},[]),Y=a.useCallback(async e=>k.filter(t=>t.toLowerCase().includes(e.toLowerCase())).map(e=>({id:e,label:e})),[k]);a.useEffect(()=>{R(),L(),y&&Q()},[R,L,Q,y]);return _?e.jsx(l,{fullScreen:!1}):e.jsxs("div",{className:"p-4 sm:p-6 max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx("button",{onClick:()=>g("/admin/promotions"),className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:e.jsx(d,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-clay-ink",children:y?"Edit Promotion":"Create Promotion"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:y?"Update promotion settings":"Set up a new BOGO or Buy X Get Y promotion"})]})]}),e.jsxs("form",{onSubmit:async e=>{e.preventDefault(),v(!0);try{const e={name:C.name,description:C.description||null,show_popup:C.show_popup,activation_type:C.activation_type,discount_code_id:"code_required"===C.activation_type&&C.discount_code_id?C.discount_code_id:null,promotion_type:C.promotion_type,qualifying_product_ids:O.map(e=>e.id),qualifying_category_ids:B.map(e=>e.id),qualifying_min_quantity:C.qualifying_min_quantity,qualifying_min_amount:C.qual
1ifying_min_amount?Number(C.qualifying_min_amount):null,reward_product_ids:$.map(e=>e.id),reward_category_ids:M.map(e=>e.id),reward_quantity:C.reward_quantity,reward_discount_type:C.reward_discount_type,reward_discount_value:C.reward_discount_value,reward_max_discount:C.reward_max_discount?Number(C.reward_max_discount):null,excluded_product_ids:A.map(e=>e.id),excluded_category_ids:T.map(e=>e.id),discount_cheapest_item:C.discount_cheapest_item,buy_quantity:C.buy_quantity,max_discounted_items:C.max_discounted_items?Number(C.max_discounted_items):null,usage_limit:C.usage_limit?Number(C.usage_limit):null,per_customer_limit:C.per_customer_limit?Number(C.per_customer_limit):null,starts_at:c(C.starts_at),expires_at:c(C.expires_at),is_active:C.is_active,is_stackable:C.is_stackable,stack_priority:C.stack_priority,excludes_discount_codes:C.excludes_discount_codes};if(y){const{data:t,error:s}=await r.from("promotions").update(e).eq("id",h).select();if(s)throw s;if(!t||0===t.length)throw new Error("Update failed — no rows were modified. You may not have permission to edit this promotion.");o.success("Promotion updated successfully")}else{const{error:t}=await r.from("promotions").insert([e]);if(t)throw t;o.success("Promotion created successfully")}g("/admin/promotions")}catch(t){o.error(t.message||"Failed to save promotion")}finally{v(!1)}},className:"space-y-8",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-clay-border p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-clay-ink mb-4",children:"Basic Information"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"lg:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Promotion Name *"}),e.jsx("input",{type:"text",value:C.name,onChange:e=>S({...C,name:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"e.g., Buy 2 Get 1 Free BPC-157",required:!0})]}),e.jsxs("div",{className:"lg:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Description"}),e.jsx("textarea",{value:C.description,onChange:e=>S({...C,description:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",rows:2,placeholder:"Describe the promotion..."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Activation Type *"}
1),e.jsxs("select",{value:C.activation_type,onChange:e=>S({...C,activation_type:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:"automatic",children:"Automatic (applies automatically)"}),e.jsx("option",{value:"code_required",children:"Code Required (link to discount code)"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-clay-border bg-clay-wash px-4 py-3",children:[e.jsx("input",{id:"show-popup",type:"checkbox",checked:C.show_popup,onChange:e=>S({...C,show_popup:e.target.checked}),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),e.jsx("label",{htmlFor:"show-popup",className:"text-sm font-medium text-gray-700",children:"Show promotion popup (daily announcement)"})]}),"code_required"===C.activation_type&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Linked Discount Code"}),e.jsxs("select",{value:C.discount_code_id,onChange:e=>S({...C,discount_code_id:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:"",children:"Select a code..."}),w.map(t=>e.jsx("option",{value:t.id,children:t.code},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Promotion Type *"}
1),e.jsxs("select",{value:C.promotion_type,onChange:e=>S({...C,promotion_type:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:"bogo_sitewide",children:"Site-Wide BOGO (Buy any 2+, cheapest discounted)"}),e.jsx("option",{value:"bogo_same",children:"BOGO Same Product (Buy N, Get M of same)"}),e.jsx("option",{value:"bogo_different",children:"BOGO Different Product (Buy A, Get B)"}),e.jsx("option",{value:"buy_x_get_y",children:"Buy X, Get Y (different products)"}),e.jsx("option",{value:"category_discount",children:"Category Discount (% or $ off all items in category)"})]}),"bogo_sitewide"===C.promotion_type&&e.jsx("p",{className:"text-xs text-blue-600 mt-1",children:"Applies to entire catalog. The cheapest eligible item receives the discount."}),"category_discount"===C.promotion_type&&e.jsx("p",{className:"text-xs text-blue-600 mt-1",children:'Applies discount to all items in selected categories. Great for "20% off all Capsules" type promotions.'})]})]})]}),"bogo_sitewide"!==C.promotion_type&&e.jsxs("div",{className:"bg-white rounded-xl border border-clay-border p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(u,{className:"w-5 h-5 text-blue-600"}),e.jsx("h2",{className:"text-lg font-semibold text-clay-ink",children:"Qualifying Criteria"})]}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"Define what must be purchased to trigger this promotion"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(b,{label:"Qualifying Products (leave empty for any)",placeholder:"Search products...",selected:O,onChange:P,fetchOptions:U}),e.jsx(b,{label:"Qualifying Categories (leave empty for any)",placeholder:"Search categories...",selected:B,onChange:G,fetchOptions:Y}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Minimum Quantity Required"}),e.jsx("input",{type:"number",min:"1",value:C.qualifying_min_quantity,onChange:e=>S({...C,qualifying_min_quantity:parseInt(e.target.value)||1}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Minimum Purchase Amount ($)"}),e.jsx("input",{type:"number",min:"0",step:"0.01",value:C.qualifying_min_amount,onChange:e=>S({...C,qualifying_min_amount:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Optional"})]})]})]}),"category_discount"===C.promotion_type&&e.jsxs("div",{className:"bg-white rounded-xl border border-clay-border p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(u,{className:"w-5 h-5 text-green-600"}),e.jsx("h2",{className:"text-lg font-semibold text-clay-ink",children:"Category Discount Settings"})]}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:'Apply a percentage or fixed discount to all products in the selected categories. For example: "20% off all Capsules" or "$10 off all Sprays"'}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(b,{label:"Target Categories *",placeholder:"Search categories...",selected:B,onChange:G,fetchOptions:Y}),e.jsx(b,{label:"Or Specific Products",placeholder:"Search products...",selected:O,onChange:P,fetchOptions:U}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Minimum Quantity (optional)"}),e.jsx("input",{type:"number",min:"1",value:C.qualifying_min_quantity,onChange:e=>S({...C,qualifying_min_quantity:parseInt(e.target.value)||1}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Minimum items from category needed to qualify"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Minimum Purchase Amount ($)"}
1),e.jsx("input",{type:"number",min:"0",step:"0.01",value:C.qualifying_min_amount,onChange:e=>S({...C,qualifying_min_amount:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Optional"})]}),e.jsx(b,{label:"Excluded Products (won't receive discount)",placeholder:"Search products to exclude...",selected:A,onChange:F,fetchOptions:U})]}),e.jsx("div",{className:"mt-4 bg-green-50 border border-green-200 rounded-lg p-4",children:e.jsxs("p",{className:"text-sm text-green-800",children:[e.jsx("strong",{children:"Note:"})," The discount is calculated from the product's ",e.jsx("em",{children:"retail price"}),", not any existing sale price. This ensures fair promotions that stack predictably."]})})]}),"bogo_sitewide"===C.promotion_type&&e.jsxs("div",{className:"bg-white rounded-xl border border-clay-border p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(u,{className:"w-5 h-5 text-blue-600"}),e.jsx("h2",{className:"text-lg font-semibold text-clay-ink",children:"Site-Wide BOGO Settings"})]}),e.jsxs("p",{className:"text-sm text-gray-500 mb-4",children:['Configure "Buy X, Get Y% Off" logic. For every ',e.jsx("strong",{children:C.buy_quantity})," item(s) at full price, customer gets ",e.jsx("strong",{children:C.reward_quantity})," item(s) at the discount.",C.max_discounted_items&&` Max ${C.max_discounted_items} discounted items per order.`]}),e.jsxs("div",{className:"bg-blue-50 rounded-lg p-4 mb-4",children:[e.jsx("h3",{className:"font-medium text-blue-800 mb-2",children:"BOGO Ratio"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-blue-700 mb-1",children:"Buy Quantity (full price)"}),e.jsx("input",{type:"number",min:"1",value:C.buy_quantity,onChange:e=>S({...C,buy_quantity:Math.max(1,parseInt(e.target.value)||1)}),className:"w-full px-4 py-2 border border-blue-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),e.jsx("p",{className:"text-xs text-blue-600 mt-1",children:"Items at full price per cycle"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-blue-700 mb-1",children:"Get Quantity (discounted)"}),e.jsx("input",{type:"number",min:"1",value:C.reward_quantity,onChange:e=>S({...C,reward_quantity:Math.max(1,parseInt(e.target.value)||1)}),className:"w-full px-4 py-2 border border-blue-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),e.jsx("p",{className:"text-xs text-blue-600 mt-1",children:"Items discounted per cycle"})]})]}),e.jsxs("div",{className:"mt-3 text-sm text-blue-800 bg-blue-100 rounded px-3 py-2",children:[e.jsx("strong",{children:"Example:"})," With 4 items in cart: ",Math.floor(4/(C.buy_quantity+C.reward_quantity))*C.reward_quantity," item(s) will be discounted"]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Minimum Items in Cart"}),e.jsx("input",{type:"number",min:C.buy_quantity+C.reward_quantity,value:C.qualifying_min_quantity,onChange:e=>S({...C,qualifying_min_quantity:Math.max(C.buy_quantity+C.reward_quantity,parseInt(e.target.value)||C.buy_quantity+C.reward_quantity)}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["At least ",C.buy_quantity+C.reward_quantity," items required for this BOGO"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Max Discounted Items Per Order"}),e.jsx("input",{type:"number",min:"1",value:C.max_discounted_items,onChange:e=>S({...C,max_discounted_items:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Leave empty for unlimited"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Limit total items that can receive discount"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Minimum Purchase Amount ($)"}
1),e.jsx("input",{type:"number",min:"0",step:"0.01",value:C.qualifying_min_amount,onChange:e=>S({...C,qualifying_min_amount:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Optional"})]}),e.jsx("div",{className:"flex items-center pt-6",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:C.discount_cheapest_item,onChange:e=>S({...C,discount_cheapest_item:e.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-700",children:"Discount the cheapest item(s)"})]})}),e.jsx(b,{label:"Excluded Products (won't qualify for discount)",placeholder:"Search products to exclude...",selected:A,onChange:F,fetchOptions:U}),e.jsx(b,{label:"Excluded Categories (won't qualify for discount)",placeholder:"Search categories to exclude...",selected:T,onChange:E,fetchOptions:Y})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-clay-border p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(m,{className:"w-5 h-5 text-green-600"}),e.jsx("h2",{className:"text-lg font-semibold text-clay-ink",children:"Reward Configuration"})]}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:"bogo_sitewide"===C.promotion_type?"Configure the discount applied to the cheapest eligible item":"category_discount"===C.promotion_type?"Configure the discount applied to items in the selected categories":"Define what the customer receives as a reward"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:["bogo_same"!==C.promotion_type&&"bogo_sitewide"!==C.promotion_type&&"category_discount"!==C.promotion_type&&e.jsxs(e.Fragment,{children:[e.jsx(b,{label:"Reward Products",placeholder:"Search products...",selected:$,onChange:D,fetchOptions:U}),e.jsx(b,{label:"Reward Categories",placeholder:"Search categories...",selected:M,onChange:I,fetchOptions:Y})]}),"bogo_sitewide"===C.promotion_type&&e.jsx("div",{className:"lg:col-span-2 bg-blue-50 border border-blue-200 rounded-lg p-4",children:e.jsxs("p",{className:"text-sm text-blue-800",children:[e.jsx("strong",{children:"BOGO Ratio:"})," Buy ",C.buy_quantity,", Get ",C.reward_quantity," at discount.",C.discount_cheapest_item?" The cheapest eligible item(s) will receive the discount.":" The most expensive eligible item(s) will receive the discount.",C.max_discounted_items&&` Max ${C.max_discounted_items} items can be discounted per order.`]})}),"category_discount"===C.promotion_type&&e.jsx("div",{className:"lg:col-span-2 bg-green-50 border border-green-200 rounded-lg p-4",children:e.jsxs("p",{className:"text-sm text-green-800",children:[e.jsx("strong",{children:"Category Discount:"})," All items in the selected categories will receive","percentage"===C.reward_discount_type?` ${C.reward_discount_value}% off`:` $${C.reward_discount_value} off`," their retail price.",B.length>0&&e.jsxs("span",{className:"block mt-1",children:[e.jsx("strong",{children:"Categories:"})," ",B.map(e=>e.label).join(", ")]})]})}),"bogo_sitewide"!==C.promotion_type&&"category_discount"!==C.promotion_type&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Reward Quantity (how many items get discounted)"}),e.jsx("input",{type:"number",min:"1",value:C.reward_quantity,onChange:e=>S({...C,reward_quantity:parseInt(e.target.value)||1}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Discount Type"}),e.jsxs("select",{value:C.reward_discount_type,onChange:e=>S({...C,reward_discount_type:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",children:[e.jsx("option",{value:"percentage",children:"Percentage Off"}),e.jsx("option",{value:"fixed",children:"Fixed Amount Off"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Discount Value ","percentage"===C.reward_discount_type?"(%)":"($)"]}),e.jsx("input",{type:"number",min:"0",max:"percentage"===C.reward_discount_type?100:void 0,step:"percentage"===C.reward_discount_type?1:.01,value:C.reward_discount_value,onChange:e=>S({...C,reward_discount_value:parseFloat(e.target.value)||0}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}),"percentage"===C.reward_discount_type&&100===C.reward_discount_value&&e.jsx("p",{className:"text-xs text-green-600 mt-1",children:"Item will be FREE ($0.01 for Stripe)"}),"bogo_sitewide"===C.promotion_type&&"percentage"===C.reward_discount_type&&50===C.reward_discount_value&&e.jsx("p",{className:"text-xs text-blue-600 mt-1",children:'Classic "Buy One Get One 50% Off" promotion'})]}),"fixed"===C.reward_discount_type&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Maximum Discount ($)"}),e.jsx("input",{type:"number",min:"0",step:"0.01",value:C.reward_max_discount,onChange:e=>S({...C,reward_max_discount:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Optional cap"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-clay-border p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(p,{className:"w-5 h-5 text-purple-600"}),e.jsx("h2",{className:"text-lg font-semibold text-clay-ink",children:"Limits & Schedule"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Total Usage Limit"}),e.jsx("input",{type:"number",min:"0",value:C.usage_limit,onChange:e=>S({...C,usage_limit:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Unlimited"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Per Customer Limit"}),e.jsx("input",{type:"number",min:"0",value:C.per_customer_limit,onChange:e=>S({...C,per_customer_limit:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500",placeholder:"Unlimited"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Start Date"}),e.jsx("input",{type:"datetime-local",value:C.starts_at,onChange:e=>S({...C,starts_at:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"End Date"}),e.jsx("input",{type:"datetime-local",value:C.expires_at,onChange:e=>S({...C,expires_at:e.target.value}),className:"w-full px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-clay-border p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-clay-ink mb-4",children:"Options"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:C.is_active,onChange:e=>S({...C,is_active:e.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-700",children:"Active"})]}),e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:C.is_stackable,onChange:e=>S({...C,is_stackable:e.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-700",children:"Can stack with other promotions"})]}),e.jsxs("label",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:C.excludes_discount_codes,onChange:e=>S({...C,excludes_discount_codes:e.target.checked}),className:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"}),e.jsx("span",{className:"text-sm text-gray-700",children:"Cannot be combined with discount codes"})]}),C.is_stackable&&e.jsxs("div",{className:"pl-7",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Stack Priority (higher = applied first)"}),e.jsx("input",{type:"number",value:C.stack_priority,onChange:e=>S({...C,stack_priority:parseInt(e.target.value)||0}),className:"w-32 px-4 py-2 border border-clay-border rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"})]})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-3 pt-4 sm:flex-row sm:justify-end",children:[e.jsx("button",{type:"button",onClick:()=>g("/admin/promotions"),className:"px-6 py-2 text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors w-full sm:w-auto",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:j,className:"flex items-center justify-center gap-2 px-6 py-2 bg-clay-gradient text-white rounded-lg hover:opacity-95 transition-colors disabled:opacity-50 w-full sm:w-auto",children:j?e.jsxs(e.Fragment,{children:[e.jsx(n,{size:"xs",variant:"light"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"w-4 h-4"}),y?"Update Promotion":"Create Promotion"]})})]})]})]})};export{g 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.