﻿<div x-data="{ open: {{ request()->routeIs('inventory.*') ? 'true' : 'false' }} }" class="mb-1">
    <button @click="open = !open"
        class="group flex items-center p-3 py-2 text-base font-medium rounded-md
        {{ request()->routeIs('inventory.*') ? 'bg-red-100 text-red-800' : 'text-gray-700 hover:bg-red-50 hover:text-red-800' }}">
        <svg xxmlns="http://www.w3.org/2000/svg"
            class="ml-3 flex-shrink-0 h-6 w-6
            {{ request()->routeIs('inventory.*') ? 'text-red-700' : 'text-gray-500 group-hover:text-red-700' }}"
            fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
        </svg>
        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Inventory System', __('Inventory System')) }}</span>
        <svg :class="{ 'rotate-180': open, 'rotate-0': !open }"
            class="mr-auto h-5 w-5 transform transition-transform duration-200" xxmlns="http://www.w3.org/2000/svg"
            viewBox="0 0 20 20" fill="currentColor">
            <path fill-rule="evenodd"
                d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
                clip-rule="evenodd" />
        </svg>
    </button>
    <div x-show="open" x-transition class="pr-4 mr-4 border-r border-gray-200">
        @permission('inventory.warehouses.view')
            <a href="{{ route('inventory.warehouses.index') }}"
                class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
            {{ request()->routeIs('inventory.warehouses.*') ? 'text-red-800' : 'text-gray-700 hover:text-red-800' }}">
                <span
                    class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.warehouses.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Warehouses', __('Warehouses')) }}</span>
            </a>
        @endpermission

        @permission('inventory.units.view')
            <a href="{{ route('inventory.units.index') }}"
                class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
            {{ request()->routeIs('inventory.units.*') ? 'text-red-800' : 'text-gray-700 hover:text-red-800' }}">
                <span
                    class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.units.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Inventory Units', __('Inventory Units')) }}</span>
            </a>
        @endpermission

        @permission('inventory.items.view')
            <a href="{{ route('inventory.items.index') }}"
                class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
            {{ request()->routeIs('inventory.items.*') ? 'text-red-800' : 'text-gray-700 hover:text-red-800' }}">
                <span
                    class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.items.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Items', __('Items')) }}</span>
            </a>
        @endpermission

        @permission('inventory.issues.view')
            <div x-data="{ open: {{ request()->routeIs('inventory.issues.*', 'inventory.raw-materials-issues.*', 'inventory.finished-goods-issues.*') ? 'true' : 'false' }} }" class="mb-1">
                <button @click="open = !open"
                    class="group flex items-center p-3 py-2 text-sm font-medium rounded-md w-full
                    {{ request()->routeIs('inventory.issues.*', 'inventory.raw-materials-issues.*', 'inventory.finished-goods-issues.*') ? 'text-red-800 bg-red-50' : 'text-gray-700 hover:bg-red-50 hover:text-red-800' }}">
                    <span
                        class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.issues.*', 'inventory.raw-materials-issues.*', 'inventory.finished-goods-issues.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                    <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Disbursement Vouchers Menu', __('اذون الصرف')) }}</span>
                    <svg :class="{ 'rotate-180': open, 'rotate-0': !open }"
                        class="mr-auto h-5 w-5 transform transition-transform duration-200" xxmlns="http://www.w3.org/2000/svg"
                        viewBox="0 0 20 20" fill="currentColor">
                        <path fill-rule="evenodd"
                            d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
                            clip-rule="evenodd" />
                    </svg>
                </button>
                <div x-show="open" x-transition class="pr-4 mr-4 border-r border-gray-200">
                    @permission('inventory.issues.view')
                        <a href="{{ route('inventory.issues.index') }}"
                            class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
                        {{ request()->routeIs('inventory.issues.*') && !request()->routeIs('inventory.raw-materials-issues.*') && !request()->routeIs('inventory.finished-goods-issues.*') ? 'text-red-800 font-semibold' : 'text-gray-700 hover:text-red-800' }}">
                            <span
                                class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.issues.*') && !request()->routeIs('inventory.raw-materials-issues.*') && !request()->routeIs('inventory.finished-goods-issues.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                            <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Finished Goods Disbursement Vouchers for Warehouses Menu', __('اذن صرف منتج تام للمخازن')) }}</span>
                        </a>
                    @endpermission

                    @permission('inventory.raw_materials.issue.view')
                        <a href="{{ route('inventory.raw-materials-issues.index') }}"
                            class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
                        {{ request()->routeIs('inventory.raw-materials-issues.*') ? 'text-red-800 font-semibold' : 'text-gray-700 hover:text-red-800' }}">
                            <span
                                class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.raw-materials-issues.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                            <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Raw Materials Disbursement Vouchers Menu', __('اذن صرف خامات')) }}</span>
                        </a>
                    @endpermission

                    @permission('inventory.finished_goods.issue.view')
                        <a href="{{ route('inventory.finished-goods-issues.index') }}"
                            class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
                        {{ request()->routeIs('inventory.finished-goods-issues.*') ? 'text-red-800 font-semibold' : 'text-gray-700 hover:text-red-800' }}">
                            <span
                                class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.finished-goods-issues.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                            <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Finished Goods Disbursement Vouchers for Customers Menu', __('اذن صرف منتج تام للعملاء')) }}</span>
                        </a>
                    @endpermission
                </div>
            </div>
        @endpermission



        @permission('inventory.receipts.view')
            <a href="{{ route('inventory.receipts.index') }}"
                class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
            {{ request()->routeIs('inventory.receipts.*') ? 'text-red-800' : 'text-gray-700 hover:text-red-800' }}">
                <span
                    class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.receipts.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Receipt Vouchers', __('Receipt Vouchers')) }}</span>
            </a>
        @endpermission
        @permission('inventory.transfers.view')
            <a href="{{ route('inventory.transfers.index') }}"
                class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
    {{ request()->routeIs('inventory.transfers.*') ? 'text-red-800' : 'text-gray-700 hover:text-red-800' }}">
                <span
                    class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.transfers.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Warehouse Transfers', __('Warehouse Transfers')) }}</span>
            </a>
        @endpermission


        @permission('inventory.counts.view')
            <a href="{{ route('inventory.counts.index') }}"
                class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
            {{ request()->routeIs('inventory.counts.*') ? 'text-red-800' : 'text-gray-700 hover:text-red-800' }}">
                <span
                    class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.counts.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Inventory Count', __('Inventory Count')) }}</span>
            </a>
        @endpermission

        @permission('inventory.reports.view')
            <a href="{{ route('inventory.reports.index') }}"
                class="group flex items-center p-3 py-2 text-sm font-medium rounded-md
            {{ request()->routeIs('inventory.reports.*') ? 'text-red-800' : 'text-gray-700 hover:text-red-800' }}">
                <span
                    class="ml-2 w-1 h-1 rounded-full {{ request()->routeIs('inventory.reports.*') ? 'bg-red-600' : 'bg-gray-500' }}"></span>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Inventory Reports', __('Inventory Reports')) }}</span>
            </a>
        @endpermission
    </div>
</div>
