@extends('layouts.admin')
<style>
    .switch {
        position: relative;
        display: inline-block;
        width: 50px;
        height: 24px;
    }

    .switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #cccccc;
        transition: .4s;
        border-radius: 24px;
    }

    .slider:before {
        position: absolute;
        content: "";
        height: 18px;
        width: 18px;
        left: 3px;
        bottom: 3px;
        background-color: white;
        transition: .4s;
        border-radius: 50%;
    }

    input:checked+.slider {
        background-color: #28a745;
    }

    input:checked+.slider:before {
        transform: translateX(26px);
    }

    .key-row {
        display: flex;
        gap: 8px;
        align-items: center;
        /* CENTER copy button */
    }

    .key-text {
        flex: 1;
        white-space: pre-wrap;
        word-break: break-all;
        overflow-wrap: anywhere;
    }

    .key-wrap {
        white-space: pre-wrap;
        word-break: break-all;
        overflow-wrap: anywhere;
    }
</style>


@section('admin-content')
    <div class="container-fluid license-show">
        <!-- Page Header -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card border-0 shadow-sm">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <h1 class="h3 mb-1 text-dark">
                                    <i class="fas fa-eye text-info me-2"></i>
                                    {{ trans('app.View License') }}
                                </h1>
                                <p class="text-muted mb-0">{{ $license->license_key }}</p>
                            </div>
                            <div>
                                <a href="{{ route('admin.licenses.edit', $license) }}" class="btn btn-primary me-2">
                                    <i class="fas fa-edit me-1"></i>
                                    {{ trans('app.Edit License') }}
                                </a>
                                <a href="{{ route('admin.licenses.index') }}" class="btn btn-outline-secondary">
                                    <i class="fas fa-arrow-left me-1"></i>
                                    {{ trans('app.Back to Licenses') }}
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Main Content -->
            <div class="col-lg-8">
                <!-- License Overview -->
                <div class="card mb-4">
                    <div class="card-header bg-primary text-white">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-key me-2"></i>
                            {{ trans('app.License Overview') }}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-key text-primary me-1"></i>
                                    {{ trans('app.License Key') }}
                                </label>
                                <div class="input-group">
                                    <input type="text" class="form-control" value="{{ $license->license_key }}" readonly>
                                    <button class="btn btn-outline-secondary copy-btn" type="button"
                                        data-text="{{ $license->license_key }}">
                                        <i class="fas fa-copy"></i>
                                    </button>
                                </div>
                            </div>

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-box text-success me-1"></i>
                                    {{ trans('app.Product') }}
                                </label>
                                <p class="text-muted">{{ $license->product->name ?? trans('app.No Product') }}</p>
                            </div>

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-user text-primary me-1"></i>
                                    {{ trans('app.Owner') }}
                                </label>
                                <p class="text-muted">
                                    @if ($license->user)
                                        <a href="{{ route('admin.users.show', $license->user) }}"
                                            class="text-decoration-none">
                                            {{ $license->user->name }} ({{ $license->user->email }})
                                        </a>
                                    @else
                                        {{ trans('app.No Owner') }}
                                    @endif
                                </p>
                            </div>

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-tag text-warning me-1"></i>
                                    {{ trans('app.License Type') }}
                                </label>
                                <p class="text-muted">
                                    <span
                                        class="badge bg-{{ $license->license_type == 'extended' ? 'success' : 'primary' }}">
                                        {{ trans('app.' . ucfirst($license->license_type)) }}
                                    </span>
                                </p>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-mobile-alt text-info me-1"></i>
                                    {{ trans('app.Device Type') }}
                                </label>

                                <p class="text-muted">
                                    <span class="badge bg-secondary">
                                        @if ($license->device_type === 'web')
                                            {{ trans('app.Web App') }}
                                        @elseif($license->device_type === 'mobile')
                                            {{ trans('app.Mobile App') }}
                                        @elseif($license->device_type === 'server')
                                            {{ trans('app.Server Application') }}
                                        @else
                                            {{ $license->device_type }}
                                        @endif
                                    </span>

                                </p>
                            </div>


                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-toggle-on text-info me-1"></i>
                                    {{ trans('app.Status') }}
                                </label>
                                <p class="text-muted">
                                    <span
                                        class="badge bg-{{ $license->status == 'active' ? 'success' : ($license->status == 'expired' ? 'danger' : 'warning') }}">
                                        {{ trans('app.' . ucfirst($license->status)) }}
                                    </span>
                                </p>
                            </div>

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-globe text-success me-1"></i>
                                    {{ trans('app.Domains') }}
                                </label>
                                <p class="text-muted">{{ $license->domains_count ?? 0 }} /
                                    {{ $license->max_domains ?? 1 }}</p>
                            </div>

                            @if ($license->expires_at)
                                <div class="col-md-6 mb-3">
                                    <label class="form-label fw-bold">
                                        <i class="fas fa-calendar text-danger me-1"></i>
                                        {{ trans('app.Expires At') }}
                                    </label>
                                    <p class="text-muted">{{ $license->expires_at->format('M d, Y H:i') }}</p>
                                </div>
                            @endif

                            @if ($license->support_expires_at)
                                <div class="col-md-6 mb-3">
                                    <label class="form-label fw-bold">
                                        <i class="fas fa-headset text-success me-1"></i>
                                        {{ trans('app.Support Expires At') }}
                                    </label>
                                    <p class="text-muted">{{ $license->support_expires_at->format('M d, Y H:i') }}</p>
                                </div>
                            @endif

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-calendar text-info me-1"></i>
                                    {{ trans('app.Created At') }}
                                </label>
                                <p class="text-muted">{{ $license->created_at->format('M d, Y H:i') }}</p>
                            </div>
                        </div>

                        @if ($license->notes)
                            <div class="mt-3">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-sticky-note text-warning me-1"></i>
                                    {{ trans('app.Notes') }}
                                </label>
                                <div class="bg-light p-3 rounded">
                                    <p class="text-muted mb-0">{{ $license->notes }}</p>
                                </div>
                            </div>
                        @endif
                    </div>
                </div>

                <!-- License Statistics -->
                <div class="card mb-4">
                    <div class="card-header bg-info text-white">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-chart-bar me-2"></i>
                            {{ trans('app.License Statistics') }}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="row text-center">
                            <div class="col-md-3 mb-3">
                                <div class="stats-card">
                                    <h3 class="text-primary">{{ $license->domains_count ?? 0 }}</h3>
                                    <p class="text-muted mb-0">{{ trans('app.Used Domains') }}</p>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="stats-card">
                                    <h3 class="text-success">{{ $license->max_domains ?? 1 }}</h3>
                                    <p class="text-muted mb-0">{{ trans('app.Max Domains') }}</p>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="stats-card">
                                    <h3 class="text-info">{{ $license->logs_count ?? 0 }}</h3>
                                    <p class="text-muted mb-0">{{ trans('app.Activity Logs') }}</p>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="stats-card">
                                    <h3 class="text-warning">{{ $license->days_remaining ?? 0 }}</h3>
                                    <p class="text-muted mb-0">{{ trans('app.Days Remaining') }}</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- License Domains -->
                @if ($license->domains && $license->domains->count() > 0)
                    <div class="card mb-4" id="license_domain_section">
                        <div class="card-header bg-success text-white">
                            <h5 class="card-title mb-0">
                                <i class="fas fa-globe me-2"></i>
                                {{ trans('app.License Domains') }}
                            </h5>
                        </div>

                        <div class="card-body">

                            <div class="table-responsive">
                                <table class="table table-striped text-center align-middle">
                                    <thead>
                                        <tr>
                                            <th>{{ trans('app.Domain') }}</th>
                                            <th>{{ trans('app.Verified At') }}</th>
                                            <th>{{ trans('app.Last Used At') }}</th>
                                            <th>{{ trans('app.Status') }}</th>
                                            <th>{{ trans('app.Actions') }}</th>
                                        </tr>
                                    </thead>

                                    <tbody>
                                        @foreach ($license->domains as $domain)
                                            <tr>
                                                <td>{{ $domain->domain }}</td>



                                                <td>{{ $domain->created_at ? $domain->created_at->format('M d, Y H:i') : '-' }}
                                                </td>
                                                <td>{{ $domain->last_used_at ? $domain->last_used_at->format('M d, Y H:i') : '-' }}
                                                </td>
                                                <td>
                                                    <label class="switch">
                                                        <input type="checkbox" class="toggle-domain-status"
                                                            data-domain-id="{{ $domain->id }}"
                                                            {{ $domain->status === 'active' ? 'checked' : '' }}>
                                                        <span class="slider round"></span>
                                                    </label>

                                                    {{-- <div class="mt-1 small fw-bold text-{{ $domain->status === 'active' ? 'success' : 'secondary' }}">
                                                        {{ $domain->status === 'active' ? trans('app.Active') : trans('app.Inactive') }}
                                                    </div> --}}
                                                </td>

                                                <td class="d-flex justify-content-center">

                                                    <!-- Delete Button Only -->
                                                    <button class="btn btn-sm btn-outline-danger remove-domain-btn"
                                                        data-domain-id="{{ $domain->id }}">
                                                        <i class="fas fa-trash"></i>
                                                    </button>

                                                </td>
                                            </tr>
                                        @endforeach
                                    </tbody>

                                </table>
                            </div>

                        </div>
                    </div>
                @endif

                <div class="card mb-4">
                    <div class="card-header bg-info text-white text-center">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-key me-2"></i>
                            {{ trans('app.License Message Key') }}
                        </h5>
                    </div>

                    <div class="d-flex justify-content-center align-items-center gap-3 mt-2">

                        <select id="message-key-select" class="form-select w-auto m-4">
                            <option value="0" {{ $license->message_key == 0 ? 'selected' : '' }}>No Message</option>
                            <option value="1" {{ $license->message_key == 1 ? 'selected' : '' }}>Soft Message
                            </option>
                            <option value="2" {{ $license->message_key == 2 ? 'selected' : '' }}>Hard Error</option>
                        </select>

                        <button id="update-message-key-btn" class="btn btn-primary m-4"
                            data-license-id="{{ $license->id }}">
                            Update Message Key
                        </button>
                        </hr>

                    </div>

                </div>

                <div class="card mb-4">
                    <div class="card-header bg-info text-white">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-cogs me-2"></i> {{ trans('app.License Settings') }}
                        </h5>
                    </div>

                    <div class="card-body d-flex justify-content-center align-items-center flex-column text-center">

                        {{-- Cache Enable --}}
                        <div class="mb-3 row align-items-center w-50">
                            <label class="col-sm-6 col-form-label fw-bold">
                                {{ trans('app.Enable Cache') }}
                            </label>
                            <div class="col-sm-6">
                                <div class="form-check form-switch d-flex justify-content-center">
                                    <input class="form-check-input setting-toggle" type="checkbox" data-setting="cache"
                                        data-license="{{ $license->id }}"
                                        {{ !empty($settings['cache']) ? 'checked' : '' }}>

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

                        {{-- Cache TTL --}}
                        <div class="mb-3 row align-items-center w-50">

                            <label class="col-sm-6 col-form-label fw-bold">
                                {{ trans('app.Cache TTL (seconds)') }}
                            </label>

                            <div class="col-sm-6 d-flex align-items-center">

                                <input type="number" id="cache-ttl-input" class="form-control text-center me-2"
                                    value="{{ $settings['cache_ttl_in_seconds'] }}" disabled>

                                <!-- Button (Edit / Save) -->
                                <button id="cache-ttl-btn" class="btn btn-sm btn-primary">
                                    <i class="fas fa-edit me-1"></i>
                                </button>

                            </div>

                        </div>
                        {{-- Push Code Enable --}}
                        <div class="mb-3 row align-items-center w-50">
                            <label class="col-sm-6 col-form-label fw-bold">
                                {{ trans('app.Push Code Enable') }}
                            </label>
                            <div class="col-sm-6">
                                <div class="form-check form-switch d-flex justify-content-center">
                                    <input class="form-check-input setting-toggle" type="checkbox"
                                        data-setting="push_code_enable" data-license="{{ $license->id }}"
                                        {{ !empty($settings['push_code_enable']) ? 'checked' : '' }}>

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

                        {{-- Strict License Error --}}
                        <div class="mb-3 row align-items-center w-50">
                            <label class="col-sm-6 col-form-label fw-bold">
                                {{ trans('app.Strict License Error') }}
                            </label>
                            <div class="col-sm-6">
                                <div class="form-check form-switch d-flex justify-content-center">
                                    <input class="form-check-input setting-toggle" type="checkbox"
                                        data-setting="strictLicenseError" data-license="{{ $license->id }}"
                                        {{ !empty($settings['strictLicenseError']) ? 'checked' : '' }}>

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

                    </div>

                </div>

                <!-- Cache TTL Update Modal -->
                <div class="modal fade" id="cacheTTLModal" tabindex="-1">
                    <div class="modal-dialog">
                        <div class="modal-content">

                            <div class="modal-header bg-primary text-white">
                                <h5 class="modal-title">
                                    <i class="fas fa-clock me-2"></i> Update Cache TTL
                                </h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                            </div>

                            <div class="modal-body">

                                <label class="form-label fw-bold">
                                    {{ trans('app.Enter new Cache TTL (seconds)') }}
                                </label>

                                <input type="number" id="modal-cache-ttl-input" class="form-control" min="1"
                                    value="{{ $settings['cache_ttl_in_seconds'] }}">
                            </div>

                            <div class="modal-footer">
                                <button class="btn btn-secondary" data-bs-dismiss="modal">
                                    <i class="fas fa-times me-1"></i> Close
                                </button>

                                <button class="btn btn-primary" id="save-cache-ttl-btn">
                                    <i class="fas fa-save me-1"></i> Save
                                </button>
                            </div>

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

                {{-- Affected Routes --}}

                <div class="card mb-4">
                    <div class="card-header bg-primary text-white text-center">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-route me-2"></i>
                            {{ trans('app.Affected Routes') }}
                        </h5>
                    </div>

                    <div class="card-body">
                        <div class="table-responsive">
                            <table id="affected-routes-table" class="table table-bordered text-center align-middle">
                                <thead class="table-light">
                                    <tr>
                                        <th>{{ trans('app.Route') }}</th>
                                        <th>{{ trans('app.Message') }}</th>
                                        <th>{{ trans('app.Probability') }}</th>
                                        <th>{{ trans('app.Actions') }}</th>
                                    </tr>
                                </thead>

                                <tbody>
                                    @if (!empty($license->affected_routes))
                                        @foreach ($license->affected_routes as $index => $item)
                                            <tr>
                                                <td>{{ $item['route'] }}</td>

                                                <td>
                                                    @if (is_array($item['message']))
                                                        <ul class="list-unstyled mb-0">
                                                            @foreach ($item['message'] as $msg)
                                                                <li>{{ $msg }}</li>
                                                            @endforeach
                                                        </ul>
                                                    @else
                                                        {{ $item['message'] }}
                                                    @endif
                                                </td>

                                                <td>{{ $item['showProbability'] }}</td>

                                                <td>
                                                    <button class="btn btn-sm btn-outline-primary edit-affected-route-btn"
                                                        data-index="{{ $index }}"
                                                        data-route="{{ $item['route'] }}"
                                                        data-message="{{ is_array($item['message']) ? implode('|', $item['message']) : $item['message'] }}"
                                                        data-probability="{{ $item['showProbability'] }}">
                                                        <i class="fas fa-edit"></i>
                                                    </button>

                                                    <button class="btn btn-sm btn-outline-danger delete-route-btn"
                                                        data-index="{{ $index }}">
                                                        <i class="fas fa-trash"></i>
                                                    </button>
                                                </td>
                                            </tr>
                                        @endforeach
                                    @else
                                        <tr>
                                            <td colspan="4" class="text-center text-muted">
                                                {{ trans('app.No affected routes found') }}
                                            </td>
                                        </tr>
                                    @endif
                                </tbody>
                            </table>
                        </div>
                        <div class="d-flex justify-content-end mt-3">
                            <button class="btn btn-success btn-sm" id="add-new-affected-route-btn">
                                <i class="fas fa-plus me-1"></i> {{ trans('app.Add New') }}
                            </button>
                        </div>

                    </div>
                </div>

                <!-- Add New Affected Route Modal -->
                <div class="modal fade" id="addAffectedRouteModal" tabindex="-1" aria-hidden="true">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <div class="modal-header btn-primary text-white">
                                <h5 class="modal-title">
                                    <i class="fas fa-plus me-2"></i>
                                    {{ trans('app.Add New Affected Route') }}
                                </h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"
                                    aria-label="Close"></button>
                            </div>
                            <div class="modal-body">
                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Route') }}</label>
                                    <input type="text" id="new_route" class="form-control">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Message') }}</label>
                                    <input type="text" id="new_message" class="form-control"
                                        placeholder="Use | to separate multiple messages">
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Probability') }}</label>
                                    <input type="number" id="new_probability" class="form-control">
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button class="btn btn-secondary"
                                    data-bs-dismiss="modal">{{ trans('app.Cancel') }}</button>
                                <button class="btn btn-primary"
                                    id="save-new-affected-route-btn">{{ trans('app.Save') }}</button>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="modal fade" id="editAffectedRouteModal" tabindex="-1" aria-hidden="true">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">

                            <div class="modal-header bg-primary text-white">
                                <h5 class="modal-title">{{ trans('app.Edit Affected Route') }}</h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                            </div>

                            <div class="modal-body">
                                <input type="hidden" id="edit_affected_route_index">

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Route') }}</label>
                                    <input type="text" id="edit_affected_route" class="form-control">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Message') }}</label>
                                    <textarea id="edit_affected_message" class="form-control" rows="4"></textarea>
                                    <small class="text-muted">
                                        {{ trans('app.For multiple messages, separate them with | (pipe symbol).') }}
                                    </small>
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Probability') }}</label>
                                    <input type="number" id="edit_affected_probability" class="form-control"
                                        min="0" max="100">
                                </div>
                            </div>

                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
                                    {{ trans('app.Cancel') }}
                                </button>
                                <button type="button" class="btn btn-primary" id="save-affected-route-btn">
                                    {{ trans('app.Save Changes') }}
                                </button>
                            </div>

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

                {{-- Affected Mobile Routes --}}
                <div class="card mb-4">
                    <div class="card-header bg-primary text-white text-center">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-mobile-alt me-2"></i>
                            {{ trans('app.Affected Mobile Routes') }}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table id="affected-mobile-routes-table"
                                class="table table-bordered text-center align-middle">
                                <thead class="table-light">
                                    <tr>
                                        <th>{{ trans('app.Screen') }}</th>
                                        <th>{{ trans('app.Message') }}</th>
                                        <th>{{ trans('app.Probability') }}</th>
                                        <th>{{ trans('app.Actions') }}</th>
                                    </tr>
                                </thead>


                                <tbody>

                                    @if (!empty($license->affected_mobile_routes))
                                        @foreach ($license->affected_mobile_routes as $index => $item)
                                            <tr>
                                                <td>{{ $item['screen'] }}</td>

                                                <td>
                                                    @if (is_array($item['message']))
                                                        <ul class="list-unstyled mb-0">
                                                            @foreach ($item['message'] as $msg)
                                                                <li>{{ $msg }}</li>
                                                            @endforeach
                                                        </ul>
                                                    @else
                                                        {{ $item['message'] }}
                                                    @endif
                                                </td>

                                                <td>{{ $item['showProbability'] }}</td>

                                                <td class="text-center">

                                                    <!-- Edit Button -->
                                                    <button class="btn btn-sm btn-outline-primary edit-mobile-route-btn"
                                                        data-index="{{ $index }}"
                                                        data-screen="{{ $item['screen'] }}"
                                                        data-message="{{ is_array($item['message']) ? implode('|', $item['message']) : $item['message'] }}"
                                                        data-probability="{{ $item['showProbability'] }}">
                                                        <i class="fas fa-edit"></i>
                                                    </button>

                                                    <!-- Delete Button -->
                                                    <button class="btn btn-sm btn-outline-danger delete-mobile-route-btn"
                                                        data-index="{{ $index }}">
                                                        <i class="fas fa-trash"></i>
                                                    </button>

                                                </td>

                                            </tr>
                                        @endforeach
                                    @else
                                        <tr>
                                            <td colspan="4" class="text-center text-muted">
                                                {{ trans('app.No mobile routes found') }}
                                            </td>
                                        </tr>
                                    @endif
                                </tbody>

                            </table>
                        </div>

                        <!-- Add New Button for Mobile Routes -->
                        <div class="d-flex justify-content-end mt-3">
                            <button class="btn btn-success btn-sm" id="add-new-mobile-route-btn">
                                <i class="fas fa-plus me-1"></i> {{ trans('app.Add New') }}
                            </button>
                        </div>

                    </div>

                </div>

                <!-- Add New Mobile Route Modal -->
                <div class="modal fade" id="addMobileRouteModal" tabindex="-1" aria-hidden="true">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">

                            <div class="modal-header btn-primary text-white">
                                <h5 class="modal-title">
                                    <i class="fas fa-mobile-alt me-2"></i>
                                    {{ trans('app.Add New Mobile Route') }}
                                </h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                            </div>

                            <div class="modal-body">

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Screen') }}</label>
                                    <input type="text" id="new_mobile_screen" class="form-control">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Message') }}</label>
                                    <input type="text" id="new_mobile_message" class="form-control"
                                        placeholder="Use | to separate multiple messages">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Probability') }}</label>
                                    <input type="number" id="new_mobile_probability" class="form-control"
                                        min="0" max="100">
                                </div>

                            </div>

                            <div class="modal-footer">
                                <button class="btn btn-secondary"
                                    data-bs-dismiss="modal">{{ trans('app.Cancel') }}</button>
                                <button class="btn btn-primary"
                                    id="save-new-mobile-route-btn">{{ trans('app.Save') }}</button>
                            </div>

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

                <!-- Edit Mobile Route Modal -->
                <div class="modal fade" id="editMobileRouteModal" tabindex="-1" aria-hidden="true">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">

                            <div class="modal-header bg-primary text-white">
                                <h5 class="modal-title">{{ trans('app.Edit Mobile Route') }}</h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                            </div>

                            <div class="modal-body">

                                <input type="hidden" id="edit_route_index">

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Screen') }}</label>
                                    <input type="text" id="edit_screen" class="form-control">
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Message') }}</label>
                                    <textarea id="edit_message" class="form-control" rows="4"></textarea>
                                    <small class="text-muted">
                                        {{ trans('app.For multiple messages, separate them with | (pipe symbol).') }}
                                    </small>
                                </div>

                                <div class="mb-3">
                                    <label class="form-label">{{ trans('app.Probability') }}</label>
                                    <input type="number" id="edit_probability" class="form-control">
                                </div>

                            </div>

                            <div class="modal-footer">
                                <button class="btn btn-secondary"
                                    data-bs-dismiss="modal">{{ trans('app.Cancel') }}</button>
                                <button type='button' class="btn btn-primary" id="save-mobile-route-btn">
                                    {{ trans('app.Save Changes') }}
                                </button>
                            </div>

                        </div>
                    </div>
                </div>
                <!-- Recent Activity -->
                <div class="card mb-4">
                    <div class="card-header bg-warning text-dark">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-history me-2"></i>
                            {{ trans('app.Recent Activity') }}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="timeline">
                            <div class="timeline-item">
                                <div class="timeline-marker bg-primary"></div>
                                <div class="timeline-content">
                                    <h6 class="timeline-title">{{ trans('app.License Created') }}</h6>
                                    <p class="timeline-text text-muted">{{ $license->created_at->format('M d, Y H:i') }}
                                    </p>
                                </div>
                            </div>
                            @if ($license->updated_at != $license->created_at)
                                <div class="timeline-item">
                                    <div class="timeline-marker bg-success"></div>
                                    <div class="timeline-content">
                                        <h6 class="timeline-title">{{ trans('app.Last Updated') }}</h6>
                                        <p class="timeline-text text-muted">
                                            {{ $license->updated_at->format('M d, Y H:i') }}</p>
                                    </div>
                                </div>
                            @endif
                            @if ($license->domains_count > 0)
                                <div class="timeline-item">
                                    <div class="timeline-marker bg-info"></div>
                                    <div class="timeline-content">
                                        <h6 class="timeline-title">{{ trans('app.Domains Added') }}</h6>
                                        <p class="timeline-text text-muted">{{ $license->domains_count }}
                                            {{ trans('app.domains') }}</p>
                                    </div>
                                </div>
                            @endif
                        </div>
                    </div>
                </div>
            </div>

            <!-- Sidebar -->
            <div class="col-lg-4">
                <div class="card mb-4">

                    <!-- Header -->
                    <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-key me-2"></i>
                            {{ trans('app.License Key') }}
                        </h5>

                        <div class="d-flex align-items-center gap-2">
                            <i class="fas fa-info-circle text-black fs-5 cursor-pointer" data-bs-toggle="modal"
                                data-bs-target="#licenseInfoModal" title="Installation Steps"></i>


                        </div>
                    </div>

                    <div class="card-body">
                        <div class="bg-light border rounded p-3 font-monospace">
                            <pre class="mb-0">PRODUCT_SLUG={{ $licenseKeys['PRODUCT_SLUG'] ?? '-' }}
VERIFICATION_KEY={{ $licenseKeys['VERIFICATION_KEY'] ?? '-' }}
API_TOKEN={{ $licenseKeys['API_TOKEN'] ?? '-' }}
LICENSE_PURCHASE_CODE={{ $licenseKeys['LICENSE_PURCHASE_CODE'] ?? '-' }}</pre>
                        </div>

                        <button type="button" class=" m-4 btn btn-primary copy-btn"
                            data-text="PRODUCT_SLUG={{ $licenseKeys['PRODUCT_SLUG'] ?? '-' }}&#10;VERIFICATION_KEY={{ $licenseKeys['VERIFICATION_KEY'] ?? '-' }}&#10;API_TOKEN={{ $licenseKeys['API_TOKEN'] ?? '-' }}&#10;LICENSE_PURCHASE_CODE={{ $licenseKeys['LICENSE_PURCHASE_CODE'] ?? '-' }}">
                            <i class="fas fa-copy me-1"></i> Copy Keys
                        </button>
                    </div>


                </div>



                <div class="card mb-4">
                    <div class="card-header bg-success text-white">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-bolt me-2"></i>
                            {{ trans('app.Quick Actions') }}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="d-grid gap-2">
                            <a href="{{ route('admin.licenses.edit', $license) }}" class="btn btn-primary">
                                <i class="fas fa-edit me-1"></i>
                                {{ trans('app.Edit License') }}
                            </a>
                            @if ($license->user)
                                <a href="{{ route('admin.users.show', $license->user) }}"
                                    class="btn btn-outline-success">
                                    <i class="fas fa-user me-1"></i>
                                    {{ trans('app.View User') }}
                                </a>
                            @endif
                            @if ($license->product)
                                <a href="{{ route('admin.products.show', $license->product) }}"
                                    class="btn btn-outline-info">
                                    <i class="fas fa-box me-1"></i>
                                    {{ trans('app.View Product') }}
                                </a>
                            @endif
                            <button id="regenerate-license-key-btn" data-license-id="{{ $license->id }}"
                                data-url="{{ route('admin.licenses.regenerate', $license->id) }}"
                                class="btn btn-outline-warning">
                                Regenerate Key
                            </button>


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

                <!-- License Details -->
                <div class="card mb-4">
                    <div class="card-header bg-info text-white">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-info-circle me-2"></i>
                            {{ trans('app.License Details') }}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="row text-center">
                            <div class="col-6 mb-3">
                                <div class="stats-card">
                                    <h4 class="text-info">{{ $license->created_at->format('M Y') }}</h4>
                                    <p class="text-muted small mb-0">{{ trans('app.Created') }}</p>
                                </div>
                            </div>
                            <div class="col-6 mb-3">
                                <div class="stats-card">
                                    <h4 class="text-warning">{{ $license->updated_at->format('M Y') }}</h4>
                                    <p class="text-muted small mb-0">{{ trans('app.Updated') }}</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- License Status -->
                <div class="card mb-4">
                    <div class="card-header bg-warning text-dark">
                        <h5 class="card-title mb-0">
                            <i class="fas fa-shield-alt me-2"></i>
                            {{ trans('app.License Status') }}
                        </h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label fw-bold">
                                <i class="fas fa-toggle-on text-success me-1"></i>
                                {{ trans('app.Status') }}
                            </label>
                            <p class="text-muted">
                                <span
                                    class="badge bg-{{ $license->status == 'active' ? 'success' : ($license->status == 'expired' ? 'danger' : 'warning') }}">
                                    {{ trans('app.' . ucfirst($license->status)) }}
                                </span>
                            </p>
                        </div>
                        <div class="mb-3">
                            <label class="form-label fw-bold">
                                <i class="fas fa-globe text-info me-1"></i>
                                {{ trans('app.Domain Usage') }}
                            </label>
                            <div class="progress mb-2">
                                <div class="progress-bar" role="progressbar"
                                    data-width="{{ $license->max_domains > 0 ? (($license->domains_count ?? 0) / $license->max_domains) * 100 : 0 }}">
                                </div>
                            </div>
                            <p class="text-muted small mb-0">
                                {{ $license->domains_count ?? 0 }} / {{ $license->max_domains ?? 1 }}
                                {{ trans('app.domains used') }}
                            </p>
                        </div>
                        @if ($license->expires_at)
                            <div class="mb-0">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-calendar text-danger me-1"></i>
                                    {{ trans('app.Expiration') }}
                                </label>
                                <p class="text-muted small mb-0">
                                    {{ $license->expires_at->format('M d, Y') }}
                                    @if ($license->expires_at->isFuture())
                                        ({{ $license->expires_at->diffForHumans() }})
                                    @else
                                        ({{ trans('app.Expired') }})
                                    @endif
                                </p>
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- License Installation Info Modal -->
    <div class="modal fade" id="licenseInfoModal" tabindex="-1" aria-labelledby="licenseInfoModalLabel"
        aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-scrollable">
            <div class="modal-content">

                <div class="modal-header bg-primary text-white">
                    <h5 class="modal-title" id="licenseInfoModalLabel">
                        <i class="fas fa-info-circle me-2"></i>
                        Kaalii Security – Installation Steps
                    </h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
                </div>

                <div class="modal-body">

                    <p class="text-muted mb-4">
                        Follow the steps below to install and configure <strong>Kaalii Security</strong> in your project.
                    </p>

                    <!-- Step 1 -->
                    <h6 class="fw-bold text-muted">1. Add License Key File</h6>
                    <p class='text-muted'>Create a file named <code>a2FhbGlp.key</code> in any one of the following paths:
                    </p>
                    <ul>
                        <li><code>project-root/a2FhbGlp.key</code></li>
                        <li><code>storage/data/a2FhbGlp.key</code></li>
                        <li><code>app/Console/a2FhbGlp.key</code></li>
                    </ul>

                    <!-- Step 2 -->
                    <h6 class="fw-bold mt-4 text-muted">2. Add License Keys in the File</h6>
                    <p class='text-muted'>Store the keys using the exact structure:</p>

                    @php
                        $keys = [
                            'PRODUCT_SLUG' => $licenseKeys['PRODUCT_SLUG'] ?? '',
                            'VERIFICATION_KEY' => $licenseKeys['VERIFICATION_KEY'] ?? '',
                            'API_TOKEN' => $licenseKeys['API_TOKEN'] ?? '',
                            'LICENSE_PURCHASE_CODE' => $licenseKeys['LICENSE_PURCHASE_CODE'] ?? '',
                        ];
                    @endphp

                    <pre class="bg-light p-3 rounded border small">
@foreach ($keys as $label => $value)
{{ $label }}={{ $value }}
@endforeach
                </pre>

                    <!-- Step 3 -->
                    <h6 class="fw-bold mt-4 text-muted">3. Add Repository Source in composer.json</h6>
                    <p class='text-muted'>Update your main <code>composer.json</code>:</p>
                    <pre class="bg-light p-3 rounded border small">
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/kaaliicore/kaalii-security"
    }
]
                </pre>

                    <!-- Step 4 -->
                    <h6 class="fw-bold mt-4 text-muted">4. Install Kaalii Security Package</h6>
                    <p class='text-muted'>Run either one of the following commands:</p>

                    <pre class="bg-light p-3 rounded border small">
composer require kaalii-security/core
                </pre>

                    <p class="text-center fw-bold my-2 text-muted">OR</p>

                    <pre class="bg-light p-3 rounded border small text-muted">
composer require kaalii-security/core --ignore-platform-reqs
                </pre>

                    <!-- Step 5 -->
                    <h6 class="fw-bold mt-4 text-muted">5. Clear cache </h6>
                    <p class='text-muted'>Run the following commands:</p>

                    <pre class="bg-light p-3 rounded border small">
php artisan optimize:clear
                </pre>

                </div>

                <div class="modal-footer">
                    <button class="btn btn-secondary" data-bs-dismiss="modal">
                        Close
                    </button>
                </div>

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










@endsection
@push('scripts')
    <script>
        document.addEventListener('click', function(e) {
            if (e.target.closest('.copy-btn')) {
                const btn = e.target.closest('.copy-btn');
                const text = btn.dataset.text;

                navigator.clipboard.writeText(text).then(() => {
                    btn.innerHTML = '<i class="fas fa-check text-success"></i>';
                    setTimeout(() => {
                        btn.innerHTML = '<i class="fas fa-copy"></i>';
                    }, 1200);
                });
            }
        });
        document.addEventListener('change', function(e) {

            if (!e.target.classList.contains('setting-toggle')) return;

            let settingKey = e.target.dataset.setting;
            let licenseId = e.target.dataset.license;
            let status = e.target.checked ? 1 : 0;

            fetch("{{ route('admin.license.updateSettingToggle') }}", {
                    method: "POST",
                    headers: {
                        "Content-Type": "application/json",
                        "X-CSRF-TOKEN": "{{ csrf_token() }}"
                    },
                    body: JSON.stringify({
                        license_id: licenseId,
                        key: settingKey,
                        value: status
                    })
                })
                .then(res => res.json())
                .then(data => {

                    if (!data.success) {

                        showNotification(
                            "{{ trans('app.Update failed') }}: " + data.message,
                            "error"
                        );

                        // revert UI
                        e.target.checked = !status;
                    } else {

                        //✔ Success Notification
                        showNotification(
                            "{{ trans('app.Setting updated successfully') }}",
                            "success"
                        );
                    }
                })
                .catch(err => {

                    //❌ Server Error
                    showNotification(
                        "{{ trans('app.Server error. Please try again.') }}",
                        "error"
                    );

                    e.target.checked = !status;
                });
        });


        $(document).ready(function() {

            // Open Add New Modal
            $('#add-new-affected-route-btn').on('click', function() {
                $('#new_route').val('');
                $('#new_message').val('');
                $('#new_probability').val('');
                $('#addAffectedRouteModal').modal('show');
            });

            // Save New Affected Route
            $('#save-new-affected-route-btn').on('click', function() {

                let route = $('#new_route').val();
                let message = $('#new_message').val();
                let probability = $('#new_probability').val();

                if (!route || !message) {
                    showNotification("{{ trans('app.Please fill all required fields') }}", "error");
                    return;
                }

                $.ajax({
                    url: "{{ route('admin.affected-routes.store', $license->id) }}",
                    method: "POST",
                    data: {
                        license_id: "{{ $license->id }}",
                        route: route,
                        message: message,
                        probability: probability,
                        _token: "{{ csrf_token() }}"
                    },
                    success: function(res) {

                        if (res.success) {

                            $('#addAffectedRouteModal').modal('hide');

                            showNotification(
                                res.message ||
                                "{{ trans('app.New route added successfully') }}",
                                "success"
                            );

                            let newIndex = res.newIndex;
                            let messagesHtml = '';

                            // Handle multiple messages
                            if (message.includes('|')) {
                                message.split('|').forEach(function(msg) {
                                    messagesHtml += '<li>' + msg.trim() + '</li>';
                                });
                                messagesHtml = '<ul class="list-unstyled mb-0">' +
                                    messagesHtml + '</ul>';
                            } else {
                                messagesHtml = message;
                            }

                            // Build New Row HTML
                            let newRow = `
                                <tr id="affected-route-${newIndex}">
                                    <td class="route">${route}</td>
                                    <td class="message">${messagesHtml}</td>
                                    <td class="probability">${probability}</td>
                                    <td>
                                        <button class="btn btn-sm btn-outline-primary edit-affected-route-btn"
                                            data-index="${newIndex}"
                                            data-route="${route}"
                                            data-message="${message}"
                                            data-probability="${probability}">
                                            <i class="fas fa-edit"></i>
                                        </button>

                                        <button class="btn btn-sm btn-outline-danger delete-route-btn"
                                            data-index="${newIndex}">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </td>
                                </tr>
                            `;

                            // ⛔ OLD WRONG CODE:
                            // $('table tbody').append(newRow);

                            // ✅ FIXED → Append only to WEB ROUTES table
                            $("#affected-routes-table tbody").append(newRow);

                        } else {

                            showNotification(
                                res.message ||
                                "{{ trans('app.Failed to add new route') }}",
                                "error"
                            );
                        }
                    },

                    error: function(xhr) {
                        showNotification(
                            "{{ trans('app.Something went wrong') }}",
                            "error"
                        );
                    }
                });
            });

        });

        $(document).ready(function() {

            $('#cache-ttl-btn').on('click', function() {
                $('#cacheTTLModal').modal('show');
            });

            // SAVE BUTTON INSIDE MODAL
            $('#save-cache-ttl-btn').on('click', function() {

                let newTTL = $('#modal-cache-ttl-input').val();

                $.ajax({
                    url: "{{ route('admin.update.cache.ttl') }}",
                    method: "POST",
                    data: {
                        license_id: "{{ $license->id }}",
                        value: newTTL,
                        _token: "{{ csrf_token() }}"
                    },
                    success: function(res) {
                        if (res.success) {

                            $('#cache-ttl-input').val(res.value);

                            $('#cacheTTLModal').modal('hide');

                            showNotification(
                                "{{ trans('app.Cache TTL updated successfully') }}",
                                "success"
                            );
                        } else {
                            showNotification(
                                "{{ trans('app.Failed to update TTL') }}",
                                "error"
                            );
                        }
                    },

                    error: function() {
                        showNotification(
                            "{{ trans('app.Server error. Please try again.') }}",
                            "error"
                        );
                    }
                });

            });

        });




        const regenerateUrl = "{{ route('admin.licenses.regenerate', ':id') }}";
        const deleteDomainUrl = "{{ route('admin.license-domains.destroy', ':id') }}";
        let updateAffectedRouteUrl =
            "{{ route('admin.licenses.affectedRoutes.update', ['license' => $license->id, 'index' => ':index']) }}";

        const deleteAffectedRouteUrl =
            "{{ route('admin.license.deleteAffectedRoute', ['license' => $license->id, 'index' => ':index']) }}";
        const deleteMobileRouteUrl =
            "{{ route('admin.license.deleteMobileRoute', ['license' => $license->id, 'index' => ':index']) }}";
        const updateMessageKeyUrl = "{{ route('admin.license.updateMessageKey', ':id') }}";

        $(document).on('change', '.toggle-domain-status', function() {

            let toggle = $(this);
            let id = toggle.data('domain-id');
            let isActive = toggle.is(':checked');

            $.ajax({
                url: "{{ route('admin.domain.toggle-status') }}",
                method: "POST",
                data: {
                    domain_id: id,
                    _token: "{{ csrf_token() }}"
                },
                success: function(res) {

                    if (res.success) {

                        toggle.prop('checked', res.status === 'active');
                        showNotification(
                            res.status === 'active' ?
                            "{{ trans('app.Domain activated successfully') }}" :
                            "{{ trans('app.Domain deactivated successfully') }}",
                            "success"
                        );

                    } else {

                        // revert toggle
                        toggle.prop('checked', !isActive);

                        showNotification(
                            "{{ trans('app.Something went wrong') }}",
                            "error"
                        );
                    }
                },

                error: function() {

                    // revert the toggle on error
                    toggle.prop('checked', !isActive);

                    showNotification(
                        "{{ trans('app.Server error. Please try again.') }}",
                        "error"
                    );
                }
            });
        });


        $(document).on('click', '.edit-mobile-route-btn', function() {

            $('#edit_route_index').val($(this).data('index'));
            $('#edit_screen').val($(this).data('screen'));

            $('#edit_message').val($(this).data('message'));

            $('#edit_probability').val($(this).data('probability'));

            $('#editMobileRouteModal').modal('show');
        });

        $(document).ready(function() {
            // Server error
            $("#add-new-mobile-route-btn").on("click", function() {
                $("#new_mobile_screen").val("");
                $("#new_mobile_message").val("");
                $("#new_mobile_probability").val("");

                $("#addMobileRouteModal").modal("show");
            });

            // -------------------------
            // SAVE NEW MOBILE ROUTE
            // -------------------------
            $("#save-new-mobile-route-btn").on("click", function() {

                let screen = $("#new_mobile_screen").val();
                let message = $("#new_mobile_message").val();
                let probability = $("#new_mobile_probability").val();

                if (!screen || !message || !probability) {
                    alert("All fields are required!");
                    return;
                }

                $.ajax({
                    url: "{{ route('admin.licenses.add-mobile-route', $license->id) }}",
                    method: "POST",
                    data: {
                        _token: "{{ csrf_token() }}",
                        screen: screen,
                        message: message,
                        probability: probability
                    },
                    success: function(response) {
                        location.reload();
                    }
                });

            });


            $('#save-mobile-route-btn').on('click', function() {

                let index = $('#edit_route_index').val();

                $.ajax({
                    url: "{{ route('admin.mobile-route.update') }}",
                    method: "POST",
                    data: {
                        license_id: "{{ $license->id }}",
                        index: index,
                        screen: $('#edit_screen').val(),
                        message: $('#edit_message').val(),
                        showProbability: $('#edit_probability').val(),
                        _token: "{{ csrf_token() }}"
                    },
                    success: function(res) {
                        if (res.success) {
                            $('#editMobileRouteModal').modal('hide');

                            showNotification(
                                "{{ trans('app.Mobile route updated successfully') }}",
                                "success"
                            );

                            location.reload();
                        } else {
                            showNotification(
                                res.message ||
                                "{{ trans('app.Failed to update mobile route') }}",
                                "error"
                            );
                        }
                    },
                    error: function(xhr, status, error) {
                        showNotification(
                            "{{ trans('app.Something went wrong') }}",
                            "error"
                        );
                        console.error(xhr.responseText);
                    }
                });

            });

        });
        $(document).on('click', '.edit-affected-route-btn', function() {

            $('#edit_affected_route_index').val($(this).data('index'));
            $('#edit_affected_route').val($(this).data('route'));

            let message = $(this).data('message');
            $('#edit_affected_message').val(message.replace(/\|/g, "\n"));

            $('#edit_affected_probability').val($(this).data('probability'));

            $('#editAffectedRouteModal').modal('show');
        });
        $(document).ready(function() {
            $('#save-affected-route-btn').on('click', function() {

                let index = $('#edit_affected_route_index').val();

                let data = {
                    route: $('#edit_affected_route').val(),
                    message: $('#edit_affected_message').val(),
                    probability: $('#edit_affected_probability').val(),
                    _token: "{{ csrf_token() }}"
                };

                let url = updateAffectedRouteUrl.replace(':index', index);

                $.ajax({
                    url: url,
                    method: "POST",
                    data: data,
                    success: function(res) {
                        if (res.success) {
                            $('#editAffectedRouteModal').modal('hide');

                            showNotification(
                                'success',
                                res.message ||
                                "{{ trans('app.Affected Route updated successfully') }}"
                            );
                            location.reload();


                        } else {
                            showNotification(
                                'error',
                                res.message || "{{ trans('app.Failed to update route') }}"
                            );
                        }
                    },
                    error: function(xhr, status, error) {
                        showNotification(
                            'error',
                            "{{ trans('app.Something went wrong') }}"
                        );
                    }

                });

            });

        });
    </script>
@endpush
