<?php
/**
 * Coupon Admin UI — shared partial for admin settings page
 *
 * Variables expected:
 *   $role  string  'admin' or 'vendor'
 *
 * This file outputs:
 *   1. The mount point <div id="wahrb-coupon-manager-root">
 *   2. wp_localize_script() for the coupon manager JS
 *
 * @package WahraRentalsBookings
 * @since   2.3.0
 */

defined('ABSPATH') || exit;

if (empty($role)) {
    $role = 'admin';
}

$mode           = wahrb_get_mode(); // 'dokan' or 'solo'
$currency       = function_exists('get_woocommerce_currency_symbol')
    ? html_entity_decode(get_woocommerce_currency_symbol())
    : '$';

// i18n strings for the JS manager
$i18n = [
    'loading'            => __('Loading…', 'wahra-rentals-bookings'),
    'createCoupon'       => __('Create Coupon', 'wahra-rentals-bookings'),
    'editCoupon'         => __('Edit Coupon', 'wahra-rentals-bookings'),
    'searchPlaceholder'  => __('Search coupons…', 'wahra-rentals-bookings'),
    'noCoupons'          => __('No coupons yet. Create your first one!', 'wahra-rentals-bookings'),
    'code'               => __('Code', 'wahra-rentals-bookings'),
    'type'               => __('Type', 'wahra-rentals-bookings'),
    'value'              => __('Value', 'wahra-rentals-bookings'),
    'usage'              => __('Usage', 'wahra-rentals-bookings'),
    'validDates'         => __('Valid', 'wahra-rentals-bookings'),
    'status'             => __('Status', 'wahra-rentals-bookings'),
    'actions'            => __('Actions', 'wahra-rentals-bookings'),
    'active'             => __('Active', 'wahra-rentals-bookings'),
    'inactive'           => __('Inactive', 'wahra-rentals-bookings'),
    'activate'           => __('Activate', 'wahra-rentals-bookings'),
    'deactivate'         => __('Deactivate', 'wahra-rentals-bookings'),
    'edit'               => __('Edit', 'wahra-rentals-bookings'),
    'delete'             => __('Delete', 'wahra-rentals-bookings'),
    'save'               => __('Save', 'wahra-rentals-bookings'),
    'cancel'             => __('Cancel', 'wahra-rentals-bookings'),
    'generate'           => __('Generate', 'wahra-rentals-bookings'),
    'description'        => __('Description', 'wahra-rentals-bookings'),
    'optional'           => __('optional', 'wahra-rentals-bookings'),
    'discountType'       => __('Discount Type', 'wahra-rentals-bookings'),
    'percent'            => __('Percentage (%)', 'wahra-rentals-bookings'),
    'fixedAmount'        => __('Fixed Amount', 'wahra-rentals-bookings'),
    'minOrder'           => __('Min Order Amount', 'wahra-rentals-bookings'),
    'noMin'              => __('no minimum', 'wahra-rentals-bookings'),
    'maxDiscount'        => __('Max Discount', 'wahra-rentals-bookings'),
    'noCap'              => __('no cap', 'wahra-rentals-bookings'),
    'usageLimit'         => __('Usage Limit', 'wahra-rentals-bookings'),
    'perUserLimit'       => __('Per User Limit', 'wahra-rentals-bookings'),
    'unlimited'          => __('unlimited', 'wahra-rentals-bookings'),
    'validFrom'          => __('Valid From', 'wahra-rentals-bookings'),
    'validUntil'         => __('Valid Until', 'wahra-rentals-bookings'),
    'categoryRestriction' => __('Category Restriction', 'wahra-rentals-bookings'),
    'commaHint'          => __('comma-separated slugs, empty = all', 'wahra-rentals-bookings'),
    'productRestriction' => __('Product ID Restriction', 'wahra-rentals-bookings'),
    'commaHintIds'       => __('comma-separated IDs, empty = all', 'wahra-rentals-bookings'),
    'codeRequired'       => __('Coupon code is required.', 'wahra-rentals-bookings'),
    'valueRequired'      => __('Discount value must be greater than 0.', 'wahra-rentals-bookings'),
    'couponCreated'      => __('Coupon created.', 'wahra-rentals-bookings'),
    'couponUpdated'      => __('Coupon updated.', 'wahra-rentals-bookings'),
    'couponDeleted'      => __('Coupon deleted.', 'wahra-rentals-bookings'),
    'activated'          => __('Coupon activated.', 'wahra-rentals-bookings'),
    'deactivated'        => __('Coupon deactivated.', 'wahra-rentals-bookings'),
    'confirmDelete'      => __('Are you sure you want to delete this coupon?', 'wahra-rentals-bookings'),
    'unknownError'       => __('An error occurred', 'wahra-rentals-bookings'),
];

// Localize the script (wahrb-coupon-admin-js handle must be enqueued before this partial is included)
wp_localize_script('wahrb-coupon-admin-js', 'wahrbCouponAdminConfig', [
    'apiUrl'         => untrailingslashit(rest_url('wahrb/v1')),
    'nonce'          => wp_create_nonce('wp_rest'),
    'role'           => $role,
    'mode'           => $mode,
    'currencySymbol' => $currency,
    'i18n'           => $i18n,
]);
?>

<div id="wahrb-coupon-manager-root" class="wahrb-coupon-manager" data-role="<?php echo esc_attr($role); ?>"></div>
