| 1 |
(()=>{"use strict";var e={n:t=>{var i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,i=window.wp.apiFetch;var n=e.n(i);const r=window.wp.components,o=window.wp.i18n,s=window.ReactJSXRuntime,a=({column:e,onUpdate:t,onRemove:i})=>{const n=(i,n)=>t(e.slug,{...e,[i]:n});return(0,s.jsxs)("div",{style:{background:"#fff",border:"1px solid #e2e4e7",borderRadius:"8px",marginBottom:"16px",display:"flex",alignItems:"flex-start",padding:"20px",gap:"20px",boxShadow:"0 1px 3px rgba(0,0,0,0.04)",position:"relative"},children:[(0,s.jsx)("style",{children:'\n\t\t\t\t.tier-column-field { flex: 1 1 200px; min-width: 0; }\n\t\t\t\t.tier-column-field select,\n\t\t\t\t.tier-column-field input[type="text"] { min-width: 0 !important; width: 100% !important; }\n\t\t\t\t.tier-remove-col-btn { position: absolute; top: 8px; right: 8px; background: none; border: none; color: #d63638; cursor: pointer; padding: 4px; display: flex; align-items: center; justify-content: center; opacity: 0.5; transition: opacity 0.2s; border-radius: 4px; }\n\t\t\t\t.tier-remove-col-btn:hover { opacity: 1; background: rgba(214, 54, 56, 0.1); }\n\t\t\t\t'}),(0,s.jsx)("div",{className:"tier-column-field",children:(0,s.jsx)(r.TextControl,{label:(0,o.__)("Column Title","tier-pricing-table"),value:e.name,onChange:e=>n("name",e),placeholder:(0,o.__)("e.g., Discounted Price","tier-pricing-table")})}),(0,s.jsx)("div",{className:"tier-column-field",children:(0,s.jsx)(r.SelectControl,{label:(0,o.__)("Column Data Type","tier-pricing-table"),value:e.type||"",options:[{label:(0,o.__)("Select column type...","tier-pricing-table"),value:"",disabled:!0},{label:(0,o.__)("Custom column","tier-pricing-table"),value:"custom"},{label:(0,o.__)("Price excluding taxes","tier-pricing-table"),value:"price_excl_taxes"},{label:(0,o.__)("Price including taxes","tier-pricing-table"),value:"price_incl_taxes"},{label:(0,o.__)("Total row price","tier-pricing-table"),value:"total_price"}],onChange:e=>n("type",e)})}),"custom"===e.type&&(0,s.jsx)("div",{className:"tier-column-field",children:(0,s.jsx)(r.SelectControl,{label:(0,o.__)("Format","tier-pricing-table"),value:e.data_type||"text",options:[{label:(0,o.__)("Price","tier-pricing-table"),value:"price"},{label:(0,o.__)("Number","tier-pricing-table"),value:"number"},{label:(0,o.__)("Text","tier-pricing-table"),value:"text"}],onChange:e=>n("data_type",e)})}),(0,s.jsx)("button",{className:"tier-remove-col-btn",onClick:()=>i(e.slug),title:(0,o.__)("Remove column","tier-pricing-table"),children:(0,s.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("path",{d:"M18 6 6 18"}),(0,s.jsx)("path",{d:"m6 6 12 12"})]})})]})},l=()=>{const[e,i]=(0,t.useState)([]),[l,c]=(0,t.useState)(!0),[d,p]=(0,t.useState)(!1),[u,m]=(0,t.useState)({message:"",type:"success"}),x=(e,t="success")=>{m({message:e,type:t}),setTimeout(()=>m({message:"",type:"success"}),4e3)};(0,t.useEffect)(()=>{n()({path:"tier-pricing-table/features/custom-columns/v1/columns"}).then(e=>{i(Array.isArray(e)?e:[]),c(!1)})},[]);const g=()=>{i([...e,{slug:"col_"+Math.random().toString(36).substr(2,9),name:"",type:"",data_type:"price"}])};return l?(0,s.jsx)(r.Flex,{align:"center",justify:"center",style:{height:"200px"},children:(0,s.jsx)(r.Spinner,{})}):(0,s.jsxs)("div",{className:"tier-custom-columns-settings",style:{marginTop:"20px",position:"relative",maxWidth:"975px"},children:[u.message&&(0,s.jsxs)("div",{style:{position:"fixed",bottom:"40px",left:"50%",transform:"translateX(-50%)",background:"#1d2327",color:"#fff",padding:"12px 24px",borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:9999,fontSize:"14px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",animation:"tierToastSlideUp 0.3s ease-out forwards"},children:[(0,s.jsx)("style",{children:"\n\t\t\t\t\t\t@keyframes tierToastSlideUp {\n\t\t\t\t\t\t\tfrom { opacity: 0; transform: translate(-50%, 20px); }\n\t\t\t\t\t\t\tto { opacity: 1; transform: translate(-50%, 0); }\n\t\t\t\t\t\t}\n\t\t\t\t\t\t"}),"success"===u.type&&(0,s.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#46b450",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M20 6 9 17l-5-5"})}),"warning"===u.type&&(0,s.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#f0b849",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,s.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,s.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,s.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),u.message]}),!window.tptCustomColumns?.isPremium&&(0,s.jsxs)("div",{style:{background:"#f0f6fc",padding:"16px 16px",marginBottom:"24px",display:"flex",justifyContent:"space-between",borderRadius:"5px",alignItems:"center",border:"1px solid #ccc"},children:[(0,s.jsxs)("p",{style:{margin:"0",fontSize:"13px"},children:[(0,s.jsx)("strong",{children:(0,o.__)("Premium Feature","tier-pricing-table")}),": ",(0,o.__)("Upgrading to premium to unlock custom columns.","tier-pricing-table")]}),(0,s.jsx)("a",{href:window.tptCustomColumns?.upgradeUrl||"#",target:"_blank",rel:"noopener noreferrer",className:"button button-primary",children:(0,o.__)("Upgrade to Premium","tier-pricing-table")})]}),0===e.length&&(0,s.jsxs)("div",{style:{padding:"40px",textAlign:"center",background:"#f8f9fa",border:"1px dashed #c3c4c7",borderRadius:"8px",marginBottom:"24px",color:"#50575e"},children:[(0,s.jsx)("svg",{style:{margin:"0 auto 12px",color:"#a7aaad",display:"block"},width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,s.jsx)("path",{d:"M12 3h7a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-7m0-18H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h7m0-18v18"})}),(0,s.jsx)("h3",{style:{margin:"0 0 8px",fontSize:"16px",color:"#1d2327",fontWeight:600},children:(0,o.__)("No Custom Columns","tier-pricing-table")}),(0,s.jsx)("p",{style:{margin:"0 0 8px",fontSize:"14px"},children:(0,o.__)("Add custom columns to display extra information alongside your pricing tiers.","tier-pricing-table")}),(0,s.jsx)("p",{}),(0,s.jsx)(r.Button,{variant:"primary",onClick:g,children:(0,o.__)("Add your first column","tier-pricing-table")})]}),e.map(t=>(0,s.jsx)(a,{column:t,onRemove:t=>i(e.filter(e=>e.slug!==t)),onUpdate:(t,n)=>i(e.map(e=>e.slug===t?n:e))},t.slug)),(0,s.jsxs)(r.Flex,{gap:"4",style:{marginTop:"20px"},children:[(0,s.jsx)(r.Button,{variant:"primary",onClick:()=>{window.tptCustomColumns?.isPremium?(p(!0),n()({path:"tier-pricing-table/features/custom-columns/v1/columns",method:"POST",data:{columns:e}}).then(()=>{p(!1),x((0,o.__)("Columns saved successfully!","tier-pricing-table"),"success")})):x((0,o.__)("Please upgrade to the Premium version to save custom columns.","tier-pricing-table"),"warning")},isBusy:d,disabled:d,children:d?(0,o.__)("Saving...","tier-pricing-table"):(0,o.__)("Save Columns","tier-pricing-table")}),(0,s.jsx)(r.Button,{variant:"secondary",onClick:g,children:(0,o.__)("+ Add Column","tier-pricing-table")})]})]})};document.addEventListener("DOMContentLoaded",()=>{const e=document.getElementById("tiered-pricing__feature__custom-columns");e&&(0,t.createRoot)(e).render((0,s.jsx)(l,{}))})})(); |