From d1de0015be1c19a073e4ad66cbb676283f5d47b5 Mon Sep 17 00:00:00 2001 From: dwindown Date: Sun, 19 Apr 2026 07:08:54 +0700 Subject: [PATCH] feat: add React metabox island for coupon editor - Create CouponMetabox React component with WPCFTO design system - Add MetaboxLayout with vertical tabs (Rules, Restrictions) - Implement Rules tab: active toggle, type radio, amount fields, multi-currency support - Implement Restrictions tab: usage limit, date limit, autocomplete for forms/products/customers - Add metabox registration in Coupon.php for formipay-coupon post type - Update ReactAdmin to load assets on post.php edit screens - Add autocomplete AJAX handler for relation fields - Disable old WPCFTO metabox in favor of React island --- build/admin-rtl.css | 2 + build/admin.asset.php | 2 +- build/admin.css | 2 + build/admin.js | 2 +- includes/Admin/ReactAdmin.php | 21 +- includes/Coupon.php | 184 +++--- .../components/coupons/CouponMetabox.css | 146 +++++ src/admin/components/coupons/CouponMetabox.js | 545 ++++++++++++++++++ src/admin/index.js | 27 + 9 files changed, 854 insertions(+), 77 deletions(-) create mode 100644 src/admin/components/coupons/CouponMetabox.css create mode 100644 src/admin/components/coupons/CouponMetabox.js diff --git a/build/admin-rtl.css b/build/admin-rtl.css index 7097a4f0e..1b32ad5d0 100644 --- a/build/admin-rtl.css +++ b/build/admin-rtl.css @@ -4,3 +4,5 @@ .formipay-order-detail{background:#f6f7f7;display:flex;flex-direction:column;height:100%}.formipay-detail-header{align-items:center;background:#fff;border-bottom:1px solid #e0e0e0;display:flex;gap:16px;justify-content:space-between;padding:16px 20px}.formipay-detail-header h1{flex:1;font-size:20px;font-weight:600;margin:0}.header-actions{display:flex;gap:8px}.formipay-detail-content{display:grid;gap:20px;grid-template-columns:2fr 1fr;overflow-y:auto;padding:20px}.formipay-detail-main,.formipay-detail-sidebar{display:flex;flex-direction:column;gap:20px}.formipay-detail-card{background:#fff;border:1px solid #e0e0e0;border-radius:4px;padding:20px}.formipay-detail-card h3{color:#1e1e1e;font-size:16px;font-weight:600;margin:0 0 16px}.detail-list{display:grid;gap:16px;grid-template-columns:repeat(2,1fr)}.detail-list>div{display:flex;flex-direction:column}.detail-list dt{color:#646970;font-size:12px;font-weight:600;margin-bottom:4px}.detail-list dd{align-items:center;color:#1e1e1e;display:flex;font-size:14px;gap:8px}.detail-list dd .components-select-control{flex:1}.items-table{border-collapse:collapse;width:100%}.items-table td,.items-table th{border-bottom:1px solid #f0f0f1;padding:10px;text-align:right}.items-table th{color:#646970;font-size:12px;font-weight:600;text-transform:uppercase}.items-table td{font-size:13px}.items-table small{color:#646970;display:block;font-size:11px}.items-table tfoot td{border-bottom:none;border-top:2px solid #1e1e1e;padding-top:16px}.customer-info{display:grid;gap:12px;grid-template-columns:1fr}.customer-info>div{display:flex;flex-direction:column}.customer-info dt{color:#646970;font-size:11px;font-weight:600;margin-bottom:2px}.customer-info dd{color:#1e1e1e;font-size:13px}.no-data{color:#646970;font-size:13px}.formipay-error,.formipay-loading{align-items:center;display:flex;flex-direction:column;gap:16px;justify-content:center;padding:60px 20px}.formipay-error p{color:#646970;margin:0} .formipay-page-header{align-items:center;display:flex;justify-content:space-between;margin-bottom:20px}.formipay-page-header h1{font-size:23px;font-weight:400;margin:0}.formipay-navigation-menu{align-items:center;background-color:#fff;box-shadow:0 4px 12px #d2d2d2;display:flex;gap:2em;right:0;margin-right:-20px;margin-top:-10px;padding:12px 50px 12px 20px;position:sticky;top:32px;width:calc(100% + 20px);z-index:1000}.formipay-navigation-menu>img{flex-shrink:0;height:48px;width:48px}.navigation-links{display:flex;flex-wrap:wrap;gap:4px}.navigation-links .nav-link{border-radius:4px;color:#646970;font-size:14px;font-weight:500;padding:8px 16px;text-decoration:none;transition:all .2s}.navigation-links .nav-link:hover{background-color:#f6f7f7;color:#2271b1}.navigation-links .nav-link.active{background-color:#2271b1;color:#fff}.status-badge{border-radius:4px;display:inline-block;font-size:12px;font-weight:500;padding:4px 8px}.status-badge.status-active,.status-badge.status-publish{background-color:#edfaef;color:#00a32a}.status-badge.status-draft,.status-badge.status-inactive{background-color:#f0f0f1;color:#646970}.status-badge.status-expired{background-color:#f6f7f7;color:#d63638}code{background-color:#f0f0f1;border-radius:3px;font-family:monospace;font-size:13px;padding:2px 6px}.formipay-modal-overlay{align-items:center;background-color:rgba(0,0,0,.5);bottom:0;display:flex;justify-content:center;right:0;position:fixed;left:0;top:0;z-index:100000}.formipay-modal-content{background-color:#fff;border-radius:8px;box-shadow:0 4px 20px rgba(0,0,0,.15);max-height:90vh;max-width:900px;overflow-y:auto;width:90%} .formipay-variation-table{border-collapse:collapse;margin-top:20px;width:100%}.formipay-variation-table thead th{border-bottom:2px solid #1e1e1e;color:#1e1e1e;font-size:13px;font-weight:600;padding:12px;text-align:right}.formipay-variation-table tbody td{border-bottom:1px solid #f0f0f1;padding:12px}.variation-row{background:#fff}.variation-name{gap:8px}.toggle-expand,.variation-name{align-items:center;display:flex}.toggle-expand{background:transparent;border:none;border-radius:2px;cursor:pointer;height:24px;justify-content:center;padding:0;width:24px}.toggle-expand:hover{background:#f0f0f1}.toggle-expand svg{fill:#646970}.variation-name strong{color:#1e1e1e;font-size:13px}.price-cell,.variation-stock,.variation-weight{min-width:120px}.price-cell input,.variation-stock input,.variation-weight input{border:1px solid #8c8f94;border-radius:2px;font-size:13px;padding:6px 8px;width:100%}.variation-stock .components-base-control,.variation-weight .components-base-control{margin:0}.variation-actions{min-width:100px}.variation-details-row{background:#f9f9f9}.variation-details-row td{padding:0}.inner-table{border-collapse:collapse;margin:0;width:100%}.inner-table thead{display:none}.inner-table td{border-bottom:1px solid #f0f0f1;padding:8px 12px}.inner-table tr:last-child td{border-bottom:none}.inner-table input[type=number]{border:1px solid #8c8f94;border-radius:2px;font-size:12px;padding:6px 8px;width:100%}.currency-name{color:#1e1e1e;font-size:12px;font-weight:600}.required{color:#dc3545;margin-right:4px} +:root{--formipay-color-primary:#2985f7;--formipay-color-sidebar-bg:#2c3e50;--formipay-color-sidebar-text:#bec5cb;--formipay-color-sidebar-active:#2985f7;--formipay-color-content-bg:#f0f3f5;--formipay-color-block-bg:#fff;--formipay-color-border:#f0f0f1;--formipay-color-border-dark:#8c99a5;--formipay-color-input-bg:#f6f9fc;--formipay-color-text:#27374e;--formipay-color-text-muted:#8c99a5;--formipay-color-danger:#d63638;--formipay-color-success:#00a32a;--formipay-color-warning:#dba617;--formipay-spacing-xs:4px;--formipay-spacing-sm:8px;--formipay-spacing-md:12px;--formipay-spacing-lg:16px;--formipay-spacing-xl:20px;--formipay-spacing-xxl:24px;--formipay-radius-sm:4px;--formipay-radius-md:10px;--formipay-radius-lg:30px;--formipay-radius-full:50%;--formipay-font-family:"Roboto",-apple-system,BlinkMacSystemFont,sans-serif;--formipay-font-size-sm:13px;--formipay-font-size-base:14px;--formipay-font-size-md:15px;--formipay-font-size-lg:18px;--formipay-font-weight-normal:400;--formipay-font-weight-medium:500;--formipay-font-weight-semibold:600;--formipay-font-weight-bold:700;--formipay-sidebar-width:273px;--formipay-field-aside-width:40%;--formipay-field-content-width:60%;--formipay-shadow-sm:0 1px 3px rgba(0,0,0,.05);--formipay-shadow-md:-2px 2px 5px rgba(0,0,0,.08);--formipay-shadow-lg:0 4px 12px rgba(0,0,0,.1);--formipay-transition-fast:0.15s ease;--formipay-transition-base:0.3s ease}.formipay-design-system *{box-sizing:border-box}.formipay-design-system{color:var(--formipay-color-text);font-family:var(--formipay-font-family);line-height:1.5}.formipay-box{background-color:var(--formipay-color-content-bg);border-radius:var(--formipay-radius-md);box-shadow:var(--formipay-shadow-sm);margin:0 0 10px;min-height:80px}.formipay-box,.formipay-box-child{position:relative}.formipay-box-child+.formipay-box-child{margin-top:1em}.formipay-box a{color:var(--formipay-color-primary);text-decoration:none;transition:color var(--formipay-transition-base)}.formipay-box a:hover{text-decoration:underline}.formipay-wpcfto-tab-nav{background-color:var(--formipay-color-sidebar-bg);flex-grow:1;padding:21px 0;width:var(--formipay-sidebar-width)}.formipay-wpcfto-tab-nav.hide{display:none}.formipay-wpcfto-tab-nav-inner{position:sticky;top:133px;z-index:99}.formipay-wpcfto-nav{background-color:transparent;color:var(--formipay-color-sidebar-text);cursor:pointer;font-size:var(--formipay-font-size-base);font-weight:400;padding:0;position:relative;text-transform:uppercase;transition:all .3s ease 0s}.formipay-wpcfto-nav-title{padding:13px 34px 13px 32px;position:relative}.formipay-wpcfto-nav i{display:block;font-size:22px;right:auto;margin-top:-11px;position:absolute;left:30px;text-align:center;top:50%;width:26px}.formipay-wpcfto-nav.active{background-color:var(--formipay-color-primary);color:#fff}.formipay-wpcfto-nav:hover{color:#fff}.formipay-wpcfto-submenus{background-color:#1e2a36;padding:18px 34px 18px 32px}.formipay-wpcfto-submenu-item{color:var(--formipay-color-text-muted);font-size:15px;font-weight:400;margin-bottom:15px;position:relative;text-transform:none}.formipay-wpcfto-submenu-item i{display:none;font-size:10px;margin-top:-5px;left:0}.formipay-wpcfto-submenu-item.active,.formipay-wpcfto-submenu-item:hover{color:#fff}.formipay-wpcfto-submenu-item.active i{display:block}.formipay-tabs{flex-grow:1;overflow:hidden}.formipay-tab{background-color:var(--formipay-color-content-bg);display:none;padding:20px 20px 20px 30px;width:100%}.formipay-tab.active{animation:fadeIn .4s ease;display:block}.formipay-tab-content{max-width:100%}@keyframes fadeIn{0%{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}.formipay-generic-field{background-color:var(--formipay-color-block-bg);border-radius:10px;display:flex;flex-wrap:wrap;justify-content:space-between;margin:0 0 10px;max-width:100%;padding:1.8rem 1rem 0;width:100%}.formipay-field-aside{padding-left:2rem;width:var(--formipay-field-aside-width)}.formipay-field-label{display:inline;font-size:var(--formipay-font-size-base);font-weight:var(--formipay-font-weight-medium)}.formipay-field-label.required .formipay-field-label-text:after{color:var(--formipay-color-danger);content:"*";margin-right:2px}.formipay-field-content{width:var(--formipay-field-content-width)}.formipay-field-description{color:var(--formipay-color-text-muted);display:block;font-size:var(--formipay-font-size-sm);margin-top:.8em}.formipay-input,.formipay-select,.formipay-textarea{background-color:var(--formipay-color-input-bg);border:1px solid var(--formipay-color-border-dark);border-radius:var(--formipay-radius-lg);color:var(--formipay-color-text);font-family:inherit;font-size:var(--formipay-font-size-base);padding:10px 16px;transition:border-color var(--formipay-transition-fast),box-shadow var(--formipay-transition-fast);width:100%}.formipay-input:focus,.formipay-select:focus,.formipay-textarea:focus{border-color:var(--formipay-color-primary);box-shadow:0 0 0 3px rgba(41,133,247,.1);outline:none}.formipay-input:disabled,.formipay-select:disabled,.formipay-textarea:disabled{cursor:not-allowed;opacity:.6}.formipay-textarea{min-height:100px;resize:vertical}.formipay-admin-checkbox{align-self:flex-end;margin-bottom:0}.formipay-admin-checkbox-wrapper{background-color:#bec5cb;border-radius:20px;cursor:pointer;display:inline-block;height:24px;position:relative;transition:background-color .3s ease;width:42px}.formipay-admin-checkbox-wrapper.active{background-color:var(--formipay-color-primary)}.formipay-checkbox-switcher{background-color:#fff;border-radius:50%;height:18px;right:3px;position:absolute;top:3px;transition:transform .3s ease;width:18px}.formipay-admin-checkbox-wrapper.active .formipay-checkbox-switcher{transform:translateX(-18px)}.formipay-admin-checkbox input{height:0;opacity:0;position:absolute;width:0}.formipay-admin-checkbox label,.formipay-btn{cursor:pointer}.formipay-btn{align-items:center;border:none;border-radius:var(--formipay-radius-sm);display:inline-flex;font-family:inherit;font-size:var(--formipay-font-size-base);font-weight:var(--formipay-font-weight-medium);gap:var(--formipay-spacing-sm);justify-content:center;padding:10px 20px;text-decoration:none;transition:all var(--formipay-transition-fast)}.formipay-btn:disabled{cursor:not-allowed;opacity:.6}.formipay-btn-primary{background-color:var(--formipay-color-primary);color:#fff}.formipay-btn-primary:hover:not(:disabled){background-color:#1e6ae6}.formipay-btn-secondary{background-color:#f0f0f1;color:var(--formipay-color-text)}.formipay-btn-secondary:hover:not(:disabled){background-color:#e0e0e1}.formipay-btn-danger{background-color:var(--formipay-color-danger);color:#fff}.formipay-btn-danger:hover:not(:disabled){background-color:#b32d2e}.formipay-btn-sm{font-size:var(--formipay-font-size-sm);padding:6px 12px}.formipay-btn-icon{aspect-ratio:1;padding:8px}.formipay-repeater{display:flex;flex-direction:column;gap:var(--formipay-spacing-md)}.formipay-repeater-item{background-color:#fafafa;border:1px solid var(--formipay-color-border);border-radius:var(--formipay-radius-sm);overflow:hidden}.formipay-repeater-header{align-items:center;background-color:#fff;border-bottom:1px solid var(--formipay-color-border);cursor:pointer;display:flex;justify-content:space-between;padding:var(--formipay-spacing-md) var(--formipay-spacing-lg);-webkit-user-select:none;-moz-user-select:none;user-select:none}.formipay-repeater-header:hover{background-color:#f8f9fa}.formipay-repeater-title{align-items:center;display:flex;font-weight:var(--formipay-font-weight-medium);gap:var(--formipay-spacing-sm)}.formipay-repeater-toggle{align-items:center;display:flex;height:20px;justify-content:center;transition:transform var(--formipay-transition-fast);width:20px}.formipay-repeater-item.collapsed .formipay-repeater-toggle{transform:rotate(90deg)}.formipay-repeater-body{padding:var(--formipay-spacing-lg)}.formipay-repeater-item.collapsed .formipay-repeater-body{display:none}.formipay-repeater-actions{display:flex;gap:var(--formipay-spacing-sm)}.formipay-repeater-delete{color:var(--formipay-color-danger);cursor:pointer;transition:color var(--formipay-transition-fast)}.formipay-repeater-delete:hover{color:#b32d2e}.formipay-repeater-add{align-items:center;background-color:transparent;border:1px dashed var(--formipay-color-border-dark);border-radius:var(--formipay-radius-sm);color:var(--formipay-color-text-muted);cursor:pointer;display:flex;gap:var(--formipay-spacing-sm);padding:var(--formipay-spacing-md) var(--formipay-spacing-lg);transition:all var(--formipay-transition-fast)}.formipay-repeater-add:hover{background-color:rgba(41,133,247,.05);border-color:var(--formipay-color-primary);color:var(--formipay-color-primary)}.formipay-table-wrapper{background-color:var(--formipay-color-content-bg);border-radius:var(--formipay-radius-md);box-shadow:var(--formipay-shadow-sm);overflow:hidden}.formipay-table{border-collapse:collapse;width:100%}.formipay-table thead{background-color:#f8f9fa}.formipay-table th{color:var(--formipay-color-text-muted);font-size:var(--formipay-font-size-sm);font-weight:var(--formipay-font-weight-semibold);letter-spacing:.5px;text-align:right;text-transform:uppercase}.formipay-table td,.formipay-table th{border-bottom:1px solid var(--formipay-color-border);padding:12px 16px}.formipay-table tbody tr:last-child td{border-bottom:none}.formipay-table tbody tr:hover{background-color:#f8f9fa}.formipay-badge{align-items:center;border-radius:var(--formipay-radius-full);display:inline-flex;font-size:var(--formipay-font-size-sm);font-weight:var(--formipay-font-weight-medium);padding:4px 12px}.formipay-badge-success{background-color:#edfaef;color:var(--formipay-color-success)}.formipay-badge-warning{background-color:#fff8e5;color:var(--formipay-color-warning)}.formipay-badge-danger{background-color:#fce8e6;color:var(--formipay-color-danger)}.formipay-badge-info{background-color:#e7f3ff;color:var(--formipay-color-primary)}.formipay-badge-default{background-color:#f0f0f1;color:var(--formipay-color-text-muted)}.formipay-group-title{align-items:center;border-bottom:1px solid #d6dade;color:var(--formipay-color-text-muted);display:flex;font-size:14px;font-weight:400;gap:8px;letter-spacing:1.4px;margin:0 0 17px;padding:0 0 12px;text-transform:uppercase;width:100%}.formipay-group-title i{display:block}.formipay-notice{align-items:flex-start;border-radius:var(--formipay-radius-sm);display:flex;gap:var(--formipay-spacing-md);margin:var(--formipay-spacing-md) 0;padding:var(--formipay-spacing-md) var(--formipay-spacing-lg)}.formipay-notice-icon{flex-shrink:0;height:20px;width:20px}.formipay-notice-content{flex:1}.formipay-notice-title{font-weight:var(--formipay-font-weight-semibold);margin-bottom:var(--formipay-spacing-xs)}.formipay-notice-success{background-color:#edfaef;border-right:4px solid var(--formipay-color-success)}.formipay-notice-warning{background-color:#fff8e5;border-right:4px solid var(--formipay-color-warning)}.formipay-notice-error{background-color:#fce8e6;border-right:4px solid var(--formipay-color-danger)}.formipay-notice-info{background-color:#e7f3ff;border-right:4px solid var(--formipay-color-primary)}.formipay-loading{align-items:center;display:flex;justify-content:center;padding:40px}.formipay-spinner{animation:formipay-spin .8s linear infinite;border:3px solid var(--formipay-color-border);border-radius:50%;border-top-color:var(--formipay-color-primary);height:32px;width:32px}@keyframes formipay-spin{to{transform:rotate(-1turn)}}.formipay-empty-state{align-items:center;display:flex;flex-direction:column;justify-content:center;padding:60px 40px;text-align:center}.formipay-empty-icon{color:var(--formipay-color-border-dark);font-size:48px;margin-bottom:var(--formipay-spacing-md)}.formipay-empty-title{font-size:var(--formipay-font-size-lg);font-weight:var(--formipay-font-weight-semibold);margin-bottom:var(--formipay-spacing-sm)}.formipay-empty-description{color:var(--formipay-color-text-muted);margin-bottom:var(--formipay-spacing-lg)}.formipay-text-center{text-align:center}.formipay-text-right{text-align:left}.formipay-text-muted{color:var(--formipay-color-text-muted)}.formipay-text-small{font-size:var(--formipay-font-size-sm)}.formipay-text-large{font-size:var(--formipay-font-size-lg)}.formipay-mt-0{margin-top:0}.formipay-mt-1{margin-top:var(--formipay-spacing-xs)}.formipay-mt-2{margin-top:var(--formipay-spacing-sm)}.formipay-mt-3{margin-top:var(--formipay-spacing-md)}.formipay-mt-4{margin-top:var(--formipay-spacing-lg)}.formipay-mb-0{margin-bottom:0}.formipay-mb-1{margin-bottom:var(--formipay-spacing-xs)}.formipay-mb-2{margin-bottom:var(--formipay-spacing-sm)}.formipay-mb-3{margin-bottom:var(--formipay-spacing-md)}.formipay-mb-4{margin-bottom:var(--formipay-spacing-lg)}.formipay-flex{display:flex}.formipay-flex-center{align-items:center;display:flex;justify-content:center}.formipay-flex-between{align-items:center;display:flex;justify-content:space-between}.formipay-flex-column{display:flex;flex-direction:column}.formipay-gap-1{gap:var(--formipay-spacing-xs)}.formipay-gap-2{gap:var(--formipay-spacing-sm)}.formipay-gap-3{gap:var(--formipay-spacing-md)}.formipay-gap-4{gap:var(--formipay-spacing-lg)}.formipay-wpcfto-metabox{background-color:#fff;border-radius:var(--formipay-radius-md);box-shadow:var(--formipay-shadow-sm);overflow:hidden}.formipay-wpcfto-metabox-inner{display:flex;min-height:400px}.formipay-wpcfto-container{display:flex;position:relative;width:100%}.formipay-wpcfto-container.horizontal{flex-direction:column}.formipay-wpcfto-container.horizontal .formipay-wpcfto-tab-nav{flex-direction:row;overflow-x:auto;padding:0;width:100%}.formipay-wpcfto-container.horizontal .formipay-wpcfto-tabs{width:100%}@media (max-width:768px){.formipay-tab-nav{flex-direction:row;overflow-x:auto}.formipay-nav-item{flex-shrink:0}.formipay-field{padding:var(--formipay-spacing-md) 0}} +.formipay-coupon-metabox{margin:-12px}.formipay-metabox-actions{background-color:#fff;border-top:1px solid #f0f0f1;display:flex;gap:12px;justify-content:flex-end;padding:20px 30px}.formipay-radio-group{display:flex;gap:16px}.formipay-radio{align-items:center;border:2px solid var(--formipay-color-border-dark);border-radius:var(--formipay-radius-lg);cursor:pointer;display:inline-flex;gap:8px;padding:8px 16px;transition:all var(--formipay-transition-fast)}.formipay-radio input{height:0;opacity:0;position:absolute;width:0}.formipay-radio span{color:var(--formipay-color-text-muted);font-weight:var(--formipay-font-weight-medium)}.formipay-radio.active,.formipay-radio:hover{border-color:var(--formipay-color-primary)}.formipay-radio.active{background-color:var(--formipay-color-primary)}.formipay-radio.active span{color:#fff}.formipay-autocomplete{position:relative}.formipay-autocomplete-selected{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:8px}.formipay-autocomplete-tag{align-items:center;background-color:var(--formipay-color-primary);border-radius:4px;color:#fff;display:inline-flex;font-size:var(--formipay-font-size-sm);gap:4px;padding:4px 8px}.formipay-autocomplete-remove{align-items:center;background:none;border:none;color:#fff;cursor:pointer;display:flex;font-size:16px;height:16px;justify-content:center;line-height:1;padding:0;width:16px}.formipay-autocomplete-remove:hover{opacity:.8}.formipay-autocomplete-input-wrapper{position:relative}.formipay-autocomplete-loading{color:var(--formipay-color-text-muted);position:absolute;left:12px;top:50%;transform:translateY(-50%)}.formipay-autocomplete-results{background-color:#fff;border:1px solid var(--formipay-color-border-dark);border-radius:var(--formipay-radius-sm);box-shadow:var(--formipay-shadow-md);right:0;margin-top:4px;max-height:200px;overflow-y:auto;position:absolute;left:0;top:100%;z-index:100}.formipay-autocomplete-result{cursor:pointer;padding:10px 16px;transition:background-color var(--formipay-transition-fast)}.formipay-autocomplete-result:hover{background-color:var(--formipay-color-content-bg)}.formipay-autocomplete-result:first-child{border-radius:var(--formipay-radius-sm) var(--formipay-radius-sm) 0 0}.formipay-autocomplete-result:last-child{border-radius:0 0 var(--formipay-radius-sm) var(--formipay-radius-sm)} diff --git a/build/admin.asset.php b/build/admin.asset.php index 54577c461..f7d4a28f0 100644 --- a/build/admin.asset.php +++ b/build/admin.asset.php @@ -1 +1 @@ - array('react', 'wp-components', 'wp-element', 'wp-i18n', 'wp-icons/build/arrow-left', 'wp-icons/build/bell', 'wp-icons/build/message', 'wp-icons/build/trash', 'wp-primitives'), 'version' => '83e1a34ae6a628833355'); + array('react', 'wp-components', 'wp-element', 'wp-i18n', 'wp-icons/build/arrow-left', 'wp-icons/build/bell', 'wp-icons/build/message', 'wp-icons/build/trash', 'wp-primitives'), 'version' => 'f1f91f1cc72d44a0469e'); diff --git a/build/admin.css b/build/admin.css index 8125677fd..216cbc52f 100644 --- a/build/admin.css +++ b/build/admin.css @@ -4,3 +4,5 @@ .formipay-order-detail{background:#f6f7f7;display:flex;flex-direction:column;height:100%}.formipay-detail-header{align-items:center;background:#fff;border-bottom:1px solid #e0e0e0;display:flex;gap:16px;justify-content:space-between;padding:16px 20px}.formipay-detail-header h1{flex:1;font-size:20px;font-weight:600;margin:0}.header-actions{display:flex;gap:8px}.formipay-detail-content{display:grid;gap:20px;grid-template-columns:2fr 1fr;overflow-y:auto;padding:20px}.formipay-detail-main,.formipay-detail-sidebar{display:flex;flex-direction:column;gap:20px}.formipay-detail-card{background:#fff;border:1px solid #e0e0e0;border-radius:4px;padding:20px}.formipay-detail-card h3{color:#1e1e1e;font-size:16px;font-weight:600;margin:0 0 16px}.detail-list{display:grid;gap:16px;grid-template-columns:repeat(2,1fr)}.detail-list>div{display:flex;flex-direction:column}.detail-list dt{color:#646970;font-size:12px;font-weight:600;margin-bottom:4px}.detail-list dd{align-items:center;color:#1e1e1e;display:flex;font-size:14px;gap:8px}.detail-list dd .components-select-control{flex:1}.items-table{border-collapse:collapse;width:100%}.items-table td,.items-table th{border-bottom:1px solid #f0f0f1;padding:10px;text-align:left}.items-table th{color:#646970;font-size:12px;font-weight:600;text-transform:uppercase}.items-table td{font-size:13px}.items-table small{color:#646970;display:block;font-size:11px}.items-table tfoot td{border-bottom:none;border-top:2px solid #1e1e1e;padding-top:16px}.customer-info{display:grid;gap:12px;grid-template-columns:1fr}.customer-info>div{display:flex;flex-direction:column}.customer-info dt{color:#646970;font-size:11px;font-weight:600;margin-bottom:2px}.customer-info dd{color:#1e1e1e;font-size:13px}.no-data{color:#646970;font-size:13px}.formipay-error,.formipay-loading{align-items:center;display:flex;flex-direction:column;gap:16px;justify-content:center;padding:60px 20px}.formipay-error p{color:#646970;margin:0} .formipay-page-header{align-items:center;display:flex;justify-content:space-between;margin-bottom:20px}.formipay-page-header h1{font-size:23px;font-weight:400;margin:0}.formipay-navigation-menu{align-items:center;background-color:#fff;box-shadow:0 4px 12px #d2d2d2;display:flex;gap:2em;left:0;margin-left:-20px;margin-top:-10px;padding:12px 20px 12px 50px;position:sticky;top:32px;width:calc(100% + 20px);z-index:1000}.formipay-navigation-menu>img{flex-shrink:0;height:48px;width:48px}.navigation-links{display:flex;flex-wrap:wrap;gap:4px}.navigation-links .nav-link{border-radius:4px;color:#646970;font-size:14px;font-weight:500;padding:8px 16px;text-decoration:none;transition:all .2s}.navigation-links .nav-link:hover{background-color:#f6f7f7;color:#2271b1}.navigation-links .nav-link.active{background-color:#2271b1;color:#fff}.status-badge{border-radius:4px;display:inline-block;font-size:12px;font-weight:500;padding:4px 8px}.status-badge.status-active,.status-badge.status-publish{background-color:#edfaef;color:#00a32a}.status-badge.status-draft,.status-badge.status-inactive{background-color:#f0f0f1;color:#646970}.status-badge.status-expired{background-color:#f6f7f7;color:#d63638}code{background-color:#f0f0f1;border-radius:3px;font-family:monospace;font-size:13px;padding:2px 6px}.formipay-modal-overlay{align-items:center;background-color:rgba(0,0,0,.5);bottom:0;display:flex;justify-content:center;left:0;position:fixed;right:0;top:0;z-index:100000}.formipay-modal-content{background-color:#fff;border-radius:8px;box-shadow:0 4px 20px rgba(0,0,0,.15);max-height:90vh;max-width:900px;overflow-y:auto;width:90%} .formipay-variation-table{border-collapse:collapse;margin-top:20px;width:100%}.formipay-variation-table thead th{border-bottom:2px solid #1e1e1e;color:#1e1e1e;font-size:13px;font-weight:600;padding:12px;text-align:left}.formipay-variation-table tbody td{border-bottom:1px solid #f0f0f1;padding:12px}.variation-row{background:#fff}.variation-name{gap:8px}.toggle-expand,.variation-name{align-items:center;display:flex}.toggle-expand{background:transparent;border:none;border-radius:2px;cursor:pointer;height:24px;justify-content:center;padding:0;width:24px}.toggle-expand:hover{background:#f0f0f1}.toggle-expand svg{fill:#646970}.variation-name strong{color:#1e1e1e;font-size:13px}.price-cell,.variation-stock,.variation-weight{min-width:120px}.price-cell input,.variation-stock input,.variation-weight input{border:1px solid #8c8f94;border-radius:2px;font-size:13px;padding:6px 8px;width:100%}.variation-stock .components-base-control,.variation-weight .components-base-control{margin:0}.variation-actions{min-width:100px}.variation-details-row{background:#f9f9f9}.variation-details-row td{padding:0}.inner-table{border-collapse:collapse;margin:0;width:100%}.inner-table thead{display:none}.inner-table td{border-bottom:1px solid #f0f0f1;padding:8px 12px}.inner-table tr:last-child td{border-bottom:none}.inner-table input[type=number]{border:1px solid #8c8f94;border-radius:2px;font-size:12px;padding:6px 8px;width:100%}.currency-name{color:#1e1e1e;font-size:12px;font-weight:600}.required{color:#dc3545;margin-left:4px} +:root{--formipay-color-primary:#2985f7;--formipay-color-sidebar-bg:#2c3e50;--formipay-color-sidebar-text:#bec5cb;--formipay-color-sidebar-active:#2985f7;--formipay-color-content-bg:#f0f3f5;--formipay-color-block-bg:#fff;--formipay-color-border:#f0f0f1;--formipay-color-border-dark:#8c99a5;--formipay-color-input-bg:#f6f9fc;--formipay-color-text:#27374e;--formipay-color-text-muted:#8c99a5;--formipay-color-danger:#d63638;--formipay-color-success:#00a32a;--formipay-color-warning:#dba617;--formipay-spacing-xs:4px;--formipay-spacing-sm:8px;--formipay-spacing-md:12px;--formipay-spacing-lg:16px;--formipay-spacing-xl:20px;--formipay-spacing-xxl:24px;--formipay-radius-sm:4px;--formipay-radius-md:10px;--formipay-radius-lg:30px;--formipay-radius-full:50%;--formipay-font-family:"Roboto",-apple-system,BlinkMacSystemFont,sans-serif;--formipay-font-size-sm:13px;--formipay-font-size-base:14px;--formipay-font-size-md:15px;--formipay-font-size-lg:18px;--formipay-font-weight-normal:400;--formipay-font-weight-medium:500;--formipay-font-weight-semibold:600;--formipay-font-weight-bold:700;--formipay-sidebar-width:273px;--formipay-field-aside-width:40%;--formipay-field-content-width:60%;--formipay-shadow-sm:0 1px 3px rgba(0,0,0,.05);--formipay-shadow-md:-2px 2px 5px rgba(0,0,0,.08);--formipay-shadow-lg:0 4px 12px rgba(0,0,0,.1);--formipay-transition-fast:0.15s ease;--formipay-transition-base:0.3s ease}.formipay-design-system *{box-sizing:border-box}.formipay-design-system{color:var(--formipay-color-text);font-family:var(--formipay-font-family);line-height:1.5}.formipay-box{background-color:var(--formipay-color-content-bg);border-radius:var(--formipay-radius-md);box-shadow:var(--formipay-shadow-sm);margin:0 0 10px;min-height:80px}.formipay-box,.formipay-box-child{position:relative}.formipay-box-child+.formipay-box-child{margin-top:1em}.formipay-box a{color:var(--formipay-color-primary);text-decoration:none;transition:color var(--formipay-transition-base)}.formipay-box a:hover{text-decoration:underline}.formipay-wpcfto-tab-nav{background-color:var(--formipay-color-sidebar-bg);flex-grow:1;padding:21px 0;width:var(--formipay-sidebar-width)}.formipay-wpcfto-tab-nav.hide{display:none}.formipay-wpcfto-tab-nav-inner{position:sticky;top:133px;z-index:99}.formipay-wpcfto-nav{background-color:transparent;color:var(--formipay-color-sidebar-text);cursor:pointer;font-size:var(--formipay-font-size-base);font-weight:400;padding:0;position:relative;text-transform:uppercase;transition:all .3s ease 0s}.formipay-wpcfto-nav-title{padding:13px 32px 13px 34px;position:relative}.formipay-wpcfto-nav i{display:block;font-size:22px;left:auto;margin-top:-11px;position:absolute;right:30px;text-align:center;top:50%;width:26px}.formipay-wpcfto-nav.active{background-color:var(--formipay-color-primary);color:#fff}.formipay-wpcfto-nav:hover{color:#fff}.formipay-wpcfto-submenus{background-color:#1e2a36;padding:18px 32px 18px 34px}.formipay-wpcfto-submenu-item{color:var(--formipay-color-text-muted);font-size:15px;font-weight:400;margin-bottom:15px;position:relative;text-transform:none}.formipay-wpcfto-submenu-item i{display:none;font-size:10px;margin-top:-5px;right:0}.formipay-wpcfto-submenu-item.active,.formipay-wpcfto-submenu-item:hover{color:#fff}.formipay-wpcfto-submenu-item.active i{display:block}.formipay-tabs{flex-grow:1;overflow:hidden}.formipay-tab{background-color:var(--formipay-color-content-bg);display:none;padding:20px 30px 20px 20px;width:100%}.formipay-tab.active{animation:fadeIn .4s ease;display:block}.formipay-tab-content{max-width:100%}@keyframes fadeIn{0%{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}.formipay-generic-field{background-color:var(--formipay-color-block-bg);border-radius:10px;display:flex;flex-wrap:wrap;justify-content:space-between;margin:0 0 10px;max-width:100%;padding:1.8rem 1rem 0;width:100%}.formipay-field-aside{padding-right:2rem;width:var(--formipay-field-aside-width)}.formipay-field-label{display:inline;font-size:var(--formipay-font-size-base);font-weight:var(--formipay-font-weight-medium)}.formipay-field-label.required .formipay-field-label-text:after{color:var(--formipay-color-danger);content:"*";margin-left:2px}.formipay-field-content{width:var(--formipay-field-content-width)}.formipay-field-description{color:var(--formipay-color-text-muted);display:block;font-size:var(--formipay-font-size-sm);margin-top:.8em}.formipay-input,.formipay-select,.formipay-textarea{background-color:var(--formipay-color-input-bg);border:1px solid var(--formipay-color-border-dark);border-radius:var(--formipay-radius-lg);color:var(--formipay-color-text);font-family:inherit;font-size:var(--formipay-font-size-base);padding:10px 16px;transition:border-color var(--formipay-transition-fast),box-shadow var(--formipay-transition-fast);width:100%}.formipay-input:focus,.formipay-select:focus,.formipay-textarea:focus{border-color:var(--formipay-color-primary);box-shadow:0 0 0 3px rgba(41,133,247,.1);outline:none}.formipay-input:disabled,.formipay-select:disabled,.formipay-textarea:disabled{cursor:not-allowed;opacity:.6}.formipay-textarea{min-height:100px;resize:vertical}.formipay-admin-checkbox{align-self:flex-end;margin-bottom:0}.formipay-admin-checkbox-wrapper{background-color:#bec5cb;border-radius:20px;cursor:pointer;display:inline-block;height:24px;position:relative;transition:background-color .3s ease;width:42px}.formipay-admin-checkbox-wrapper.active{background-color:var(--formipay-color-primary)}.formipay-checkbox-switcher{background-color:#fff;border-radius:50%;height:18px;left:3px;position:absolute;top:3px;transition:transform .3s ease;width:18px}.formipay-admin-checkbox-wrapper.active .formipay-checkbox-switcher{transform:translateX(18px)}.formipay-admin-checkbox input{height:0;opacity:0;position:absolute;width:0}.formipay-admin-checkbox label,.formipay-btn{cursor:pointer}.formipay-btn{align-items:center;border:none;border-radius:var(--formipay-radius-sm);display:inline-flex;font-family:inherit;font-size:var(--formipay-font-size-base);font-weight:var(--formipay-font-weight-medium);gap:var(--formipay-spacing-sm);justify-content:center;padding:10px 20px;text-decoration:none;transition:all var(--formipay-transition-fast)}.formipay-btn:disabled{cursor:not-allowed;opacity:.6}.formipay-btn-primary{background-color:var(--formipay-color-primary);color:#fff}.formipay-btn-primary:hover:not(:disabled){background-color:#1e6ae6}.formipay-btn-secondary{background-color:#f0f0f1;color:var(--formipay-color-text)}.formipay-btn-secondary:hover:not(:disabled){background-color:#e0e0e1}.formipay-btn-danger{background-color:var(--formipay-color-danger);color:#fff}.formipay-btn-danger:hover:not(:disabled){background-color:#b32d2e}.formipay-btn-sm{font-size:var(--formipay-font-size-sm);padding:6px 12px}.formipay-btn-icon{aspect-ratio:1;padding:8px}.formipay-repeater{display:flex;flex-direction:column;gap:var(--formipay-spacing-md)}.formipay-repeater-item{background-color:#fafafa;border:1px solid var(--formipay-color-border);border-radius:var(--formipay-radius-sm);overflow:hidden}.formipay-repeater-header{align-items:center;background-color:#fff;border-bottom:1px solid var(--formipay-color-border);cursor:pointer;display:flex;justify-content:space-between;padding:var(--formipay-spacing-md) var(--formipay-spacing-lg);-webkit-user-select:none;-moz-user-select:none;user-select:none}.formipay-repeater-header:hover{background-color:#f8f9fa}.formipay-repeater-title{align-items:center;display:flex;font-weight:var(--formipay-font-weight-medium);gap:var(--formipay-spacing-sm)}.formipay-repeater-toggle{align-items:center;display:flex;height:20px;justify-content:center;transition:transform var(--formipay-transition-fast);width:20px}.formipay-repeater-item.collapsed .formipay-repeater-toggle{transform:rotate(-90deg)}.formipay-repeater-body{padding:var(--formipay-spacing-lg)}.formipay-repeater-item.collapsed .formipay-repeater-body{display:none}.formipay-repeater-actions{display:flex;gap:var(--formipay-spacing-sm)}.formipay-repeater-delete{color:var(--formipay-color-danger);cursor:pointer;transition:color var(--formipay-transition-fast)}.formipay-repeater-delete:hover{color:#b32d2e}.formipay-repeater-add{align-items:center;background-color:transparent;border:1px dashed var(--formipay-color-border-dark);border-radius:var(--formipay-radius-sm);color:var(--formipay-color-text-muted);cursor:pointer;display:flex;gap:var(--formipay-spacing-sm);padding:var(--formipay-spacing-md) var(--formipay-spacing-lg);transition:all var(--formipay-transition-fast)}.formipay-repeater-add:hover{background-color:rgba(41,133,247,.05);border-color:var(--formipay-color-primary);color:var(--formipay-color-primary)}.formipay-table-wrapper{background-color:var(--formipay-color-content-bg);border-radius:var(--formipay-radius-md);box-shadow:var(--formipay-shadow-sm);overflow:hidden}.formipay-table{border-collapse:collapse;width:100%}.formipay-table thead{background-color:#f8f9fa}.formipay-table th{color:var(--formipay-color-text-muted);font-size:var(--formipay-font-size-sm);font-weight:var(--formipay-font-weight-semibold);letter-spacing:.5px;text-align:left;text-transform:uppercase}.formipay-table td,.formipay-table th{border-bottom:1px solid var(--formipay-color-border);padding:12px 16px}.formipay-table tbody tr:last-child td{border-bottom:none}.formipay-table tbody tr:hover{background-color:#f8f9fa}.formipay-badge{align-items:center;border-radius:var(--formipay-radius-full);display:inline-flex;font-size:var(--formipay-font-size-sm);font-weight:var(--formipay-font-weight-medium);padding:4px 12px}.formipay-badge-success{background-color:#edfaef;color:var(--formipay-color-success)}.formipay-badge-warning{background-color:#fff8e5;color:var(--formipay-color-warning)}.formipay-badge-danger{background-color:#fce8e6;color:var(--formipay-color-danger)}.formipay-badge-info{background-color:#e7f3ff;color:var(--formipay-color-primary)}.formipay-badge-default{background-color:#f0f0f1;color:var(--formipay-color-text-muted)}.formipay-group-title{align-items:center;border-bottom:1px solid #d6dade;color:var(--formipay-color-text-muted);display:flex;font-size:14px;font-weight:400;gap:8px;letter-spacing:1.4px;margin:0 0 17px;padding:0 0 12px;text-transform:uppercase;width:100%}.formipay-group-title i{display:block}.formipay-notice{align-items:flex-start;border-radius:var(--formipay-radius-sm);display:flex;gap:var(--formipay-spacing-md);margin:var(--formipay-spacing-md) 0;padding:var(--formipay-spacing-md) var(--formipay-spacing-lg)}.formipay-notice-icon{flex-shrink:0;height:20px;width:20px}.formipay-notice-content{flex:1}.formipay-notice-title{font-weight:var(--formipay-font-weight-semibold);margin-bottom:var(--formipay-spacing-xs)}.formipay-notice-success{background-color:#edfaef;border-left:4px solid var(--formipay-color-success)}.formipay-notice-warning{background-color:#fff8e5;border-left:4px solid var(--formipay-color-warning)}.formipay-notice-error{background-color:#fce8e6;border-left:4px solid var(--formipay-color-danger)}.formipay-notice-info{background-color:#e7f3ff;border-left:4px solid var(--formipay-color-primary)}.formipay-loading{align-items:center;display:flex;justify-content:center;padding:40px}.formipay-spinner{animation:formipay-spin .8s linear infinite;border:3px solid var(--formipay-color-border);border-radius:50%;border-top-color:var(--formipay-color-primary);height:32px;width:32px}@keyframes formipay-spin{to{transform:rotate(1turn)}}.formipay-empty-state{align-items:center;display:flex;flex-direction:column;justify-content:center;padding:60px 40px;text-align:center}.formipay-empty-icon{color:var(--formipay-color-border-dark);font-size:48px;margin-bottom:var(--formipay-spacing-md)}.formipay-empty-title{font-size:var(--formipay-font-size-lg);font-weight:var(--formipay-font-weight-semibold);margin-bottom:var(--formipay-spacing-sm)}.formipay-empty-description{color:var(--formipay-color-text-muted);margin-bottom:var(--formipay-spacing-lg)}.formipay-text-center{text-align:center}.formipay-text-right{text-align:right}.formipay-text-muted{color:var(--formipay-color-text-muted)}.formipay-text-small{font-size:var(--formipay-font-size-sm)}.formipay-text-large{font-size:var(--formipay-font-size-lg)}.formipay-mt-0{margin-top:0}.formipay-mt-1{margin-top:var(--formipay-spacing-xs)}.formipay-mt-2{margin-top:var(--formipay-spacing-sm)}.formipay-mt-3{margin-top:var(--formipay-spacing-md)}.formipay-mt-4{margin-top:var(--formipay-spacing-lg)}.formipay-mb-0{margin-bottom:0}.formipay-mb-1{margin-bottom:var(--formipay-spacing-xs)}.formipay-mb-2{margin-bottom:var(--formipay-spacing-sm)}.formipay-mb-3{margin-bottom:var(--formipay-spacing-md)}.formipay-mb-4{margin-bottom:var(--formipay-spacing-lg)}.formipay-flex{display:flex}.formipay-flex-center{align-items:center;display:flex;justify-content:center}.formipay-flex-between{align-items:center;display:flex;justify-content:space-between}.formipay-flex-column{display:flex;flex-direction:column}.formipay-gap-1{gap:var(--formipay-spacing-xs)}.formipay-gap-2{gap:var(--formipay-spacing-sm)}.formipay-gap-3{gap:var(--formipay-spacing-md)}.formipay-gap-4{gap:var(--formipay-spacing-lg)}.formipay-wpcfto-metabox{background-color:#fff;border-radius:var(--formipay-radius-md);box-shadow:var(--formipay-shadow-sm);overflow:hidden}.formipay-wpcfto-metabox-inner{display:flex;min-height:400px}.formipay-wpcfto-container{display:flex;position:relative;width:100%}.formipay-wpcfto-container.horizontal{flex-direction:column}.formipay-wpcfto-container.horizontal .formipay-wpcfto-tab-nav{flex-direction:row;overflow-x:auto;padding:0;width:100%}.formipay-wpcfto-container.horizontal .formipay-wpcfto-tabs{width:100%}@media (max-width:768px){.formipay-tab-nav{flex-direction:row;overflow-x:auto}.formipay-nav-item{flex-shrink:0}.formipay-field{padding:var(--formipay-spacing-md) 0}} +.formipay-coupon-metabox{margin:-12px}.formipay-metabox-actions{background-color:#fff;border-top:1px solid #f0f0f1;display:flex;gap:12px;justify-content:flex-end;padding:20px 30px}.formipay-radio-group{display:flex;gap:16px}.formipay-radio{align-items:center;border:2px solid var(--formipay-color-border-dark);border-radius:var(--formipay-radius-lg);cursor:pointer;display:inline-flex;gap:8px;padding:8px 16px;transition:all var(--formipay-transition-fast)}.formipay-radio input{height:0;opacity:0;position:absolute;width:0}.formipay-radio span{color:var(--formipay-color-text-muted);font-weight:var(--formipay-font-weight-medium)}.formipay-radio.active,.formipay-radio:hover{border-color:var(--formipay-color-primary)}.formipay-radio.active{background-color:var(--formipay-color-primary)}.formipay-radio.active span{color:#fff}.formipay-autocomplete{position:relative}.formipay-autocomplete-selected{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:8px}.formipay-autocomplete-tag{align-items:center;background-color:var(--formipay-color-primary);border-radius:4px;color:#fff;display:inline-flex;font-size:var(--formipay-font-size-sm);gap:4px;padding:4px 8px}.formipay-autocomplete-remove{align-items:center;background:none;border:none;color:#fff;cursor:pointer;display:flex;font-size:16px;height:16px;justify-content:center;line-height:1;padding:0;width:16px}.formipay-autocomplete-remove:hover{opacity:.8}.formipay-autocomplete-input-wrapper{position:relative}.formipay-autocomplete-loading{color:var(--formipay-color-text-muted);position:absolute;right:12px;top:50%;transform:translateY(-50%)}.formipay-autocomplete-results{background-color:#fff;border:1px solid var(--formipay-color-border-dark);border-radius:var(--formipay-radius-sm);box-shadow:var(--formipay-shadow-md);left:0;margin-top:4px;max-height:200px;overflow-y:auto;position:absolute;right:0;top:100%;z-index:100}.formipay-autocomplete-result{cursor:pointer;padding:10px 16px;transition:background-color var(--formipay-transition-fast)}.formipay-autocomplete-result:hover{background-color:var(--formipay-color-content-bg)}.formipay-autocomplete-result:first-child{border-radius:var(--formipay-radius-sm) var(--formipay-radius-sm) 0 0}.formipay-autocomplete-result:last-child{border-radius:0 0 var(--formipay-radius-sm) var(--formipay-radius-sm)} diff --git a/build/admin.js b/build/admin.js index 7062ac727..58f132de7 100644 --- a/build/admin.js +++ b/build/admin.js @@ -1 +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.i18n,r=window.wp.components,o=window.Swal;function l({initialData:e=[],columns:l,filterOptions:i=null,statusCounts:c=null,searchable:s=!0,searchPlaceholder:m=(0,n.__)("Search...","formipay"),sortable:p=!0,defaultSort:d={id:"ID",desc:!0},selectable:u=!0,pagination:f=!0,pageSize:y=10,pageSizeOptions:_=[10,20,50,100],actions:w={addNew:!1,bulkDelete:!0,inline:!0},emptyMessage:h=(0,n.__)("No items found","formipay"),ajaxUrl:E,nonce:b,tableAction:g,deleteAction:v,duplicateAction:k,onSelectionChange:N}){const[C,S]=(0,a.useState)(e),[D,A]=(0,a.useState)(!0),[x,P]=(0,a.useState)(0),[I,T]=(0,a.useState)("all"),[U,B]=(0,a.useState)(""),[O,$]=(0,a.useState)(d.id||"ID"),[j,L]=(0,a.useState)(d.desc?"desc":"asc"),[F,R]=(0,a.useState)(1),[M,z]=(0,a.useState)(y),[q,J]=(0,a.useState)(new Set),[H,Z]=(0,a.useState)(!1);(0,a.useEffect)(()=>{N&&N(q)},[q,N]);const[V,X]=(0,a.useState)(!1),[G,W]=(0,a.useState)(""),K=g.replace("formipay-tabledata-",""),Q=w.bulkDelete?.action||`formipay-bulk-delete-${K}`,Y=(0,a.useCallback)(async()=>{A(!0);const e=new URLSearchParams({action:g,_wpnonce:b,limit:M.toString(),offset:((F-1)*M).toString()});i&&"all"!==I&&e.append(i.key,I),U&&e.append("search",U),e.append("orderby",O),e.append("sort",j);try{const t=await fetch(`${E}?${e.toString()}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e}),a=await t.json(),n=a.data?.results||a.results||a.data||[];S(n),P(a.total||n.length)}catch(e){console.error("Load data error:",e)}finally{A(!1)}},[E,b,g,M,F,I,U,O,j,i]);return(0,a.useEffect)(()=>{Y()},[Y]),(0,a.useEffect)(()=>{const e=setTimeout(()=>{null!==U&&R(1)},500);return()=>clearTimeout(e)},[U]),(0,t.createElement)("div",{className:"formipay-data-table-wrapper"},(0,t.createElement)("div",{className:"formipay-table-toolbar"},w.addNew&&(0,t.createElement)(r.Button,{variant:"primary",onClick:()=>X(!0)},w.addNew.label||(0,n.__)("+ Add New","formipay")),w.bulkDelete&&u&&q.size>0&&(0,t.createElement)(r.Button,{variant:"secondary",isDestructive:!0,onClick:async()=>{0!==q.size&&(await o.fire({icon:"info",html:(0,n.__)("Do you want to delete the selected item(s)?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${E}?action=${Q}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({ids:Array.from(q),_wpnonce:b})}),J(new Set),Z(!1),Y(),o.fire({title:(0,n.__)("Done!","formipay"),html:(0,n.__)("Items deleted successfully.","formipay"),icon:"success"}))}},(0,n.__)("Delete Selected","formipay")," (",q.size,")"),s&&(0,t.createElement)(r.TextControl,{placeholder:m,value:U,onChange:B,className:"formipay-table-search"}),p&&(0,t.createElement)(r.SelectControl,{value:`${O}-${j}`,options:[{label:(0,n.__)("ID ↓","formipay"),value:"ID-desc"},{label:(0,n.__)("ID ↑","formipay"),value:"ID-asc"},{label:(0,n.__)("Date ↓","formipay"),value:"date-desc"},{label:(0,n.__)("Date ↑","formipay"),value:"date-asc"},{label:(0,n.__)("Title A-Z","formipay"),value:"title-asc"},{label:(0,n.__)("Title Z-A","formipay"),value:"title-desc"}],onChange:e=>{const[t,a]=e.split("-");$(t),L(a)}}),(0,t.createElement)(r.Button,{variant:"secondary",onClick:Y,disabled:D},D?(0,n.__)("Refreshing...","formipay"):(0,n.__)("Refresh","formipay"))),i&&(0,t.createElement)("div",{className:"formipay-filter-tabs"},i.options.map(e=>(0,t.createElement)("button",{key:e.value,className:"filter-tab "+(I===e.value?"active":""),onClick:()=>{return t=e.value,T(t),void R(1);var t}},e.label,c&&(0,t.createElement)("span",{className:"count"},c[e.value]||0)))),(0,t.createElement)("div",{className:"formipay-table-container"},D?(0,t.createElement)("div",{className:"formipay-table-loading"},(0,t.createElement)(r.Spinner,null)):0===C.length?(0,t.createElement)("div",{className:"formipay-table-empty"},h):(0,t.createElement)("table",{className:"formipay-table wp-list-table widefat fixed striped"},(0,t.createElement)("thead",null,(0,t.createElement)("tr",null,u&&(0,t.createElement)("th",{className:"column-select"},(0,t.createElement)("input",{type:"checkbox",checked:H,onChange:()=>{J(H?new Set:new Set(C.map(e=>e.ID||e.id))),Z(!H)}})),l.map(e=>(0,t.createElement)("th",{key:e.key,className:`column-${e.key}`},e.label)))),(0,t.createElement)("tbody",null,C.map((e,a)=>{const n=e.ID||e.id;return(0,t.createElement)("tr",{key:a,className:"formipay-table-row"},u&&(0,t.createElement)("td",null,(0,t.createElement)("input",{type:"checkbox",checked:q.has(n),onChange:()=>(e=>{const t=new Set(q);t.has(e)?t.delete(e):t.add(e),J(t),Z(!1)})(n)})),l.map(a=>(0,t.createElement)("td",{key:a.key},a.render?a.render(e):e[a.key])))})))),f&&x>M&&(0,t.createElement)("div",{className:"formipay-table-pagination"},(0,t.createElement)("div",{className:"pagination-info"},(0,n.__)("Showing","formipay")," ",(F-1)*M+1," - ",Math.min(F*M,x)," ",(0,n.__)("of","formipay")," ",x),(0,t.createElement)("div",{className:"pagination-controls"},(0,t.createElement)(r.Button,{variant:"secondary",disabled:1===F,onClick:()=>R(1)},"««"),(0,t.createElement)(r.Button,{variant:"secondary",disabled:1===F,onClick:()=>R(F-1)},"‹"),(0,t.createElement)("span",{className:"page-info"},(0,n.__)("Page","formipay")," ",F," ",(0,n.__)("of","formipay")," ",Math.ceil(x/M)),(0,t.createElement)(r.Button,{variant:"secondary",disabled:F>=Math.ceil(x/M),onClick:()=>R(F+1)},"›"),(0,t.createElement)(r.Button,{variant:"secondary",disabled:F>=Math.ceil(x/M),onClick:()=>R(Math.ceil(x/M))},"»"),(0,t.createElement)(r.SelectControl,{value:M.toString(),options:_.map(e=>({label:e.toString(),value:e.toString()})),onChange:e=>{z(parseInt(e)),R(1)}}))),w.addNew&&V&&(0,t.createElement)(r.Modal,{title:w.addNew.label||(0,n.__)("Add New","formipay"),onRequestClose:()=>{X(!1),W("")}},(0,t.createElement)(r.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:(0,n.__)("Title","formipay"),value:G,onChange:W,autoFocus:!0}),(0,t.createElement)("div",{className:"formipay-modal-actions"},(0,t.createElement)(r.Button,{variant:"secondary",onClick:()=>{X(!1),W("")}},(0,n.__)("Cancel","formipay")),(0,t.createElement)(r.Button,{variant:"primary",onClick:async()=>{if(!G.trim())return void o.fire({html:(0,n.__)("Title is required.","formipay"),icon:"error"});const e=w.addNew.action,t=await fetch(`${E}?action=${e}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({title:G,_wpnonce:b})}),a=await t.json();a.success?(X(!1),W(""),a.data.edit_post_url?window.location.href=a.data.edit_post_url:Y()):o.fire({html:a.data.message||(0,n.__)("Error creating item.","formipay"),icon:"error"})}},(0,n.__)("Create","formipay")))))}const i=(0,a.forwardRef)(function({icon:e,size:t=24,...n},r){return(0,a.cloneElement)(e,{width:t,height:t,...n,ref:r})}),c=window.wp["icons/build/arrowLeft"];var s=e.n(c);const m=window.wp["icons/build/trash"];var p=e.n(m);const d=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",u=window.formipayAdmin?.nonce||"";async function f(e,t={}){const a=new FormData;a.append("action",e),a.append("_wpnonce",u),Object.keys(t).forEach(e=>{"object"==typeof t[e]?a.append(e,JSON.stringify(t[e])):a.append(e,t[e])}),console.log(`[AJAX] Sending request: ${e}`,{nonce:u,data:t});try{const t=await fetch(d,{method:"POST",credentials:"same-origin",body:a});console.log(`[AJAX] Response status: ${e}`,t.status);const n=await t.json();if(console.log(`[AJAX] Response data: ${e}`,n),!t.ok||!1===n.success){const e=n.data?.message||n.message||"Request failed";throw new Error(e)}return n}catch(t){throw console.error(`AJAX error [${e}]:`,t),t}}window.formipayAdmin;const y=["on-hold","payment-confirm","in-progress","shipping","completed"],_={"on-hold":(0,n.__)("On Hold","formipay"),"payment-confirm":(0,n.__)("Payment Confirmed","formipay"),"in-progress":(0,n.__)("In Progress","formipay"),shipping:(0,n.__)("Shipping","formipay"),completed:(0,n.__)("Completed","formipay"),failed:(0,n.__)("Failed","formipay"),refunded:(0,n.__)("Refunded","formipay"),cancelled:(0,n.__)("Cancelled","formipay")};function w({orderId:e}){const[r,o]=(0,a.useState)([]);return(0,a.useEffect)(()=>{const e=[{status:"on-hold",date:(new Date).toISOString(),note:(0,n.__)("Order placed","formipay")}];o(e)},[e]),(0,t.createElement)("div",{className:"formipay-order-timeline"},(0,t.createElement)("h3",null,(0,n.__)("Order Timeline","formipay")),(0,t.createElement)("div",{className:"timeline-progress"},y.map((e,a)=>(0,t.createElement)("div",{key:e,className:`timeline-step ${0===a?"first":""} ${a===y.length-1?"last":""}`},(0,t.createElement)("div",{className:"timeline-dot"}),a(0,t.createElement)("li",{key:a},(0,t.createElement)("span",{className:"event-status"},_[e.status]||e.status),(0,t.createElement)("span",{className:"event-date"},new Date(e.date).toLocaleString()),e.note&&(0,t.createElement)("span",{className:"event-note"},e.note))))))}const h=window.wp["icons/build/bell"];var E=e.n(h);const b=window.wp["icons/build/message"];var g=e.n(b);function v(){const e=[{id:1,type:"email",recipient:"customer@example.com",subject:"Order Confirmation",status:"sent",date:(new Date).toISOString()}],a=e=>{switch(e){case"email":default:return E()();case"sms":case"whatsapp":return g()()}};return(0,t.createElement)("div",{className:"formipay-notification-log"},(0,t.createElement)("h3",null,(0,t.createElement)(i,{icon:E()(),size:18}),(0,n.__)("Notification Log","formipay")),0===e.length?(0,t.createElement)("p",{className:"no-logs"},(0,n.__)("No notifications sent yet","formipay")):(0,t.createElement)("ul",{className:"notification-list"},e.map(e=>(0,t.createElement)("li",{key:e.id,className:`notification-item ${e.status}`},(0,t.createElement)("div",{className:"notification-icon"},(0,t.createElement)(i,{icon:a(e.type),size:20})),(0,t.createElement)("div",{className:"notification-content"},(0,t.createElement)("div",{className:"notification-header"},(0,t.createElement)("span",{className:"notification-type"},e.type.toUpperCase()),(0,t.createElement)("span",{className:"notification-status"},e.status)),(0,t.createElement)("div",{className:"notification-details"},(0,t.createElement)("strong",null,e.subject||e.type),(0,t.createElement)("span",{className:"notification-recipient"},(0,n.__)("To:","formipay")," ",e.recipient)),(0,t.createElement)("div",{className:"notification-date"},new Date(e.date).toLocaleString()))))))}const k=[{value:"on-hold",label:(0,n.__)("On Hold","formipay")},{value:"payment-confirm",label:(0,n.__)("Payment Confirmed","formipay")},{value:"in-progress",label:(0,n.__)("In Progress","formipay")},{value:"shipping",label:(0,n.__)("Shipping","formipay")},{value:"completed",label:(0,n.__)("Completed","formipay")},{value:"failed",label:(0,n.__)("Failed","formipay")},{value:"refunded",label:(0,n.__)("Refunded","formipay")},{value:"cancelled",label:(0,n.__)("Cancelled","formipay")}];function N({orderId:e,onBack:o}){const[l,c]=(0,a.useState)(null),[m,d]=(0,a.useState)(!0),[u,y]=(0,a.useState)(!1),[_,h]=(0,a.useState)(""),E=(0,a.useCallback)(()=>{d(!0),(e=>f("formipay-get-order",{order_id:e}))(e).then(e=>{e.data&&(c(e.data),h(e.data.status))}).catch(e=>{console.error("Load order error:",e)}).finally(()=>{d(!1)})},[e]);return(0,a.useEffect)(()=>{E()},[E]),m?(0,t.createElement)("div",{className:"formipay-order-detail"},(0,t.createElement)("div",{className:"formipay-loading"},(0,t.createElement)("span",{className:"spinner is-active"}))):l?(0,t.createElement)("div",{className:"formipay-order-detail"},(0,t.createElement)("div",{className:"formipay-detail-header"},(0,t.createElement)(r.Button,{variant:"secondary",onClick:o},(0,t.createElement)(i,{icon:s()(),size:16}),(0,n.__)("Back","formipay")),(0,t.createElement)("h1",null,(0,n.__)("Order","formipay")," #",l.id),(0,t.createElement)("div",{className:"header-actions"},(0,t.createElement)(r.Button,{variant:"secondary",isDestructive:!0,onClick:()=>{var t;confirm((0,n.__)("Are you sure you want to delete this order?","formipay"))&&(t=[e],f("formipay-bulk-delete-order",{ids:t})).then(e=>{e.success&&o?.()}).catch(e=>{console.error("Delete order error:",e)})}},(0,t.createElement)(i,{icon:p()(),size:16}),(0,n.__)("Delete","formipay")))),(0,t.createElement)("div",{className:"formipay-detail-content"},(0,t.createElement)("div",{className:"formipay-detail-main"},(0,t.createElement)("div",{className:"formipay-detail-card"},(0,t.createElement)("h3",null,(0,n.__)("Order Details","formipay")),(0,t.createElement)("dl",{className:"detail-list"},(0,t.createElement)("div",null,(0,t.createElement)("dt",null,(0,n.__)("Status","formipay")),(0,t.createElement)("dd",null,(0,t.createElement)(r.SelectControl,{value:_,options:k,onChange:h,disabled:u}),_!==l.status&&(0,t.createElement)(r.Button,{variant:"primary",size:"small",onClick:()=>{_&&_!==l.status&&(y(!0),((e,t)=>f("formipay-update-order-status",{order_id:e,status:t}))(e,_).then(e=>{(e.success||e.data?.valid)&&E()}).catch(e=>{console.error("Update status error:",e)}).finally(()=>{y(!1)}))},disabled:u,isBusy:u},u?(0,n.__)("Updating...","formipay"):(0,n.__)("Update Status","formipay")))),(0,t.createElement)("div",null,(0,t.createElement)("dt",null,(0,n.__)("Date Created","formipay")),(0,t.createElement)("dd",null,(b=l.created_date)?new Date(b).toLocaleString():"-")),(0,t.createElement)("div",null,(0,t.createElement)("dt",null,(0,n.__)("Form ID","formipay")),(0,t.createElement)("dd",null,l.form_id)),(0,t.createElement)("div",null,(0,t.createElement)("dt",null,(0,n.__)("Payment Gateway","formipay")),(0,t.createElement)("dd",null,l.payment_gateway||"-")))),(0,t.createElement)("div",{className:"formipay-detail-card"},(0,t.createElement)("h3",null,(0,n.__)("Items","formipay")),(0,t.createElement)("table",{className:"items-table"},(0,t.createElement)("thead",null,(0,t.createElement)("tr",null,(0,t.createElement)("th",null,(0,n.__)("Item","formipay")),(0,t.createElement)("th",null,(0,n.__)("Qty","formipay")),(0,t.createElement)("th",null,(0,n.__)("Subtotal","formipay")))),(0,t.createElement)("tbody",null,l.items?.map((e,a)=>(0,t.createElement)("tr",{key:a},(0,t.createElement)("td",null,(0,t.createElement)("strong",null,e.item),e.description&&(0,t.createElement)("small",null,e.description)),(0,t.createElement)("td",null,e.qty||1),(0,t.createElement)("td",null,e.subtotal_formatted||e.subtotal)))||(0,t.createElement)("tr",null,(0,t.createElement)("td",{colSpan:"3",className:"text-center"},(0,n.__)("No items","formipay")))),(0,t.createElement)("tfoot",null,(0,t.createElement)("tr",null,(0,t.createElement)("td",{colSpan:"2"},(0,t.createElement)("strong",null,(0,n.__)("Total","formipay"))),(0,t.createElement)("td",null,(0,t.createElement)("strong",null,l.total_formatted||l.total))))))),(0,t.createElement)("div",{className:"formipay-detail-sidebar"},(0,t.createElement)("div",{className:"formipay-detail-card"},(0,t.createElement)("h3",null,(0,n.__)("Customer Information","formipay")),l.form_data?(0,t.createElement)("dl",{className:"customer-info"},Object.entries(l.form_data).map(([e,a])=>["payment","payment_gateway","coupon_code","qty"].includes(e)?null:(0,t.createElement)("div",{key:e},(0,t.createElement)("dt",null,e.replace(/_/g," ")),(0,t.createElement)("dd",null,a?.value||a||"-")))):(0,t.createElement)("p",{className:"no-data"},(0,n.__)("No customer data available","formipay"))),(0,t.createElement)(w,{orderId:e}),(0,t.createElement)(v,null)))):(0,t.createElement)("div",{className:"formipay-order-detail"},(0,t.createElement)("div",{className:"formipay-error"},(0,t.createElement)("p",null,(0,n.__)("Order not found","formipay")),(0,t.createElement)(r.Button,{variant:"secondary",onClick:o},(0,t.createElement)(i,{icon:s()(),size:16}),(0,n.__)("Back to Orders","formipay"))));var b}const C=window.wp.primitives,S=(0,t.createElement)(C.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,t.createElement)(C.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"}));function D({productId:e,productDetails:r}){const[o,l]=(0,a.useState)([]),[i,c]=(0,a.useState)([]),[s,m]=(0,a.useState)(!0),p=(0,a.useRef)(null),d=(0,a.useRef)(null),u=(0,a.useRef)(null),f=(0,a.useCallback)(()=>String(r?.default_currency||"").split(":::")[0]||r?.default_currency_code||"USD",[r]),y=(0,a.useCallback)(e=>{const t=r?.global_currencies||[],a=String(e).split(":::")[0],n=t.find(e=>String(e.currency).split(":::")[0]===a);return parseInt(n?.decimal_digits,10)||2},[r]),_=(0,a.useCallback)(()=>{const e=r?.global_selected_currencies||{};let t=Object.keys(e);if(!t.length){const e=r?.default_currency||"";e&&(t=[e])}return t.map(e=>{const t=String(e).split(":::")[0];return{currency:e,regular_price:"",sale_price:"",currency_decimal_digits:y(t)}})},[r,y]),w=(0,a.useCallback)(e=>{const t={...e};void 0===t.expanded&&(t.expanded=!1);const a=_(),n=e=>String(e).split(":::")[0];if(Array.isArray(t.prices)){const e=new Set(a.map(e=>n(e.currency)));t.prices=t.prices.filter(t=>t&&e.has(n(t.currency))),a.forEach(e=>{const a=n(e.currency);t.prices.some(e=>n(e.currency)===a)||t.prices.push(JSON.parse(JSON.stringify(e)))})}else t.prices=JSON.parse(JSON.stringify(a));Array.isArray(t.prices)&&0!==t.prices.length||(t.prices=JSON.parse(JSON.stringify(a))),t.prices.forEach(e=>{const t=n(e.currency);e.currency_decimal_digits=y(t),void 0!==e.regular_price&&null!==e.regular_price||(e.regular_price=""),void 0!==e.sale_price&&null!==e.sale_price||(e.sale_price="")});const r=f();return t.prices.sort((e,t)=>n(e.currency)===r?-1:n(t.currency)===r?1:0),delete t.price,delete t.sale,t},[_,y,f]),h=(0,a.useCallback)(()=>new Promise(e=>{let t=0;const a=setInterval(()=>{const n=document.querySelector('input[name="product_variation_attributes"]');if(n&&n.value)try{const t=JSON.parse(n.value);clearInterval(a),e(Array.isArray(t)?t:[])}catch(t){clearInterval(a),e([])}else++t>=100&&(clearInterval(a),e([]))},50)}),[]),E=(0,a.useCallback)(e=>{const t=e.map(e=>(e.attribute_variations||[]).map(e=>({label:e.variation_label}))).filter(e=>e.length>0);return t.length?t.reduce((e,t)=>e.flatMap(e=>t.map(t=>[].concat(e,t)))).map(e=>{const t=Array.isArray(e)?e.map(e=>e.label):[e.label];return{key:t.join("||"),label:t.join(" - ")}}):[]},[]),b=(0,a.useCallback)(async()=>{try{const e=await h();if(!e.length)return l([]),void g([]);const t=E(e).filter(e=>!i.includes(e.key)).map(e=>{const t=o.find(t=>t.key===e.key);return t?Object.assign(w(t),{name:e.label}):w({key:e.key,name:e.label,stock:"",weight:0,active:!0})});l(t),g(t)}catch(e){console.warn("Attributes not available; initializing empty variations."),l([]),g([])}},[h,E,i,o,w]),g=(0,a.useCallback)(e=>{p.current&&(p.current.value=JSON.stringify(e||[]))},[]),v=(0,a.useCallback)(async()=>{if(e)try{const t=new FormData;t.append("action","get_product_variables"),t.append("post_id",e),t.append("_wpnonce",window.formipayAdmin?.nonce||"");const a=await fetch(window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",{method:"POST",credentials:"same-origin",body:t}),n=await a.json();if(n.success&&Array.isArray(n.data)&&n.data.length){const e=n.data.map(e=>w(e));l(e),c([]),g(e)}else await b()}catch{await b()}else await b()},[e,w,b,g]),k=(0,a.useCallback)(()=>{const e=()=>{setTimeout(()=>{b()},200)},t=document.querySelector('input[name="product_variation_attributes"]');if(t){t.addEventListener("input",e),t.addEventListener("change",e);const a=new MutationObserver(e);a.observe(t,{attributes:!0,attributeFilter:["value"]}),u.current=a,d.current=setInterval(()=>{const t=document.querySelector('input[name="product_variation_attributes"]');t&&t.value!==p.current?.value&&e()},300)}return()=>{u.current&&u.current.disconnect(),d.current&&clearInterval(d.current)}},[b]);(0,a.useEffect)(()=>{const e=r?.multicurrency,t=r?.global_selected_currencies||{},a=Object.keys(t).length;return m(!e||a<=1),v(),k()},[r,v,k]);const N=(0,a.useCallback)((e,t,a,n)=>{const r=[...o];r[e].prices[t][a]=n,l(r),g(r)},[o,g]),C=(0,a.useCallback)(e=>{const t=[...o];t[e].expanded=!t[e].expanded,l(t)},[o]),S=(0,a.useCallback)((e,t,a)=>{const n=[...o];n[e][t]=a,l(n),g(n)},[o,g]),D=(0,a.useCallback)(e=>{const t=o[e],a=[...i,t.key];c(a);const n=o.filter((t,a)=>a!==e);l(n),g(n)},[o,i,g]),x=(0,a.useCallback)(()=>{const e=f();for(const t of o){const a=t.prices?.find(t=>String(t.currency).split(":::")[0]===e);if(!a||!a.regular_price)return{currencyCode:e,rowLabel:t.name}}return null},[o,f]);return(0,a.useEffect)(()=>{const e=document.getElementById("post");if(!e)return;const t=e=>{const t=x();if(t){e.preventDefault(),e.stopImmediatePropagation();const a=(r?.variation_table?.error_missing_default_price||'Please fill Regular Price for default currency (%1$s) in variation "%2$s".').replace("%1$s",t.currencyCode).replace("%2$s",t.rowLabel);return alert(a),!1}};return e.addEventListener("submit",t,!0),()=>e.removeEventListener("submit",t,!0)},[x,r]),(0,t.createElement)(t.Fragment,null,(0,t.createElement)("input",{ref:p,type:"hidden",name:"product_variation_variables",value:JSON.stringify(o)}),(0,t.createElement)("table",{className:"formipay-variation-table",id:"product-variables-table"},(0,t.createElement)("thead",null,(0,t.createElement)("tr",null,(0,t.createElement)("th",null,(0,n.__)("Variation","formipay")),s?(0,t.createElement)(t.Fragment,null,(0,t.createElement)("th",null,(0,n.__)("Price","formipay")),(0,t.createElement)("th",null,(0,n.__)("Sale Price","formipay"))):null,(0,t.createElement)("th",null,(0,n.__)("Stock","formipay")),(0,t.createElement)("th",null,(0,n.__)("Weight","formipay")),(0,t.createElement)("th",null,(0,n.__)("Actions","formipay")))),(0,t.createElement)("tbody",null,o.map((e,a)=>(0,t.createElement)(A,{key:e.key,row:e,rowIndex:a,showFlatPricing:s,defaultCurrencyCode:f(),onToggleExpanded:()=>C(a),onUpdatePrice:(e,t,n)=>N(a,e,t,n),onUpdateField:(e,t)=>S(a,e,t),onDelete:()=>D(a)})))))}function A({row:e,rowIndex:a,showFlatPricing:o,defaultCurrencyCode:l,onToggleExpanded:i,onUpdatePrice:c,onUpdateField:s,onDelete:m}){return(0,t.createElement)(t.Fragment,null,(0,t.createElement)("tr",{className:"variation-row"},(0,t.createElement)("td",{className:"variation-name"},(0,t.createElement)("button",{type:"button",className:"toggle-expand",onClick:i},e.expanded?"▼":"▶"),(0,t.createElement)("strong",null,e.name)),o&&e.prices?.[0]?(0,t.createElement)(t.Fragment,null,(0,t.createElement)(x,{price:e.prices[0],field:"regular_price",onChange:(e,t)=>c(0,e,t)}),(0,t.createElement)(x,{price:e.prices[0],field:"sale_price",onChange:(e,t)=>c(0,e,t)})):null,(0,t.createElement)("td",{className:"variation-stock"},(0,t.createElement)(r.TextControl,{type:"number",value:e.stock,onChange:e=>s("stock",e),placeholder:"Unlimited"})),(0,t.createElement)("td",{className:"variation-weight"},(0,t.createElement)(r.TextControl,{type:"number",value:e.weight,onChange:e=>s("weight",e),step:"0.01"})),(0,t.createElement)("td",{className:"variation-actions"},(0,t.createElement)(r.Button,{variant:"secondary",size:"small",isDestructive:!0,onClick:m,icon:S},(0,n.__)("Delete","formipay")))),!o&&e.expanded&&(0,t.createElement)("tr",{className:"variation-details-row"},(0,t.createElement)("td",{colSpan:"5"},(0,t.createElement)("table",{className:"inner-table"},(0,t.createElement)("tbody",null,(e.prices||[]).map((e,a)=>{const n=String(e.currency).split(":::")[0]===l,r=e.currency_decimal_digits?1/Math.pow(10,e.currency_decimal_digits):.01;return(0,t.createElement)("tr",{key:a},(0,t.createElement)("td",{className:"currency-name"},e.currency,n&&(0,t.createElement)("span",{className:"required"},"*")),(0,t.createElement)("td",null,(0,t.createElement)("input",{type:"number",value:e.regular_price,onChange:e=>c(a,"regular_price",e.target.value),step:r,placeholder:"Regular Price",required:n})),(0,t.createElement)("td",null,(0,t.createElement)("input",{type:"number",value:e.sale_price,onChange:e=>c(a,"sale_price",e.target.value),step:r,placeholder:"Sale Price"})))}))))))}function x({price:e,field:a,onChange:n}){if(!e)return(0,t.createElement)("td",{className:"price-cell"},"-");const r=e.currency_decimal_digits?1/Math.pow(10,e.currency_decimal_digits):.01;return(0,t.createElement)("td",{className:"price-cell"},(0,t.createElement)("input",{type:"number",value:e[a],onChange:e=>n(a,e.target.value),step:r,placeholder:"Auto"}))}const P=window.Swal,I=window.Swal,T=window.Swal,U=window.Swal,B=window.Swal;function O({currentPage:e,onPageNavigate:a}){const r=[{key:"forms",label:(0,n.__)("Forms","formipay")},{key:"products",label:(0,n.__)("Products","formipay")},{key:"coupons",label:(0,n.__)("Coupons","formipay")},{key:"orders",label:(0,n.__)("Orders","formipay")},{key:"customers",label:(0,n.__)("Customers","formipay")},{key:"access",label:(0,n.__)("Access","formipay")},{key:"licenses",label:(0,n.__)("Licenses","formipay")}];return(0,t.createElement)("div",{className:"formipay-navigation-menu"},(0,t.createElement)("img",{src:`${window.formipayAdmin?.pluginUrl||""}/admin/assets/img/formipay-logo-circle-white_256.png`,alt:"Formipay",width:"48",height:"48"}),(0,t.createElement)("nav",{className:"navigation-links"},r.map(n=>(0,t.createElement)("a",{key:n.key,href:`#${n.key}`,className:"nav-link "+(e===n.key?"active":""),onClick:e=>((e,t)=>{e.preventDefault(),a&&a(t)})(e,n.key)},n.label))))}const $={orders:function(){const[e,r]=(0,a.useState)(null);if(e)return(0,t.createElement)(N,{orderId:e,onBack:()=>r(null)});const o=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,t.createElement)("strong",null,"#",e.id)},{key:"created_date",label:(0,n.__)("Date","formipay"),render:e=>{const t=e.created_date||e.date;return t?new Date(t).toLocaleDateString():"-"}},{key:"customer",label:(0,n.__)("Customer","formipay"),render:e=>{if(e.form_data&&Array.isArray(e.form_data)){const t=e.form_data.find(e=>"name"===e.name)?.value,a=e.form_data.find(e=>"email"===e.name)?.value;return t||a||"-"}return"-"}},{key:"total",label:(0,n.__)("Total","formipay"),render:e=>e.total_formatted||e.total||"-"},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const a={"on-hold":(0,n.__)("On Hold","formipay"),"payment-confirm":(0,n.__)("Payment Confirmed","formipay"),"in-progress":(0,n.__)("In Progress","formipay"),shipping:(0,n.__)("Shipping","formipay"),completed:(0,n.__)("Completed","formipay"),failed:(0,n.__)("Failed","formipay"),refunded:(0,n.__)("Refunded","formipay"),cancelled:(0,n.__)("Cancelled","formipay")},r=e.status||"unknown";return(0,t.createElement)("span",{className:`status-label status-${r}`},a[r]||r)}},{key:"actions",label:(0,n.__)("Actions","formipay"),render:e=>(0,t.createElement)("button",{className:"button button-small",onClick:()=>r(e.id)},(0,n.__)("View","formipay"))}];return(0,t.createElement)(l,{columns:o,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-orders",selectable:!1,inline:!1,emptyMessage:(0,n.__)("No orders found","formipay")})},customers:function(){const e=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,t.createElement)("strong",null,"#",e.ID)},{key:"name",label:(0,n.__)("Name","formipay"),render:e=>(0,t.createElement)(t.Fragment,null,(0,t.createElement)("strong",null,e.name||e.full_name||"-"),(0,t.createElement)("span",{className:"row-actions"},(0,t.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/admin.php?page=formipay-customers&customer_id=${e.ID}`},(0,n.__)("view","formipay"))))},{key:"email",label:(0,n.__)("Email","formipay")},{key:"phone",label:(0,n.__)("Phone","formipay"),render:e=>e.phone||e.whatsapp||"-"},{key:"total_order",label:(0,n.__)("Total Orders","formipay"),render:e=>e.total_order||e.total_orders||0}];return(0,t.createElement)("div",{className:"formipay-page-customers"},(0,t.createElement)(l,{columns:e,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-customers",selectable:!1,inline:!1,emptyMessage:(0,n.__)("No customers found","formipay")}))},products:function(){const[e,r]=(0,a.useState)(!1),[o,i]=(0,a.useState)(null),c=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",s=window.formipayAdmin?.nonce||"";if(e&&o)return(0,t.createElement)("div",{className:"formipay-page-products"},(0,t.createElement)("div",{className:"formipay-page-header"},(0,t.createElement)("button",{type:"button",className:"button button-secondary",onClick:()=>r(!1)},"← ",(0,n.__)("Back to Products","formipay")),(0,t.createElement)("h1",null,(0,n.__)("Edit Product","formipay"))),(0,t.createElement)("div",{className:"formipay-product-editor"},(0,t.createElement)(D,{productId:o,productDetails:{}})));const m=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,t.createElement)("strong",null,"#",e.ID)},{key:"title",label:(0,n.__)("Title","formipay"),render:e=>(0,t.createElement)(t.Fragment,null,(0,t.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${e.ID}&action=edit`},(0,t.createElement)("strong",null,e.post_title||e.title||(0,n.__)("Untitled","formipay"))),(0,t.createElement)("span",{className:"row-actions"},(0,t.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${e.ID}&action=edit`},(0,n.__)("edit","formipay"))," | ",(0,t.createElement)("button",{className:"button-link",onClick:()=>{i(e.ID),r(!0)}},(0,n.__)("edit variations","formipay"))," | ",(0,t.createElement)("button",{className:"button-link delete",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async e=>{(await P.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${c}?action=formipay-delete-product`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:e,_wpnonce:s})}),window.location.reload())})(e.ID)}},(0,n.__)("delete","formipay"))," | ",(0,t.createElement)("button",{className:"button-link duplicate",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async e=>{(await P.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${c}?action=formipay-duplicate-product`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:e,_wpnonce:s})}),window.location.reload())})(e.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"price",label:(0,n.__)("Price","formipay"),render:e=>{const a=e.prices||e.price;return Array.isArray(a)&&a.length>0?a.map(e=>(0,t.createElement)("div",{key:e.currency,style:{display:"flex",alignItems:"center",gap:"4px",marginBottom:"2px"}},e.flag&&(0,t.createElement)("img",{src:e.flag,alt:"",height:"14",style:{verticalAlign:"middle"}}),e.has_sale?(0,t.createElement)(t.Fragment,null,(0,t.createElement)("span",{style:{fontSize:"12px",textDecoration:"line-through",opacity:"0.7",marginRight:"4px"}},e.regular_price),(0,t.createElement)("span",{style:{fontSize:"13px",fontWeight:"500"}},e.sale_price)):(0,t.createElement)("span",{style:{fontSize:"13px"}},e.regular_price))):"-"}},{key:"type",label:(0,n.__)("Type","formipay"),render:e=>"physical"===(e.product_type||e.type||"digital")?(0,n.__)("Physical","formipay"):(0,n.__)("Digital","formipay")},{key:"stock",label:(0,n.__)("Stock","formipay"),render:e=>{const t=e.stock;return null===t||""===t?(0,n.__)("Unlimited","formipay"):t}},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const a=e.post_status||e.status||"unknown",r={publish:(0,n.__)("Published","formipay"),draft:(0,n.__)("Draft","formipay")};return(0,t.createElement)("span",{className:`status-label ${a}`},r[a]||a)}}];return(0,t.createElement)("div",{className:"formipay-page-products"},(0,t.createElement)(l,{columns:m,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-products",deleteAction:"formipay-delete-product",duplicateAction:"formipay-duplicate-product",filterOptions:{key:"post_status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"publish",label:(0,n.__)("Published","formipay")},{value:"draft",label:(0,n.__)("Draft","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Product","formipay"),action:"formipay-create-product-post"},bulkDelete:{action:"formipay-bulk-delete-product"},inline:!0},emptyMessage:(0,n.__)("No products found","formipay")}))},forms:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",a=window.formipayAdmin?.nonce||"",r=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,t.createElement)("strong",null,"#",e.ID)},{key:"title",label:(0,n.__)("Title","formipay"),render:r=>(0,t.createElement)(t.Fragment,null,(0,t.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,t.createElement)("strong",null,r.title)),(0,t.createElement)("span",{className:"row-actions"},(0,t.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,n.__)("edit","formipay"))," | ",(0,t.createElement)("button",{className:"button-link delete",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async t=>{(await I.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-form`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:t,_wpnonce:a})}),window.location.reload())})(r.ID)}},(0,n.__)("delete","formipay"))," | ",(0,t.createElement)("button",{className:"button-link duplicate",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async t=>{(await I.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-duplicate-form`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:t,_wpnonce:a})}),window.location.reload())})(r.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"date",label:(0,n.__)("Date","formipay"),render:e=>{const a=new Date(e.date);return(0,t.createElement)("span",{style:{whiteSpace:"nowrap"}},a.toLocaleDateString(),(0,t.createElement)("br",null),(0,t.createElement)("span",{style:{fontSize:"smaller",color:"#646970"}},a.toLocaleTimeString()))}},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const a=e.post_status||e.status||"unknown",r={publish:(0,n.__)("Published","formipay"),draft:(0,n.__)("Draft","formipay"),pending:(0,n.__)("Pending","formipay")};return(0,t.createElement)("span",{className:`status-label ${a}`},r[a]||a)}},{key:"shortcode",label:(0,n.__)("Shortcode","formipay"),render:e=>(0,t.createElement)(t.Fragment,null,(0,t.createElement)("input",{className:"formipay-form-shortcode",value:`[formipay form=${e.ID}]`,disabled:!0}),(0,t.createElement)("button",{className:"copy-shortcode","data-copy":`[formipay form=${e.ID}]`,onClick:e=>{const t=e.currentTarget.dataset.copy;navigator.clipboard.writeText(t).then(()=>{const t=e.currentTarget.innerHTML;e.currentTarget.innerHTML="[Copied]",setTimeout(()=>{e.currentTarget.innerHTML=t},2e3),I.fire({icon:"success",title:(0,n.__)("Shortcode copied!","formipay"),toast:!0,position:"top-end",showConfirmButton:!1,timer:3e3,timerProgressBar:!0})})}},(0,n.__)("Copy","formipay")))}];return(0,t.createElement)(l,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-forms",deleteAction:"formipay-delete-form",duplicateAction:"formipay-duplicate-form",filterOptions:{key:"post_status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"publish",label:(0,n.__)("Published","formipay")},{value:"draft",label:(0,n.__)("Draft","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Form","formipay"),action:"formipay-create-form-post"},bulkDelete:{action:"formipay-bulk-delete-form"},inline:!0},emptyMessage:(0,n.__)("No forms found","formipay")})},coupons:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",a=window.formipayAdmin?.nonce||"",r=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,t.createElement)("strong",null,"#",e.ID)},{key:"code",label:(0,n.__)("Coupon Code","formipay"),render:r=>(0,t.createElement)(t.Fragment,null,(0,t.createElement)("strong",null,r.code||r.post_title),(0,t.createElement)("span",{className:"row-actions"},(0,t.createElement)("button",{className:"button-link",onClick:e=>{var t;e.preventDefault(),t=r.ID,window.location.href=`/wp-admin/post.php?post=${t}&action=edit`}},(0,n.__)("edit","formipay"))," | ",(0,t.createElement)("button",{className:"button-link delete",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async t=>{(await T.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-coupon`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:t,_wpnonce:a})}),window.location.reload())})(r.ID)}},(0,n.__)("delete","formipay"))," | ",(0,t.createElement)("button",{className:"button-link duplicate",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async t=>{(await T.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-duplicate-coupon`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:t,_wpnonce:a})}),window.location.reload())})(r.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"type",label:(0,n.__)("Type","formipay"),render:e=>"percentage"===(e.coupon_type||e.type||"percentage")?(0,n.__)("%","formipay"):(0,n.__)("Fixed","formipay")},{key:"amount",label:(0,n.__)("Amount","formipay"),render:e=>{const a=e.amount;return Array.isArray(a)?a.map(e=>(0,t.createElement)("div",{key:e.raw,style:{display:"flex",alignItems:"center",gap:"4px"}},e.flag&&(0,t.createElement)("img",{src:e.flag,alt:"",height:"14",style:{verticalAlign:"middle"}}),(0,t.createElement)("span",null,e.amount))):"number"==typeof a?a+"%":a||"-"}},{key:"usages",label:(0,n.__)("Usages","formipay"),render:e=>e.usage_count||e.usages||0},{key:"date_limit",label:(0,n.__)("Date Limit","formipay"),render:e=>{const t=e.date_limit;return t&&"none"!==t?new Date(t).toLocaleDateString():(0,n.__)("Unlimited","formipay")}},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const a=e.post_status||e.status||"unknown",r="on"===e.active||"publish"===a;return(0,t.createElement)("span",{className:"status-label "+(r?"publish":"draft")},r?(0,n.__)("Active","formipay"):(0,n.__)("Inactive","formipay"))}}];return(0,t.createElement)("div",{className:"formipay-page-coupons"},(0,t.createElement)(l,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-coupons",deleteAction:"formipay-delete-coupon",duplicateAction:"formipay-duplicate-coupon",filterOptions:{key:"status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"active",label:(0,n.__)("Active","formipay")},{value:"inactive",label:(0,n.__)("Inactive","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Coupon","formipay"),href:"/wp-admin/post-new.php?post_type=formipay_coupon"},bulkDelete:{action:"formipay-bulk-delete-coupon"},inline:!0},emptyMessage:(0,n.__)("No coupons found","formipay")}))},access:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",a=window.formipayAdmin?.nonce||"",r=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,t.createElement)("strong",null,"#",e.ID)},{key:"title",label:(0,n.__)("Title","formipay"),render:r=>(0,t.createElement)(t.Fragment,null,(0,t.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,t.createElement)("strong",null,r.title||r.post_title||(0,n.__)("Untitled","formipay"))),(0,t.createElement)("span",{className:"row-actions"},(0,t.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,n.__)("edit","formipay"))," | ",(0,t.createElement)("button",{className:"button-link delete",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async t=>{(await U.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-access-item`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:t,_wpnonce:a})}),window.location.reload())})(r.ID)}},(0,n.__)("delete","formipay"))," | ",(0,t.createElement)("button",{className:"button-link duplicate",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async t=>{(await U.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-duplicate-access-item`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:t,_wpnonce:a})}),window.location.reload())})(r.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"product_name",label:(0,n.__)("Product","formipay")},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const a=e.post_status||e.status||"unknown",r={publish:(0,n.__)("Published","formipay"),draft:(0,n.__)("Draft","formipay")}[a]||a;return(0,t.createElement)("span",{className:`status-label ${a}`},r)}},{key:"date",label:(0,n.__)("Date","formipay"),render:e=>{const t=e.post_date||e.date;return t?new Date(t).toLocaleDateString():"-"}}];return(0,t.createElement)("div",{className:"formipay-page-access"},(0,t.createElement)(l,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-access-items",deleteAction:"formipay-delete-access-item",duplicateAction:"formipay-duplicate-access-item",filterOptions:{key:"post_status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"publish",label:(0,n.__)("Published","formipay")},{value:"draft",label:(0,n.__)("Draft","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Item","formipay"),action:"formipay-create-access-item-post"},bulkDelete:{action:"formipay-bulk-delete-access-item"},inline:!0},emptyMessage:(0,n.__)("No access items found","formipay")}))},licenses:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",a=window.formipayAdmin?.nonce||"",r=[{key:"id",label:(0,n.__)("ID","formipay"),render:e=>(0,t.createElement)("strong",null,"#",e.id)},{key:"license_key",label:(0,n.__)("License Key","formipay"),render:r=>(0,t.createElement)(t.Fragment,null,(0,t.createElement)("code",null,r.license_key||"-"),(0,t.createElement)("span",{className:"row-actions"},(0,t.createElement)("button",{className:"button-link delete",onClick:t=>{t.preventDefault(),t.stopPropagation(),(async t=>{(await B.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-license`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:t,_wpnonce:a})}),window.location.reload())})(r.id)}},(0,n.__)("delete","formipay"))))},{key:"product",label:(0,n.__)("Product","formipay"),render:e=>e.product_name||e.product||"-"},{key:"order",label:(0,n.__)("Order","formipay"),render:e=>e.order_id||`#${e.order}`||"-"},{key:"email",label:(0,n.__)("Email","formipay")},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const a=e.status||"unknown",r={active:(0,n.__)("Active","formipay"),inactive:(0,n.__)("Inactive","formipay"),expired:(0,n.__)("Expired","formipay")},o="active"===a?"publish":"expired"===a?"pending":"draft";return(0,t.createElement)("span",{className:`status-label ${o}`},r[a]||a)}}];return(0,t.createElement)("div",{className:"formipay-page-licenses"},(0,t.createElement)(l,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-licenses",selectable:!1,inline:!1,emptyMessage:(0,n.__)("No licenses found","formipay")}))}};function j({page:e,initialData:n}){const[r,o]=(0,a.useState)(()=>{const t=window.location.hash.replace("#","");return $[t]?t:e});(0,a.useEffect)(()=>{document.querySelectorAll("li.wp-first-item.current, li.wp-first-item .current").forEach(e=>{e.classList.remove("current","wp-first-item")});const e={forms:"admin.php?page=formipay",products:"admin.php?page=formipay-products",coupons:"admin.php?page=formipay-coupons",orders:"admin.php?page=formipay-orders",customers:"admin.php?page=formipay-customers",access:"admin.php?page=formipay-access",licenses:"admin.php?page=formipay-licenses"}[r];e&&document.querySelectorAll("#toplevel_page_formipay .wp-submenu a").forEach(t=>{t.parentElement.classList.remove("current"),t.classList.remove("current"),t.getAttribute("href")?.includes(e)&&("forms"===r?document.querySelectorAll("#toplevel_page_formipay .wp-submenu li:nth-child(2) a").forEach(e=>{e.parentElement.classList.add("current"),e.classList.add("current")}):(t.parentElement.classList.add("current"),t.classList.add("current")))})},[r]),(0,a.useEffect)(()=>{const e=()=>{const e=window.location.hash.replace("#","");$[e]&&o(e)};return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[]);const l=$[r];return l?(0,t.createElement)("div",{className:"formipay-admin-wrap"},(0,t.createElement)(O,{currentPage:r,onPageNavigate:e=>{o(e),window.location.hash=e}}),(0,t.createElement)(l,{initialData:n})):(0,t.createElement)("div",{className:"formipay-error"},(0,t.createElement)("p",null,"Unknown page: ",r))}const L=()=>{const e=document.querySelectorAll("[data-formipay-mount]");console.log("[Formipay] Mount points found:",e.length),console.log("[Formipay] formipayAdmin data:",window.formipayAdmin),e.forEach(e=>{const n=e.dataset.formipayMount,r=window.formipayAdmin?.[n]||{};console.log("[Formipay] Mounting page:",n,"with data:",r);try{(0,a.render)((0,t.createElement)(j,{page:n,initialData:r}),e),console.log("[Formipay] Successfully mounted:",n)}catch(e){console.error("[Formipay] Failed to mount:",n,e)}})};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",L):L()})(); \ No newline at end of file +(()=>{"use strict";var e={n:a=>{var t=a&&a.__esModule?()=>a.default:()=>a;return e.d(t,{a:t}),t},d:(a,t)=>{for(var n in t)e.o(t,n)&&!e.o(a,n)&&Object.defineProperty(a,n,{enumerable:!0,get:t[n]})},o:(e,a)=>Object.prototype.hasOwnProperty.call(e,a)};const a=window.React,t=window.wp.element,n=window.wp.i18n,r=window.wp.components,o=window.Swal;function i({initialData:e=[],columns:i,filterOptions:l=null,statusCounts:c=null,searchable:m=!0,searchPlaceholder:s=(0,n.__)("Search...","formipay"),sortable:p=!0,defaultSort:d={id:"ID",desc:!0},selectable:u=!0,pagination:f=!0,pageSize:y=10,pageSizeOptions:_=[10,20,50,100],actions:w={addNew:!1,bulkDelete:!0,inline:!0},emptyMessage:h=(0,n.__)("No items found","formipay"),ajaxUrl:E,nonce:b,tableAction:g,deleteAction:v,duplicateAction:k,onSelectionChange:N}){const[C,S]=(0,t.useState)(e),[x,D]=(0,t.useState)(!0),[A,T]=(0,t.useState)(0),[P,I]=(0,t.useState)("all"),[$,U]=(0,t.useState)(""),[j,O]=(0,t.useState)(d.id||"ID"),[L,B]=(0,t.useState)(d.desc?"desc":"asc"),[F,R]=(0,t.useState)(1),[M,q]=(0,t.useState)(y),[z,J]=(0,t.useState)(new Set),[H,G]=(0,t.useState)(!1);(0,t.useEffect)(()=>{N&&N(z)},[z,N]);const[Z,V]=(0,t.useState)(!1),[X,Q]=(0,t.useState)(""),W=g.replace("formipay-tabledata-",""),K=w.bulkDelete?.action||`formipay-bulk-delete-${W}`,Y=(0,t.useCallback)(async()=>{D(!0);const e=new URLSearchParams({action:g,_wpnonce:b,limit:M.toString(),offset:((F-1)*M).toString()});l&&"all"!==P&&e.append(l.key,P),$&&e.append("search",$),e.append("orderby",j),e.append("sort",L);try{const a=await fetch(`${E}?${e.toString()}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:e}),t=await a.json(),n=t.data?.results||t.results||t.data||[];S(n),T(t.total||n.length)}catch(e){console.error("Load data error:",e)}finally{D(!1)}},[E,b,g,M,F,P,$,j,L,l]);return(0,t.useEffect)(()=>{Y()},[Y]),(0,t.useEffect)(()=>{const e=setTimeout(()=>{null!==$&&R(1)},500);return()=>clearTimeout(e)},[$]),(0,a.createElement)("div",{className:"formipay-data-table-wrapper"},(0,a.createElement)("div",{className:"formipay-table-toolbar"},w.addNew&&(0,a.createElement)(r.Button,{variant:"primary",onClick:()=>V(!0)},w.addNew.label||(0,n.__)("+ Add New","formipay")),w.bulkDelete&&u&&z.size>0&&(0,a.createElement)(r.Button,{variant:"secondary",isDestructive:!0,onClick:async()=>{0!==z.size&&(await o.fire({icon:"info",html:(0,n.__)("Do you want to delete the selected item(s)?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${E}?action=${K}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({ids:Array.from(z),_wpnonce:b})}),J(new Set),G(!1),Y(),o.fire({title:(0,n.__)("Done!","formipay"),html:(0,n.__)("Items deleted successfully.","formipay"),icon:"success"}))}},(0,n.__)("Delete Selected","formipay")," (",z.size,")"),m&&(0,a.createElement)(r.TextControl,{placeholder:s,value:$,onChange:U,className:"formipay-table-search"}),p&&(0,a.createElement)(r.SelectControl,{value:`${j}-${L}`,options:[{label:(0,n.__)("ID ↓","formipay"),value:"ID-desc"},{label:(0,n.__)("ID ↑","formipay"),value:"ID-asc"},{label:(0,n.__)("Date ↓","formipay"),value:"date-desc"},{label:(0,n.__)("Date ↑","formipay"),value:"date-asc"},{label:(0,n.__)("Title A-Z","formipay"),value:"title-asc"},{label:(0,n.__)("Title Z-A","formipay"),value:"title-desc"}],onChange:e=>{const[a,t]=e.split("-");O(a),B(t)}}),(0,a.createElement)(r.Button,{variant:"secondary",onClick:Y,disabled:x},x?(0,n.__)("Refreshing...","formipay"):(0,n.__)("Refresh","formipay"))),l&&(0,a.createElement)("div",{className:"formipay-filter-tabs"},l.options.map(e=>(0,a.createElement)("button",{key:e.value,className:"filter-tab "+(P===e.value?"active":""),onClick:()=>{return a=e.value,I(a),void R(1);var a}},e.label,c&&(0,a.createElement)("span",{className:"count"},c[e.value]||0)))),(0,a.createElement)("div",{className:"formipay-table-container"},x?(0,a.createElement)("div",{className:"formipay-table-loading"},(0,a.createElement)(r.Spinner,null)):0===C.length?(0,a.createElement)("div",{className:"formipay-table-empty"},h):(0,a.createElement)("table",{className:"formipay-table wp-list-table widefat fixed striped"},(0,a.createElement)("thead",null,(0,a.createElement)("tr",null,u&&(0,a.createElement)("th",{className:"column-select"},(0,a.createElement)("input",{type:"checkbox",checked:H,onChange:()=>{J(H?new Set:new Set(C.map(e=>e.ID||e.id))),G(!H)}})),i.map(e=>(0,a.createElement)("th",{key:e.key,className:`column-${e.key}`},e.label)))),(0,a.createElement)("tbody",null,C.map((e,t)=>{const n=e.ID||e.id;return(0,a.createElement)("tr",{key:t,className:"formipay-table-row"},u&&(0,a.createElement)("td",null,(0,a.createElement)("input",{type:"checkbox",checked:z.has(n),onChange:()=>(e=>{const a=new Set(z);a.has(e)?a.delete(e):a.add(e),J(a),G(!1)})(n)})),i.map(t=>(0,a.createElement)("td",{key:t.key},t.render?t.render(e):e[t.key])))})))),f&&A>M&&(0,a.createElement)("div",{className:"formipay-table-pagination"},(0,a.createElement)("div",{className:"pagination-info"},(0,n.__)("Showing","formipay")," ",(F-1)*M+1," - ",Math.min(F*M,A)," ",(0,n.__)("of","formipay")," ",A),(0,a.createElement)("div",{className:"pagination-controls"},(0,a.createElement)(r.Button,{variant:"secondary",disabled:1===F,onClick:()=>R(1)},"««"),(0,a.createElement)(r.Button,{variant:"secondary",disabled:1===F,onClick:()=>R(F-1)},"‹"),(0,a.createElement)("span",{className:"page-info"},(0,n.__)("Page","formipay")," ",F," ",(0,n.__)("of","formipay")," ",Math.ceil(A/M)),(0,a.createElement)(r.Button,{variant:"secondary",disabled:F>=Math.ceil(A/M),onClick:()=>R(F+1)},"›"),(0,a.createElement)(r.Button,{variant:"secondary",disabled:F>=Math.ceil(A/M),onClick:()=>R(Math.ceil(A/M))},"»"),(0,a.createElement)(r.SelectControl,{value:M.toString(),options:_.map(e=>({label:e.toString(),value:e.toString()})),onChange:e=>{q(parseInt(e)),R(1)}}))),w.addNew&&Z&&(0,a.createElement)(r.Modal,{title:w.addNew.label||(0,n.__)("Add New","formipay"),onRequestClose:()=>{V(!1),Q("")}},(0,a.createElement)(r.TextControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,label:(0,n.__)("Title","formipay"),value:X,onChange:Q,autoFocus:!0}),(0,a.createElement)("div",{className:"formipay-modal-actions"},(0,a.createElement)(r.Button,{variant:"secondary",onClick:()=>{V(!1),Q("")}},(0,n.__)("Cancel","formipay")),(0,a.createElement)(r.Button,{variant:"primary",onClick:async()=>{if(!X.trim())return void o.fire({html:(0,n.__)("Title is required.","formipay"),icon:"error"});const e=w.addNew.action,a=await fetch(`${E}?action=${e}`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({title:X,_wpnonce:b})}),t=await a.json();t.success?(V(!1),Q(""),t.data.edit_post_url?window.location.href=t.data.edit_post_url:Y()):o.fire({html:t.data.message||(0,n.__)("Error creating item.","formipay"),icon:"error"})}},(0,n.__)("Create","formipay")))))}const l=(0,t.forwardRef)(function({icon:e,size:a=24,...n},r){return(0,t.cloneElement)(e,{width:a,height:a,...n,ref:r})}),c=window.wp["icons/build/arrowLeft"];var m=e.n(c);const s=window.wp["icons/build/trash"];var p=e.n(s);const d=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",u=window.formipayAdmin?.nonce||"";async function f(e,a={}){const t=new FormData;t.append("action",e),t.append("_wpnonce",u),Object.keys(a).forEach(e=>{"object"==typeof a[e]?t.append(e,JSON.stringify(a[e])):t.append(e,a[e])}),console.log(`[AJAX] Sending request: ${e}`,{nonce:u,data:a});try{const a=await fetch(d,{method:"POST",credentials:"same-origin",body:t});console.log(`[AJAX] Response status: ${e}`,a.status);const n=await a.json();if(console.log(`[AJAX] Response data: ${e}`,n),!a.ok||!1===n.success){const e=n.data?.message||n.message||"Request failed";throw new Error(e)}return n}catch(a){throw console.error(`AJAX error [${e}]:`,a),a}}window.formipayAdmin;const y=["on-hold","payment-confirm","in-progress","shipping","completed"],_={"on-hold":(0,n.__)("On Hold","formipay"),"payment-confirm":(0,n.__)("Payment Confirmed","formipay"),"in-progress":(0,n.__)("In Progress","formipay"),shipping:(0,n.__)("Shipping","formipay"),completed:(0,n.__)("Completed","formipay"),failed:(0,n.__)("Failed","formipay"),refunded:(0,n.__)("Refunded","formipay"),cancelled:(0,n.__)("Cancelled","formipay")};function w({orderId:e}){const[r,o]=(0,t.useState)([]);return(0,t.useEffect)(()=>{const e=[{status:"on-hold",date:(new Date).toISOString(),note:(0,n.__)("Order placed","formipay")}];o(e)},[e]),(0,a.createElement)("div",{className:"formipay-order-timeline"},(0,a.createElement)("h3",null,(0,n.__)("Order Timeline","formipay")),(0,a.createElement)("div",{className:"timeline-progress"},y.map((e,t)=>(0,a.createElement)("div",{key:e,className:`timeline-step ${0===t?"first":""} ${t===y.length-1?"last":""}`},(0,a.createElement)("div",{className:"timeline-dot"}),t(0,a.createElement)("li",{key:t},(0,a.createElement)("span",{className:"event-status"},_[e.status]||e.status),(0,a.createElement)("span",{className:"event-date"},new Date(e.date).toLocaleString()),e.note&&(0,a.createElement)("span",{className:"event-note"},e.note))))))}const h=window.wp["icons/build/bell"];var E=e.n(h);const b=window.wp["icons/build/message"];var g=e.n(b);function v(){const e=[{id:1,type:"email",recipient:"customer@example.com",subject:"Order Confirmation",status:"sent",date:(new Date).toISOString()}],t=e=>{switch(e){case"email":default:return E()();case"sms":case"whatsapp":return g()()}};return(0,a.createElement)("div",{className:"formipay-notification-log"},(0,a.createElement)("h3",null,(0,a.createElement)(l,{icon:E()(),size:18}),(0,n.__)("Notification Log","formipay")),0===e.length?(0,a.createElement)("p",{className:"no-logs"},(0,n.__)("No notifications sent yet","formipay")):(0,a.createElement)("ul",{className:"notification-list"},e.map(e=>(0,a.createElement)("li",{key:e.id,className:`notification-item ${e.status}`},(0,a.createElement)("div",{className:"notification-icon"},(0,a.createElement)(l,{icon:t(e.type),size:20})),(0,a.createElement)("div",{className:"notification-content"},(0,a.createElement)("div",{className:"notification-header"},(0,a.createElement)("span",{className:"notification-type"},e.type.toUpperCase()),(0,a.createElement)("span",{className:"notification-status"},e.status)),(0,a.createElement)("div",{className:"notification-details"},(0,a.createElement)("strong",null,e.subject||e.type),(0,a.createElement)("span",{className:"notification-recipient"},(0,n.__)("To:","formipay")," ",e.recipient)),(0,a.createElement)("div",{className:"notification-date"},new Date(e.date).toLocaleString()))))))}const k=[{value:"on-hold",label:(0,n.__)("On Hold","formipay")},{value:"payment-confirm",label:(0,n.__)("Payment Confirmed","formipay")},{value:"in-progress",label:(0,n.__)("In Progress","formipay")},{value:"shipping",label:(0,n.__)("Shipping","formipay")},{value:"completed",label:(0,n.__)("Completed","formipay")},{value:"failed",label:(0,n.__)("Failed","formipay")},{value:"refunded",label:(0,n.__)("Refunded","formipay")},{value:"cancelled",label:(0,n.__)("Cancelled","formipay")}];function N({orderId:e,onBack:o}){const[i,c]=(0,t.useState)(null),[s,d]=(0,t.useState)(!0),[u,y]=(0,t.useState)(!1),[_,h]=(0,t.useState)(""),E=(0,t.useCallback)(()=>{d(!0),(e=>f("formipay-get-order",{order_id:e}))(e).then(e=>{e.data&&(c(e.data),h(e.data.status))}).catch(e=>{console.error("Load order error:",e)}).finally(()=>{d(!1)})},[e]);return(0,t.useEffect)(()=>{E()},[E]),s?(0,a.createElement)("div",{className:"formipay-order-detail"},(0,a.createElement)("div",{className:"formipay-loading"},(0,a.createElement)("span",{className:"spinner is-active"}))):i?(0,a.createElement)("div",{className:"formipay-order-detail"},(0,a.createElement)("div",{className:"formipay-detail-header"},(0,a.createElement)(r.Button,{variant:"secondary",onClick:o},(0,a.createElement)(l,{icon:m()(),size:16}),(0,n.__)("Back","formipay")),(0,a.createElement)("h1",null,(0,n.__)("Order","formipay")," #",i.id),(0,a.createElement)("div",{className:"header-actions"},(0,a.createElement)(r.Button,{variant:"secondary",isDestructive:!0,onClick:()=>{var a;confirm((0,n.__)("Are you sure you want to delete this order?","formipay"))&&(a=[e],f("formipay-bulk-delete-order",{ids:a})).then(e=>{e.success&&o?.()}).catch(e=>{console.error("Delete order error:",e)})}},(0,a.createElement)(l,{icon:p()(),size:16}),(0,n.__)("Delete","formipay")))),(0,a.createElement)("div",{className:"formipay-detail-content"},(0,a.createElement)("div",{className:"formipay-detail-main"},(0,a.createElement)("div",{className:"formipay-detail-card"},(0,a.createElement)("h3",null,(0,n.__)("Order Details","formipay")),(0,a.createElement)("dl",{className:"detail-list"},(0,a.createElement)("div",null,(0,a.createElement)("dt",null,(0,n.__)("Status","formipay")),(0,a.createElement)("dd",null,(0,a.createElement)(r.SelectControl,{value:_,options:k,onChange:h,disabled:u}),_!==i.status&&(0,a.createElement)(r.Button,{variant:"primary",size:"small",onClick:()=>{_&&_!==i.status&&(y(!0),((e,a)=>f("formipay-update-order-status",{order_id:e,status:a}))(e,_).then(e=>{(e.success||e.data?.valid)&&E()}).catch(e=>{console.error("Update status error:",e)}).finally(()=>{y(!1)}))},disabled:u,isBusy:u},u?(0,n.__)("Updating...","formipay"):(0,n.__)("Update Status","formipay")))),(0,a.createElement)("div",null,(0,a.createElement)("dt",null,(0,n.__)("Date Created","formipay")),(0,a.createElement)("dd",null,(b=i.created_date)?new Date(b).toLocaleString():"-")),(0,a.createElement)("div",null,(0,a.createElement)("dt",null,(0,n.__)("Form ID","formipay")),(0,a.createElement)("dd",null,i.form_id)),(0,a.createElement)("div",null,(0,a.createElement)("dt",null,(0,n.__)("Payment Gateway","formipay")),(0,a.createElement)("dd",null,i.payment_gateway||"-")))),(0,a.createElement)("div",{className:"formipay-detail-card"},(0,a.createElement)("h3",null,(0,n.__)("Items","formipay")),(0,a.createElement)("table",{className:"items-table"},(0,a.createElement)("thead",null,(0,a.createElement)("tr",null,(0,a.createElement)("th",null,(0,n.__)("Item","formipay")),(0,a.createElement)("th",null,(0,n.__)("Qty","formipay")),(0,a.createElement)("th",null,(0,n.__)("Subtotal","formipay")))),(0,a.createElement)("tbody",null,i.items?.map((e,t)=>(0,a.createElement)("tr",{key:t},(0,a.createElement)("td",null,(0,a.createElement)("strong",null,e.item),e.description&&(0,a.createElement)("small",null,e.description)),(0,a.createElement)("td",null,e.qty||1),(0,a.createElement)("td",null,e.subtotal_formatted||e.subtotal)))||(0,a.createElement)("tr",null,(0,a.createElement)("td",{colSpan:"3",className:"text-center"},(0,n.__)("No items","formipay")))),(0,a.createElement)("tfoot",null,(0,a.createElement)("tr",null,(0,a.createElement)("td",{colSpan:"2"},(0,a.createElement)("strong",null,(0,n.__)("Total","formipay"))),(0,a.createElement)("td",null,(0,a.createElement)("strong",null,i.total_formatted||i.total))))))),(0,a.createElement)("div",{className:"formipay-detail-sidebar"},(0,a.createElement)("div",{className:"formipay-detail-card"},(0,a.createElement)("h3",null,(0,n.__)("Customer Information","formipay")),i.form_data?(0,a.createElement)("dl",{className:"customer-info"},Object.entries(i.form_data).map(([e,t])=>["payment","payment_gateway","coupon_code","qty"].includes(e)?null:(0,a.createElement)("div",{key:e},(0,a.createElement)("dt",null,e.replace(/_/g," ")),(0,a.createElement)("dd",null,t?.value||t||"-")))):(0,a.createElement)("p",{className:"no-data"},(0,n.__)("No customer data available","formipay"))),(0,a.createElement)(w,{orderId:e}),(0,a.createElement)(v,null)))):(0,a.createElement)("div",{className:"formipay-order-detail"},(0,a.createElement)("div",{className:"formipay-error"},(0,a.createElement)("p",null,(0,n.__)("Order not found","formipay")),(0,a.createElement)(r.Button,{variant:"secondary",onClick:o},(0,a.createElement)(l,{icon:m()(),size:16}),(0,n.__)("Back to Orders","formipay"))));var b}const C=window.wp.primitives,S=(0,a.createElement)(C.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(C.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"}));function x({productId:e,productDetails:r}){const[o,i]=(0,t.useState)([]),[l,c]=(0,t.useState)([]),[m,s]=(0,t.useState)(!0),p=(0,t.useRef)(null),d=(0,t.useRef)(null),u=(0,t.useRef)(null),f=(0,t.useCallback)(()=>String(r?.default_currency||"").split(":::")[0]||r?.default_currency_code||"USD",[r]),y=(0,t.useCallback)(e=>{const a=r?.global_currencies||[],t=String(e).split(":::")[0],n=a.find(e=>String(e.currency).split(":::")[0]===t);return parseInt(n?.decimal_digits,10)||2},[r]),_=(0,t.useCallback)(()=>{const e=r?.global_selected_currencies||{};let a=Object.keys(e);if(!a.length){const e=r?.default_currency||"";e&&(a=[e])}return a.map(e=>{const a=String(e).split(":::")[0];return{currency:e,regular_price:"",sale_price:"",currency_decimal_digits:y(a)}})},[r,y]),w=(0,t.useCallback)(e=>{const a={...e};void 0===a.expanded&&(a.expanded=!1);const t=_(),n=e=>String(e).split(":::")[0];if(Array.isArray(a.prices)){const e=new Set(t.map(e=>n(e.currency)));a.prices=a.prices.filter(a=>a&&e.has(n(a.currency))),t.forEach(e=>{const t=n(e.currency);a.prices.some(e=>n(e.currency)===t)||a.prices.push(JSON.parse(JSON.stringify(e)))})}else a.prices=JSON.parse(JSON.stringify(t));Array.isArray(a.prices)&&0!==a.prices.length||(a.prices=JSON.parse(JSON.stringify(t))),a.prices.forEach(e=>{const a=n(e.currency);e.currency_decimal_digits=y(a),void 0!==e.regular_price&&null!==e.regular_price||(e.regular_price=""),void 0!==e.sale_price&&null!==e.sale_price||(e.sale_price="")});const r=f();return a.prices.sort((e,a)=>n(e.currency)===r?-1:n(a.currency)===r?1:0),delete a.price,delete a.sale,a},[_,y,f]),h=(0,t.useCallback)(()=>new Promise(e=>{let a=0;const t=setInterval(()=>{const n=document.querySelector('input[name="product_variation_attributes"]');if(n&&n.value)try{const a=JSON.parse(n.value);clearInterval(t),e(Array.isArray(a)?a:[])}catch(a){clearInterval(t),e([])}else++a>=100&&(clearInterval(t),e([]))},50)}),[]),E=(0,t.useCallback)(e=>{const a=e.map(e=>(e.attribute_variations||[]).map(e=>({label:e.variation_label}))).filter(e=>e.length>0);return a.length?a.reduce((e,a)=>e.flatMap(e=>a.map(a=>[].concat(e,a)))).map(e=>{const a=Array.isArray(e)?e.map(e=>e.label):[e.label];return{key:a.join("||"),label:a.join(" - ")}}):[]},[]),b=(0,t.useCallback)(async()=>{try{const e=await h();if(!e.length)return i([]),void g([]);const a=E(e).filter(e=>!l.includes(e.key)).map(e=>{const a=o.find(a=>a.key===e.key);return a?Object.assign(w(a),{name:e.label}):w({key:e.key,name:e.label,stock:"",weight:0,active:!0})});i(a),g(a)}catch(e){console.warn("Attributes not available; initializing empty variations."),i([]),g([])}},[h,E,l,o,w]),g=(0,t.useCallback)(e=>{p.current&&(p.current.value=JSON.stringify(e||[]))},[]),v=(0,t.useCallback)(async()=>{if(e)try{const a=new FormData;a.append("action","get_product_variables"),a.append("post_id",e),a.append("_wpnonce",window.formipayAdmin?.nonce||"");const t=await fetch(window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",{method:"POST",credentials:"same-origin",body:a}),n=await t.json();if(n.success&&Array.isArray(n.data)&&n.data.length){const e=n.data.map(e=>w(e));i(e),c([]),g(e)}else await b()}catch{await b()}else await b()},[e,w,b,g]),k=(0,t.useCallback)(()=>{const e=()=>{setTimeout(()=>{b()},200)},a=document.querySelector('input[name="product_variation_attributes"]');if(a){a.addEventListener("input",e),a.addEventListener("change",e);const t=new MutationObserver(e);t.observe(a,{attributes:!0,attributeFilter:["value"]}),u.current=t,d.current=setInterval(()=>{const a=document.querySelector('input[name="product_variation_attributes"]');a&&a.value!==p.current?.value&&e()},300)}return()=>{u.current&&u.current.disconnect(),d.current&&clearInterval(d.current)}},[b]);(0,t.useEffect)(()=>{const e=r?.multicurrency,a=r?.global_selected_currencies||{},t=Object.keys(a).length;return s(!e||t<=1),v(),k()},[r,v,k]);const N=(0,t.useCallback)((e,a,t,n)=>{const r=[...o];r[e].prices[a][t]=n,i(r),g(r)},[o,g]),C=(0,t.useCallback)(e=>{const a=[...o];a[e].expanded=!a[e].expanded,i(a)},[o]),S=(0,t.useCallback)((e,a,t)=>{const n=[...o];n[e][a]=t,i(n),g(n)},[o,g]),x=(0,t.useCallback)(e=>{const a=o[e],t=[...l,a.key];c(t);const n=o.filter((a,t)=>t!==e);i(n),g(n)},[o,l,g]),A=(0,t.useCallback)(()=>{const e=f();for(const a of o){const t=a.prices?.find(a=>String(a.currency).split(":::")[0]===e);if(!t||!t.regular_price)return{currencyCode:e,rowLabel:a.name}}return null},[o,f]);return(0,t.useEffect)(()=>{const e=document.getElementById("post");if(!e)return;const a=e=>{const a=A();if(a){e.preventDefault(),e.stopImmediatePropagation();const t=(r?.variation_table?.error_missing_default_price||'Please fill Regular Price for default currency (%1$s) in variation "%2$s".').replace("%1$s",a.currencyCode).replace("%2$s",a.rowLabel);return alert(t),!1}};return e.addEventListener("submit",a,!0),()=>e.removeEventListener("submit",a,!0)},[A,r]),(0,a.createElement)(a.Fragment,null,(0,a.createElement)("input",{ref:p,type:"hidden",name:"product_variation_variables",value:JSON.stringify(o)}),(0,a.createElement)("table",{className:"formipay-variation-table",id:"product-variables-table"},(0,a.createElement)("thead",null,(0,a.createElement)("tr",null,(0,a.createElement)("th",null,(0,n.__)("Variation","formipay")),m?(0,a.createElement)(a.Fragment,null,(0,a.createElement)("th",null,(0,n.__)("Price","formipay")),(0,a.createElement)("th",null,(0,n.__)("Sale Price","formipay"))):null,(0,a.createElement)("th",null,(0,n.__)("Stock","formipay")),(0,a.createElement)("th",null,(0,n.__)("Weight","formipay")),(0,a.createElement)("th",null,(0,n.__)("Actions","formipay")))),(0,a.createElement)("tbody",null,o.map((e,t)=>(0,a.createElement)(D,{key:e.key,row:e,rowIndex:t,showFlatPricing:m,defaultCurrencyCode:f(),onToggleExpanded:()=>C(t),onUpdatePrice:(e,a,n)=>N(t,e,a,n),onUpdateField:(e,a)=>S(t,e,a),onDelete:()=>x(t)})))))}function D({row:e,rowIndex:t,showFlatPricing:o,defaultCurrencyCode:i,onToggleExpanded:l,onUpdatePrice:c,onUpdateField:m,onDelete:s}){return(0,a.createElement)(a.Fragment,null,(0,a.createElement)("tr",{className:"variation-row"},(0,a.createElement)("td",{className:"variation-name"},(0,a.createElement)("button",{type:"button",className:"toggle-expand",onClick:l},e.expanded?"▼":"▶"),(0,a.createElement)("strong",null,e.name)),o&&e.prices?.[0]?(0,a.createElement)(a.Fragment,null,(0,a.createElement)(A,{price:e.prices[0],field:"regular_price",onChange:(e,a)=>c(0,e,a)}),(0,a.createElement)(A,{price:e.prices[0],field:"sale_price",onChange:(e,a)=>c(0,e,a)})):null,(0,a.createElement)("td",{className:"variation-stock"},(0,a.createElement)(r.TextControl,{type:"number",value:e.stock,onChange:e=>m("stock",e),placeholder:"Unlimited"})),(0,a.createElement)("td",{className:"variation-weight"},(0,a.createElement)(r.TextControl,{type:"number",value:e.weight,onChange:e=>m("weight",e),step:"0.01"})),(0,a.createElement)("td",{className:"variation-actions"},(0,a.createElement)(r.Button,{variant:"secondary",size:"small",isDestructive:!0,onClick:s,icon:S},(0,n.__)("Delete","formipay")))),!o&&e.expanded&&(0,a.createElement)("tr",{className:"variation-details-row"},(0,a.createElement)("td",{colSpan:"5"},(0,a.createElement)("table",{className:"inner-table"},(0,a.createElement)("tbody",null,(e.prices||[]).map((e,t)=>{const n=String(e.currency).split(":::")[0]===i,r=e.currency_decimal_digits?1/Math.pow(10,e.currency_decimal_digits):.01;return(0,a.createElement)("tr",{key:t},(0,a.createElement)("td",{className:"currency-name"},e.currency,n&&(0,a.createElement)("span",{className:"required"},"*")),(0,a.createElement)("td",null,(0,a.createElement)("input",{type:"number",value:e.regular_price,onChange:e=>c(t,"regular_price",e.target.value),step:r,placeholder:"Regular Price",required:n})),(0,a.createElement)("td",null,(0,a.createElement)("input",{type:"number",value:e.sale_price,onChange:e=>c(t,"sale_price",e.target.value),step:r,placeholder:"Sale Price"})))}))))))}function A({price:e,field:t,onChange:n}){if(!e)return(0,a.createElement)("td",{className:"price-cell"},"-");const r=e.currency_decimal_digits?1/Math.pow(10,e.currency_decimal_digits):.01;return(0,a.createElement)("td",{className:"price-cell"},(0,a.createElement)("input",{type:"number",value:e[t],onChange:e=>n(t,e.target.value),step:r,placeholder:"Auto"}))}const T=window.Swal,P=window.Swal,I=window.Swal,$=window.Swal,U=window.Swal;function j({currentPage:e,onPageNavigate:t}){const r=[{key:"forms",label:(0,n.__)("Forms","formipay")},{key:"products",label:(0,n.__)("Products","formipay")},{key:"coupons",label:(0,n.__)("Coupons","formipay")},{key:"orders",label:(0,n.__)("Orders","formipay")},{key:"customers",label:(0,n.__)("Customers","formipay")},{key:"access",label:(0,n.__)("Access","formipay")},{key:"licenses",label:(0,n.__)("Licenses","formipay")}];return(0,a.createElement)("div",{className:"formipay-navigation-menu"},(0,a.createElement)("img",{src:`${window.formipayAdmin?.pluginUrl||""}/admin/assets/img/formipay-logo-circle-white_256.png`,alt:"Formipay",width:"48",height:"48"}),(0,a.createElement)("nav",{className:"navigation-links"},r.map(n=>(0,a.createElement)("a",{key:n.key,href:`#${n.key}`,className:"nav-link "+(e===n.key?"active":""),onClick:e=>((e,a)=>{e.preventDefault(),t&&t(a)})(e,n.key)},n.label))))}const O={orders:function(){const[e,r]=(0,t.useState)(null);if(e)return(0,a.createElement)(N,{orderId:e,onBack:()=>r(null)});const o=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,a.createElement)("strong",null,"#",e.id)},{key:"created_date",label:(0,n.__)("Date","formipay"),render:e=>{const a=e.created_date||e.date;return a?new Date(a).toLocaleDateString():"-"}},{key:"customer",label:(0,n.__)("Customer","formipay"),render:e=>{if(e.form_data&&Array.isArray(e.form_data)){const a=e.form_data.find(e=>"name"===e.name)?.value,t=e.form_data.find(e=>"email"===e.name)?.value;return a||t||"-"}return"-"}},{key:"total",label:(0,n.__)("Total","formipay"),render:e=>e.total_formatted||e.total||"-"},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const t={"on-hold":(0,n.__)("On Hold","formipay"),"payment-confirm":(0,n.__)("Payment Confirmed","formipay"),"in-progress":(0,n.__)("In Progress","formipay"),shipping:(0,n.__)("Shipping","formipay"),completed:(0,n.__)("Completed","formipay"),failed:(0,n.__)("Failed","formipay"),refunded:(0,n.__)("Refunded","formipay"),cancelled:(0,n.__)("Cancelled","formipay")},r=e.status||"unknown";return(0,a.createElement)("span",{className:`status-label status-${r}`},t[r]||r)}},{key:"actions",label:(0,n.__)("Actions","formipay"),render:e=>(0,a.createElement)("button",{className:"button button-small",onClick:()=>r(e.id)},(0,n.__)("View","formipay"))}];return(0,a.createElement)(i,{columns:o,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-orders",selectable:!1,inline:!1,emptyMessage:(0,n.__)("No orders found","formipay")})},customers:function(){const e=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,a.createElement)("strong",null,"#",e.ID)},{key:"name",label:(0,n.__)("Name","formipay"),render:e=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)("strong",null,e.name||e.full_name||"-"),(0,a.createElement)("span",{className:"row-actions"},(0,a.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/admin.php?page=formipay-customers&customer_id=${e.ID}`},(0,n.__)("view","formipay"))))},{key:"email",label:(0,n.__)("Email","formipay")},{key:"phone",label:(0,n.__)("Phone","formipay"),render:e=>e.phone||e.whatsapp||"-"},{key:"total_order",label:(0,n.__)("Total Orders","formipay"),render:e=>e.total_order||e.total_orders||0}];return(0,a.createElement)("div",{className:"formipay-page-customers"},(0,a.createElement)(i,{columns:e,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-customers",selectable:!1,inline:!1,emptyMessage:(0,n.__)("No customers found","formipay")}))},products:function(){const[e,r]=(0,t.useState)(!1),[o,l]=(0,t.useState)(null),c=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",m=window.formipayAdmin?.nonce||"";if(e&&o)return(0,a.createElement)("div",{className:"formipay-page-products"},(0,a.createElement)("div",{className:"formipay-page-header"},(0,a.createElement)("button",{type:"button",className:"button button-secondary",onClick:()=>r(!1)},"← ",(0,n.__)("Back to Products","formipay")),(0,a.createElement)("h1",null,(0,n.__)("Edit Product","formipay"))),(0,a.createElement)("div",{className:"formipay-product-editor"},(0,a.createElement)(x,{productId:o,productDetails:{}})));const s=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,a.createElement)("strong",null,"#",e.ID)},{key:"title",label:(0,n.__)("Title","formipay"),render:e=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${e.ID}&action=edit`},(0,a.createElement)("strong",null,e.post_title||e.title||(0,n.__)("Untitled","formipay"))),(0,a.createElement)("span",{className:"row-actions"},(0,a.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${e.ID}&action=edit`},(0,n.__)("edit","formipay"))," | ",(0,a.createElement)("button",{className:"button-link",onClick:()=>{l(e.ID),r(!0)}},(0,n.__)("edit variations","formipay"))," | ",(0,a.createElement)("button",{className:"button-link delete",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async e=>{(await T.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${c}?action=formipay-delete-product`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:e,_wpnonce:m})}),window.location.reload())})(e.ID)}},(0,n.__)("delete","formipay"))," | ",(0,a.createElement)("button",{className:"button-link duplicate",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async e=>{(await T.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${c}?action=formipay-duplicate-product`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:e,_wpnonce:m})}),window.location.reload())})(e.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"price",label:(0,n.__)("Price","formipay"),render:e=>{const t=e.prices||e.price;return Array.isArray(t)&&t.length>0?t.map(e=>(0,a.createElement)("div",{key:e.currency,style:{display:"flex",alignItems:"center",gap:"4px",marginBottom:"2px"}},e.flag&&(0,a.createElement)("img",{src:e.flag,alt:"",height:"14",style:{verticalAlign:"middle"}}),e.has_sale?(0,a.createElement)(a.Fragment,null,(0,a.createElement)("span",{style:{fontSize:"12px",textDecoration:"line-through",opacity:"0.7",marginRight:"4px"}},e.regular_price),(0,a.createElement)("span",{style:{fontSize:"13px",fontWeight:"500"}},e.sale_price)):(0,a.createElement)("span",{style:{fontSize:"13px"}},e.regular_price))):"-"}},{key:"type",label:(0,n.__)("Type","formipay"),render:e=>"physical"===(e.product_type||e.type||"digital")?(0,n.__)("Physical","formipay"):(0,n.__)("Digital","formipay")},{key:"stock",label:(0,n.__)("Stock","formipay"),render:e=>{const a=e.stock;return null===a||""===a?(0,n.__)("Unlimited","formipay"):a}},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const t=e.post_status||e.status||"unknown",r={publish:(0,n.__)("Published","formipay"),draft:(0,n.__)("Draft","formipay")};return(0,a.createElement)("span",{className:`status-label ${t}`},r[t]||t)}}];return(0,a.createElement)("div",{className:"formipay-page-products"},(0,a.createElement)(i,{columns:s,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-products",deleteAction:"formipay-delete-product",duplicateAction:"formipay-duplicate-product",filterOptions:{key:"post_status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"publish",label:(0,n.__)("Published","formipay")},{value:"draft",label:(0,n.__)("Draft","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Product","formipay"),action:"formipay-create-product-post"},bulkDelete:{action:"formipay-bulk-delete-product"},inline:!0},emptyMessage:(0,n.__)("No products found","formipay")}))},forms:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",t=window.formipayAdmin?.nonce||"",r=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,a.createElement)("strong",null,"#",e.ID)},{key:"title",label:(0,n.__)("Title","formipay"),render:r=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,a.createElement)("strong",null,r.title)),(0,a.createElement)("span",{className:"row-actions"},(0,a.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,n.__)("edit","formipay"))," | ",(0,a.createElement)("button",{className:"button-link delete",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async a=>{(await P.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-form`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:a,_wpnonce:t})}),window.location.reload())})(r.ID)}},(0,n.__)("delete","formipay"))," | ",(0,a.createElement)("button",{className:"button-link duplicate",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async a=>{(await P.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-duplicate-form`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:a,_wpnonce:t})}),window.location.reload())})(r.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"date",label:(0,n.__)("Date","formipay"),render:e=>{const t=new Date(e.date);return(0,a.createElement)("span",{style:{whiteSpace:"nowrap"}},t.toLocaleDateString(),(0,a.createElement)("br",null),(0,a.createElement)("span",{style:{fontSize:"smaller",color:"#646970"}},t.toLocaleTimeString()))}},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const t=e.post_status||e.status||"unknown",r={publish:(0,n.__)("Published","formipay"),draft:(0,n.__)("Draft","formipay"),pending:(0,n.__)("Pending","formipay")};return(0,a.createElement)("span",{className:`status-label ${t}`},r[t]||t)}},{key:"shortcode",label:(0,n.__)("Shortcode","formipay"),render:e=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)("input",{className:"formipay-form-shortcode",value:`[formipay form=${e.ID}]`,disabled:!0}),(0,a.createElement)("button",{className:"copy-shortcode","data-copy":`[formipay form=${e.ID}]`,onClick:e=>{const a=e.currentTarget.dataset.copy;navigator.clipboard.writeText(a).then(()=>{const a=e.currentTarget.innerHTML;e.currentTarget.innerHTML="[Copied]",setTimeout(()=>{e.currentTarget.innerHTML=a},2e3),P.fire({icon:"success",title:(0,n.__)("Shortcode copied!","formipay"),toast:!0,position:"top-end",showConfirmButton:!1,timer:3e3,timerProgressBar:!0})})}},(0,n.__)("Copy","formipay")))}];return(0,a.createElement)(i,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-forms",deleteAction:"formipay-delete-form",duplicateAction:"formipay-duplicate-form",filterOptions:{key:"post_status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"publish",label:(0,n.__)("Published","formipay")},{value:"draft",label:(0,n.__)("Draft","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Form","formipay"),action:"formipay-create-form-post"},bulkDelete:{action:"formipay-bulk-delete-form"},inline:!0},emptyMessage:(0,n.__)("No forms found","formipay")})},coupons:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",t=window.formipayAdmin?.nonce||"",r=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,a.createElement)("strong",null,"#",e.ID)},{key:"code",label:(0,n.__)("Coupon Code","formipay"),render:r=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)("strong",null,r.code||r.post_title),(0,a.createElement)("span",{className:"row-actions"},(0,a.createElement)("button",{className:"button-link",onClick:e=>{var a;e.preventDefault(),a=r.ID,window.location.href=`/wp-admin/post.php?post=${a}&action=edit`}},(0,n.__)("edit","formipay"))," | ",(0,a.createElement)("button",{className:"button-link delete",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async a=>{(await I.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-coupon`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:a,_wpnonce:t})}),window.location.reload())})(r.ID)}},(0,n.__)("delete","formipay"))," | ",(0,a.createElement)("button",{className:"button-link duplicate",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async a=>{(await I.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-duplicate-coupon`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:a,_wpnonce:t})}),window.location.reload())})(r.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"type",label:(0,n.__)("Type","formipay"),render:e=>"percentage"===(e.coupon_type||e.type||"percentage")?(0,n.__)("%","formipay"):(0,n.__)("Fixed","formipay")},{key:"amount",label:(0,n.__)("Amount","formipay"),render:e=>{const t=e.amount;return Array.isArray(t)?t.map(e=>(0,a.createElement)("div",{key:e.raw,style:{display:"flex",alignItems:"center",gap:"4px"}},e.flag&&(0,a.createElement)("img",{src:e.flag,alt:"",height:"14",style:{verticalAlign:"middle"}}),(0,a.createElement)("span",null,e.amount))):"number"==typeof t?t+"%":t||"-"}},{key:"usages",label:(0,n.__)("Usages","formipay"),render:e=>e.usage_count||e.usages||0},{key:"date_limit",label:(0,n.__)("Date Limit","formipay"),render:e=>{const a=e.date_limit;return a&&"none"!==a?new Date(a).toLocaleDateString():(0,n.__)("Unlimited","formipay")}},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const t=e.post_status||e.status||"unknown",r="on"===e.active||"publish"===t;return(0,a.createElement)("span",{className:"status-label "+(r?"publish":"draft")},r?(0,n.__)("Active","formipay"):(0,n.__)("Inactive","formipay"))}}];return(0,a.createElement)("div",{className:"formipay-page-coupons"},(0,a.createElement)(i,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-coupons",deleteAction:"formipay-delete-coupon",duplicateAction:"formipay-duplicate-coupon",filterOptions:{key:"status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"active",label:(0,n.__)("Active","formipay")},{value:"inactive",label:(0,n.__)("Inactive","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Coupon","formipay"),href:"/wp-admin/post-new.php?post_type=formipay_coupon"},bulkDelete:{action:"formipay-bulk-delete-coupon"},inline:!0},emptyMessage:(0,n.__)("No coupons found","formipay")}))},access:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",t=window.formipayAdmin?.nonce||"",r=[{key:"ID",label:(0,n.__)("ID","formipay"),render:e=>(0,a.createElement)("strong",null,"#",e.ID)},{key:"title",label:(0,n.__)("Title","formipay"),render:r=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,a.createElement)("strong",null,r.title||r.post_title||(0,n.__)("Untitled","formipay"))),(0,a.createElement)("span",{className:"row-actions"},(0,a.createElement)("a",{href:`${window.formipayAdmin?.siteUrl||""}/wp-admin/post.php?post=${r.ID}&action=edit`},(0,n.__)("edit","formipay"))," | ",(0,a.createElement)("button",{className:"button-link delete",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async a=>{(await $.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-access-item`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:a,_wpnonce:t})}),window.location.reload())})(r.ID)}},(0,n.__)("delete","formipay"))," | ",(0,a.createElement)("button",{className:"button-link duplicate",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async a=>{(await $.fire({icon:"info",html:(0,n.__)("Do you want to duplicate this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Confirm","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-duplicate-access-item`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:a,_wpnonce:t})}),window.location.reload())})(r.ID)}},(0,n.__)("duplicate","formipay"))))},{key:"product_name",label:(0,n.__)("Product","formipay")},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const t=e.post_status||e.status||"unknown",r={publish:(0,n.__)("Published","formipay"),draft:(0,n.__)("Draft","formipay")}[t]||t;return(0,a.createElement)("span",{className:`status-label ${t}`},r)}},{key:"date",label:(0,n.__)("Date","formipay"),render:e=>{const a=e.post_date||e.date;return a?new Date(a).toLocaleDateString():"-"}}];return(0,a.createElement)("div",{className:"formipay-page-access"},(0,a.createElement)(i,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-access-items",deleteAction:"formipay-delete-access-item",duplicateAction:"formipay-duplicate-access-item",filterOptions:{key:"post_status",options:[{value:"all",label:(0,n.__)("All","formipay")},{value:"publish",label:(0,n.__)("Published","formipay")},{value:"draft",label:(0,n.__)("Draft","formipay")}]},actions:{addNew:{label:(0,n.__)("+ Add New Item","formipay"),action:"formipay-create-access-item-post"},bulkDelete:{action:"formipay-bulk-delete-access-item"},inline:!0},emptyMessage:(0,n.__)("No access items found","formipay")}))},licenses:function(){const e=window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",t=window.formipayAdmin?.nonce||"",r=[{key:"id",label:(0,n.__)("ID","formipay"),render:e=>(0,a.createElement)("strong",null,"#",e.id)},{key:"license_key",label:(0,n.__)("License Key","formipay"),render:r=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)("code",null,r.license_key||"-"),(0,a.createElement)("span",{className:"row-actions"},(0,a.createElement)("button",{className:"button-link delete",onClick:a=>{a.preventDefault(),a.stopPropagation(),(async a=>{(await U.fire({icon:"info",html:(0,n.__)("Do you want to delete this item?","formipay"),showCancelButton:!0,confirmButtonText:(0,n.__)("Delete Permanently","formipay"),cancelButtonText:(0,n.__)("Cancel","formipay")})).isConfirmed&&(await fetch(`${e}?action=formipay-delete-license`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:a,_wpnonce:t})}),window.location.reload())})(r.id)}},(0,n.__)("delete","formipay"))))},{key:"product",label:(0,n.__)("Product","formipay"),render:e=>e.product_name||e.product||"-"},{key:"order",label:(0,n.__)("Order","formipay"),render:e=>e.order_id||`#${e.order}`||"-"},{key:"email",label:(0,n.__)("Email","formipay")},{key:"status",label:(0,n.__)("Status","formipay"),render:e=>{const t=e.status||"unknown",r={active:(0,n.__)("Active","formipay"),inactive:(0,n.__)("Inactive","formipay"),expired:(0,n.__)("Expired","formipay")},o="active"===t?"publish":"expired"===t?"pending":"draft";return(0,a.createElement)("span",{className:`status-label ${o}`},r[t]||t)}}];return(0,a.createElement)("div",{className:"formipay-page-licenses"},(0,a.createElement)(i,{columns:r,ajaxUrl:window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php",nonce:window.formipayAdmin?.nonce||"",tableAction:"formipay-tabledata-licenses",selectable:!1,inline:!1,emptyMessage:(0,n.__)("No licenses found","formipay")}))}};function L({page:e,initialData:n}){const[r,o]=(0,t.useState)(()=>{const a=window.location.hash.replace("#","");return O[a]?a:e});(0,t.useEffect)(()=>{document.querySelectorAll("li.wp-first-item.current, li.wp-first-item .current").forEach(e=>{e.classList.remove("current","wp-first-item")});const e={forms:"admin.php?page=formipay",products:"admin.php?page=formipay-products",coupons:"admin.php?page=formipay-coupons",orders:"admin.php?page=formipay-orders",customers:"admin.php?page=formipay-customers",access:"admin.php?page=formipay-access",licenses:"admin.php?page=formipay-licenses"}[r];e&&document.querySelectorAll("#toplevel_page_formipay .wp-submenu a").forEach(a=>{a.parentElement.classList.remove("current"),a.classList.remove("current"),a.getAttribute("href")?.includes(e)&&("forms"===r?document.querySelectorAll("#toplevel_page_formipay .wp-submenu li:nth-child(2) a").forEach(e=>{e.parentElement.classList.add("current"),e.classList.add("current")}):(a.parentElement.classList.add("current"),a.classList.add("current")))})},[r]),(0,t.useEffect)(()=>{const e=()=>{const e=window.location.hash.replace("#","");O[e]&&o(e)};return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[]);const i=O[r];return i?(0,a.createElement)("div",{className:"formipay-admin-wrap"},(0,a.createElement)(j,{currentPage:r,onPageNavigate:e=>{o(e),window.location.hash=e}}),(0,a.createElement)(i,{initialData:n})):(0,a.createElement)("div",{className:"formipay-error"},(0,a.createElement)("p",null,"Unknown page: ",r))}function B({tabs:e,activeTab:t,onTabChange:n,orientation:r="vertical"}){return(0,a.createElement)("div",{className:"formipay-wpcfto-tab-nav "+("vertical"===r?"formipay-wpcfto-sidebar":"")},(0,a.createElement)("div",{className:"formipay-wpcfto-tab-nav-inner"},e.map(e=>(0,a.createElement)("div",{key:e.id,className:`formipay-wpcfto-nav ${t===e.id?"active":""} ${e.submenu?"has-submenu":""} ${e.icon?"":"no-icon"}`,onClick:()=>n(e.id)},(0,a.createElement)("div",{className:"formipay-wpcfto-nav-title"},e.icon&&(0,a.createElement)("i",{className:e.icon}),(0,a.createElement)("span",null,e.label)),e.submenu&&(0,a.createElement)("div",{className:"formipay-wpcfto-submenus"},e.submenu.map(r=>(0,a.createElement)("div",{key:`${e.id}_${r.id}`,className:"formipay-wpcfto-submenu-item "+(t===`${e.id}_${r.id}`?"active":""),onClick:a=>{a.stopPropagation(),n(`${e.id}_${r.id}`)}},r.label,(0,a.createElement)("i",{className:"fa fa-chevron-right"}))))))))}function F({tabs:e,activeTab:t,children:n}){return(0,a.createElement)("div",{className:"formipay-tabs"},e.map((e,r)=>(0,a.createElement)("div",{key:e.id,className:"formipay-tab "+(e.id===t?"active":"")},(0,a.createElement)("div",{className:"formipay-tab-content"},"function"==typeof n?n(e,r):n))))}function R({label:e,description:t,required:n=!1,children:r,className:o="",...i}){return(0,a.createElement)("div",{className:`formipay-generic-field ${o}`,...i},(0,a.createElement)("div",{className:"formipay-field-aside"},e&&(0,a.createElement)("div",{className:"formipay-field-label "+(n?"required":"")},(0,a.createElement)("span",{className:"formipay-field-label-text"},e)),t&&(0,a.createElement)("div",{className:"formipay-field-description"},t)),(0,a.createElement)("div",{className:"formipay-field-content"},r))}function M({label:e,description:t,required:n=!1,className:r="",...o}){return(0,a.createElement)(R,{label:e,description:t,required:n},(0,a.createElement)("input",{className:`formipay-input ${r}`,...o}))}function q({label:e,checked:t,onChange:n,className:r="",isToggle:o=!0,...i}){return(0,a.createElement)("label",{className:`formipay-admin-checkbox ${t?"active":""} ${r}`},(0,a.createElement)("div",{className:"formipay-admin-checkbox-wrapper "+(o?"is_toggle":"")},(0,a.createElement)("div",{className:"formipay-checkbox-switcher"}),(0,a.createElement)("input",{type:"checkbox",checked:t,onChange:n,...i})),(0,a.createElement)("span",null,e))}function z({variant:e="primary",size:t="md",icon:n,children:r,className:o="",disabled:i=!1,onClick:l,...c}){const m="md"!==t?`formipay-btn-${t}`:"",s=`formipay-btn-${e}`;return(0,a.createElement)("button",{className:`formipay-btn ${s} ${m} ${o}`,disabled:i,onClick:l,...c},n&&(0,a.createElement)("span",{className:"formipay-btn-icon"},(0,a.createElement)(n,null)),r)}function J({type:e="info",title:t,children:n,onDismiss:r,className:o=""}){return(0,a.createElement)("div",{className:`formipay-notice formipay-notice-${e} ${o}`},(0,a.createElement)("div",{className:"formipay-notice-icon"},"success"===e&&"✓","warning"===e&&"⚠","error"===e&&"✕","info"===e&&"ℹ"),(0,a.createElement)("div",{className:"formipay-notice-content"},t&&(0,a.createElement)("div",{className:"formipay-notice-title"},t),(0,a.createElement)("div",null,n)),r&&(0,a.createElement)("button",{className:"formipay-notice-dismiss",onClick:r,"aria-label":"Dismiss"},"✕"))}function H({title:e,icon:t,className:n=""}){return(0,a.createElement)("div",{className:`formipay-group-title ${n}`},t&&(0,a.createElement)("i",{className:t}),e)}function G({tabs:e,activeTab:t,onTabChange:n,children:r}){return(0,a.createElement)("div",{className:"formipay-wpcfto-metabox"},(0,a.createElement)("div",{className:"formipay-wpcfto-metabox-inner"},(0,a.createElement)("div",{className:"formipay-wpcfto-container"},(0,a.createElement)(B,{tabs:e,activeTab:t,onTabChange:n}),(0,a.createElement)("div",{className:"formipay-wpcfto-tabs"},r))))}const Z=()=>window.formipayGlobalCurrencies?window.formipayGlobalCurrencies:[],V=e=>e.split(":::")[1]||e,X=e=>e.split(":::")[0]||e,Q=e=>window.formipayGetFlag?window.formipayGetFlag(e):"";function W({postId:e}){const[r,o]=(0,t.useState)("rules"),[i,l]=(0,t.useState)(!0),[c,m]=(0,t.useState)(!1),[s,p]=(0,t.useState)(null),[d,u]=(0,t.useState)({active:"on",type:"percentage",amount_percentage:"",case_sensitive:"",free_shipping:"",quantity_active:"",use_limit:"",date_limit:"",amounts_fixed:{},max_amounts:{},forms:[],products:[],customers:[]}),f=[{id:"rules",label:(0,n.__)("Rules","formipay"),icon:"fa fa-cog"},{id:"restriction",label:(0,n.__)("Restrictions","formipay"),icon:"fa fa-lock"}];(0,t.useEffect)(()=>{e>0?y():l(!1)},[e]);const y=async()=>{try{const a=await fetch(`${window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php"}?action=formipay-get-coupon`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({id:e,_wpnonce:window.formipayAdmin?.nonce||""})}),t=await a.json();if(t.success){const e=t.data;u(a=>({...a,active:e.active||"on",type:e.type||"percentage",amount_percentage:e.amount_percentage||"",case_sensitive:e.case_sensitive||"",free_shipping:e.free_shipping||"",quantity_active:e.quantity_active||"",use_limit:e.use_limit||"",date_limit:e.date_limit||"",amounts_fixed:e.amounts_fixed?.reduce((e,a)=>(e[a.symbol]=a.amount,e),{})||{},max_amounts:e.max_amounts?.reduce((e,a)=>(e[a.symbol]=a.amount,e),{})||{},forms:e.forms||[],products:e.products||[],customers:e.customers||[]}))}}catch(e){console.error("Failed to load coupon:",e),p({type:"error",text:(0,n.__)("Failed to load coupon data.","formipay")})}finally{l(!1)}},_=(e,a)=>{u(t=>({...t,[e]:a}))},w="percentage"===d.type,h="fixed"===d.type;return i?(0,a.createElement)("div",{className:"formipay-loading"},(0,n.__)("Loading...","formipay")):(0,a.createElement)("div",{className:"formipay-coupon-metabox"},s&&(0,a.createElement)(J,{type:s.type,onDismiss:()=>p(null)},s.text),(0,a.createElement)(G,{tabs:f,activeTab:r,onTabChange:o},(0,a.createElement)(F,{tabs:f,activeTab:r},e=>"rules"===e.id?(0,a.createElement)("div",{className:"formipay-tab-content"},(0,a.createElement)(H,{title:(0,n.__)("General","formipay"),icon:"fa fa-cog"}),(0,a.createElement)(R,{label:(0,n.__)("Active","formipay"),description:(0,n.__)("Enable this coupon.","formipay")},(0,a.createElement)(q,{checked:"on"===d.active,onChange:e=>_("active",e.target.checked?"on":"")})),(0,a.createElement)(R,{label:(0,n.__)("Type","formipay"),description:(0,n.__)("Choose discount type.","formipay"),required:!0},(0,a.createElement)("div",{className:"formipay-radio-group"},(0,a.createElement)("label",{className:"formipay-radio "+(h?"active":"")},(0,a.createElement)("input",{type:"radio",name:"type",value:"fixed",checked:h,onChange:e=>_("type",e.target.value)}),(0,a.createElement)("span",null,(0,n.__)("Fixed","formipay"))),(0,a.createElement)("label",{className:"formipay-radio "+(w?"active":"")},(0,a.createElement)("input",{type:"radio",name:"type",value:"percentage",checked:w,onChange:e=>_("type",e.target.value)}),(0,a.createElement)("span",null,(0,n.__)("Percentage","formipay"))))),w&&(0,a.createElement)(R,{label:(0,n.__)("Amount","formipay"),description:(0,n.__)("Discount percentage.","formipay"),required:!0},(0,a.createElement)(M,{type:"number",min:"0",max:"100",step:"0.01",value:d.amount_percentage,onChange:e=>_("amount_percentage",e.target.value)})),h&&(0,a.createElement)(a.Fragment,null,(0,a.createElement)(H,{title:(0,n.__)("Discount Amount","formipay"),icon:"fa fa-money"}),Z().map(e=>{const t=V(e.currency),r=X(e.currency),o=Q(e.currency),i=e.decimal_digits>0?1/(10*e.decimal_digits):1;return(0,a.createElement)("div",{key:r,className:"formipay-generic-field"},(0,a.createElement)("div",{className:"formipay-field-aside"},(0,a.createElement)("div",{className:"formipay-field-label required"},(0,a.createElement)("span",{className:"formipay-field-label-text"},o&&(0,a.createElement)("img",{src:o,alt:"",width:"18",style:{verticalAlign:"middle",marginRight:"4px"}}),(0,n.__)("Amount in","formipay")," ",t))),(0,a.createElement)("div",{className:"formipay-field-content"},(0,a.createElement)(M,{type:"number",min:"0",step:i,placeholder:(0,n.__)("Enter Amount...","formipay"),value:d.amounts_fixed[t]||"",onChange:e=>_("amounts_fixed",{...d.amounts_fixed,[t]:e.target.value})})))})),(0,a.createElement)(H,{title:(0,n.__)("Max Discount Amount","formipay"),icon:"fa fa-calculator"}),Z().map(e=>{const t=V(e.currency),r=X(e.currency),o=Q(e.currency),i=e.decimal_digits>0?1/(10*e.decimal_digits):1;return(0,a.createElement)(R,{key:`max_${r}`,label:(0,a.createElement)("span",null,o&&(0,a.createElement)("img",{src:o,alt:"",width:"18",style:{verticalAlign:"middle",marginRight:"4px"}}),(0,n.__)("Max Amount in","formipay")," ",t),description:(0,n.__)("Leave empty to not limit the max discount amount.","formipay")},(0,a.createElement)(M,{type:"number",min:"0",step:i,placeholder:(0,n.__)("Enter Max Amount...","formipay"),value:d.max_amounts[t]||"",onChange:e=>_("max_amounts",{...d.max_amounts,[t]:e.target.value})}))}),(0,a.createElement)(H,{title:(0,n.__)("Rules","formipay"),icon:"fa fa-list"}),(0,a.createElement)(R,{label:(0,n.__)("Case Sensitive","formipay"),description:(0,n.__)("If activated, coupon codes must be entered with the exact capitalization.","formipay")},(0,a.createElement)(q,{checked:"on"===d.case_sensitive,onChange:e=>_("case_sensitive",e.target.checked?"on":"")})),(0,a.createElement)(R,{label:(0,n.__)("Free Shipping","formipay"),description:(0,n.__)("Shipping cost will be free when this coupon is applied.","formipay")},(0,a.createElement)(q,{checked:"on"===d.free_shipping,onChange:e=>_("free_shipping",e.target.checked?"on":"")})),h&&(0,a.createElement)(R,{label:(0,n.__)("Influenced by Quantity","formipay"),description:(0,n.__)("Example: when buyer buys 4 items, 4 × discount amount will be applied.","formipay")},(0,a.createElement)(q,{checked:"on"===d.quantity_active,onChange:e=>_("quantity_active",e.target.checked?"on":"")}))):"restriction"===e.id?(0,a.createElement)("div",{className:"formipay-tab-content"},(0,a.createElement)(H,{title:(0,n.__)("Restrictions","formipay"),icon:"fa fa-lock"}),(0,a.createElement)(R,{label:(0,n.__)("Usage Limit","formipay"),description:(0,n.__)("Leave empty or 0 (zero) for unlimited usage.","formipay")},(0,a.createElement)(M,{type:"number",min:"0",value:d.use_limit,onChange:e=>_("use_limit",e.target.value)})),(0,a.createElement)(R,{label:(0,n.__)("Date Limit","formipay"),description:(0,n.__)("Last day the coupon can be used. Leave empty for no limit.","formipay")},(0,a.createElement)(M,{type:"date",value:d.date_limit,onChange:e=>_("date_limit",e.target.value)})),(0,a.createElement)(R,{label:(0,n.__)("Forms","formipay"),description:(0,n.__)("Only selected form(s) can use the coupon. Leave empty to apply to all forms.","formipay")},(0,a.createElement)(K,{postType:"formipay-form",value:d.forms,onChange:e=>_("forms",e)})),(0,a.createElement)(R,{label:(0,n.__)("Products","formipay"),description:(0,n.__)("Only selected product(s) can use the coupon. Leave empty to apply to all products.","formipay")},(0,a.createElement)(K,{postType:"formipay-product",value:d.products,onChange:e=>_("products",e)})),(0,a.createElement)(R,{label:(0,n.__)("Customers","formipay"),description:(0,n.__)("Only selected customer(s) can use the coupon. Leave empty to apply to all customers.","formipay")},(0,a.createElement)(K,{postType:"formipay-customer",value:d.customers,onChange:e=>_("customers",e)}))):null),(0,a.createElement)("div",{className:"formipay-metabox-actions"},(0,a.createElement)(z,{variant:"primary",onClick:async()=>{m(!0),p(null);try{const a=new URLSearchParams({id:e,title:document.querySelector("#title input")?.value||"",_wpnonce:window.formipayAdmin?.nonce||"",...d});Object.entries(d.amounts_fixed).forEach(([e,t])=>{a.append(`amount_fixed_${e}`,t)}),Object.entries(d.max_amounts).forEach(([e,t])=>{a.append(`max_amount_${e}`,t)});const t=await fetch(`${window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php"}?action=formipay-save-coupon`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:a}),r=await t.json();r.success?p({type:"success",text:r.data.message||(0,n.__)("Coupon saved successfully.","formipay")}):p({type:"error",text:r.data?.message||(0,n.__)("Failed to save coupon.","formipay")})}catch(e){console.error("Failed to save coupon:",e),p({type:"error",text:(0,n.__)("Failed to save coupon.","formipay")})}finally{m(!1)}},disabled:c},c?(0,n.__)("Saving...","formipay"):(0,n.__)("Save Coupon","formipay")))))}function K({postType:e,value:r,onChange:o}){const[i,l]=(0,t.useState)(""),[c,m]=(0,t.useState)([]),[s,p]=(0,t.useState)(!1),[d,u]=(0,t.useState)(!1),f=r||[];return(0,a.createElement)("div",{className:"formipay-autocomplete"},(0,a.createElement)("div",{className:"formipay-autocomplete-selected"},f.map(e=>(0,a.createElement)("span",{key:e,className:"formipay-autocomplete-tag"},e,(0,a.createElement)("button",{type:"button",className:"formipay-autocomplete-remove",onClick:()=>{return a=e,void o(f.filter(e=>e!==a));var a}},"×")))),(0,a.createElement)("div",{className:"formipay-autocomplete-input-wrapper"},(0,a.createElement)(M,{type:"text",value:i,onChange:a=>(async a=>{if(l(a),a.length<2)m([]);else{p(!0);try{const t=await fetch(`${window.formipayAdmin?.ajaxUrl||"/wp-admin/admin-ajax.php"}?action=formipay-autocomplete-search`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({post_type:e,search:a,_wpnonce:window.formipayAdmin?.nonce||""})}),n=await t.json();n.success&&m(n.data||[])}catch(e){console.error("Autocomplete search failed:",e)}finally{p(!1)}}})(a.target.value),onFocus:()=>u(!0),placeholder:(0,n.__)("Search...","formipay")}),s&&(0,a.createElement)("span",{className:"formipay-autocomplete-loading"},"...")),d&&c.length>0&&(0,a.createElement)("div",{className:"formipay-autocomplete-results"},c.map(e=>(0,a.createElement)("div",{key:e.value,className:"formipay-autocomplete-result",onClick:()=>(e=>{f.includes(e.value)||o([...f,e.value]),l(""),m([])})(e)},e.label))))}const Y=()=>{const e=document.querySelectorAll("[data-formipay-mount]");console.log("[Formipay] Mount points found:",e.length),console.log("[Formipay] formipayAdmin data:",window.formipayAdmin),e.forEach(e=>{const n=e.dataset.formipayMount,r=window.formipayAdmin?.[n]||{};console.log("[Formipay] Mounting page:",n,"with data:",r);try{(0,t.render)((0,a.createElement)(L,{page:n,initialData:r}),e),console.log("[Formipay] Successfully mounted:",n)}catch(e){console.error("[Formipay] Failed to mount:",n,e)}});const n=document.querySelectorAll("[data-formipay-metabox]");console.log("[Formipay] Metabox points found:",n.length),n.forEach(e=>{const n=e.dataset.formipayMetabox,r=parseInt(e.dataset.postId||"0");console.log("[Formipay] Mounting metabox:",n,"for post:",r);try{"coupon"===n&&((0,t.render)((0,a.createElement)(W,{postId:r}),e),console.log("[Formipay] Successfully mounted coupon metabox"))}catch(e){console.error("[Formipay] Failed to mount metabox:",n,e)}})};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",Y):Y()})(); \ No newline at end of file diff --git a/includes/Admin/ReactAdmin.php b/includes/Admin/ReactAdmin.php index 07cfafd6b..57788473d 100644 --- a/includes/Admin/ReactAdmin.php +++ b/includes/Admin/ReactAdmin.php @@ -19,8 +19,11 @@ class ReactAdmin { $screen = get_current_screen(); - // Only load React assets on Formipay admin pages - if ( strpos( $screen->id, 'formipay' ) === false ) { + // Load React assets on Formipay admin pages OR on post edit screens for our CPTs + $is_formipay_admin = strpos($screen->id, 'formipay') !== false; + $is_formipay_cpt = $screen->base === 'post' && in_array($screen->post_type, ['formipay-coupon', 'formipay-product', 'formipay-form']); + + if (!$is_formipay_admin && !$is_formipay_cpt) { return; } @@ -28,7 +31,7 @@ class ReactAdmin { $build_dir = FORMIPAY_PATH . 'build'; $build_url = FORMIPAY_URL . 'build'; - if ( ! file_exists( $build_dir . '/admin.asset.php' ) ) { + if (!file_exists($build_dir . '/admin.asset.php')) { error_log('[Formipay] Build files not found at: ' . $build_dir . '/admin.asset.php'); return; // Build not generated yet } @@ -61,19 +64,19 @@ class ReactAdmin { ); // Localize script with required data - $data = apply_filters( 'formipay/admin/data', [ - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), - 'restUrl' => rest_url( 'formipay/v1' ), - 'nonce' => wp_create_nonce( 'formipay-admin' ), + $data = apply_filters('formipay/admin/data', [ + 'ajaxUrl' => admin_url('admin-ajax.php'), + 'restUrl' => rest_url('formipay/v1'), + 'nonce' => wp_create_nonce('formipay-admin'), 'pluginUrl' => FORMIPAY_URL, 'siteUrl' => site_url(), - ] ); + ]); // Debug logging error_log('[Formipay] Enqueuing React assets on screen: ' . $screen->id); error_log('[Formipay] Page data: ' . wp_json_encode($data)); - wp_localize_script( 'formipay-admin', 'formipayAdmin', $data ); + wp_localize_script('formipay-admin', 'formipayAdmin', $data); } diff --git a/includes/Coupon.php b/includes/Coupon.php index 278fba027..8faab486c 100644 --- a/includes/Coupon.php +++ b/includes/Coupon.php @@ -37,6 +37,11 @@ class Coupon { add_action( 'wp_ajax_formipay-duplicate-coupon', [$this, 'formipay_duplicate_coupon'] ); add_action( 'wp_ajax_formipay-get-coupon', [$this, 'formipay_get_coupon'] ); add_action( 'wp_ajax_formipay-save-coupon', [$this, 'formipay_save_coupon'] ); + add_action( 'wp_ajax_formipay-autocomplete-search', [$this, 'formipay_autocomplete_search'] ); + + // React Metabox + add_action( 'add_meta_boxes', [$this, 'add_react_metabox'] ); + add_action( 'admin_footer-post.php', [$this, 'render_react_metabox_template'] ); // Order add_filter( 'formipay/order/order-details', [$this, 'order_details'], 99, 3 ); @@ -101,79 +106,29 @@ class Coupon { } public function enqueue_admin() { - // Assets now handled by ReactAdmin class - return; - - if($current_screen->id == 'formipay_page_formipay-coupons') { - - wp_enqueue_style( 'page-coupons', FORMIPAY_URL . 'admin/assets/css/page-coupons.css', [], FORMIPAY_VERSION, 'all' ); - wp_enqueue_script( 'page-coupons', FORMIPAY_URL . 'admin/assets/js/page-coupons.js', ['jquery', 'gridjs'], FORMIPAY_VERSION, true ); - - wp_localize_script( 'page-coupons', 'formipay_coupons_page', [ - 'ajax_url' => admin_url('admin-ajax.php'), - 'site_url' => site_url(), - 'columns' => [ - 'id' => esc_html__( 'ID', 'formipay' ), - 'code' => esc_html__( 'Coupon Code', 'formipay' ), - 'usages' => esc_html__( 'Usages', 'formipay' ), - 'date_limit' => esc_html__( 'Date Limit', 'formipay' ), - 'status' => esc_html__( 'Status', 'formipay' ), - 'type' => esc_html__( 'Type', 'formipay' ), - 'amount' => esc_html__( 'Amount', 'formipay' ) - ], - 'filter_form' => [ - 'products' => [ - 'placeholder' => esc_html__( 'Filter by Product', 'formipay' ), - 'noresult_text' => esc_html__( 'No results found', 'formipay' ) - ] - ], - 'modal' => [ - 'add' => [ - 'title' => esc_html__( 'Your New Coupon Code', 'formipay' ), - 'validation' => esc_html__( 'Coupon code is still empty. Please input the code before continue', 'formipay' ), - 'cancelButton' => esc_html__( 'Cancel', 'formipay' ), - 'confirmButton' => esc_html__( 'Create New Coupon', 'formipay' ) - ], - 'delete' => [ - 'question' => esc_html__( 'Do you want to delete the coupon?', 'formipay' ), - 'cancelButton' => esc_html__( 'Cancel', 'formipay' ), - 'confirmButton' => esc_html__( 'Delete Permanently', 'formipay' ) - ], - 'bulk_delete' => [ - 'question' => esc_html__( 'Do you want to delete the selected the coupon(s)?', 'formipay' ), - 'cancelButton' => esc_html__( 'Cancel', 'formipay' ), - 'confirmButton' => esc_html__( 'Confirm', 'formipay' ) - ], - 'duplicate' => [ - 'question' => esc_html__( 'Do you want to duplicate the coupon?', 'formipay' ), - 'cancelButton' => esc_html__( 'Cancel', 'formipay' ), - 'confirmButton' => esc_html__( 'Confirm', 'formipay' ) - ], - ], - 'nonce' => wp_create_nonce('formipay-admin-coupon-page') - ] ); - } - $screen = get_current_screen(); - if ( $screen->post_type === 'formipay-coupon' && $screen->base === 'post' ) { - wp_enqueue_style( 'sweetalert2', FORMIPAY_URL . 'vendor/SweetAlert2/sweetalert2.min.css', [], '11.14.4', 'all'); - wp_enqueue_script( 'sweetalert2', FORMIPAY_URL . 'vendor/SweetAlert2/sweetalert2.min.js', ['jquery'], '11.14.4', true); - - wp_localize_script( 'sweetalert2', 'formipay_admin', [ - 'ajax_url' => admin_url('admin-ajax.php'), - 'site_url' => site_url(), - ] ); + // Enqueue SweetAlert2 for coupon post edit screen + if ($screen && $screen->post_type === 'formipay-coupon' && $screen->base === 'post') { + wp_enqueue_style('sweetalert2', FORMIPAY_URL . 'vendor/SweetAlert2/sweetalert2.min.css', [], '11.14.4', 'all'); + wp_enqueue_script('sweetalert2', FORMIPAY_URL . 'vendor/SweetAlert2/sweetalert2.min.js', ['jquery'], '11.14.4', true); + // Localize admin data + wp_localize_script('formipay-admin', 'formipayAdmin', [ + 'ajaxUrl' => admin_url('admin-ajax.php'), + 'siteUrl' => site_url(), + 'nonce' => wp_create_nonce('formipay-admin'), + ]); } } public function cpt_post_fields_box($boxes) { - $boxes['formipay_coupon_settings'] = array( - 'post_type' => array('formipay-coupon'), - 'label' => __('Details', 'formipay'), - ); - + // Disabled - using React metabox instead + // $boxes['formipay_coupon_settings'] = array( + // 'post_type' => array('formipay-coupon'), + // 'label' => __('Details', 'formipay'), + // ); + return $boxes; } @@ -1046,4 +1001,101 @@ class Coupon { ] ); } + /** + * Add React metabox for coupon editor + */ + public function add_react_metabox() { + add_meta_box( + 'formipay_coupon_reactor_metabox', + __( 'Coupon Settings', 'formipay' ), + [$this, 'render_react_metabox'], + 'formipay-coupon', + 'normal', + 'high' + ); + } + + /** + * Render React metabox container + */ + public function render_react_metabox($post) { + ?> +
+
+
+
+
+ post_type !== 'formipay-coupon') { + return; + } + + // Get global currencies + $global_currencies = get_global_currency_array(); + + ?> + + 'Unauthorized' ] ); + } + + $post_type = isset($_REQUEST['post_type']) ? sanitize_text_field(wp_unslash($_REQUEST['post_type'])) : ''; + $search = isset($_REQUEST['search']) ? sanitize_text_field(wp_unslash($_REQUEST['search'])) : ''; + + if (empty($post_type) || strlen($search) < 2) { + wp_send_json_error( [ 'message' => 'Invalid request' ] ); + } + + $query = get_posts([ + 'post_type' => $post_type, + 's' => $search, + 'posts_per_page' => 20, + 'post_status' => ['publish', 'draft'], + ]); + + $results = []; + if (!empty($query)) { + foreach ($query as $post) { + $results[] = [ + 'value' => $post->ID, + 'label' => $post->post_title, + ]; + } + } + + wp_send_json_success($results); + } + } \ No newline at end of file diff --git a/src/admin/components/coupons/CouponMetabox.css b/src/admin/components/coupons/CouponMetabox.css new file mode 100644 index 000000000..0d3a09671 --- /dev/null +++ b/src/admin/components/coupons/CouponMetabox.css @@ -0,0 +1,146 @@ +/** + * Coupon Metabox Styles + * WPCFTO-inspired design for React metabox island + */ + +.formipay-coupon-metabox { + margin: -12px; +} + +.formipay-metabox-actions { + padding: 20px 30px; + background-color: #fff; + border-top: 1px solid #f0f0f1; + display: flex; + justify-content: flex-end; + gap: 12px; +} + +/* Radio Group */ +.formipay-radio-group { + display: flex; + gap: 16px; +} + +.formipay-radio { + display: inline-flex; + align-items: center; + gap: 8px; + cursor: pointer; + padding: 8px 16px; + border: 2px solid var(--formipay-color-border-dark); + border-radius: var(--formipay-radius-lg); + transition: all var(--formipay-transition-fast); +} + +.formipay-radio input { + position: absolute; + opacity: 0; + width: 0; + height: 0; +} + +.formipay-radio span { + font-weight: var(--formipay-font-weight-medium); + color: var(--formipay-color-text-muted); +} + +.formipay-radio:hover { + border-color: var(--formipay-color-primary); +} + +.formipay-radio.active { + background-color: var(--formipay-color-primary); + border-color: var(--formipay-color-primary); +} + +.formipay-radio.active span { + color: white; +} + +/* Autocomplete Field */ +.formipay-autocomplete { + position: relative; +} + +.formipay-autocomplete-selected { + display: flex; + flex-wrap: wrap; + gap: 8px; + margin-bottom: 8px; +} + +.formipay-autocomplete-tag { + display: inline-flex; + align-items: center; + gap: 4px; + padding: 4px 8px; + background-color: var(--formipay-color-primary); + color: white; + border-radius: 4px; + font-size: var(--formipay-font-size-sm); +} + +.formipay-autocomplete-remove { + background: none; + border: none; + color: white; + cursor: pointer; + font-size: 16px; + line-height: 1; + padding: 0; + width: 16px; + height: 16px; + display: flex; + align-items: center; + justify-content: center; +} + +.formipay-autocomplete-remove:hover { + opacity: 0.8; +} + +.formipay-autocomplete-input-wrapper { + position: relative; +} + +.formipay-autocomplete-loading { + position: absolute; + right: 12px; + top: 50%; + transform: translateY(-50%); + color: var(--formipay-color-text-muted); +} + +.formipay-autocomplete-results { + position: absolute; + top: 100%; + left: 0; + right: 0; + max-height: 200px; + overflow-y: auto; + background-color: white; + border: 1px solid var(--formipay-color-border-dark); + border-radius: var(--formipay-radius-sm); + box-shadow: var(--formipay-shadow-md); + z-index: 100; + margin-top: 4px; +} + +.formipay-autocomplete-result { + padding: 10px 16px; + cursor: pointer; + transition: background-color var(--formipay-transition-fast); +} + +.formipay-autocomplete-result:hover { + background-color: var(--formipay-color-content-bg); +} + +.formipay-autocomplete-result:first-child { + border-radius: var(--formipay-radius-sm) var(--formipay-radius-sm) 0 0; +} + +.formipay-autocomplete-result:last-child { + border-radius: 0 0 var(--formipay-radius-sm) var(--formipay-radius-sm); +} diff --git a/src/admin/components/coupons/CouponMetabox.js b/src/admin/components/coupons/CouponMetabox.js new file mode 100644 index 000000000..368e3d3da --- /dev/null +++ b/src/admin/components/coupons/CouponMetabox.js @@ -0,0 +1,545 @@ +/** + * Coupon Metabox - React metabox island for post.php editor + * Uses WPCFTO design system components + */ + +import { useState, useEffect } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { MetaboxLayout, TabNav, TabPanel, Field, Input, Checkbox, Textarea, Button, Notice, GroupTitle } from '../../design-system'; + +// Currency helper functions +const getGlobalCurrencies = () => { + if (window.formipayGlobalCurrencies) { + return window.formipayGlobalCurrencies; + } + return []; +}; + +const getCurrencySymbol = (currencyRaw) => { + const parts = currencyRaw.split(':::'); + return parts[1] || currencyRaw; +}; + +const getCurrencyCode = (currencyRaw) => { + const parts = currencyRaw.split(':::'); + return parts[0] || currencyRaw; +}; + +const getFlagByCurrency = (currencyRaw) => { + if (window.formipayGetFlag) { + return window.formipayGetFlag(currencyRaw); + } + return ''; +}; + +export default function CouponMetabox({ postId }) { + const [activeTab, setActiveTab] = useState('rules'); + const [loading, setLoading] = useState(true); + const [saving, setSaving] = useState(false); + const [message, setMessage] = useState(null); + + // Form state + const [formData, setFormData] = useState({ + active: 'on', + type: 'percentage', + amount_percentage: '', + case_sensitive: '', + free_shipping: '', + quantity_active: '', + use_limit: '', + date_limit: '', + amounts_fixed: {}, + max_amounts: {}, + forms: [], + products: [], + customers: [], + }); + + const tabs = [ + { id: 'rules', label: __('Rules', 'formipay'), icon: 'fa fa-cog' }, + { id: 'restriction', label: __('Restrictions', 'formipay'), icon: 'fa fa-lock' }, + ]; + + // Load coupon data + useEffect(() => { + if (postId > 0) { + loadCouponData(); + } else { + setLoading(false); + } + }, [postId]); + + const loadCouponData = async () => { + try { + const response = await fetch(`${window.formipayAdmin?.ajaxUrl || '/wp-admin/admin-ajax.php'}?action=formipay-get-coupon`, { + method: 'POST', + credentials: 'same-origin', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: new URLSearchParams({ + id: postId, + _wpnonce: window.formipayAdmin?.nonce || '', + }), + }); + + const result = await response.json(); + + if (result.success) { + const data = result.data; + setFormData(prev => ({ + ...prev, + active: data.active || 'on', + type: data.type || 'percentage', + amount_percentage: data.amount_percentage || '', + case_sensitive: data.case_sensitive || '', + free_shipping: data.free_shipping || '', + quantity_active: data.quantity_active || '', + use_limit: data.use_limit || '', + date_limit: data.date_limit || '', + amounts_fixed: data.amounts_fixed?.reduce((acc, item) => { + acc[item.symbol] = item.amount; + return acc; + }, {}) || {}, + max_amounts: data.max_amounts?.reduce((acc, item) => { + acc[item.symbol] = item.amount; + return acc; + }, {}) || {}, + forms: data.forms || [], + products: data.products || [], + customers: data.customers || [], + })); + } + } catch (error) { + console.error('Failed to load coupon:', error); + setMessage({ type: 'error', text: __('Failed to load coupon data.', 'formipay') }); + } finally { + setLoading(false); + } + }; + + const handleChange = (field, value) => { + setFormData(prev => ({ ...prev, [field]: value })); + }; + + const handleSave = async () => { + setSaving(true); + setMessage(null); + + try { + const params = new URLSearchParams({ + id: postId, + title: document.querySelector('#title input')?.value || '', + _wpnonce: window.formipayAdmin?.nonce || '', + ...formData, + }); + + // Add fixed amounts + Object.entries(formData.amounts_fixed).forEach(([symbol, amount]) => { + params.append(`amount_fixed_${symbol}`, amount); + }); + + // Add max amounts + Object.entries(formData.max_amounts).forEach(([symbol, amount]) => { + params.append(`max_amount_${symbol}`, amount); + }); + + const response = await fetch(`${window.formipayAdmin?.ajaxUrl || '/wp-admin/admin-ajax.php'}?action=formipay-save-coupon`, { + method: 'POST', + credentials: 'same-origin', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: params, + }); + + const result = await response.json(); + + if (result.success) { + setMessage({ type: 'success', text: result.data.message || __('Coupon saved successfully.', 'formipay') }); + } else { + setMessage({ type: 'error', text: result.data?.message || __('Failed to save coupon.', 'formipay') }); + } + } catch (error) { + console.error('Failed to save coupon:', error); + setMessage({ type: 'error', text: __('Failed to save coupon.', 'formipay') }); + } finally { + setSaving(false); + } + }; + + const isPercentage = formData.type === 'percentage'; + const isFixed = formData.type === 'fixed'; + + if (loading) { + return
{__('Loading...', 'formipay')}
; + } + + return ( +
+ {message && ( + setMessage(null)} + > + {message.text} + + )} + + + + {(tab) => { + if (tab.id === 'rules') { + return ( +
+ {/* General Settings */} + + + + handleChange('active', e.target.checked ? 'on' : '')} + /> + + + +
+ + +
+
+ + {isPercentage && ( + + handleChange('amount_percentage', e.target.value)} + /> + + )} + + {/* Fixed Amount Section */} + {isFixed && ( + <> + + + {getGlobalCurrencies().map((currency) => { + const symbol = getCurrencySymbol(currency.currency); + const currencyCode = getCurrencyCode(currency.currency); + const flag = getFlagByCurrency(currency.currency); + const step = currency.decimal_digits > 0 ? 1 / (currency.decimal_digits * 10) : 1; + + return ( +
+
+
+ + {flag && } + {__('Amount in', 'formipay')} {symbol} + +
+
+
+ handleChange('amounts_fixed', { + ...formData.amounts_fixed, + [symbol]: e.target.value + })} + /> +
+
+ ); + })} + + )} + + {/* Max Discount Section */} + + + {getGlobalCurrencies().map((currency) => { + const symbol = getCurrencySymbol(currency.currency); + const currencyCode = getCurrencyCode(currency.currency); + const flag = getFlagByCurrency(currency.currency); + const step = currency.decimal_digits > 0 ? 1 / (currency.decimal_digits * 10) : 1; + + return ( + + {flag && } + {__('Max Amount in', 'formipay')} {symbol} + + } + description={__('Leave empty to not limit the max discount amount.', 'formipay')} + > + handleChange('max_amounts', { + ...formData.max_amounts, + [symbol]: e.target.value + })} + /> + + ); + })} + + {/* Rules Section */} + + + + handleChange('case_sensitive', e.target.checked ? 'on' : '')} + /> + + + + handleChange('free_shipping', e.target.checked ? 'on' : '')} + /> + + + {isFixed && ( + + handleChange('quantity_active', e.target.checked ? 'on' : '')} + /> + + )} +
+ ); + } + + if (tab.id === 'restriction') { + return ( +
+ + + + handleChange('use_limit', e.target.value)} + /> + + + + handleChange('date_limit', e.target.value)} + /> + + + + handleChange('forms', values)} + /> + + + + handleChange('products', values)} + /> + + + + handleChange('customers', values)} + /> + +
+ ); + } + + return null; + }} +
+ +
+ +
+
+
+ ); +} + +// Simple Autocomplete Field Component +function AutocompleteField({ postType, value, onChange }) { + const [search, setSearch] = useState(''); + const [results, setResults] = useState([]); + const [loading, setLoading] = useState(false); + const [open, setOpen] = useState(false); + + const selectedItems = value || []; + + const handleSearch = async (query) => { + setSearch(query); + if (query.length < 2) { + setResults([]); + return; + } + + setLoading(true); + try { + const response = await fetch(`${window.formipayAdmin?.ajaxUrl || '/wp-admin/admin-ajax.php'}?action=formipay-autocomplete-search`, { + method: 'POST', + credentials: 'same-origin', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: new URLSearchParams({ + post_type: postType, + search: query, + _wpnonce: window.formipayAdmin?.nonce || '', + }), + }); + + const result = await response.json(); + if (result.success) { + setResults(result.data || []); + } + } catch (error) { + console.error('Autocomplete search failed:', error); + } finally { + setLoading(false); + } + }; + + const handleSelect = (item) => { + if (!selectedItems.includes(item.value)) { + onChange([...selectedItems, item.value]); + } + setSearch(''); + setResults([]); + }; + + const handleRemove = (valueToRemove) => { + onChange(selectedItems.filter(v => v !== valueToRemove)); + }; + + return ( +
+
+ {selectedItems.map(val => ( + + {val} + + + ))} +
+
+ handleSearch(e.target.value)} + onFocus={() => setOpen(true)} + placeholder={__('Search...', 'formipay')} + /> + {loading && ...} +
+ {open && results.length > 0 && ( +
+ {results.map(item => ( +
handleSelect(item)} + > + {item.label} +
+ ))} +
+ )} +
+ ); +} diff --git a/src/admin/index.js b/src/admin/index.js index e5640a0c2..5f30f3b9b 100644 --- a/src/admin/index.js +++ b/src/admin/index.js @@ -4,9 +4,12 @@ import { render } from '@wordpress/element'; import App from './components/App'; +import CouponMetabox from './components/coupons/CouponMetabox'; +import './components/coupons/CouponMetabox.css'; // Mount the React app to all available mount points const mountApps = () => { + // Mount main admin app pages const mountPoints = document.querySelectorAll('[data-formipay-mount]'); console.log('[Formipay] Mount points found:', mountPoints.length); @@ -28,6 +31,30 @@ const mountApps = () => { console.error('[Formipay] Failed to mount:', page, error); } }); + + // Mount metabox islands + const metaboxPoints = document.querySelectorAll('[data-formipay-metabox]'); + + console.log('[Formipay] Metabox points found:', metaboxPoints.length); + + metaboxPoints.forEach((mountPoint) => { + const metaboxType = mountPoint.dataset.formipayMetabox; + const postId = parseInt(mountPoint.dataset.postId || '0'); + + console.log('[Formipay] Mounting metabox:', metaboxType, 'for post:', postId); + + try { + if (metaboxType === 'coupon') { + render( + , + mountPoint + ); + console.log('[Formipay] Successfully mounted coupon metabox'); + } + } catch (error) { + console.error('[Formipay] Failed to mount metabox:', metaboxType, error); + } + }); }; // Initialize when DOM is ready