PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.1.0 8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 All 92 releases
← All changes | src/Addons/Tools/build/index.js +3 -1 7.1.5 → 8.1.0 View file →
@@ -1 +1,3 @@
1 -(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var l in a)e.o(a,l)&&!e.o(t,l)&&Object.defineProperty(t,l,{enumerable:!0,get:a[l]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React,a=window.wp.element,l=window.wp.components,n=window.wp.i18n,i=window.wp.primitives,r=(0,t.createElement)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(i.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})),o=(0,t.createElement)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(i.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})),s=window.wp.apiFetch;var c=e.n(s);const p=({label:e,type:i,selectedElements:r,onElementsChange:o})=>{const[s,p]=(0,a.useState)([]),[m,d]=(0,a.useState)(!1),[g,u]=(0,a.useState)({}),[b,h]=(0,a.useState)(null);return(0,a.useEffect)(()=>{const e={...g};r.forEach(t=>{const a=`${t.name} (#${t.id})`;e[a]=t}),u(e)},[]),(0,t.createElement)("div",{style:{marginBottom:"20px"}},(0,t.createElement)(l.FormTokenField,{label:e,value:r.map(e=>`${e.name} (#${e.id})`),suggestions:s,onInputChange:e=>{if(b&&clearTimeout(b),!e||e.length<3)return void p([]);const t=setTimeout(()=>{d(!0);const t="product"===i?`/wc/v3/products?search=${encodeURIComponent(e)}&per_page=10`:`/wc/v3/products/categories?search=${encodeURIComponent(e)}&per_page=10`;c()({path:t}).then(e=>{const t=[],a={...g};e.forEach(e=>{const l=`${e.name} (#${e.id})`;t.push(l),a[l]=e}),p(t),u(a),d(!1)}).catch(()=>d(!1))},500);h(t)},onChange:e=>{const t=e.map(e=>g[e]||null).filter(Boolean);o(t)},maxLength:100,__experimentalShowHowTo:!1,messages:{added:(0,n.__)("Item added","tier-pricing-table"),removed:(0,n.__)("Item removed","tier-pricing-table"),remove:(0,n.__)("Remove item","tier-pricing-table")}}),m&&(0,t.createElement)(l.Spinner,{style:{marginTop:"-10px",display:"block"}}))};function m(){const[e,i]=(0,a.useState)(!1),[r,s]=(0,a.useState)(!1),[m,d]=(0,a.useState)("none"),[g,u]=(0,a.useState)([]),[b,h]=(0,a.useState)([]),[y,_]=(0,a.useState)([]),[E,f]=(0,a.useState)(!1),[x,v]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[S,k]=(0,a.useState)([]),[T,B]=(0,a.useState)(!0),[R,P]=(0,a.useState)(null);(0,a.useEffect)(()=>{c()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities"}).then(e=>{if(e.roles){const t=e.roles.map(e=>({label:e.name,value:e.key}));k(t)}B(!1)}).catch(()=>{B(!1)})},[]);const N=e||"all"===m||"specific"===m&&g.length>0||r||E||x;return(0,t.createElement)("div",{className:"tpt-tools-app"},R&&(0,t.createElement)(l.Notice,{status:R.type,onRemove:()=>P(null)},R.message),(0,t.createElement)(l.Card,null,(0,t.createElement)(l.CardHeader,null,(0,t.createElement)("h3",{style:{margin:0}},(0,n.__)("Clean Up & Reset Options","tier-pricing-table"))),(0,t.createElement)(l.CardBody,null,(0,t.createElement)("p",{style:{backgroundColor:"#fcf0f1",color:"#d63638",padding:"12px 16px",borderLeft:"4px solid #d63638",borderRadius:"4px",marginTop:"0",marginBottom:"20px"}},(0,t.createElement)("strong",null,(0,n.__)("Warning:","tier-pricing-table"))," ",(0,n.__)("The actions below will permanently delete data from your database. Please make a backup before proceeding.","tier-pricing-table")),(0,t.createElement)(l.Panel,{className:"tpt-cleanup-panel",style:{marginBottom:"20px"}},(0,t.createElement)(l.PanelBody,{title:(0,n.__)("1. Product Level Data","tier-pricing-table"),initialOpen:!0},(0,t.createElement)("p",{style:{color:"#64748b",marginTop:0,marginBottom:"15px"}},(0,n.__)("Remove tiered pricing rules directly attached to individual products.","tier-pricing-table")),(0,t.createElement)(l.CheckboxControl,{label:(0,n.__)("Clean Standard Tiered Pricing Data","tier-pricing-table"),checked:e,onChange:i}),(0,t.createElement)("h4",{style:{marginTop:"15px",marginBottom:"10px"}},(0,n.__)("Customer Based Data","tier-pricing-table")),(0,t.createElement)(l.CheckboxControl,{label:(0,n.__)("Clean All Customer Based Pricing Data","tier-pricing-table"),checked:r,onChange:s}),(0,t.createElement)("h4",{style:{marginTop:"15px",marginBottom:"10px"}},(0,n.__)("Role Based Data","tier-pricing-table")),(0,t.createElement)(l.RadioControl,{selected:m,options:[{label:(0,n.__)("Do not clean role based data","tier-pricing-table"),value:"none"},{label:(0,n.__)("Clean all roles","tier-pricing-table"),value:"all"},{label:(0,n.__)("Select specific roles to clean","tier-pricing-table"),value:"specific"}],onChange:e=>d(e)}),"specific"===m&&(T?(0,t.createElement)(l.Spinner,{style:{marginTop:"10px"}}):(0,t.createElement)("div",{style:{display:"flex",flexDirection:"column",gap:"8px",marginTop:"10px",marginLeft:"25px",paddingLeft:"15px",borderLeft:"2px solid #e2e8f0"}},S.map(e=>(0,t.createElement)(l.CheckboxControl,{key:e.value,label:e.label,checked:g.includes(e.value),onChange:()=>{return t=e.value,void u(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);var t}})))),(e||"none"!==m||r)&&(0,t.createElement)("div",{style:{marginTop:"20px",padding:"15px",background:"#f8fafc",borderRadius:"4px",border:"1px solid #e2e8f0"}},(0,t.createElement)("h4",{style:{marginTop:0,marginBottom:"5px"}},(0,n.__)("Filters (Optional)","tier-pricing-table")),(0,t.createElement)("p",{style:{color:"#64748b",fontSize:"0.9em",marginTop:0,marginBottom:"15px"}},(0,n.__)("Leave blank to apply the cleanup to all products. Otherwise, select specific categories or products.","tier-pricing-table")),(0,t.createElement)(p,{label:(0,n.__)("Select Categories","tier-pricing-table"),type:"category",selectedElements:b,onElementsChange:h}),(0,t.createElement)(p,{label:(0,n.__)("Select Products","tier-pricing-table"),type:"product",selectedElements:y,onElementsChange:_})))),(0,t.createElement)(l.Panel,{className:"tpt-cleanup-panel",style:{marginBottom:"20px"}},(0,t.createElement)(l.PanelBody,{title:(0,n.__)("2. Global Pricing Rules","tier-pricing-table"),initialOpen:!0},(0,t.createElement)("p",{style:{color:"#64748b",marginTop:0,marginBottom:"15px"}},(0,n.__)("Global pricing rules apply to multiple products at once.","tier-pricing-table")),(0,t.createElement)(l.CheckboxControl,{label:(0,t.createElement)("span",{style:{color:"#d63638",fontWeight:"500"}},(0,n.__)("Delete all Global Pricing Rules","tier-pricing-table")),checked:E,onChange:f}))),(0,t.createElement)(l.Panel,{className:"tpt-cleanup-panel",style:{marginBottom:"20px"}},(0,t.createElement)(l.PanelBody,{title:(0,n.__)("3. Plugin Settings","tier-pricing-table"),initialOpen:!0},(0,t.createElement)("p",{style:{color:"#64748b",marginTop:0,marginBottom:"15px"}},(0,n.__)("Reset general settings, labels, and table column configurations.","tier-pricing-table")),(0,t.createElement)(l.CheckboxControl,{label:(0,t.createElement)("span",{style:{color:"#d63638",fontWeight:"500"}},(0,n.__)("Reset all plugin settings to defaults","tier-pricing-table")),checked:x,onChange:v}))),(0,t.createElement)("div",{style:{marginTop:"30px",borderTop:"1px solid #e2e8f0",paddingTop:"20px",display:"flex",alignItems:"center"}},(0,t.createElement)(l.Button,{isPrimary:!0,isDestructive:!0,icon:o,isBusy:C,disabled:C||!N,onClick:async()=>{if(!confirm((0,n.__)("Are you sure you want to delete the selected data? This action cannot be undone.","tier-pricing-table")))return;w(!0),P(null);const t=[];let a=[],l=!1;if(e||"none"!==m||r){const i={clean_standard:e,clean_users:r,clean_all_roles:"all"===m,roles:"specific"===m?g:[],categories:b.map(e=>e.id),products:y.map(e=>e.id)};t.push(c()({path:"/tier-pricing-table/features/tools/v1/cleanup",method:"POST",data:i}).then(e=>{e.success?a.push(e.message||(0,n.__)("Product data cleaned up.","tier-pricing-table")):(l=!0,a.push(e.message))}).catch(e=>{l=!0,a.push(e.message)}))}if(E&&t.push(c()({path:"/tier-pricing-table/features/tools/v1/delete_global_rules",method:"POST"}).then(e=>{e.success?a.push(e.message||(0,n.__)("Global rules deleted.","tier-pricing-table")):(l=!0,a.push(e.message))}).catch(e=>{l=!0,a.push(e.message)})),x&&t.push(c()({path:"/tier-pricing-table/features/tools/v1/reset_settings",method:"POST"}).then(e=>{e.success?a.push(e.message||(0,n.__)("Settings reset to default.","tier-pricing-table")):(l=!0,a.push(e.message))}).catch(e=>{l=!0,a.push(e.message)})),0!==t.length){try{await Promise.all(t),l?P({type:"error",message:a.join(" ")}):(P({type:"success",message:a.join(" ")}),i(!1),s(!1),d("none"),u([]),h([]),_([]),f(!1),v(!1))}catch(e){P({type:"error",message:(0,n.__)("An unexpected error occurred.","tier-pricing-table")})}w(!1)}else w(!1)},style:{padding:"8px 24px"}},C?(0,n.__)("Processing...","tier-pricing-table"):(0,n.__)("Execute Cleanup","tier-pricing-table")),!N&&(0,t.createElement)("span",{style:{marginLeft:"15px",color:"#64748b",fontSize:"0.9em"}},(0,n.__)("Select at least one option above to proceed.","tier-pricing-table"))))))}const d=(0,t.createElement)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(i.Path,{d:"M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z"})),g=(0,t.createElement)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(i.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"}));function u(){const[e,i]=(0,a.useState)([]),[r,s]=(0,a.useState)([]),[p,m]=(0,a.useState)(!0),[u,b]=(0,a.useState)(null),[h,y]=(0,a.useState)(!1),[_,E]=(0,a.useState)(null),[f,x]=(0,a.useState)({key:"",name:"",capabilities:{}}),[v,C]=(0,a.useState)(!1),[w,S]=(0,a.useState)(""),[k,T]=(0,a.useState)(""),B=()=>{m(!0),c()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities"}).then(e=>{i(e.roles),s(e.all_capabilities),m(!1)}).catch(e=>{b({type:"error",message:e.message||"Failed to load roles."}),m(!1)})};(0,a.useEffect)(()=>{B()},[]);const R=["administrator","editor","author","contributor","subscriber"],P=r.filter(e=>e.toLowerCase().includes(k.toLowerCase()));return(0,t.createElement)("div",{className:"tpt-roles-management"},u&&(0,t.createElement)(l.Notice,{status:u.type,onRemove:()=>b(null)},u.message),(0,t.createElement)(l.Card,null,(0,t.createElement)(l.CardHeader,{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"15px 20px"}},(0,t.createElement)("h3",{style:{margin:0}},(0,n.__)("Roles and Capabilities","tier-pricing-table")),(0,t.createElement)(l.Button,{isPrimary:!0,icon:d,onClick:()=>{E(null),x({key:"",name:"",capabilities:{}}),S(""),y(!0)}},(0,n.__)("Add New Role","tier-pricing-table"))),(0,t.createElement)(l.CardBody,{style:{padding:"0"}},p?(0,t.createElement)(l.Spinner,null):(0,t.createElement)("div",{className:"tpt-modern-table",style:{borderRadius:"4px",border:"none",overflow:"hidden",boxShadow:"0 1px 2px rgba(0,0,0,0.05)"}},(0,t.createElement)("div",{style:{display:"grid",gridTemplateColumns:"2fr 2fr 1fr 1fr",padding:"12px 20px",background:"#f8f9fa",borderBottom:"1px solid #e2e4e7",fontWeight:600,color:"#1e1e1e",fontSize:"13px",textTransform:"uppercase",letterSpacing:"0.5px"}},(0,t.createElement)("div",null,(0,n.__)("Role Name","tier-pricing-table")),(0,t.createElement)("div",null,(0,n.__)("Role Key","tier-pricing-table")),(0,t.createElement)("div",null,(0,n.__)("Capabilities Count","tier-pricing-table")),(0,t.createElement)("div",null,(0,n.__)("Actions","tier-pricing-table"))),(0,t.createElement)("div",{style:{display:"flex",flexDirection:"column"}},e.map((a,i)=>(0,t.createElement)("div",{key:a.key,style:{display:"grid",gridTemplateColumns:"2fr 2fr 1fr 1fr",padding:"15px 20px",alignItems:"center",borderBottom:i<e.length-1?"1px solid #e2e4e7":"none",background:"#fff",transition:"background 0.2s"},onMouseEnter:e=>e.currentTarget.style.background="#fafafa",onMouseLeave:e=>e.currentTarget.style.background="#fff"},(0,t.createElement)("div",null,(0,t.createElement)("strong",{style:{fontSize:"14px",color:"#1d2327"}},a.name)),(0,t.createElement)("div",null,(0,t.createElement)("code",{style:{background:"#f0f0f1",padding:"4px 8px",borderRadius:"4px",color:"#2271b1",fontSize:"13px"}},a.key)),(0,t.createElement)("div",null,(0,t.createElement)("span",{style:{background:"#e4f0f6",color:"#006ea6",padding:"4px 10px",borderRadius:"20px",fontSize:"12px",fontWeight:600}},a.capabilities?Object.keys(a.capabilities).filter(e=>a.capabilities[e]).length:0)),(0,t.createElement)("div",null,(0,t.createElement)(l.Flex,{gap:2},(0,t.createElement)(l.FlexItem,null,(0,t.createElement)(l.Button,{isSecondary:!0,variant:"tertiary",icon:g,onClick:()=>(e=>{E(e);const t={};e.capabilities&&Object.keys(e.capabilities).forEach(a=>{e.capabilities[a]&&(t[a]=!0)}),x({key:e.key,name:e.name,capabilities:t}),y(!0)})(a)},(0,n.__)("Edit","tier-pricing-table"))),!R.includes(a.key)&&(0,t.createElement)(l.FlexItem,null,(0,t.createElement)(l.Button,{isDestructive:!0,variant:"tertiary",icon:o,onClick:()=>(e=>{confirm(`Are you sure you want to delete the role "${e.name}"?`)&&c()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities",method:"DELETE",data:{key:e.key}}).then(e=>{e.success?(b({type:"success",message:e.message}),B()):b({type:"error",message:e.message})}).catch(e=>{b({type:"error",message:e.message})})})(a)},(0,n.__)("Delete","tier-pricing-table"))))))))))),h&&(0,t.createElement)(l.Modal,{title:_?(0,n.__)("Edit Role Capabilities","tier-pricing-table"):(0,n.__)("Create New Role","tier-pricing-table"),onRequestClose:()=>y(!1),style:{width:"800px",maxWidth:"90vw"}},(0,t.createElement)("div",{style:{marginBottom:"20px"}},(0,t.createElement)(l.TextControl,{label:(0,n.__)("Role Name","tier-pricing-table"),value:f.name,onChange:e=>x(t=>({...t,name:e})),disabled:!!_}),(0,t.createElement)(l.TextControl,{label:(0,n.__)("Role Key (e.g., custom_role)","tier-pricing-table"),value:f.key,onChange:e=>x(t=>({...t,key:e.toLowerCase().replace(/[^a-z0-9_]/g,"")})),disabled:!!_}),!_&&(0,t.createElement)("div",{style:{marginTop:"15px"}},(0,t.createElement)(l.SelectControl,{label:(0,n.__)("Copy capabilities from existing role","tier-pricing-table"),value:w,options:[{label:(0,n.__)("Select a role...","tier-pricing-table"),value:""},...e.map(e=>({label:e.name,value:e.key}))],onChange:t=>{if(S(t),!t)return void x(e=>({...e,capabilities:{}}));const a=e.find(e=>e.key===t);if(a){const e={};a.capabilities&&Object.keys(a.capabilities).forEach(t=>{a.capabilities[t]&&(e[t]=!0)}),x(t=>({...t,capabilities:e}))}}}))),(0,t.createElement)("hr",null),(0,t.createElement)("h3",null,(0,n.__)("Capabilities","tier-pricing-table")),(0,t.createElement)("div",{style:{marginBottom:"15px"}},(0,t.createElement)(l.SearchControl,{value:k,onChange:T,placeholder:(0,n.__)("Search capabilities...","tier-pricing-table")})),(0,t.createElement)("div",{style:{maxHeight:"300px",overflowY:"auto",border:"1px solid #ddd",padding:"10px"}},P.map(e=>(0,t.createElement)(l.CheckboxControl,{key:e,label:e,style:{marginBottom:"5px"},checked:!!f.capabilities[e],onChange:()=>(e=>{x(t=>({...t,capabilities:{...t.capabilities,[e]:!t.capabilities[e]}}))})(e)}))),(0,t.createElement)("div",{style:{marginTop:"20px",display:"flex",justifyContent:"flex-end",gap:"10px"}},(0,t.createElement)(l.Button,{isSecondary:!0,onClick:()=>y(!1)},(0,n.__)("Cancel","tier-pricing-table")),(0,t.createElement)(l.Button,{isPrimary:!0,isBusy:v,disabled:v,onClick:()=>{if(!f.key||!f.name)return void alert("Key and Name are required.");C(!0);const e=Object.keys(f.capabilities).filter(e=>f.capabilities[e]),t={key:f.key,name:f.name,capabilities:e},a=_?"PUT":"POST";c()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities",method:a,data:t}).then(e=>{e.success?(b({type:"success",message:e.message}),y(!1),B()):b({type:"error",message:e.message}),C(!1)}).catch(e=>{b({type:"error",message:e.message}),C(!1)})}},(0,n.__)("Save Role","tier-pricing-table")))))}function b(){const e=window.location.hash?window.location.hash.replace("#",""):"roles";return(0,t.createElement)("div",{className:"tpt-tools-app",style:{background:"#fff",padding:"20px",borderRadius:"4px",margin:"15px 0"}},(0,t.createElement)(l.TabPanel,{className:"tpt-tools-tabs",activeClass:"is-active",initialTabName:e,onSelect:e=>{window.location.hash=e},tabs:[{name:"roles",title:(0,t.createElement)("span",{style:{display:"flex",alignItems:"center",gap:"8px"}},(0,t.createElement)(l.Icon,{icon:r,size:18})," ",(0,n.__)("Roles Management","tier-pricing-table")),className:"tpt-tab-roles"},{name:"cleanup",title:(0,t.createElement)("span",{style:{display:"flex",alignItems:"center",gap:"8px"}},(0,t.createElement)(l.Icon,{icon:o,size:18})," ",(0,n.__)("Data Clean Up","tier-pricing-table")),className:"tpt-tab-cleanup"}]},e=>(0,t.createElement)("div",{style:{marginTop:"20px"}},"cleanup"===e.name&&(0,t.createElement)(m,null),"roles"===e.name&&(0,t.createElement)(u,null))))}document.addEventListener("DOMContentLoaded",()=>{const e=document.getElementById("tiered-pricing__feature__tools");e&&(0,a.createRoot)(e).render((0,t.createElement)(b,null))})})();
1 +(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var n in a)e.o(a,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React,a=window.wp.element,n=window.wp.components,i=window.wp.i18n,l=window.wp.primitives,r=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})),s=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{fillRule:"evenodd",d:"M16.83 6.342l.602.3.625-.25.443-.176v12.569l-.443-.178-.625-.25-.603.301-1.444.723-2.41-.804-.475-.158-.474.158-2.41.803-1.445-.722-.603-.3-.625.25-.443.177V6.215l.443.178.625.25.603-.301 1.444-.722 2.41.803.475.158.474-.158 2.41-.803 1.445.722zM20 4l-1.5.6-1 .4-2-1-3 1-3-1-2 1-1-.4L5 4v17l1.5-.6 1-.4 2 1 3-1 3 1 2-1 1 .4 1.5.6V4zm-3.5 6.25v-1.5h-8v1.5h8zm0 3v-1.5h-8v1.5h8zm-8 3v-1.5h8v1.5h-8z",clipRule:"evenodd"})),c=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})),o=window.wp.apiFetch;var p=e.n(o);const m=({label:e,type:l,selectedElements:r,onElementsChange:s})=>{const[c,o]=(0,a.useState)([]),[m,g]=(0,a.useState)(!1),[d,u]=(0,a.useState)({}),[_,b]=(0,a.useState)(null);return(0,a.useEffect)(()=>{const e={...d};r.forEach(t=>{const a=`${t.name} (#${t.id})`;e[a]=t}),u(e)},[]),(0,t.createElement)("div",{style:{marginBottom:"20px"}},(0,t.createElement)(n.FormTokenField,{label:e,value:r.map(e=>`${e.name} (#${e.id})`),suggestions:c,onInputChange:e=>{if(_&&clearTimeout(_),!e||e.length<3)return void o([]);const t=setTimeout(()=>{g(!0);const t="product"===l?`/wc/v3/products?search=${encodeURIComponent(e)}&per_page=10`:`/wc/v3/products/categories?search=${encodeURIComponent(e)}&per_page=10`;p()({path:t}).then(e=>{const t=[],a={...d};e.forEach(e=>{const n=`${e.name} (#${e.id})`;t.push(n),a[n]=e}),o(t),u(a),g(!1)}).catch(()=>g(!1))},500);b(t)},onChange:e=>{const t=e.map(e=>d[e]||null).filter(Boolean);s(t)},maxLength:100,__experimentalShowHowTo:!1,messages:{added:(0,i.__)("Item added","tier-pricing-table"),removed:(0,i.__)("Item removed","tier-pricing-table"),remove:(0,i.__)("Remove item","tier-pricing-table")}}),m&&(0,t.createElement)(n.Spinner,{style:{marginTop:"-10px",display:"block"}}))};function g(){const[e,l]=(0,a.useState)(!1),[r,s]=(0,a.useState)(!1),[o,g]=(0,a.useState)("none"),[d,u]=(0,a.useState)([]),[_,b]=(0,a.useState)([]),[h,f]=(0,a.useState)([]),[E,y]=(0,a.useState)(!1),[x,v]=(0,a.useState)(!1),[w,C]=(0,a.useState)(!1),[S,k]=(0,a.useState)([]),[T,N]=(0,a.useState)(!0),[R,P]=(0,a.useState)(null);(0,a.useEffect)(()=>{p()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities"}).then(e=>{if(e.roles){const t=e.roles.map(e=>({label:e.name,value:e.key}));k(t)}N(!1)}).catch(()=>{N(!1)})},[]);const B=e||"all"===o||"specific"===o&&d.length>0||r||E||x;return(0,t.createElement)("div",{className:"tpt-tools-app"},R&&(0,t.createElement)(n.Notice,{status:R.type,onRemove:()=>P(null)},R.message),(0,t.createElement)(n.Card,null,(0,t.createElement)(n.CardHeader,null,(0,t.createElement)("h3",{style:{margin:0}},(0,i.__)("Clean Up & Reset Options","tier-pricing-table"))),(0,t.createElement)(n.CardBody,null,(0,t.createElement)("p",{style:{backgroundColor:"#fcf0f1",color:"#d63638",padding:"12px 16px",borderLeft:"4px solid #d63638",borderRadius:"4px",marginTop:"0",marginBottom:"20px"}},(0,t.createElement)("strong",null,(0,i.__)("Warning:","tier-pricing-table"))," ",(0,i.__)("The actions below will permanently delete data from your database. Please make a backup before proceeding.","tier-pricing-table")),(0,t.createElement)(n.Panel,{className:"tpt-cleanup-panel",style:{marginBottom:"20px"}},(0,t.createElement)(n.PanelBody,{title:(0,i.__)("1. Product Level Data","tier-pricing-table"),initialOpen:!0},(0,t.createElement)("p",{style:{color:"#64748b",marginTop:0,marginBottom:"15px"}},(0,i.__)("Remove tiered pricing rules directly attached to individual products.","tier-pricing-table")),(0,t.createElement)(n.CheckboxControl,{label:(0,i.__)("Clean Standard Tiered Pricing Data","tier-pricing-table"),checked:e,onChange:l}),(0,t.createElement)("h4",{style:{marginTop:"15px",marginBottom:"10px"}},(0,i.__)("Customer Based Data","tier-pricing-table")),(0,t.createElement)(n.CheckboxControl,{label:(0,i.__)("Clean All Customer Based Pricing Data","tier-pricing-table"),checked:r,onChange:s}),(0,t.createElement)("h4",{style:{marginTop:"15px",marginBottom:"10px"}},(0,i.__)("Role Based Data","tier-pricing-table")),(0,t.createElement)(n.RadioControl,{selected:o,options:[{label:(0,i.__)("Do not clean role based data","tier-pricing-table"),value:"none"},{label:(0,i.__)("Clean all roles","tier-pricing-table"),value:"all"},{label:(0,i.__)("Select specific roles to clean","tier-pricing-table"),value:"specific"}],onChange:e=>g(e)}),"specific"===o&&(T?(0,t.createElement)(n.Spinner,{style:{marginTop:"10px"}}):(0,t.createElement)("div",{style:{display:"flex",flexDirection:"column",gap:"8px",marginTop:"10px",marginLeft:"25px",paddingLeft:"15px",borderLeft:"2px solid #e2e8f0"}},S.map(e=>(0,t.createElement)(n.CheckboxControl,{key:e.value,label:e.label,checked:d.includes(e.value),onChange:()=>{return t=e.value,void u(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t]);var t}})))),(e||"none"!==o||r)&&(0,t.createElement)("div",{style:{marginTop:"20px",padding:"15px",background:"#f8fafc",borderRadius:"4px",border:"1px solid #e2e8f0"}},(0,t.createElement)("h4",{style:{marginTop:0,marginBottom:"5px"}},(0,i.__)("Filters (Optional)","tier-pricing-table")),(0,t.createElement)("p",{style:{color:"#64748b",fontSize:"0.9em",marginTop:0,marginBottom:"15px"}},(0,i.__)("Leave blank to apply the cleanup to all products. Otherwise, select specific categories or products.","tier-pricing-table")),(0,t.createElement)(m,{label:(0,i.__)("Select Categories","tier-pricing-table"),type:"category",selectedElements:_,onElementsChange:b}),(0,t.createElement)(m,{label:(0,i.__)("Select Products","tier-pricing-table"),type:"product",selectedElements:h,onElementsChange:f})))),(0,t.createElement)(n.Panel,{className:"tpt-cleanup-panel",style:{marginBottom:"20px"}},(0,t.createElement)(n.PanelBody,{title:(0,i.__)("2. Global Pricing Rules","tier-pricing-table"),initialOpen:!0},(0,t.createElement)("p",{style:{color:"#64748b",marginTop:0,marginBottom:"15px"}},(0,i.__)("Global pricing rules apply to multiple products at once.","tier-pricing-table")),(0,t.createElement)(n.CheckboxControl,{label:(0,t.createElement)("span",{style:{color:"#d63638",fontWeight:"500"}},(0,i.__)("Delete all Global Pricing Rules","tier-pricing-table")),checked:E,onChange:y}))),(0,t.createElement)(n.Panel,{className:"tpt-cleanup-panel",style:{marginBottom:"20px"}},(0,t.createElement)(n.PanelBody,{title:(0,i.__)("3. Plugin Settings","tier-pricing-table"),initialOpen:!0},(0,t.createElement)("p",{style:{color:"#64748b",marginTop:0,marginBottom:"15px"}},(0,i.__)("Reset general settings, labels, and table column configurations.","tier-pricing-table")),(0,t.createElement)(n.CheckboxControl,{label:(0,t.createElement)("span",{style:{color:"#d63638",fontWeight:"500"}},(0,i.__)("Reset all plugin settings to defaults","tier-pricing-table")),checked:x,onChange:v}))),(0,t.createElement)("div",{style:{marginTop:"30px",borderTop:"1px solid #e2e8f0",paddingTop:"20px",display:"flex",alignItems:"center"}},(0,t.createElement)(n.Button,{isPrimary:!0,isDestructive:!0,icon:c,isBusy:w,disabled:w||!B,onClick:async()=>{if(!confirm((0,i.__)("Are you sure you want to delete the selected data? This action cannot be undone.","tier-pricing-table")))return;C(!0),P(null);const t=[];let a=[],n=!1;if(e||"none"!==o||r){const l={clean_standard:e,clean_users:r,clean_all_roles:"all"===o,roles:"specific"===o?d:[],categories:_.map(e=>e.id),products:h.map(e=>e.id)};t.push(p()({path:"/tier-pricing-table/features/tools/v1/cleanup",method:"POST",data:l}).then(e=>{e.success?a.push(e.message||(0,i.__)("Product data cleaned up.","tier-pricing-table")):(n=!0,a.push(e.message))}).catch(e=>{n=!0,a.push(e.message)}))}if(E&&t.push(p()({path:"/tier-pricing-table/features/tools/v1/delete_global_rules",method:"POST"}).then(e=>{e.success?a.push(e.message||(0,i.__)("Global rules deleted.","tier-pricing-table")):(n=!0,a.push(e.message))}).catch(e=>{n=!0,a.push(e.message)})),x&&t.push(p()({path:"/tier-pricing-table/features/tools/v1/reset_settings",method:"POST"}).then(e=>{e.success?a.push(e.message||(0,i.__)("Settings reset to default.","tier-pricing-table")):(n=!0,a.push(e.message))}).catch(e=>{n=!0,a.push(e.message)})),0!==t.length){try{await Promise.all(t),n?P({type:"error",message:a.join(" ")}):(P({type:"success",message:a.join(" ")}),l(!1),s(!1),g("none"),u([]),b([]),f([]),y(!1),v(!1))}catch(e){P({type:"error",message:(0,i.__)("An unexpected error occurred.","tier-pricing-table")})}C(!1)}else C(!1)},style:{padding:"8px 24px"}},w?(0,i.__)("Processing...","tier-pricing-table"):(0,i.__)("Execute Cleanup","tier-pricing-table")),!B&&(0,t.createElement)("span",{style:{marginLeft:"15px",color:"#64748b",fontSize:"0.9em"}},(0,i.__)("Select at least one option above to proceed.","tier-pricing-table"))))))}const d=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{d:"M11 12.5V17.5H12.5V12.5H17.5V11H12.5V6H11V11H6V12.5H11Z"})),u=(0,t.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(l.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"}));function _(){const[e,l]=(0,a.useState)([]),[r,s]=(0,a.useState)([]),[o,m]=(0,a.useState)(!0),[g,_]=(0,a.useState)(null),[b,h]=(0,a.useState)(!1),[f,E]=(0,a.useState)(null),[y,x]=(0,a.useState)({key:"",name:"",capabilities:{}}),[v,w]=(0,a.useState)(!1),[C,S]=(0,a.useState)(""),[k,T]=(0,a.useState)(""),N=()=>{m(!0),p()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities"}).then(e=>{l(e.roles),s(e.all_capabilities),m(!1)}).catch(e=>{_({type:"error",message:e.message||"Failed to load roles."}),m(!1)})};(0,a.useEffect)(()=>{N()},[]);const R=["administrator","editor","author","contributor","subscriber"],P=r.filter(e=>e.toLowerCase().includes(k.toLowerCase()));return(0,t.createElement)("div",{className:"tpt-roles-management"},g&&(0,t.createElement)(n.Notice,{status:g.type,onRemove:()=>_(null)},g.message),(0,t.createElement)(n.Card,null,(0,t.createElement)(n.CardHeader,{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"15px 20px"}},(0,t.createElement)("h3",{style:{margin:0}},(0,i.__)("Roles and Capabilities","tier-pricing-table")),(0,t.createElement)(n.Button,{isPrimary:!0,icon:d,onClick:()=>{E(null),x({key:"",name:"",capabilities:{}}),S(""),h(!0)}},(0,i.__)("Add New Role","tier-pricing-table"))),(0,t.createElement)(n.CardBody,{style:{padding:"0"}},o?(0,t.createElement)(n.Spinner,null):(0,t.createElement)("div",{className:"tpt-modern-table",style:{borderRadius:"4px",border:"none",overflow:"hidden",boxShadow:"0 1px 2px rgba(0,0,0,0.05)"}},(0,t.createElement)("div",{style:{display:"grid",gridTemplateColumns:"2fr 2fr 1fr 1fr",padding:"12px 20px",background:"#f8f9fa",borderBottom:"1px solid #e2e4e7",fontWeight:600,color:"#1e1e1e",fontSize:"13px",textTransform:"uppercase",letterSpacing:"0.5px"}},(0,t.createElement)("div",null,(0,i.__)("Role Name","tier-pricing-table")),(0,t.createElement)("div",null,(0,i.__)("Role Key","tier-pricing-table")),(0,t.createElement)("div",null,(0,i.__)("Capabilities Count","tier-pricing-table")),(0,t.createElement)("div",null,(0,i.__)("Actions","tier-pricing-table"))),(0,t.createElement)("div",{style:{display:"flex",flexDirection:"column"}},e.map((a,l)=>(0,t.createElement)("div",{key:a.key,style:{display:"grid",gridTemplateColumns:"2fr 2fr 1fr 1fr",padding:"15px 20px",alignItems:"center",borderBottom:l<e.length-1?"1px solid #e2e4e7":"none",background:"#fff",transition:"background 0.2s"},onMouseEnter:e=>e.currentTarget.style.background="#fafafa",onMouseLeave:e=>e.currentTarget.style.background="#fff"},(0,t.createElement)("div",null,(0,t.createElement)("strong",{style:{fontSize:"14px",color:"#1d2327"}},a.name)),(0,t.createElement)("div",null,(0,t.createElement)("code",{style:{background:"#f0f0f1",padding:"4px 8px",borderRadius:"4px",color:"#2271b1",fontSize:"13px"}},a.key)),(0,t.createElement)("div",null,(0,t.createElement)("span",{style:{background:"#e4f0f6",color:"#006ea6",padding:"4px 10px",borderRadius:"20px",fontSize:"12px",fontWeight:600}},a.capabilities?Object.keys(a.capabilities).filter(e=>a.capabilities[e]).length:0)),(0,t.createElement)("div",null,(0,t.createElement)(n.Flex,{gap:2},(0,t.createElement)(n.FlexItem,null,(0,t.createElement)(n.Button,{isSecondary:!0,variant:"tertiary",icon:u,onClick:()=>(e=>{E(e);const t={};e.capabilities&&Object.keys(e.capabilities).forEach(a=>{e.capabilities[a]&&(t[a]=!0)}),x({key:e.key,name:e.name,capabilities:t}),h(!0)})(a)},(0,i.__)("Edit","tier-pricing-table"))),!R.includes(a.key)&&(0,t.createElement)(n.FlexItem,null,(0,t.createElement)(n.Button,{isDestructive:!0,variant:"tertiary",icon:c,onClick:()=>(e=>{confirm(`Are you sure you want to delete the role "${e.name}"?`)&&p()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities",method:"DELETE",data:{key:e.key}}).then(e=>{e.success?(_({type:"success",message:e.message}),N()):_({type:"error",message:e.message})}).catch(e=>{_({type:"error",message:e.message})})})(a)},(0,i.__)("Delete","tier-pricing-table"))))))))))),b&&(0,t.createElement)(n.Modal,{title:f?(0,i.__)("Edit Role Capabilities","tier-pricing-table"):(0,i.__)("Create New Role","tier-pricing-table"),onRequestClose:()=>h(!1),style:{width:"800px",maxWidth:"90vw"}},(0,t.createElement)("div",{style:{marginBottom:"20px"}},(0,t.createElement)(n.TextControl,{label:(0,i.__)("Role Name","tier-pricing-table"),value:y.name,onChange:e=>x(t=>({...t,name:e})),disabled:!!f}),(0,t.createElement)(n.TextControl,{label:(0,i.__)("Role Key (e.g., custom_role)","tier-pricing-table"),value:y.key,onChange:e=>x(t=>({...t,key:e.toLowerCase().replace(/[^a-z0-9_]/g,"")})),disabled:!!f}),!f&&(0,t.createElement)("div",{style:{marginTop:"15px"}},(0,t.createElement)(n.SelectControl,{label:(0,i.__)("Copy capabilities from existing role","tier-pricing-table"),value:C,options:[{label:(0,i.__)("Select a role...","tier-pricing-table"),value:""},...e.map(e=>({label:e.name,value:e.key}))],onChange:t=>{if(S(t),!t)return void x(e=>({...e,capabilities:{}}));const a=e.find(e=>e.key===t);if(a){const e={};a.capabilities&&Object.keys(a.capabilities).forEach(t=>{a.capabilities[t]&&(e[t]=!0)}),x(t=>({...t,capabilities:e}))}}}))),(0,t.createElement)("hr",null),(0,t.createElement)("h3",null,(0,i.__)("Capabilities","tier-pricing-table")),(0,t.createElement)("div",{style:{marginBottom:"15px"}},(0,t.createElement)(n.SearchControl,{value:k,onChange:T,placeholder:(0,i.__)("Search capabilities...","tier-pricing-table")})),(0,t.createElement)("div",{style:{maxHeight:"300px",overflowY:"auto",border:"1px solid #ddd",padding:"10px"}},P.map(e=>(0,t.createElement)(n.CheckboxControl,{key:e,label:e,style:{marginBottom:"5px"},checked:!!y.capabilities[e],onChange:()=>(e=>{x(t=>({...t,capabilities:{...t.capabilities,[e]:!t.capabilities[e]}}))})(e)}))),(0,t.createElement)("div",{style:{marginTop:"20px",display:"flex",justifyContent:"flex-end",gap:"10px"}},(0,t.createElement)(n.Button,{isSecondary:!0,onClick:()=>h(!1)},(0,i.__)("Cancel","tier-pricing-table")),(0,t.createElement)(n.Button,{isPrimary:!0,isBusy:v,disabled:v,onClick:()=>{if(!y.key||!y.name)return void alert("Key and Name are required.");w(!0);const e=Object.keys(y.capabilities).filter(e=>y.capabilities[e]),t={key:y.key,name:y.name,capabilities:e},a=f?"PUT":"POST";p()({path:"/tier-pricing-table/features/tools/v1/roles_capabilities",method:a,data:t}).then(e=>{e.success?(_({type:"success",message:e.message}),h(!1),N()):_({type:"error",message:e.message}),w(!1)}).catch(e=>{_({type:"error",message:e.message}),w(!1)})}},(0,i.__)("Save Role","tier-pricing-table")))))}const b=window.tptToolsConfig||{},h=b.pricingTest||{};function f(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}function E({label:e,help:l,value:r,onChange:s,action:c,nonce:o}){const[p,m]=(0,a.useState)(r?[r]:[]),[g,d]=(0,a.useState)(!1),u=(0,a.useRef)(null),_=(0,a.useRef)(0);return(0,a.useEffect)(()=>()=>clearTimeout(u.current),[]),(0,t.createElement)("div",{style:{position:"relative"}},(0,t.createElement)(n.ComboboxControl,{label:e,help:l,value:r?r.value:null,options:p,onChange:e=>s(p.find(t=>t.value===e)||null),onFilterValueChange:e=>{clearTimeout(u.current),!e||e.length<2||(u.current=setTimeout(()=>{const t=++_.current;d(!0),function(e,t,a){const n=new URL(b.ajaxUrl||"/wp-admin/admin-ajax.php",window.location.href);return n.searchParams.set("action",e),n.searchParams.set("security",t),n.searchParams.set("term",a),window.fetch(n.toString(),{credentials:"same-origin"}).then(e=>e.json()).then(e=>Object.keys(e||{}).map(t=>({value:String(t),label:f(String(e[t]))})))}(c,o,e).then(e=>{if(t!==_.current)return;const a=r&&!e.some(e=>e.value===r.value)?[r]:[];m([...a,...e])}).catch(()=>{}).finally(()=>{t===_.current&&d(!1)})},300))},messages:{selected:(0,i.__)("Selected","tier-pricing-table")},__next40pxDefaultSize:!0}),g&&(0,t.createElement)(n.Spinner,{style:{position:"absolute",right:"44px",top:"30px",margin:0}}))}const y={wins:{tone:"win",label:(0,i.__)("Matches and is applied","tier-pricing-table")},overridden:{tone:"warn",label:(0,i.__)("Matches, but product pricing is applied","tier-pricing-table")},outranked:{tone:"warn",label:(0,i.__)("Matches, but a higher-priority rule is applied","tier-pricing-table")},skipped:{tone:"warn",label:(0,i.__)("Matches, but changes nothing","tier-pricing-table")},inactive:{tone:"warn",label:(0,i.__)("Would match","tier-pricing-table")},no:{tone:"no",label:(0,i.__)("Does not match","tier-pricing-table")}},x={suspended:(0,i.__)("Suspended","tier-pricing-table"),scheduled:(0,i.__)("Scheduled","tier-pricing-table"),expired:(0,i.__)("Expired","tier-pricing-table"),draft:(0,i.__)("Not published","tier-pricing-table")};function v({tone:e,children:a}){return(0,t.createElement)("span",{className:`tpt-pricing-test__badge tpt-pricing-test__badge--${e}`},a)}function w({result:e}){const{winner:a,pricing:n,rulesEnabled:l}=e;let r;return r=l?a.id&&a.overridden?(0,i.sprintf)(/* translators: 1: rule title, 2: pricing source, e.g. "the product's own pricing" */ /* translators: 1: rule title, 2: pricing source, e.g. "the product's own pricing" */
2 +(0,i.__)("%1$s matches, but the prices come from %2$s because of the rule's priority settings.","tier-pricing-table"),a.title,n.source):a.id?(0,i.sprintf)((0,i.__)("The prices come from %s.","tier-pricing-table"),a.title):(0,i.__)("No global pricing rule matches this product for this customer.","tier-pricing-table"):(0,i.__)("No global pricing rule takes part: the Global pricing rules add-on is switched off.","tier-pricing-table"),(0,t.createElement)(t.Fragment,null,(0,t.createElement)("p",{className:"tpt-pricing-test__summary"},a.id?(0,t.createElement)(t.Fragment,null,r.split(a.title)[0],(0,t.createElement)("a",{href:a.url},a.title),r.split(a.title).slice(1).join(a.title)):r),(0,t.createElement)("p",{className:"tpt-pricing-test__muted tpt-pricing-test__source"},(0,i.sprintf)((0,i.__)("Source of the prices: %s.","tier-pricing-table"),n.source)," ",n.limits.length
3 +/* translators: %s: list of limits, e.g. "minimum 10, step 5" */?(0,i.sprintf)((0,i.__)("Quantity limits: %s.","tier-pricing-table"),n.limits.join(", ")):(0,i.__)("No quantity limits.","tier-pricing-table")))}function C({rows:e}){return(0,t.createElement)("table",{className:"widefat striped tpt-pricing-test__table tpt-pricing-test__table--prices"},(0,t.createElement)("thead",null,(0,t.createElement)("tr",null,(0,t.createElement)("th",null,(0,i.__)("Quantity","tier-pricing-table")),(0,t.createElement)("th",null,(0,i.__)("Price per item","tier-pricing-table")),(0,t.createElement)("th",null,(0,i.__)("Discount","tier-pricing-table")),(0,t.createElement)("th",null,(0,i.__)("Total","tier-pricing-table")))),(0,t.createElement)("tbody",null,e.map(e=>(0,t.createElement)("tr",{key:e.quantity},(0,t.createElement)("td",null,e.quantity),(0,t.createElement)("td",null,e.price),(0,t.createElement)("td",null,e.discount>0?`${e.discount}%`:"—"),(0,t.createElement)("td",null,e.total)))))}function S({rules:e}){return(0,t.createElement)("table",{className:"widefat striped tpt-pricing-test__table tpt-pricing-test__table--rules"},(0,t.createElement)("thead",null,(0,t.createElement)("tr",null,(0,t.createElement)("th",null,(0,i.__)("Rule","tier-pricing-table")),(0,t.createElement)("th",null,(0,i.__)("Verdict","tier-pricing-table")),(0,t.createElement)("th",null,(0,i.__)("Why","tier-pricing-table")))),(0,t.createElement)("tbody",null,e.map(e=>{const a=y[e.verdict]||y.no;return(0,t.createElement)("tr",{key:e.id,className:e.highlighted?"is-highlighted":""},(0,t.createElement)("td",null,(0,t.createElement)("a",{className:"tpt-pricing-test__rule-title",href:e.url},e.title),x[e.status]&&(0,t.createElement)(v,{tone:"status"},x[e.status]),(0,t.createElement)("div",{className:"tpt-pricing-test__origin"},(0,i.sprintf)((0,i.__)("Priority %d","tier-pricing-table"),e.priority),e.schedule?` · ${e.schedule}`:""),e.highlighted&&(0,t.createElement)("div",{className:"tpt-pricing-test__origin"},(0,i.__)("The rule you came from","tier-pricing-table"))),(0,t.createElement)("td",null,(0,t.createElement)(v,{tone:a.tone},a.label),e.notes.length>0&&(0,t.createElement)("ul",{className:"tpt-pricing-test__notes"},e.notes.map((e,a)=>(0,t.createElement)("li",{key:a},e)))),(0,t.createElement)("td",null,(0,t.createElement)("ul",null,e.reasons.map((e,a)=>(0,t.createElement)("li",{key:a},e)))))})))}function k({result:e}){const{product:a,customer:l,pricing:r,rules:s,rulesEnabled:c}=e;return(0,t.createElement)("div",{className:"tpt-pricing-test__result"},(0,t.createElement)("p",{className:"tpt-pricing-test__subject"},(0,t.createElement)("a",{href:a.url},(0,t.createElement)("strong",null,a.name))," "+(0,i.__)("for","tier-pricing-table")+" ",(0,t.createElement)("strong",null,l.label),l.roles&&(0,t.createElement)("span",{className:"tpt-pricing-test__muted"}," (",l.roles,")")),(0,t.createElement)(n.Card,{size:"small"},(0,t.createElement)(n.CardHeader,null,(0,t.createElement)("strong",null,(0,i.__)("What the customer pays","tier-pricing-table"))),(0,t.createElement)(n.CardBody,null,(0,t.createElement)(w,{result:e}),(0,t.createElement)(C,{rows:r.rows}))),(0,t.createElement)(n.Card,{size:"small"},(0,t.createElement)(n.CardHeader,null,(0,t.createElement)("strong",null,(0,i.__)("Global pricing rules","tier-pricing-table")),(0,t.createElement)("span",{className:"tpt-pricing-test__muted tpt-pricing-test__hint"},(0,i.__)("Rules are matched in priority order: the lowest number first, and the newer rule first when numbers are equal. The first active rule that matches is applied.","tier-pricing-table"))),(0,t.createElement)(n.CardBody,null,!c&&(0,t.createElement)(n.Notice,{status:"warning",isDismissible:!1},(0,i.__)("The Global pricing rules add-on is switched off (see the modules above), so no rule takes part in pricing.","tier-pricing-table")),c&&0===s.length&&(0,t.createElement)("p",{className:"tpt-pricing-test__empty"},(0,i.__)("There are no global pricing rules yet.","tier-pricing-table")," ",(0,t.createElement)("a",{href:h.newRuleUrl},(0,i.__)("Add a pricing rule","tier-pricing-table"))),s.length>0&&(0,t.createElement)(S,{rules:s}))),r.log.length>0&&(0,t.createElement)("details",{className:"tpt-pricing-test__log"},(0,t.createElement)("summary",null,(0,i.__)("Pricing log","tier-pricing-table")),(0,t.createElement)("ol",null,r.log.map((e,a)=>(0,t.createElement)("li",{key:a},e)))))}function T(){const[e,l]=(0,a.useState)(null),[r,s]=(0,a.useState)("guest"),[c,o]=(0,a.useState)(null),[m,g]=(0,a.useState)(h.rule||null),[d,u]=(0,a.useState)(!1),[_,f]=(0,a.useState)(null),[y,x]=(0,a.useState)(null);return(0,t.createElement)("div",{className:"tpt-pricing-test"},(0,t.createElement)("style",null,'\n.tpt-pricing-test .components-card__header { padding: 16px 20px; }\n.tpt-pricing-test .components-card__body { padding: 20px; }\n/* ".tpt-tools-app" prefix: the panel sits in a WooCommerce settings table, whose ".form-table td p" rule outranks a single class */\n.tpt-tools-app .tpt-pricing-test__intro { margin: 4px 0 0; color: #646970; }\n.tpt-pricing-test__rule-notice { margin: 0 0 20px; }\n.tpt-pricing-test__rule-notice .components-notice { margin: 0; }\n.tpt-pricing-test__form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 32px; align-items: start; }\n.tpt-pricing-test__label { display: block; margin: 0 0 8px; font-size: 11px; font-weight: 500; line-height: 1.4; text-transform: uppercase; }\n.tpt-pricing-test__radios { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; min-height: 40px; }\n.tpt-pricing-test__radios label { display: inline-flex; align-items: center; gap: 6px; margin: 0; }\n.tpt-pricing-test__radios input[type="radio"] { margin: 0; }\n.tpt-pricing-test__customer { margin-top: 12px; }\n.tpt-pricing-test__actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }\n.tpt-pricing-test__error { margin: 16px 0 0; }\n.tpt-pricing-test__error .components-notice { margin: 0; }\n.tpt-pricing-test__result { margin-top: 28px; padding-top: 24px; border-top: 1px solid #dcdcde; }\n.tpt-tools-app .tpt-pricing-test__subject { margin: 0 0 16px; font-size: 14px; }\n.tpt-pricing-test__result .components-card { margin-bottom: 16px; }\n.tpt-pricing-test__result .components-card__header { padding: 12px 16px; gap: 16px; }\n.tpt-pricing-test__result .components-card__body { padding: 16px; }\n.tpt-tools-app .tpt-pricing-test__summary { margin: 0 0 6px; }\n.tpt-tools-app .tpt-pricing-test__source { margin: 0 0 14px; }\n.tpt-pricing-test__muted { color: #646970; }\n.tpt-pricing-test__hint { font-size: 12px; font-weight: 400; }\n.tpt-tools-app .tpt-pricing-test__empty { margin: 0; }\n.tpt-tools-app .tpt-pricing-test__table th,\n.tpt-tools-app .tpt-pricing-test__table td { padding: 10px 12px; line-height: 1.5; vertical-align: top; width: auto; font-weight: 400; }\n.tpt-tools-app .tpt-pricing-test__table th { font-weight: 600; }\n.tpt-tools-app .tpt-pricing-test__table--prices { max-width: 640px; }\n.tpt-tools-app .tpt-pricing-test__table--prices th:first-child,\n.tpt-tools-app .tpt-pricing-test__table--prices td:first-child { width: 90px; }\n.tpt-tools-app .tpt-pricing-test__table--rules th:nth-child(1),\n.tpt-tools-app .tpt-pricing-test__table--rules th:nth-child(2) { width: 26%; }\n.tpt-pricing-test__table ul { margin: 0; padding-left: 18px; list-style: disc; }\n.tpt-pricing-test__table tr.is-highlighted td { background: #f0f6fc; }\n.tpt-pricing-test__table tr.is-highlighted td:first-child { box-shadow: inset 3px 0 0 #2271b1; }\n.tpt-pricing-test__rule-title { font-weight: 600; }\n.tpt-pricing-test__origin { margin-top: 2px; font-size: 12px; color: #646970; }\n.tpt-pricing-test__table td > ul > li + li { margin-top: 4px; }\n.tpt-pricing-test__badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 1.4; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }\n.tpt-pricing-test__badge--win { background: #edfaef; color: #007017; }\n.tpt-pricing-test__badge--warn { background: #fcf9e8; color: #996800; }\n.tpt-pricing-test__badge--no { background: #f0f0f1; color: #50575e; }\n.tpt-pricing-test__badge--status { background: #f0f0f1; color: #50575e; margin-left: 8px; vertical-align: 1px; }\n.tpt-pricing-test__table ul.tpt-pricing-test__notes { margin: 6px 0 0; padding: 0; list-style: none; color: #646970; font-size: 12px; }\n.tpt-pricing-test__log { margin: 0; padding: 10px 14px; border: 1px solid #dcdcde; border-radius: 4px; background: #f6f7f7; }\n.tpt-pricing-test__log summary { cursor: pointer; font-weight: 600; }\n.tpt-pricing-test__log ol { margin: 10px 0 0; padding-left: 24px; color: #50575e; font-family: Menlo, Consolas, monospace; font-size: 12px; }\n@media (max-width: 782px) { .tpt-pricing-test__form { grid-template-columns: minmax(0, 1fr); } }\n'),(0,t.createElement)(n.Card,null,(0,t.createElement)(n.CardHeader,null,(0,t.createElement)("div",null,(0,t.createElement)("h3",{style:{margin:0}},(0,i.__)("Pricing Test","tier-pricing-table")),(0,t.createElement)("p",{className:"tpt-pricing-test__intro"},(0,i.__)("See what a customer pays for a product without opening the storefront: which global pricing rule applies and why, which one wins when several match, and the prices per quantity.","tier-pricing-table")))),(0,t.createElement)(n.CardBody,null,m&&(0,t.createElement)("div",{className:"tpt-pricing-test__rule-notice"},(0,t.createElement)(n.Notice,{status:"info",onRemove:()=>g(null)},(0,i.__)("Checking the rule","tier-pricing-table")," ",(0,t.createElement)("a",{href:m.url},(0,t.createElement)("strong",null,m.title)),". ",(0,i.__)("Pick a product and a customer; the rule is highlighted in the results.","tier-pricing-table"))),(0,t.createElement)("div",{className:"tpt-pricing-test__form"},(0,t.createElement)(E,{label:(0,i.__)("Product","tier-pricing-table"),help:(0,i.__)("Type to search products and variations.","tier-pricing-table"),value:e,onChange:l,action:"woocommerce_json_search_products_and_variations",nonce:b.searchProductsNonce}),(0,t.createElement)("div",null,(0,t.createElement)("span",{className:"tpt-pricing-test__label"},(0,i.__)("Customer","tier-pricing-table")),(0,t.createElement)("div",{className:"tpt-pricing-test__radios"},(0,t.createElement)("label",null,(0,t.createElement)("input",{type:"radio",name:"tpt_pricing_test_customer",value:"guest",checked:"guest"===r,onChange:()=>s("guest")}),(0,i.__)("Visitor (not logged in)","tier-pricing-table")),(0,t.createElement)("label",null,(0,t.createElement)("input",{type:"radio",name:"tpt_pricing_test_customer",value:"customer",checked:"customer"===r,onChange:()=>s("customer")}),(0,i.__)("A customer","tier-pricing-table"))),"customer"===r&&(0,t.createElement)("div",{className:"tpt-pricing-test__customer"},(0,t.createElement)(E,{label:(0,i.__)("Which customer","tier-pricing-table"),help:(0,i.__)("Type a name or an email address.","tier-pricing-table"),value:c,onChange:o,action:"woocommerce_json_search_customers",nonce:b.searchCustomersNonce})))),(0,t.createElement)("div",{className:"tpt-pricing-test__actions"},(0,t.createElement)(n.Button,{variant:"primary",onClick:()=>{e?(u(!0),f(null),p()({path:"/tier-pricing-table/features/tools/v1/pricing_test",method:"POST",data:{product_id:parseInt(e.value,10),user_id:"customer"===r&&c?parseInt(c.value,10):0,rule_id:m?m.id:0}}).then(e=>{x(e)}).catch(e=>{f(e&&e.message||(0,i.__)("The test could not run. Reload the page and try again.","tier-pricing-table"))}).finally(()=>u(!1))):f((0,i.__)("Pick a product first.","tier-pricing-table"))},isBusy:d,disabled:d},d?(0,i.__)("Testing…","tier-pricing-table"):(0,i.__)("Run the test","tier-pricing-table")),(0,t.createElement)("span",{className:"tpt-pricing-test__muted tpt-pricing-test__hint"},(0,i.__)("Rules are tested as they are saved.","tier-pricing-table"))),_&&(0,t.createElement)("div",{className:"tpt-pricing-test__error"},(0,t.createElement)(n.Notice,{status:"error",isDismissible:!1},_)),y&&!_&&(0,t.createElement)(k,{result:y}))))}function N(){const e=window.location.hash?window.location.hash.replace("#",""):"roles";return(0,a.useEffect)(()=>{if(new URLSearchParams(window.location.search).has("tpt_rule")){const e=document.getElementById("tiered-pricing__feature__tools");e&&e.scrollIntoView({block:"start"})}},[]),(0,t.createElement)("div",{className:"tpt-tools-app",style:{background:"#fff",padding:"20px",borderRadius:"4px",margin:"15px 0",scrollMarginTop:"90px"}},(0,t.createElement)(n.TabPanel,{className:"tpt-tools-tabs",activeClass:"is-active",initialTabName:e,onSelect:e=>{const t="#"+e;window.location.hash===t||!window.location.hash&&"roles"===e||window.history.replaceState(null,"",t)},tabs:[{name:"roles",title:(0,t.createElement)("span",{style:{display:"flex",alignItems:"center",gap:"8px"}},(0,t.createElement)(n.Icon,{icon:r,size:18})," ",(0,i.__)("Roles Management","tier-pricing-table")),className:"tpt-tab-roles"},{name:"pricing-test",title:(0,t.createElement)("span",{style:{display:"flex",alignItems:"center",gap:"8px"}},(0,t.createElement)(n.Icon,{icon:s,size:18})," ",(0,i.__)("Pricing Test","tier-pricing-table")),className:"tpt-tab-pricing-test"},{name:"cleanup",title:(0,t.createElement)("span",{style:{display:"flex",alignItems:"center",gap:"8px"}},(0,t.createElement)(n.Icon,{icon:c,size:18})," ",(0,i.__)("Data Clean Up","tier-pricing-table")),className:"tpt-tab-cleanup"}]},e=>(0,t.createElement)("div",{style:{marginTop:"20px"}},"cleanup"===e.name&&(0,t.createElement)(g,null),"roles"===e.name&&(0,t.createElement)(_,null),"pricing-test"===e.name&&(0,t.createElement)(T,null))))}document.addEventListener("DOMContentLoaded",()=>{const e=document.getElementById("tiered-pricing__feature__tools");e&&(0,a.createRoot)(e).render((0,t.createElement)(N,null))})})();