/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
/******/ (() => { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ "./src/js/bp-dashboard-pagination.js"
/*!*******************************************!*\
  !*** ./src/js/bp-dashboard-pagination.js ***!
  \*******************************************/
() {

eval("{/**\n * Better Payment – User Dashboard Pagination\n *\n * Shared script for Transactions and Subscriptions tabs.\n * Works for both Elementor widget and Gutenberg block frontend renders.\n *\n * Security  : every REST request is authenticated via the X-WP-Nonce header.\n * Config    : reads restUrl + nonce from window.betterPaymentUserDash (localized by PHP).\n * Data      : reads per-table config from data-bp-settings JSON attribute on the wrapper.\n * Ellipsis  : clicking \"...\" navigates to the midpoint of the hidden page range, allowing\n *             progressive discovery of pages without cluttering the UI.\n */\n/* jshint esversion: 5 */\n(function () {\n  'use strict';\n\n  /* ── Global config ───────────────────────────────────────────────────── */\n  var dash = window.betterPaymentUserDash || {};\n  var restUrl = dash.restUrl || '';\n  var nonce = dash.nonce || '';\n\n  /* ── Helpers ─────────────────────────────────────────────────────────── */\n  function esc(s) {\n    return String(s == null ? '' : s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;');\n  }\n  function formatDate(ts) {\n    if (!ts) return '';\n    var d = new Date(Number(ts) * 1000);\n    var mo = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n    return ('0' + d.getDate()).slice(-2) + ' ' + mo[d.getMonth()] + ', ' + d.getFullYear();\n  }\n  function sourceImg(src, assetsUrl) {\n    var s = (src || '').toLowerCase();\n    if (s === 'paypal') return '<img class=\"source--img\" src=\"' + esc(assetsUrl + '/img/paypal.png') + '\" alt=\"PayPal\">';\n    if (s === 'stripe') return '<img class=\"source--img\" src=\"' + esc(assetsUrl + '/img/stripe.svg') + '\" alt=\"Stripe\">';\n    if (s === 'paystack') return '<img class=\"source--img\" src=\"' + esc(assetsUrl + '/img/paystack.svg') + '\" alt=\"Paystack\">';\n    return '';\n  }\n\n  /* ── Pagination HTML ─────────────────────────────────────────────────── */\n  /**\n   * Build the pagination <ul> HTML.\n   * Mirrors the admin bp_paginate_links() structure so existing plugin CSS applies.\n   * Ellipsis items are rendered as clickable <a> tags that jump to the midpoint\n   * of the hidden page range, letting users progressively discover all pages.\n   *\n   * @param {number} current  - current page (1-based)\n   * @param {number} total    - total number of pages\n   * @returns {string} HTML string\n   */\n  function buildPaginationHtml(current, total) {\n    if (total <= 1) return '';\n    var html = '<ul>';\n\n    // ── Prev button ───────────────────────────────────────────────────\n    if (current > 1) {\n      html += '<li><a href=\"#\" class=\"pagination-previous bp--prev\" aria-label=\"Previous\">' + '<i class=\"bp-icon bp-caret-left\"></i></a></li>';\n    } else {\n      html += '<li><a class=\"pagination-previous bp--prev disabled\" aria-disabled=\"true\" aria-label=\"Previous\">' + '<i class=\"bp-icon bp-caret-left\"></i></a></li>';\n    }\n\n    // ── Page numbers with smart ellipsis ─────────────────────────────\n    if (total <= 7) {\n      // Show every page when the total is small enough\n      for (var i = 1; i <= total; i++) {\n        var ac = i === current ? ' is-current active' : '';\n        html += '<li><a href=\"#\" class=\"pagination-link bp--page-num' + ac + '\" data-page=\"' + i + '\" aria-label=\"Page ' + i + '\"> ' + i + ' </a></li>';\n      }\n    } else {\n      // Smart window: always show first, last, and current ± 2.\n      // Render an interactive \"...\" between gaps.\n      var rendered = {}; // tracks pages already output\n      var ellipsisLeft = false; // have we output a left  \"...\" yet?\n      var ellipsisRight = false; // have we output a right \"...\" yet?\n\n      for (var p = 1; p <= total; p++) {\n        var inWindow = p === 1 || p === total || p >= current - 2 && p <= current + 2;\n        if (inWindow) {\n          var cls = p === current ? ' is-current active' : '';\n          html += '<li><a href=\"#\" class=\"pagination-link bp--page-num' + cls + '\" data-page=\"' + p + '\" aria-label=\"Page ' + p + '\"> ' + p + ' </a></li>';\n          rendered[p] = true;\n        } else {\n          // Gap between last rendered page and this one — output one \"...\"\n          var prevRendered = p - 1;\n          while (prevRendered >= 1 && !rendered[prevRendered]) {\n            prevRendered--;\n          }\n          var inLeftGap = p < current - 2 && !ellipsisLeft;\n          var inRightGap = p > current + 2 && !ellipsisRight;\n          if (inLeftGap) {\n            // Midpoint of hidden range: from (last always-shown = 1+1=2) to current-3\n            var leftHiddenStart = 2;\n            var leftHiddenEnd = current - 3;\n            var leftMid = Math.max(1, Math.round((leftHiddenStart + leftHiddenEnd) / 2));\n            html += '<li><a href=\"#\" class=\"pagination-link bp--ellipsis bp--page-num\" data-page=\"' + leftMid + '\" title=\"Jump to page ' + leftMid + '\">...</a></li>';\n            ellipsisLeft = true;\n          } else if (inRightGap) {\n            // Midpoint of hidden range: from current+3 to total-1\n            var rightHiddenStart = current + 3;\n            var rightHiddenEnd = total - 1;\n            var rightMid = Math.min(total, Math.round((rightHiddenStart + rightHiddenEnd) / 2));\n            html += '<li><a href=\"#\" class=\"pagination-link bp--ellipsis bp--page-num\" data-page=\"' + rightMid + '\" title=\"Jump to page ' + rightMid + '\">...</a></li>';\n            ellipsisRight = true;\n          }\n        }\n      }\n    }\n\n    // ── Next button ───────────────────────────────────────────────────\n    if (current < total) {\n      html += '<li><a href=\"#\" class=\"pagination-next bp--next\" aria-label=\"Next\">' + '<i class=\"bp-icon bp-caret-right\"></i></a></li>';\n    } else {\n      html += '<li><a class=\"pagination-next bp--next disabled\" aria-disabled=\"true\" aria-label=\"Next\">' + '<i class=\"bp-icon bp-caret-right\"></i></a></li>';\n    }\n    html += '</ul>';\n    return html;\n  }\n\n  /* ── Row builders ────────────────────────────────────────────────────── */\n  function noItemsRow(label) {\n    return '<div class=\"flex justify-center m-5\"><p class=\"bp-no_subscription-text\">' + esc(label) + '</p></div>';\n  }\n  function buildTransactionRows(txns, s) {\n    if (!txns.length) return noItemsRow(s.no_items_label);\n    return txns.map(function (t, i) {\n      var c = i + 1;\n      var row = '<div class=\"better-payment-user-dashboard-table-body bp--table-body bp-min_width-1300 flex items-center justify-between gap-1\">';\n      if (s.name) {\n        var imp = t.is_imported ? '<span class=\"bp-icon bp-imported imported-icon\"></span> ' : '';\n        row += '<div class=\"td details user-name flex items-center gap-3\"><p>' + imp + esc(t.customer_name) + '</p></div>';\n      }\n      if (s.email) {\n        row += '<div class=\"td details email flex items-center gap-3\"><p>' + '<span id=\"bp_email_copy_clipboard_input_' + c + '\">' + esc(t.customer_email) + '</span> ' + '<span id=\"bp_email_copy_clipboard_' + c + '\" class=\"bp-icon bp-copy-square bp-email-copy-clipboard\" data-bp_txn_counter=\"' + c + '\" title=\"Copy\"></span>' + '</p></div>';\n      }\n      if (s.amount) {\n        row += '<div class=\"td details amount flex items-center gap-3\"><p>' + esc(t.currency) + ' ' + esc(t.amount) + '</p></div>';\n      }\n      if (s.payment_type) {\n        row += '<div class=\"td details flex items-center gap-3\"><p>' + esc(t.is_subscription) + '</p></div>';\n      }\n      if (s.transaction_id) {\n        row += '<div class=\"td details transaction flex items-center gap-3\">';\n        if (t.transaction_id) {\n          row += '<p><span id=\"bp_copy_clipboard_input_' + c + '\">' + esc(t.transaction_id) + '</span> ' + '<span id=\"bp_copy_clipboard_' + c + '\" class=\"bp-icon bp-copy-square bp-copy-clipboard\" data-bp_txn_counter=\"' + c + '\" title=\"Copy\"></span></p>';\n        }\n        row += '</div>';\n      }\n      if (s.source) {\n        row += '<div class=\"td details flex justify-center gap-3\">' + sourceImg(t.source, s.assets_url) + '</div>';\n      }\n      if (s.status) {\n        row += '<div class=\"td details flex justify-center gap-3\"><p data-id=\"' + t.id + '\">' + '<span style=\"color:#fff;padding:7px 15px;border-radius:20px;background:' + esc(t.status_color) + '\">' + esc(t.status_label) + '</span>' + '</p></div>';\n      }\n      if (s.date) {\n        row += '<div class=\"td details flex justify-center gap-3\"><p>' + esc(t.payment_date) + '</p></div>';\n      }\n      if (s.action) {\n        row += '<div class=\"td details flex justify-center d-none\">' + '<a href=\"' + esc(s.admin_url + '?page=better-payment-transactions&action=view&id=' + t.id) + '\" class=\"button button--sm view-button\" data-id=\"' + t.id + '\">' + '<span class=\"bp-icon bp-view font-bold\"></span></a></div>';\n      }\n      row += '</div>';\n      return row;\n    }).join('');\n  }\n  function buildSubscriptionRows(txns, s) {\n    if (!txns.length) return noItemsRow(s.no_items_label);\n    return txns.map(function (t, i) {\n      var c = i + 1;\n      var isActive = t.subscription_status === 'active' || t.subscription_status === 'complete';\n      var stLabel = isActive ? s.status_active_label : s.status_inactive_label;\n      var row = '<div class=\"better-payment-user-dashboard-table-body bp--table-body flex items-center justify-between gap-3\">';\n      if (s.subscription_id_show) {\n        row += '<div class=\"td details flex items-center gap-3 min-w-300 max-w-300\">' + '<div class=\"bp-flexbox-container\">' + '<h5 class=\"bp-shortend-text\"><span id=\"bp_copy_clipboard_input_' + c + '\">' + esc(t.subscription_id) + '</span></h5>' + '<p><span id=\"bp_copy_clipboard_' + c + '\" class=\"bp-icon bp-copy-square bp-copy-clipboard\" data-bp_txn_counter=\"' + c + '\"></span></p>' + '</div></div>';\n      }\n      row += '<div class=\"td details d-none\"><p>' + esc(t.subscription_customer_id || '') + '</p></div>';\n      if (s.plan_id_show) {\n        row += '<div class=\"td details flex items-center gap-3 min-w-300 max-w-300\"><p>' + esc(t.subscription_plan_id || '') + '</p></div>';\n      }\n      if (s.status_show) {\n        row += '<div class=\"td details flex justify-center bp-user-dashboard-subscription-status\">' + '<button class=\"' + esc(t.subscription_status || '') + ' ' + (isActive ? 'active' : 'inactive') + '\">' + esc(stLabel) + '</button>' + '</div>';\n      }\n      if (s.amount_show) {\n        row += '<div class=\"td details\"><p class=\"flex items-center\">' + esc(t.currency) + ' ' + esc(t.amount) + '<span class=\"price\">/' + esc(t.subscription_interval || '') + '</span>' + '</p></div>';\n      }\n      if (s.created_date_show) {\n        row += '<div class=\"td details\"><p>' + esc(formatDate(t.subscription_created_date)) + '</p></div>';\n      }\n      if (s.current_period_show) {\n        row += '<div class=\"td details\"><p>' + esc(formatDate(t.subscription_current_period_end)) + '</p></div>';\n      }\n      if (s.action_show) {\n        var showCancel = isActive && !t.is_payment_split_payment ? '' : 'is-hidden';\n        row += '<div class=\"td details flex justify-center\">' + '<button class=\"cancel bp-user-dashboard-subscription-cancel ' + esc(t.subscription_status || '') + ' ' + (isActive ? 'active' : 'inactive') + ' ' + showCancel + '\" data-subscriptionid=\"' + esc(t.subscription_id || '') + '\">' + esc(s.action_cancel_label) + '</button></div>';\n      }\n      row += '</div>';\n      return row;\n    }).join('');\n  }\n\n  /* ── Per-table init ──────────────────────────────────────────────────── */\n  function initTable(wrapper) {\n    // Guard against double-init (Elementor can fire element_ready multiple times)\n    if (wrapper.dataset.bpInitialized) return;\n    wrapper.dataset.bpInitialized = '1';\n    var paginationEl = wrapper.querySelector('.bp--pagination');\n    var tbody = wrapper.querySelector('.bp--table-tbody');\n    if (!tbody) return;\n    var tab = wrapper.dataset.bpTab || 'transactions';\n    var totalPages = parseInt(wrapper.dataset.bpTotalPages, 10) || 1;\n    var perPage = parseInt(wrapper.dataset.bpPerPage, 10) || 10;\n    var curPage = 1;\n    var settings = {};\n    try {\n      settings = JSON.parse(wrapper.dataset.bpSettings || '{}');\n    } catch (e) {/* ignore */}\n    function buildRows(txns) {\n      return tab === 'subscriptions' ? buildSubscriptionRows(txns, settings) : buildTransactionRows(txns, settings);\n    }\n    function renderPagination() {\n      if (!paginationEl) return;\n      if (totalPages <= 1) {\n        paginationEl.innerHTML = '';\n        paginationEl.style.display = 'none';\n        return;\n      }\n      paginationEl.style.display = '';\n      paginationEl.innerHTML = buildPaginationHtml(curPage, totalPages);\n    }\n    function loadPage(page) {\n      if (!restUrl) return;\n      if (page < 1 || page > totalPages) return;\n      tbody.style.opacity = '0.5';\n      var url = restUrl + '?tab=' + encodeURIComponent(tab) + '&page=' + encodeURIComponent(page) + '&per_page=' + encodeURIComponent(perPage);\n      fetch(url, {\n        credentials: 'same-origin',\n        headers: {\n          'X-WP-Nonce': nonce\n        }\n      }).then(function (r) {\n        if (!r.ok) throw new Error('HTTP ' + r.status);\n        return r.json();\n      }).then(function (data) {\n        tbody.innerHTML = buildRows(data.transactions || []);\n        curPage = data.page || page;\n        totalPages = data.pages || totalPages;\n        renderPagination();\n        tbody.style.opacity = '';\n\n        // Scroll table into view smoothly on page change\n        wrapper.scrollIntoView({\n          behavior: 'smooth',\n          block: 'nearest'\n        });\n      }).catch(function () {\n        tbody.style.opacity = '';\n      });\n    }\n\n    // Build initial pagination from PHP-supplied data attributes\n    renderPagination();\n\n    // Event delegation — works for both the initial render and JS-rebuilt HTML\n    if (paginationEl) {\n      paginationEl.addEventListener('click', function (e) {\n        e.preventDefault();\n        var a = e.target.closest('a');\n        if (!a) return;\n        if (a.classList.contains('disabled') || a.getAttribute('aria-disabled') === 'true') return;\n        if (a.classList.contains('bp--prev')) {\n          if (curPage > 1) loadPage(curPage - 1);\n        } else if (a.classList.contains('bp--next')) {\n          if (curPage < totalPages) loadPage(curPage + 1);\n        } else if (a.classList.contains('bp--page-num')) {\n          // Handles both normal page links and ellipsis jump links (both use bp--page-num)\n          var p = parseInt(a.dataset.page, 10);\n          if (p && p !== curPage) loadPage(p);\n        }\n      });\n    }\n  }\n\n  /* ── Bootstrap ───────────────────────────────────────────────────────── */\n  function init() {\n    document.querySelectorAll('.bp--table-wrapper[data-bp-tab]').forEach(initTable);\n  }\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', init);\n  } else {\n    init();\n  }\n\n  /* ── MutationObserver — Elementor editor AJAX re-renders ─────────────── */\n  // When Elementor re-renders a widget (settings change), it injects new DOM\n  // into the preview. DOMContentLoaded has already fired, so we watch for the\n  // new .bp--table-wrapper elements and init them when they appear.\n  if (typeof MutationObserver !== 'undefined' && document.body) {\n    var observer = new MutationObserver(function (mutations) {\n      mutations.forEach(function (m) {\n        m.addedNodes.forEach(function (node) {\n          if (node.nodeType !== 1) return;\n          if (node.matches && node.matches('.bp--table-wrapper[data-bp-tab]')) {\n            // Elementor may re-render with fresh localization data\n            var freshDash = window.betterPaymentUserDash || {};\n            restUrl = freshDash.restUrl || restUrl;\n            nonce = freshDash.nonce || nonce;\n            initTable(node);\n          }\n          if (node.querySelectorAll) {\n            node.querySelectorAll('.bp--table-wrapper[data-bp-tab]').forEach(function (w) {\n              var freshDash = window.betterPaymentUserDash || {};\n              restUrl = freshDash.restUrl || restUrl;\n              nonce = freshDash.nonce || nonce;\n              initTable(w);\n            });\n          }\n        });\n      });\n    });\n    observer.observe(document.body, {\n      childList: true,\n      subtree: true\n    });\n  }\n\n  /* ── Elementor frontend hook — element_ready ─────────────────────────── */\n  // Fires after each widget is rendered in the Elementor editor preview.\n  // Ensures pagination is init'd even when elementorFrontend loads after this script.\n  function bindElementorHook() {\n    if (window.elementorFrontend && window.elementorFrontend.hooks) {\n      window.elementorFrontend.hooks.addAction('frontend/element_ready/global', function ($scope) {\n        if (!$scope || !$scope[0]) return;\n        var freshDash = window.betterPaymentUserDash || {};\n        restUrl = freshDash.restUrl || restUrl;\n        nonce = freshDash.nonce || nonce;\n        $scope[0].querySelectorAll('.bp--table-wrapper[data-bp-tab]').forEach(initTable);\n      });\n    }\n  }\n  if (window.elementorFrontend) {\n    bindElementorHook();\n  } else {\n    window.addEventListener('elementor/frontend/init', bindElementorHook);\n  }\n})();\n\n//# sourceURL=webpack://better-payment/./src/js/bp-dashboard-pagination.js?\n}");

/***/ }

/******/ 	});
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module can't be inlined because the eval devtool is used.
/******/ 	var __webpack_exports__ = {};
/******/ 	__webpack_modules__["./src/js/bp-dashboard-pagination.js"]();
/******/ 	
/******/ })()
;