<?php
/**
 * filtersAdmin.php
 *
 * @since      1.0.0
 * @author     alfiopiccione <alfio.piccione@gmail.com>

 * @license    http://opensource.org/licenses/gpl-2.0.php GPL v2
 *
 * Copyright (C) 2025 alfiopiccione <alfio.piccione@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

if (! defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

$resources = new \WooPoPToFattureAruba\Resources();

//
//  array(
//      'filter'        => '',
//      'callback'      => '',
//      'priority'      => '',
//      'accepted_args' => '',
//  )
//
return apply_filters('waf-filters_admin', array(
    'admin' => array(
        'action' => array(
            /**
             * Reset Login data
             */
            array(
                'filter'   => 'admin_init',
                'callback' => 'WooPoPToFattureAruba\\Functions\\resetApi',
                'priority' => 10,
            ),

            /**
             * Fatture Aruba Actions Login
             */
            array(
                'filter'   => 'wc_el_inv-before_closing_settings_form',
                'callback' => 'WooPoPToFattureAruba\\Filters::loginAction',
                'priority' => 10,
            ),

            /**
             * Admin enqueue scripts
             */
            array(
                'filter'   => 'admin_enqueue_scripts',
                'callback' => array($resources, 'enqueue'),
                'priority' => 20,
            ),
            array(
                'filter'   => 'admin_enqueue_scripts',
                'callback' => array($resources, 'register'),
                'priority' => 30,
            ),
            array(
                'filter'   => 'admin_enqueue_scripts',
                'callback' => array($resources, 'localizeScript'),
                'priority' => 40,
            ),

            /**
             * Ajax Modal dialog container
             */
            array(
                'filter'   => 'admin_footer',
                'callback' => function () {
                    echo "<!-- waf modal -->\n<div class='waf_ajax_modal close'><div class='modal_content'><div class='modal_card close'></div><span class='close'></span></div></div>\n<!-- /waf modal -->";
                },
                'priority' => PHP_INT_MAX,
            ),

            /**
             * Cron Jobs on order status change
             */
            array(
                'filter'        => 'woocommerce_order_status_changed',
                'callback'      => 'WooPoPToFattureAruba\\Jobs::changeStatus',
                'priority'      => 10,
                'accepted_args' => 3,
            ),

            /**
             * Aruba Actions in column billing_address
             */
            array(
                'filter'   => 'wc_el_inv-after_billing_address_wc-orders_custom_column',
                'callback' => 'WooPoPToFattureAruba\\Filters::actionsInOrder',
                'priority' => 30,
            ),
        ),
        'filter' => array(
            /**
             * Fatture Aruba Actions Title
             */
            array(
                'filter'        => 'wc_el_inv-xml_order_list_table_actions',
                'callback'      => function ($output, $id, $item) {
                    $choiceType       = isset($item['choice_type']) && '' !== $item['choice_type'] ? $item['choice_type'] : 'invoice';
                    if ('receipt' === $choiceType) {
                        return $output . sprintf('<p class="waf_error">%s</p>', __('Aruba does not manage receipts, unable to send the xml', WP_FATT_ARUBA_TEXTDOMAIN));
                    }

                    $text = __('Fatture Aruba', WP_FATT_ARUBA_TEXTDOMAIN);
                    return $output . "<h4>{$text}:</h4>";
                },
                'priority'      => 5,
                'accepted_args' => 3,
            ),

            /**
             * Fatture Aruba Actions Import
             */
            array(
                'filter'        => 'wc_el_inv-xml_order_list_table_actions',
                'callback'      => 'WooPoPToFattureAruba\\Filters::importAction',
                'priority'      => 20,
                'accepted_args' => 3,
            ),

            /**
             * Fatture Aruba Actions Delete
             */
            array(
                'filter'        => 'wc_el_inv-xml_order_list_table_actions',
                'callback'      => 'WooPoPToFattureAruba\\Filters::deleteAction',
                'priority'      => 30,
                'accepted_args' => 3,
            ),

            /**
             * Fatture Aruba Actions in order
             */
            array(
                'filter'   => 'woocommerce_admin_order_data_after_order_details',
                'callback' => 'WooPoPToFattureAruba\\Filters::actionsInOrder',
                'priority' => 30,
            ),

            /**
             * Fatture Aruba Actions in refund order
             */
            array(
                'filter'   => 'wc_el_inv-after_refund_order_item_td',
                'callback' => 'WooPoPToFattureAruba\\Filters::refundActions',
                'priority' => 30,
            ),
        ),
    ),
));
