@extends('admin.partials.master')
@section('admin_content')
<section id="dashboard-ecommerce">
    <div class="row">
        <div class="col-12">
            <form action="{{ route('admin.package.insert') }}" method="POST" enctype="multipart/form-data">@csrf
                <input type="hidden" name="id" value="{{ $data ? $data->id : '' }}">
                <div class="card">
                    <div class="card-header">
                        <h4 class="card-title d-flex justify-content-between">
                            <div>{{ $data ? 'Update' : 'Create New' }} Package</div>
                            <div>
                                <a href="{{ route('admin.package.index') }}" class="btn btn-primary btn-sm">
                                    <i class="bx bx-left-arrow"></i> Package List
                                </a>
                            </div>
                        </h4>
                    </div>
                    <div class="card-content">
                        <div class="card-body">
                            <div class="row">
                                {{-- Package Category --}}
                                <div class="col-sm-6">
                                    <label for="package_id">Package Category</label>
                                    <select name="package_id" id="package_id" class="form-control is-valid">
                                        <option value="">Select a option</option>
                                        @php $packages = \App\Models\Package::whereNull('package_id')->get(); @endphp
                                        @foreach($packages as $package)
                                            <option value="{{ $package->id }}" @if($data && $data->package_id == $package->id) selected @endif>
                                                {{ $package->name }} ({{ $package->label }})
                                            </option>
                                        @endforeach
                                    </select>
                                </div>

                                {{-- Tab --}}
                                <div class="col-sm-6">
                                    <label for="tab">Tab</label>
                                    <select name="tab" id="tab" class="form-control is-valid" required>
                                        <option value="">Select a option</option>
                                        <option value="vip" @if($data && $data->tab=='vip') selected @endif>VIP</option>
                                        <option value="fixed" @if($data && $data->tab=='fixed') selected @endif>FIXED</option>
                                        <option value="event" @if($data && $data->tab=='event') selected @endif>EVENT</option>
                                    </select>
                                </div>

                                {{-- Name --}}
                                <div class="col-sm-6">
                                    <label for="name">Package Name</label>
                                    <input type="text" class="form-control is-valid" name="name" id="name" placeholder="Name"
                                        value="{{ $data ? $data->name : '' }}" required>
                                </div>

                                {{-- Label --}}
                                <div class="col-sm-6">
                                    <label for="label">Label</label>
                                    <input type="text" class="form-control is-valid" name="label" id="label" placeholder="Label"
                                        value="{{ $data ? $data->label : '' }}" required>
                                </div>

                                {{-- Upload Photo --}}
                                <div class="col-sm-12 mt-2">
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <label for="photo">Upload Photo <small>(Suggested: 200x200 px)</small></label>
                                            <input type="file" name="photo" class="form-control" id="photo" onchange="showPreview(event)" @if(!$data) required @endif>
                                        </div>
                                        <div class="col-sm-6">
                                            <img src="{{ $data ? asset(view_image($data->photo)) : asset(not_found_img()) }}"
                                                 id="file-ip-1-preview" class="rounded" style="width:100px;height:100px;" alt="Preview Image">
                                        </div>
                                    </div>
                                </div>

                                {{-- Price --}}
                                <div class="col-sm-6">
                                    <label for="price">Price</label>
                                    <input type="number" name="price" class="form-control" value="{{ $data ? $data->price : '' }}" required>
                                </div>

                                {{-- Validity --}}
                                <div class="col-sm-6">
                                    <label for="validity">Validity (Days)</label>
                                    <input type="number" name="validity" class="form-control" value="{{ $data ? $data->validity : '' }}" required>
                                </div>

                             

                                {{-- Daily Watch Limit --}}
                                <div class="col-sm-6">
                                    <label for="daily_watch_limit">Daily Watch Limit</label>
                                    <input type="number" name="daily_watch_limit" class="form-control" value="{{ $data ? $data->daily_watch_limit : '' }}" required>
                                </div>

                               

                                {{-- Commission --}}
                                <div class="col-sm-6">
                                    <label for="commission_with_avg_amount">Commission with Avg Amount</label>
                                    <input type="number" name="commission_with_avg_amount" class="form-control" value="{{ $data ? $data->commission_with_avg_amount : '' }}" required>
                                </div>

                                {{-- Ref Commissions --}}
                                <div class="col-sm-4">
                                    <label for="ref1">First Refer (%)</label>
                                    <input type="number" name="ref1" class="form-control" value="{{ $data ? $data->ref1 : '' }}" required>
                                </div>
                                <div class="col-sm-4">
                                    <label for="ref2">Second Refer (%)</label>
                                    <input type="number" name="ref2" class="form-control" value="{{ $data ? $data->ref2 : '' }}" required>
                                </div>
                                <div class="col-sm-4">
                                    <label for="ref3">Third Refer (%)</label>
                                    <input type="number" name="ref3" class="form-control" value="{{ $data ? $data->ref3 : '' }}" required>
                                </div>

                                {{-- Description --}}
                                <div class="col-sm-12 mt-2">
                                    <label for="desc">Description</label>
                                    <textarea name="desc" class="form-control" rows="3">{{ $data ? $data->desc : '' }}</textarea>
                                </div>

                               {{-- Default & Status --}}
<div class="col-sm-6 mt-2">
    <label for="is_default">Is Default?</label>
    <select name="is_default" class="form-control">
        <option value="0" @if($data && $data->is_default==0) selected @endif>No</option>
        <option value="1" @if($data && $data->is_default==1) selected @endif>Yes</option>
    </select>
</div>

<div class="col-sm-6 mt-2">
    <label for="status">Status</label>
    <select name="status" class="form-control">
        <option value="active" @if($data && $data->status=='active') selected @endif>Active</option>
        <option value="inactive" @if($data && $data->status=='inactive') selected @endif>Inactive</option>
    </select>
</div>


                            </div>
                        </div>
                    </div>

                    <div class="card mt-2">
                        <div class="card-header d-flex justify-content-between">
                            <div style="margin-top:.7rem;">Submit Your Package Information</div>
                            <div>
                                <button type="submit" class="btn btn-success">
                                    <i class="bx bx-plus"></i> {{ $data ? 'Update' : 'Submit' }}
                                </button>
                            </div>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </section>

    <script>
        function showPreview(event){
            if(event.target.files.length > 0){
                var src = URL.createObjectURL(event.target.files[0]);
                var preview = document.getElementById("file-ip-1-preview");
                preview.src = src;
                preview.style.display = "block";
            }
        }
    </script>
@endsection
