Files
formipay/build/admin.js

1 line
47 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(()=>{"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",$),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,$,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:`${$}-${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("-");O(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<y.length-1&&(0,t.createElement)("div",{className:"timeline-line"}),(0,t.createElement)("span",{className:"timeline-label"},_[e])))),(0,t.createElement)("div",{className:"timeline-events"},0===r.length?(0,t.createElement)("p",{className:"no-events"},(0,n.__)("No timeline events yet","formipay")):(0,t.createElement)("ul",null,r.map((e,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 $({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 O={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)("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 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"),action:"formipay-create-coupon-post"},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 O[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("#","");O[e]&&o(e)};return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)},[]);const l=O[r];return l?(0,t.createElement)("div",{className:"formipay-admin-wrap"},(0,t.createElement)($,{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()})();