@extends('admin.layouts.admin')
@section('content')
    <div class="pagetitle">
      <h1>Dashboard</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="#">Home</a></li>
          <li class="breadcrumb-item">Dashboard</li>
          <li class="breadcrumb-item active">Plans</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section dashboard">
        <div class="row">

            <!-- Left side columns -->
            <div class="col-lg-12">


                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">{{ isset($plan) ? 'Edit Plan' : 'Create New Plan' }}</h5>
                        {{-- <p>Personal accounts list where admin can edit, update and delete their records.</p> --}}


                        @if ($errors->any())
                            <div class="alert alert-danger">
                                <ul>
                                    @foreach ($errors->all() as $error)
                                        <li>{{ $error }}</li>
                                    @endforeach
                                </ul>
                            </div>
                        @endif


                        <form action="{{ isset($plan) ? route('admin.plans.update', $plan->id) : route('admin.plans.store') }}" method="POST">
                            @csrf
                            @if(isset($plan))
                                @method('PUT')
                            @endif

                            <div class="form-group mb-3">
                                <label for="title">Title</label>
                                <input type="text" name="title" class="form-control" value="{{ isset($plan) ? $plan->title : old('title') }}" required>
                            </div>

                            <div class="form-group mb-3">
                                <label for="days">Days</label>
                                <input type="number" name="days" class="form-control" value="{{ isset($plan) ? $plan->days : old('days') }}" required>
                            </div>

                            <div class="form-group mb-3">
                                <label for="price">Price</label>
                                <input type="text" name="price" class="form-control" value="{{ isset($plan) ? $plan->price : old('price') }}" required>
                            </div>

                            <div class="form-group mb-3">
                                <label for="status">Status</label>
                                <select name="status" class="form-control" required>
                                    <option value="1" {{ isset($plan) && $plan->status == 1 ? 'selected' : '' }}>Active</option>
                                    <option value="0" {{ isset($plan) && $plan->status == 0 ? 'selected' : '' }}>Inactive</option>
                                </select>
                            </div>

                            <div class="form-group mb-3">
                                <label for="trial_days">Trial Days</label>
                                <input type="number" name="trial_days" class="form-control" value="{{ isset($plan) ? $plan->trial_days : old('trial_days') }}" required>
                            </div>

                            <div class="form-group mb-3">
                                <label for="plan_type">Plan Type</label>
                                <select name="plan_type" class="form-control" required>
                                    <option value="free" {{ isset($plan) && $plan->plan_type == 'free' ? 'selected' : '' }}>Free</option>
                                    <option value="paid" {{ isset($plan) && $plan->plan_type == 'paid' ? 'selected' : '' }}>Paid</option>
                                </select>
                            </div>

                            <button type="submit" class="btn btn-success">{{ isset($plan) ? 'Update Plan' : 'Create Plan' }}</button>
                        </form>


                    </div>
                </div>

            </div><!-- End Left side columns -->

        </div>
    </section>

@endsection
