@props([
    'id' => 'actionsModal',
])

@php
    $actionsRtl = (bool) ($isRtl ?? false) || app()->getLocale() === 'ar';
    $actionsDir = $actionsRtl ? 'rtl' : 'ltr';
    $confirmId = $id.'Confirm';
@endphp

{{-- Primary actions modal (existing visual design) --}}
<div class="modal fade erp-actions-modal" id="{{ $id }}" tabindex="-1" aria-hidden="true" dir="{{ $actionsDir }}"
     @class(['erp-actions-modal--rtl' => $actionsRtl])
     data-erp-action-modal>
    <div class="modal-dialog modal-dialog-centered modal-md" dir="{{ $actionsDir }}">
        <div class="modal-content" dir="{{ $actionsDir }}">
            <div class="modal-header bg-gradient-primary text-white erp-actions-modal__header">
                <div class="erp-actions-modal__header-text">
                    <h5 class="modal-title mb-1" data-role="title">{{ __('common.actions') }}</h5>
                    <div class="small opacity-75" data-role="subtitle">{{ __('common.actions_modal.selected_item') }}</div>
                </div>
                <button type="button" class="btn-close-custom" data-bs-dismiss="modal"
                        aria-label="{{ __('common.close') }}">
                    <i class="fe fe-x"></i>
                </button>
            </div>
            <div class="modal-body erp-actions-modal__body">
                <div class="erp-actions-modal__list" data-role="actions">
                    <a class="action-card action-card--primary d-none" href="#" data-action="view">
                        <div class="action-icon action-icon--primary" aria-hidden="true"><i class="fe fe-eye"></i></div>
                        <div class="action-content">
                            <p class="action-title mb-0">{{ __('common.actions_modal.view') }}</p>
                            <small class="action-description">{{ __('common.actions_modal.view_desc') }}</small>
                        </div>
                    </a>

                    <a class="action-card action-card--primary d-none" href="#" data-action="edit">
                        <div class="action-icon action-icon--primary" aria-hidden="true"><i class="fe fe-edit-2"></i></div>
                        <div class="action-content">
                            <p class="action-title mb-0">{{ __('common.actions_modal.edit') }}</p>
                            <small class="action-description">{{ __('common.actions_modal.edit_desc') }}</small>
                        </div>
                    </a>

                    <button class="action-card action-card--primary d-none" type="button" data-action="duplicate">
                        <div class="action-icon action-icon--primary" aria-hidden="true"><i class="fe fe-copy"></i></div>
                        <div class="action-content">
                            <p class="action-title mb-0">{{ __('common.actions_modal.duplicate') }}</p>
                            <small class="action-description">{{ __('common.actions_modal.duplicate_desc') }}</small>
                        </div>
                    </button>

                    <a class="action-card action-card--primary d-none" href="#" target="_blank" rel="noopener" data-action="print">
                        <div class="action-icon action-icon--primary" aria-hidden="true"><i class="fe fe-printer"></i></div>
                        <div class="action-content">
                            <p class="action-title mb-0">{{ __('common.actions_modal.print') }}</p>
                            <small class="action-description">{{ __('common.actions_modal.print_desc') }}</small>
                        </div>
                    </a>

                    <button class="action-card action-card--warning d-none" type="button" data-action="activate">
                        <div class="action-icon action-icon--warning" aria-hidden="true"><i class="fe fe-check-circle"></i></div>
                        <div class="action-content">
                            <p class="action-title mb-0">{{ __('common.actions_modal.activate') }}</p>
                            <small class="action-description">{{ __('common.actions_modal.status_desc') }}</small>
                        </div>
                    </button>

                    <button class="action-card action-card--warning d-none" type="button" data-action="deactivate">
                        <div class="action-icon action-icon--warning" aria-hidden="true"><i class="fe fe-slash"></i></div>
                        <div class="action-content">
                            <p class="action-title mb-0">{{ __('common.actions_modal.deactivate') }}</p>
                            <small class="action-description">{{ __('common.actions_modal.status_desc') }}</small>
                        </div>
                    </button>

                    <button class="action-card action-card--danger delete-action d-none" type="button" data-action="delete">
                        <div class="action-icon action-icon--danger" aria-hidden="true"><i class="fe fe-trash-2"></i></div>
                        <div class="action-content">
                            <p class="action-title mb-0">{{ __('common.actions_modal.delete') }}</p>
                            <small class="action-description">{{ __('common.actions_modal.delete_desc') }}</small>
                        </div>
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

{{-- Shared confirmation dialog --}}
<div class="modal fade erp-actions-confirm" id="{{ $confirmId }}" tabindex="-1" aria-hidden="true" dir="{{ $actionsDir }}"
     data-erp-action-confirm>
    <div class="modal-dialog modal-dialog-centered modal-sm">
        <div class="modal-content">
            <div class="modal-header border-0 pb-0">
                <h5 class="modal-title" data-role="confirm-title">{{ __('common.confirm') }}</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{{ __('common.close') }}"></button>
            </div>
            <div class="modal-body pt-2">
                <p class="mb-2" data-role="confirm-message"></p>
                <p class="fw-semibold mb-2" data-role="confirm-record"></p>
                <p class="text-muted small mb-0" data-role="confirm-hint"></p>
            </div>
            <div class="modal-footer border-0 pt-0">
                <button type="button" class="btn btn-light" data-bs-dismiss="modal">{{ __('common.cancel') }}</button>
                <button type="button" class="btn btn-danger" data-role="confirm-submit">{{ __('common.delete') }}</button>
            </div>
        </div>
    </div>
</div>

<form id="{{ $id }}Form" method="POST" class="d-none" data-erp-action-form>
    @csrf
    <input type="hidden" name="_method" value="POST" data-role="method">
</form>

@once
    @push('scripts')
        @php
            $erpActionModalI18n = [
                'selectedItem' => __('common.actions_modal.selected_item'),
                'deleteTitle' => __('common.actions_modal.delete_title'),
                'deleteMessage' => __('common.actions_modal.delete_message'),
                'deleteIrreversible' => __('common.actions_modal.delete_irreversible'),
                'deleteButton' => __('common.delete'),
                'activateTitle' => __('common.actions_modal.activate_title'),
                'deactivateTitle' => __('common.actions_modal.deactivate_title'),
                'statusMessage' => __('common.actions_modal.status_message'),
                'activateButton' => __('common.actions_modal.activate'),
                'deactivateButton' => __('common.actions_modal.deactivate'),
                'duplicateTitle' => __('common.actions_modal.duplicate_title'),
                'duplicateMessage' => __('common.actions_modal.duplicate_message'),
                'duplicateButton' => __('common.actions_modal.duplicate'),
            ];
        @endphp
        <script>
            window.erpActionModalI18n = @json($erpActionModalI18n);
        </script>
        <script src="{{ asset('assets/admin/js/actions-modal.js') }}?v={{ @filemtime(public_path('assets/admin/js/actions-modal.js')) ?: '2' }}"></script>
    @endpush
@endonce
