{{--
    Every override the team can apply to a shop.

    All of them share the same shape on purpose: explain the consequence in
    plain words, demand a reason, then act. The reason is not bureaucracy —
    six months later it is the only record of why a shop got three free weeks.
--}}

@php $fmt = app(\App\Services\Formatter::class); @endphp

{{-- --------------------------------------------------------------- suspend --}}
<x-ui.modal show="action === 'suspend'" title="Suspend this shop" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        The shop is locked out immediately, whatever their subscription says. Their data is untouched
        and their remaining days are preserved — reinstating gives back exactly the term they paid for.
    </p>

    <div class="mt-4">
        <x-ui.textarea label="Why?" wire:model="reason" rows="3"
                       :error="$errors->first('reason')"
                       placeholder="e.g. chargeback dispute, abuse report, non-payment after three reminders" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="danger" wire:click="suspend" loading="suspend">Suspend shop</x-ui.button>
    </x-slot:footer>
</x-ui.modal>

{{-- ------------------------------------------------------------- reinstate --}}
<x-ui.modal show="action === 'reinstate'" title="Reinstate this shop" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        Access is restored and the account status is recalculated from the subscription dates.
    </p>

    <div class="mt-4">
        <x-ui.textarea label="Note (optional)" wire:model="reason" rows="2"
                       placeholder="e.g. dispute resolved, payment cleared" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="primary" wire:click="reinstate" loading="reinstate">Reinstate</x-ui.button>
    </x-slot:footer>
</x-ui.modal>

{{-- --------------------------------------------------------------- approve --}}
<x-ui.modal show="action === 'approve'" title="Approve this signup" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        Marks the account as approved so the shop can start using the product.
    </p>

    <div class="mt-4">
        <x-ui.textarea label="Note (optional)" wire:model="reason" rows="2" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="primary" wire:click="approve" loading="approve">Approve</x-ui.button>
    </x-slot:footer>
</x-ui.modal>

{{-- ------------------------------------------------------------------ note --}}
<x-ui.modal show="action === 'note'" title="Add an internal note" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        Stamped with your name and the time, and appended to the account history. Shop owners never see it.
    </p>

    <div class="mt-4">
        <x-ui.textarea label="Note" wire:model="reason" rows="3" :error="$errors->first('reason')" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="primary" wire:click="addNote" loading="addNote">Save note</x-ui.button>
    </x-slot:footer>
</x-ui.modal>

{{-- ---------------------------------------------------------------- extend --}}
<x-ui.modal show="action === 'extend'" title="Extend or shorten the term" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        Days are added to whichever is later — today or the current end date — so granting a week to a
        live subscription really does add a week. A negative number pulls the date back in.
    </p>

    @if ($subscription)
        <div class="mt-3 rounded-lg bg-slate-50 p-3 text-xs dark:bg-slate-800">
            Currently ends <strong>{{ $fmt->date($subscription->ends_at) }}</strong>
            ({{ $subscription->daysRemaining() }} day(s) left).
        </div>
    @endif

    <div class="mt-4 grid gap-3 sm:grid-cols-3">
        <x-ui.input label="Days" type="number" wire:model="extendDays" :error="$errors->first('extendDays')" />

        <div class="sm:col-span-2">
            <p class="field-label">Quick pick</p>
            <div class="flex flex-wrap gap-1.5">
                @foreach ([7, 14, 30, 90] as $preset)
                    <button type="button" wire:click="$set('extendDays', {{ $preset }})" class="btn btn-secondary btn-sm">
                        +{{ $preset }}d
                    </button>
                @endforeach
            </div>
        </div>
    </div>

    <div class="mt-3">
        <x-ui.textarea label="Why?" wire:model="reason" rows="2" :error="$errors->first('reason')"
                       placeholder="e.g. goodwill after the outage on 12 Aug" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="primary" wire:click="extend" loading="extend">Apply</x-ui.button>
    </x-slot:footer>
</x-ui.modal>

{{-- ----------------------------------------------------------- change plan --}}
<x-ui.modal show="action === 'change-plan'" title="Change the plan" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        Swaps the plan for the rest of the current term and rewrites the entitlement snapshot, so
        features and limits change immediately. Dates and invoices are untouched.
    </p>

    <div class="mt-4 space-y-3">
        <x-ui.select label="New plan" wire:model="planId" :options="$planOptions" :error="$errors->first('planId')" />
        <x-ui.textarea label="Why?" wire:model="reason" rows="2" :error="$errors->first('reason')" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="primary" wire:click="changePlan" loading="changePlan">Change plan</x-ui.button>
    </x-slot:footer>
</x-ui.modal>

{{-- ------------------------------------------------------------ grant term --}}
<x-ui.modal show="action === 'grant'" title="Grant a paid term" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        For money collected outside the app — cash to a salesman, a cheque, a reseller's bulk order.
        A paid invoice is written alongside it so revenue reporting stays complete. If the shop already
        has a live term, this one queues behind it rather than overwriting it.
    </p>

    <div class="mt-4 space-y-3">
        <x-ui.select label="Plan" wire:model="planId" :options="$planOptions" :error="$errors->first('planId')" />

        <x-ui.select label="Billing cycle" wire:model="cycle" :options="$cycles" />

        <x-ui.input label="Amount received" type="number" step="0.01" wire:model="amount"
                    hint="Leave blank to use the plan's list price." :error="$errors->first('amount')" />

        <x-ui.textarea label="Why / how was it paid?" wire:model="reason" rows="2" :error="$errors->first('reason')"
                       placeholder="e.g. Rs 30,000 cash collected by Bilal, receipt #442" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="primary" wire:click="grantTerm" loading="grantTerm">Grant subscription</x-ui.button>
    </x-slot:footer>
</x-ui.modal>

{{-- ---------------------------------------------------------------- cancel --}}
<x-ui.modal show="action === 'cancel'" title="Cancel the subscription" width="lg" close-action="closeAction">
    <p class="text-sm text-slate-600 dark:text-slate-300">
        Stops auto-renewal. By default the shop keeps the days it has already paid for.
    </p>

    <div class="mt-4 space-y-3">
        <x-ui.toggle
            wire:model="cancelImmediately"
            label="Cut access off today"
            hint="Only for refunds or fraud — otherwise let the paid term run out."
        />

        <x-ui.textarea label="Why?" wire:model="reason" rows="2" :error="$errors->first('reason')" />
    </div>

    <x-slot:footer>
        <x-ui.button wire:click="closeAction">Cancel</x-ui.button>
        <x-ui.button variant="danger" wire:click="cancel" loading="cancel">Cancel subscription</x-ui.button>
    </x-slot:footer>
</x-ui.modal>
