@props([
    'action',
    'method' => 'POST',
    'plan' => null,
    'modules' => [],
    'selectedModules' => [],
    'submitLabel',
])

<form method="POST" action="{{ $action }}" novalidate>
    @csrf
    @if (strtoupper($method) !== 'POST')
        @method($method)
    @endif

    <div class="card">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-6">
                    <x-ui.form.input
                        name="name"
                        :label="__('plans.fields.name')"
                        :value="$plan?->name"
                        required
                    />
                </div>

                <div class="col-md-6">
                    <x-ui.form.input
                        name="slug"
                        :label="__('plans.fields.slug')"
                        :value="$plan?->slug"
                        required
                    />
                </div>

                <div class="col-12">
                    <x-ui.form.input
                        name="description"
                        :label="__('plans.fields.description')"
                        :value="$plan?->description"
                        optional
                    />
                </div>

                <div class="col-md-4">
                    <x-ui.form.input
                        name="price"
                        type="number"
                        step="0.01"
                        min="0"
                        :label="__('plans.fields.price')"
                        :value="$plan?->price ?? 0"
                        required
                    />
                </div>

                <div class="col-md-4">
                    <x-ui.form.input
                        name="currency"
                        :label="__('plans.fields.currency')"
                        :value="$plan?->currency ?? 'USD'"
                        required
                    />
                </div>

                <div class="col-md-4">
                    <x-ui.form.select
                        name="billing_cycle"
                        :label="__('plans.fields.cycle')"
                        :options="[
                            'monthly' => __('plans.cycles.monthly'),
                            'yearly' => __('plans.cycles.yearly'),
                            'lifetime' => __('plans.cycles.lifetime'),
                        ]"
                        :selected="$plan?->billing_cycle ?? 'monthly'"
                        required
                    />
                </div>

                <div class="col-md-4">
                    <x-ui.form.input
                        name="trial_days"
                        type="number"
                        min="0"
                        max="365"
                        :label="__('plans.fields.trial_days')"
                        :value="$plan?->trial_days ?? 0"
                        required
                    />
                </div>

                <div class="col-md-8 d-flex align-items-end">
                    <div class="d-flex gap-4 flex-wrap">
                        <x-ui.form.checkbox
                            name="is_trial"
                            :label="__('plans.fields.is_trial')"
                            :checked="$plan?->is_trial ?? false"
                        />
                        <x-ui.form.checkbox
                            name="is_default"
                            :label="__('plans.fields.is_default')"
                            :checked="$plan?->is_default ?? false"
                        />
                        <x-ui.form.checkbox
                            name="is_active"
                            :label="__('plans.fields.is_active')"
                            :checked="$plan?->is_active ?? true"
                        />
                    </div>
                </div>

                <div class="col-12">
                    <x-ui.form.checkbox-list
                        name="modules"
                        :label="__('plans.fields.modules')"
                        :options="$modules"
                        :selected="$selectedModules"
                        :columns="3"
                    />
                </div>
            </div>
        </div>

        <div class="card-footer d-flex justify-content-end gap-2 bg-white">
            <x-ui.buttons.secondary :href="route('admin.plans.index')">
                {{ __('common.cancel') }}
            </x-ui.buttons.secondary>
            <x-ui.buttons.primary type="submit" icon="fe fe-save">
                {{ $submitLabel }}
            </x-ui.buttons.primary>
        </div>
    </div>
</form>
