@extends('layouts.dashboard')
@section('content')
@php
/**
* Vendor → Coupons: this restaurant's discount codes, with what they have actually
* cost. Every performance figure is read from the orders each code was applied to
* (orders.coupon_id), not from a running counter, so the discount given and the
* basket it bought are both real (CouponController::index()).
*
* @var array $rows the current pager window of coupon rows
* @var array $pager paginate() metadata
* @var array $rangeLinks ['options' => [days => label], 'selected' => string]
* @var int $rangeDays the selected window, in days
* @var bool $showMoney false for a manager: discount cost stays with the owner
* @var int $redemptions orders in the window that carried a code
* @var float $discountGiven
* @var float|null $aovCoupon average order value with a code (null = none in window)
* @var float|null $aovPlain average order value without a code
* @var int $plainOrders
* @var float|null $usageRate % of capped headroom used (null = no capped codes)
* @var int $capUsed @var int $capTotal
* @var array $byCode coupon_id => ['uses' => int, 'discount' => float]
* @var array $trendChart @var array $trendMeta redemptions per day
* @var array $codeChart @var array $codeMeta redemptions by code
*/
$showMoney = $showMoney ?? true;
$byCode = $byCode ?? [];
// The lift a code buys: how a coupon basket compares with an ordinary one. Only
// meaningful when both sides of the comparison actually happened in the window.
$lift = ($aovCoupon !== null && $aovPlain !== null && $aovPlain > 0)
? round(($aovCoupon - $aovPlain) / $aovPlain * 100, 1)
: null;
// The coupon table takes no filters beyond the restaurant scope (the range control drives
// the analytics above, not the code list), so the export needs no query string.
$qs = '';
@endphp
@php /* .qm-d2: the dashboard density standard (app.css §35) */
@endphp
@php // Page primary action → top-bar subheader slot (leaves the table card header for the
// title + any table-scoped utility). ob_start captures the button HTML for the layout slot.
ob_start();
@endphp
@php \App\Support\View::slot('subhead', ob_get_clean());
@endphp
@php /* Trends beside the breakdown: when codes are being spent, and which ones. Each
card's caption and its accessible summary are the same sentence. */
@endphp
@php /* Window mixes a "Now"/"No end date" fallback with a date, so that cell carries the
start date in data-sort-value instead — the composite text won't parse either way. */
@endphp
@php /* Discount mixes a percentage with a money amount, which are not one scale, so that
carries no data-sort — no honest sort key exists across the two. */
@endphp