<div wire:loading.remove>
    <style>
        table {
            width: 100%;
            table-layout: auto;
        }

        .table-responsive {
            overflow-x: auto;
        }
    </style>
    <main class="m-2">
        @if ($action === 'list')
            @if ($message)
                <div class="alert alert-success">
                    <div wire:ignore x-data="{ show: true }" x-init="setTimeout(() => show = false, 3000)"
                        x-show.transition.duration.500ms="show"
                        class="fixed top-5 right-5 z-50 bg-green-500 text-white py-2 px-4 rounded-md shadow-lg">
                        {{ $message }}
                    </div>
                </div>
            @endif
            <div class="grid grid-cols-1 gap-4 sm:gap-5 lg:gap-6">
                <div class="pb-4">
                    <div class="my-3 flex h-8 items-center justify-between px-4 sm:px-5">
                        <h2 class="font-medium tracking-wide text-slate-700 line-clamp-1 dark:text-navy-100 lg:text-base">
                            SPN Parameter
                        </h2>
                    </div>
                    <div class="flex justify-between">
                        <div class="px-2 ml-4">
                            <button type="button" class="py-2 px-3 bg-stone-700 rounded-lg text-white"
                                wire:click="showparameterAddForm">Add</button>
                                <button type="button" class="py-2 px-3 bg-stone-700 rounded-lg text-white"
                                onclick="confirmDeleteSelected()">Delete</button>
                        </div>
                        <div class="inline-flex flex-initial">
                            <div x-data="{ isInputActive: true }">
                                <div class="flex flex-wrap gap-4 px-5 items-center">
                                    <button @click="isInputActive = !isInputActive"
                                        class="btn  h-8 w-14 rounded-full p-0  hover:bg-slate-300/20 focus:bg-slate-300/20 active:bg-slate-300/25 dark:hover:bg-navy-300/20 dark:focus:bg-navy-300/20 dark:active:bg-navy-300/25">
                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-4.5 w-4.5" fill="none"
                                            viewBox="0 0 24 24" stroke="black">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
                                                d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
                                        </svg>
                                    </button>
                                    <span class="w-64" x-show="isInputActive === true">
                                        <input
                                            class="form-input h-9 peer w-full rounded-lg border border-slate-300 bg-transparent px-3 py-2  placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                                            placeholder="Search Keyword" type="text" wire:model.defer="keyword" />
                                    </span>
                                    <span class="w-52" x-show="isInputActive === true">
                                        <select wire:model.defer="searchSelected"
                                            class="form-select h-9  w-full rounded-lg border border-slate-300 bg-white px-3 py-2 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent">
                                            @foreach ($searchBy as $key => $by)
                                                <option value="{{ $key }}">{{ $by }}</option>
                                            @endforeach
                                        </select>
                                    </span>
                                    <span class="w-26" x-show="isInputActive === true">
                                       Page
                                    </span>
                                    <span class="w-52" x-show="isInputActive === true">
                                        <select wire:model.defer="searchSelectedPage"
                                            class="form-select h-9 w-full rounded-lg border border-slate-300 bg-white px-3 py-2 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:bg-navy-700 dark:hover:border-navy-400 dark:focus:border-accent">
                                            @foreach ($searchByPage as $page)
                                                <option value="{{ $page['pagecode'] }}">{{ $page['pagename'] }}</option>
                                            @endforeach
                                        </select>
                                    </span>
                                    <button type="button" class="bg-stone-700 text-white px-4 py-2 rounded"
                                        wire:click="search">Search</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="mx-3 mt-3 px-4">
                        <div class="is-scrollbar-hidden min-w-full table-responsive" x-data="pages.tables.initExample1">
                           <table aria-describedby="mydesc"  class="is-hoverable table w-full text-left">
                                <thead>
                                    <tr>
                                        <th scope="col" 
                                            class="whitespace-nowrap rounded-tl-lg bg-slate-200 px-4 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-5">
                                            #
                                        </th>
                                        <th scope="col" 
                                            class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
                                            Name
                                        </th>
                                        <th scope="col" 
                                            class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
                                            Value
                                        </th>
                                        <th scope="col" 
                                            class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
                                            Description
                                        </th>
                                        <th scope="col" 
                                            class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
                                            Page
                                        </th>
                                        <th scope="col" 
                                            class="whitespace-nowrap bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
                                            Active
                                        </th>
                                        <th scope="col" 
                                            class="whitespace-nowrap rounded-tr-lg bg-slate-200 px-2 py-3 font-semibold uppercase text-slate-800 dark:bg-navy-800 dark:text-navy-100 lg:px-2">
                                            Action
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($results as $para)
                                        <tr class="border-y border-transparent border-b-slate-200 dark:border-b-navy-500">
                                            <td class="whitespace-nowrap px-4 py-3 sm:px-5">
                                                <label class="inline-flex items-center space-x-2">
                                                    <input
                                                        class="form-checkbox is-basic h-4 w-4 rounded border-slate-400/70 checked:bg-primary checked:border-primary hover:border-primary focus:border-primary dark:bg-navy-900 dark:border-navy-500 dark:checked:bg-accent dark:checked:border-accent dark:hover:border-accent dark:focus:border-accent"
                                                        type="checkbox" wire:model.defer="selectedParameters"
                                                        value="{{ $para->PID }}" />
                                                </label>
                                            </td>
                                            <td class="whitespace-nowrap px-1 py-3 sm:px-2">
                                                {{ \Illuminate\Support\Str::limit($para->name, 40) }}</td>
                                            <td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $para->value }}</td>
                                            <td class="whitespace-nowrap px-1 py-3 sm:px-2" title="{{ $para->description }}">
                                            {{ \Illuminate\Support\Str::limit($para->description, 40) }}
                                            </td>
                                            <td class="whitespace-nowrap px-1 py-3 sm:px-2" title="{{ $para->pageCode }}">
                                            {{ \Illuminate\Support\Str::limit($para->pageCode, 40) }}
                                            </td>
                                            <td class="whitespace-nowrap px-1 py-3 sm:px-2">{{ $para->active }}</td>
                                            <td class="whitespace-nowrap px-1 py-3 sm:px-2">
                                                <div class="flex justify-center space-x-2">
                                                    <a wire:click="showparameterEditForm({{ $para->PID }})"
                                                        class="btn h-8 w-8 p-0 text-info hover:bg-info/20 focus:bg-info/20 active:bg-info/25">
                                                        <i aria-hidden="true" class="fa fa-edit"></i>
                                                    </a>
                                                    <a onclick="confirmDelete({{ $para->PID }})"
                                                        class="btn h-8 w-8 p-0 text-danger hover:bg-danger/20 focus:bg-danger/20 active:bg-danger/25">
                                                        <i aria-hidden="true" class="fa fa-trash"></i>
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                        <livewire:delete-modal />
                        {{ $results->links('livewire.paginate-custom') }}
                    </div>
                </div>
            </div>
        @elseif($action === 'add')
            <livewire:pages.parameter.parameter-create />
        @elseif($action === 'edit')
        @livewire('pages.parameter.parameter-edit', ['editPid' => $editPid])
        @endif
    </main>
   

</div>
<!-- <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script> -->






