@salla.sa/twilight-components
Version:
Salla Web Component
525 lines (520 loc) • 30.8 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
'use strict';
var index = require('./index-uoA36zqH.js');
var helpers = require('./helpers-BJ2rnhxz.js');
require('./interfaces-Bh7W0bEU.js');
const sallaOrderEditCss = ":host{display:block}";
const SallaOrderEdit = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.loading = true;
this.saveLoading = false;
this.payload = { items: { update: [], remove: [], add: [] } };
this.expired = false;
this.editPreview = null;
this.productSearchQuery = '';
this.productsListKey = 0;
this.productsListSource = 'latest';
this.productsListSourceValue = '';
this.selectedProductToAdd = null;
this.addProductQuantity = 1;
this.addProductLoading = false;
this.addProductConfirmLoading = false;
this.mobileProductsModalMounted = false;
this.isMobileViewport = false;
this.isRTL = true;
// Plain field (not @State): scroll-loading guard never affects rendering, so avoid re-render churn.
this.mobileProductsListLoading = false;
this.confirming = false;
this.handleMobileProductSelected = (event) => {
event.stopPropagation();
void this.handleProductSelected(event);
};
this.productsPanelMobileQuery = '(max-width: 768px)';
this.handleProductsPanelViewportChange = (event) => {
this.isMobileViewport = event.matches;
};
this.hasProductTypeFilter = (url) => {
const queryStart = url.indexOf('?');
const query = (queryStart >= 0 ? url.slice(queryStart + 1) : url).split('#')[0];
return Array.from(new URLSearchParams(query)).some(([key, value]) => (value === 'product' &&
/^filters\[types\](?:\[(?:\d*)\])?$/.test(key)));
};
this.hasExcludedCategoriesFilter = (url) => {
const queryStart = url.indexOf('?');
const query = (queryStart >= 0 ? url.slice(queryStart + 1) : url).split('#')[0];
return Array.from(new URLSearchParams(query)).some(([key]) => (/^filters(?:\[|%5B)excluded_categories(?:\]|%5D)(?:\[|%5B)(?:\d*)(?:\]|%5D)$/.test(key)));
};
this.normalizeProductsListArrayParams = (url) => {
return url.replace(/(^|[?&])(includes|source_value|filters(?:\[|%5B)[^&=\]%]+?(?:\]|%5D))(\[|%5B)\d+(\]|%5D)(?==)/gi, (_, sep, name, open, close) => `${sep}${name}${open}${close}`);
};
this.handleBeforeBuildListUrl = (ctx) => {
if (ctx.component?.productCardComponent !== 'salla-order-edit-product-card' ||
typeof ctx.url !== 'string') {
return;
}
ctx.url = this.normalizeProductsListArrayParams(ctx.url);
if (!this.hasProductTypeFilter(ctx.url)) {
ctx.url += `${ctx.url.includes('?') ? '&' : '?'}filters[types][]=product`;
}
const excludedIds = this.getParsedExcludedCategories();
if (excludedIds.length > 0 && !this.hasExcludedCategoriesFilter(ctx.url)) {
const params = excludedIds.map(id => `filters[excluded_categories][]=${encodeURIComponent(id)}`).join('&');
ctx.url += `${ctx.url.includes('?') ? '&' : '?'}${params}`;
}
};
this.defaultProductsListSource = 'latest';
this.debouncedProductSearch = salla.helpers.debounce((query) => this.applyProductSearch(query), 500);
salla.onReady(() => {
this.isRTL = salla.config.get('theme.is_rtl', true);
});
}
getParsedExcludedCategories() {
if (!this.excludedCategories) {
return [];
}
try {
const parsed = typeof this.excludedCategories === 'string' ? JSON.parse(this.excludedCategories) : this.excludedCategories;
if (!Array.isArray(parsed)) {
return [];
}
return parsed.filter(id => Number.isInteger(id) && id > 0);
}
catch {
return [];
}
}
async componentWillLoad() {
this.setupProductsPanelViewportQuery();
await salla.onReady();
this.unregisterBeforeBuildListUrlHook = salla.hooks.registerHook('salla-products-list', 'beforeBuildListUrl', this.handleBeforeBuildListUrl);
this.loadFromProp();
this.startExpiryCheck();
}
disconnectedCallback() {
clearInterval(this.expiryInterval);
this.unregisterBeforeBuildListUrlHook?.();
this.productsPanelViewportQuery?.removeEventListener('change', this.handleProductsPanelViewportChange);
this.mobileProductsModal?.removeEventListener('orderEditProductSelected', this.handleMobileProductSelected);
}
setupProductsPanelViewportQuery() {
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
return;
}
this.productsPanelViewportQuery = window.matchMedia(this.productsPanelMobileQuery);
this.isMobileViewport = this.productsPanelViewportQuery.matches;
this.productsPanelViewportQuery.addEventListener('change', this.handleProductsPanelViewportChange);
}
startExpiryCheck() {
const endsAt = this.order?.customer_editing_session?.ends_at;
if (!endsAt)
return;
const isExpired = () => new Date(`${endsAt.replace(' ', 'T')}+03:00`).getTime() <= Date.now();
if (isExpired()) {
this.expired = true;
return;
}
this.expiryInterval = setInterval(() => {
if (isExpired()) {
this.expired = true;
clearInterval(this.expiryInterval);
}
}, 1000);
}
loadFromProp() {
try {
if (!this.orderData) {
this.error = salla.lang.getWithDefault('pages.orders.order_not_found', 'الطلب غير موجود');
return;
}
const data = typeof this.orderData === 'string' ? JSON.parse(this.orderData) : this.orderData;
this.order = {
...data,
items: data.items.map(item => ({
...item,
selectedOptions: helpers.getOrderItemSelectedOptions(item),
})),
};
}
catch (e) {
this.error = salla.lang.getWithDefault('pages.orders.order_not_found', 'الطلب غير موجود');
}
finally {
this.loading = false;
}
}
applyProductSearch(query) {
const normalizedQuery = query?.trim() || '';
const nextSource = normalizedQuery ? 'search' : this.defaultProductsListSource;
const nextSourceValue = nextSource === 'search' ? JSON.stringify(normalizedQuery) : '';
if (this.productsListSource === nextSource &&
this.productsListSourceValue === nextSourceValue) {
return;
}
this.productsListSource = nextSource;
this.productsListSourceValue = nextSourceValue;
this.productsListKey += 1;
}
handleProductSearch(event) {
const value = event.target?.value || '';
this.productSearchQuery = value;
this.debouncedProductSearch(value);
}
getProductsListKey(scope) {
return `${scope}-${this.productsListSource}-${this.productsListSourceValue}-${this.productsListKey}`;
}
handleMobileProductsScroll(event) {
const container = event.currentTarget;
const distanceToBottom = container.scrollHeight - container.scrollTop - container.clientHeight;
if (distanceToBottom > 200 || this.mobileProductsListLoading) {
return;
}
const productsList = container.querySelector('salla-products-list');
if (!productsList) {
return;
}
this.mobileProductsListLoading = true;
void productsList.loadMore().finally(() => {
this.mobileProductsListLoading = false;
});
}
waitForNextFrame() {
return new Promise(resolve => requestAnimationFrame(() => resolve(undefined)));
}
async openMobileProductsModal() {
if (!this.mobileProductsModalMounted) {
this.mobileProductsModalMounted = true;
await this.waitForNextFrame();
}
await this.mobileProductsModal?.open?.();
}
setMobileProductsModal(modal) {
if (this.mobileProductsModal === modal) {
return;
}
this.mobileProductsModal?.removeEventListener('orderEditProductSelected', this.handleMobileProductSelected);
this.mobileProductsModal = modal;
this.mobileProductsModal?.addEventListener('orderEditProductSelected', this.handleMobileProductSelected);
}
resetAddProductDrawer() {
this.selectedProductToAdd = null;
this.addProductQuantity = 1;
this.addProductLoading = false;
this.addProductConfirmLoading = false;
this.addProductOptions = null;
}
getAddProductMaxQuantity(product = this.selectedProductToAdd) {
return helpers.getOrderEditProductMaxQuantity(product);
}
clampAddProductQuantity(quantity, product = this.selectedProductToAdd) {
return helpers.clampOrderEditQuantity(quantity, this.getAddProductMaxQuantity(product));
}
getApiErrorMessage(error) {
return error?.response?.data?.error?.message || error?.response?.data?.message;
}
notifyApiError(error) {
const message = this.getApiErrorMessage(error);
if (message) {
salla.notify.error(message);
}
}
async validateAddProductOptions() {
if (!this.selectedProductToAdd?.options?.length) {
return true;
}
if (!this.addProductOptions) {
return false;
}
return ((await this.addProductOptions.validateAndScroll?.()) ??
(await this.addProductOptions.reportValidity?.()) ??
false);
}
updateLocalOrderItem(itemId, quantity, optionDefinitions, selectedOptions) {
this.order = {
...this.order,
items: helpers.updateOrderItems(this.order.items, itemId, quantity, optionDefinitions, selectedOptions),
};
}
removeLocalOrderItem(itemId) {
this.order = {
...this.order,
items: helpers.removeOrderItems(this.order.items, itemId),
};
}
setPayloadItems(patch) {
this.payload = {
...this.payload,
items: helpers.mergePayloadItems(this.payload.items, patch),
};
}
handleAddProductQuantityChange(event) {
const detail = event.detail;
const newQuantity = detail?.quantity ?? parseInt(event.target?.value, 10);
if (isNaN(newQuantity) || newQuantity < 1) {
return;
}
this.addProductQuantity = this.clampAddProductQuantity(newQuantity);
}
async handleProductSelected(event) {
const product = event.detail?.product;
if (!product?.id || this.addProductLoading) {
return;
}
this.addProductLoading = true;
try {
this.selectedProductToAdd = helpers.cloneOrderEditProduct(product);
this.addProductQuantity = 1;
await this.mobileProductsModal?.close?.();
await this.waitForNextFrame();
await this.addProductDrawer?.open?.();
}
catch (error) {
this.notifyApiError(error);
}
finally {
this.addProductLoading = false;
}
}
async confirmAddProduct() {
if (!this.selectedProductToAdd?.id) {
return;
}
if (this.addProductConfirmLoading) {
return;
}
this.addProductConfirmLoading = true;
try {
const maxQuantity = this.getAddProductMaxQuantity();
const normalizedQuantity = this.clampAddProductQuantity(this.addProductQuantity);
if (normalizedQuantity !== this.addProductQuantity) {
this.addProductQuantity = normalizedQuantity;
}
const productOptions = this.addProductOptions;
const optionsAreValid = await this.validateAddProductOptions();
if (!optionsAreValid) {
salla.notify.error(salla.lang.getWithDefault('common.messages.required_fields', 'يرجى تعبئة الحقول المطلوبة'));
return;
}
const selectedOptionsPayload = (await productOptions?.getSelectedOptionsData?.()) || {};
const optionDefinitions = (await productOptions?.getOptionsData?.()) ||
this.selectedProductToAdd.options ||
[];
const existingItem = helpers.findMergeableItem(this.order?.items, this.selectedProductToAdd.id, selectedOptionsPayload);
if (existingItem) {
const mergedQuantity = helpers.clampOrderEditQuantity(existingItem.quantity + normalizedQuantity, maxQuantity);
this.updateLocalOrderItem(existingItem.id, mergedQuantity, optionDefinitions, selectedOptionsPayload);
if (existingItem.isNew) {
this.setPayloadItems({
add: helpers.updateAddedPayloadList(this.payload.items.add, existingItem.id, mergedQuantity, selectedOptionsPayload),
});
}
else {
this.setPayloadItems({
update: helpers.upsertPayloadUpdateList(this.payload.items.update, existingItem.id, mergedQuantity, selectedOptionsPayload),
});
}
await this.addProductDrawer?.close?.();
return;
}
const newItem = helpers.createAddedOrderItem(this.selectedProductToAdd, normalizedQuantity, optionDefinitions, selectedOptionsPayload);
const addEntry = {
itemId: newItem.id,
product_id: this.selectedProductToAdd.id,
quantity: normalizedQuantity,
options: selectedOptionsPayload,
};
this.order = {
...this.order,
items: [...this.order.items, newItem],
};
this.setPayloadItems({
add: [...this.payload.items.add, addEntry],
});
await this.addProductDrawer?.close?.();
}
catch (error) {
this.notifyApiError(error);
}
finally {
this.addProductConfirmLoading = false;
}
}
handleItemUpdated(event) {
if (!this.order)
return;
const { itemId, quantity, options, optionDefinitions } = event.detail;
const currentItem = this.order.items.find(item => item.id === itemId);
if (!currentItem) {
return;
}
const safeQuantity = helpers.clampOrderEditQuantity(quantity, helpers.getOrderEditProductMaxQuantity(currentItem.product));
if (currentItem.isNew) {
this.setPayloadItems({
add: helpers.updateAddedPayloadList(this.payload.items.add, itemId, safeQuantity, options),
});
this.updateLocalOrderItem(itemId, safeQuantity, optionDefinitions, options);
return;
}
this.setPayloadItems({
update: helpers.upsertPayloadUpdateList(this.payload.items.update, itemId, safeQuantity, options ?? {}),
});
this.updateLocalOrderItem(itemId, safeQuantity, optionDefinitions, options);
}
handleItemRemoved(event) {
if (!this.order)
return;
if (this.order.items.length <= 1) {
salla.notify.error(salla.lang.getWithDefault('pages.orders.order_cannot_be_empty', 'لا يمكن إزالة جميع المنتجات من الطلب'));
return;
}
const { itemId } = event.detail;
const currentItem = this.order.items.find(item => item.id === itemId);
if (!currentItem) {
return;
}
if (currentItem.isNew) {
this.setPayloadItems({
add: this.payload.items.add.filter(item => item.itemId !== itemId),
});
this.removeLocalOrderItem(itemId);
return;
}
this.setPayloadItems({
update: this.payload.items.update.filter(u => u.id !== itemId),
remove: [...this.payload.items.remove, itemId],
});
this.removeLocalOrderItem(itemId);
}
get hasChanges() {
return (this.payload.items.update.length > 0 ||
this.payload.items.remove.length > 0 ||
this.payload.items.add.length > 0);
}
async saveOrder() {
if (!this.hasChanges)
return;
this.saveLoading = true;
try {
const response = await salla.order.api.editOrder(this.orderId, helpers.buildSavePayload(this.payload));
this.editPreview = response?.data?.data || response?.data;
await this.saveModal?.open?.();
}
catch (error) {
this.notifyApiError(error);
}
finally {
this.saveLoading = false;
}
}
navigateToOrder() {
const url = new URL(window.location.href);
url.pathname = url.pathname.replace(/\/edit\/?$/, '');
url.search = '';
window.location.href = url.href;
}
handleConfirm() {
this.confirming = true;
if (this.editPreview?.payment?.required && this.editPreview.payment.payment_url) {
window.location.href = this.editPreview.payment.payment_url;
}
else {
this.navigateToOrder();
}
}
returnToOrderDetails() {
this.confirming = true;
this.navigateToOrder();
}
getConfirmButtonIconClass() {
return this.isRTL ? 'sicon-keyboard_arrow_left' : 'sicon-keyboard_arrow_right';
}
async cancelEditSession() {
try {
await salla.order.api.cancelEditSession(this.orderId);
this.navigateToOrder();
}
catch (error) {
this.notifyApiError(error);
}
}
renderProductsPanel() {
const addProductTitle = salla.lang.getWithDefault('pages.orders.add_product_to_order', 'أضف منتج للطلب');
return (index.h("section", { class: "s-order-edit-products-panel" }, index.h("div", { class: "s-order-edit-products-header" }, index.h("h2", { class: "s-order-edit-products-title" }, addProductTitle)), this.renderProductsPickerContent('panel')));
}
renderProductsPickerContent(scope) {
return (index.h("div", { class: {
's-order-edit-products-picker': true,
's-order-edit-products-modal-content': scope === 'modal',
} }, index.h("label", { class: "s-order-edit-products-search" }, index.h("i", { class: "sicon-search" }), index.h("input", { type: "search", class: "s-order-edit-products-search-input", placeholder: salla.lang.getWithDefault('pages.products.search_for_product', 'ابحث عن منتج'), value: this.productSearchQuery, onInput: event => this.handleProductSearch(event) })), index.h("div", { class: "s-order-edit-products-list", onScroll: scope === 'modal' ? event => this.handleMobileProductsScroll(event) : undefined }, index.h("salla-products-list", { key: this.getProductsListKey(scope), includes: ['options'], source: this.productsListSource, "source-value": this.productsListSourceValue, autoload: true, "product-card-component": "salla-order-edit-product-card" }))));
}
renderMobileProductsModal() {
return (index.h("salla-modal", { ref: modal => this.setMobileProductsModal(modal), width: "md", class: "s-order-edit-mobile-products-modal", "modal-title": salla.lang.getWithDefault('pages.orders.add_product_to_order', 'أضف منتج للطلب'), onModalVisibilityChanged: (e) => {
if (!e.detail) {
this.mobileProductsModalMounted = false;
}
} }, this.mobileProductsModalMounted ? this.renderProductsPickerContent('modal') : null));
}
renderAddProductDrawer() {
const product = this.selectedProductToAdd;
const productName = product?.name || salla.lang.getWithDefault('common.elements.product', 'منتج');
const price = product?.price;
const maxQuantity = this.getAddProductMaxQuantity(product);
const optionsInstanceKey = product ? `order-edit-add-${product.id}` : 'order-edit-add';
const quantityAttrs = {
value: this.clampAddProductQuantity(this.addProductQuantity, product),
};
if (maxQuantity) {
quantityAttrs.max = maxQuantity;
}
return (index.h("salla-modal", { ref: drawer => (this.addProductDrawer = drawer), width: "md", "modal-title": salla.lang.getWithDefault('pages.orders.add_product_to_order', 'أضف منتج للطلب'), onModalVisibilityChanged: (e) => {
if (!e.detail) {
this.resetAddProductDrawer();
}
} }, index.h("div", { class: "s-order-edit-add-modal" }, this.addProductLoading ? (index.h("div", { class: "s-order-edit-add-modal-loading" }, index.h("salla-loading", null))) : product ? (index.h("div", { class: "s-order-edit-add-modal-content" }, index.h("div", { class: "s-order-edit-add-modal-header" }, index.h("div", { class: "s-order-edit-add-modal-media" }, product.image?.url && (index.h("img", { src: product.image.url, alt: product.image.alt || productName, class: "s-order-edit-add-modal-image" })), index.h("div", { class: "s-order-edit-add-modal-details" }, index.h("h3", { class: "s-order-edit-add-modal-name" }, productName), price != null && (index.h("span", { class: "s-order-edit-add-modal-price", innerHTML: salla.money(price) }))))), index.h("div", { class: "s-order-edit-add-modal-quantity" }, index.h("h3", { class: "s-order-edit-add-modal-section-title" }, salla.lang.getWithDefault('common.elements.quantity', 'الكمية')), index.h("div", { class: "s-order-edit-add-modal-quantity-input" }, index.h("salla-quantity-input", { ...quantityAttrs, onChange: event => this.handleAddProductQuantityChange(event) }))), product.options?.length > 0 && (index.h("form", { onSubmit: e => e.preventDefault() }, index.h("salla-product-options", { ref: el => (this.addProductOptions = el), "product-id": product.id, "unique-key": optionsInstanceKey, options: JSON.stringify(product.options), key: `${optionsInstanceKey}-options` }))), index.h("div", { class: "s-order-edit-add-modal-actions" }, index.h("salla-button", { onClick: () => this.confirmAddProduct(), loading: this.addProductConfirmLoading }, salla.lang.getWithDefault('common.elements.confirm', 'تأكيد')), index.h("salla-button", { color: "gray", fill: "outline", onClick: () => this.addProductDrawer?.close?.() }, salla.lang.getWithDefault('common.elements.cancel', 'الغاء'))))) : null)));
}
renderSaveModal() {
const preview = this.editPreview;
const hasRemainingAmount = preview?.totals?.remaining_amount?.amount > 0;
const hasRefundAmount = preview?.totals?.refund_amount?.amount > 0;
const taxAmount = preview?.totals?.tax?.amount?.amount;
return (index.h("salla-modal", { ref: modal => (this.saveModal = modal), width: "md", isClosable: false, onModalVisibilityChanged: async (e) => {
if (!e.detail) {
this.editPreview = null;
if (!this.confirming) {
await this.cancelEditSession();
}
this.confirming = false;
}
} }, index.h("div", { class: "s-order-edit-modal" }, index.h("h2", { class: "s-order-edit-modal-title" }, salla.lang.getWithDefault('pages.orders.edit_summary_title', 'ملخص الطلب بعد التعديل')), index.h("p", { class: "s-order-edit-modal-subtitle" }, salla.lang.getWithDefault('pages.orders.cart_edits_saved', 'Your cart edits have been saved')), preview?.items?.length > 0 && (index.h("div", { class: "s-order-edit-modal-items" }, preview.items.map(item => {
const orderItem = this.order?.items?.find(oi => oi.id == item.id);
const imageUrl = orderItem?.product?.image?.url;
const optionsLabel = item.options?.join('/ ');
return (index.h("div", { class: "s-order-edit-modal-item" }, index.h("div", { class: "s-order-edit-modal-item-start" }, imageUrl && (index.h("img", { src: imageUrl, alt: item.name, class: "s-order-edit-modal-item-image" })), index.h("div", null, index.h("p", { class: "s-order-edit-modal-item-name" }, item.name), optionsLabel && (index.h("span", { class: "s-order-edit-modal-item-options" }, optionsLabel)))), index.h("div", { class: "s-order-edit-modal-item-end" }, index.h("span", { class: "s-order-edit-modal-item-quantity", dir: "ltr", innerHTML: item.quantity + " x " + item.price.amount }), index.h("span", { class: "s-order-edit-modal-item-price", innerHTML: salla.money(item.price.amount * item.quantity) }))));
}))), preview?.totals?.updated_products_total && (index.h("div", { class: "s-order-edit-modal-row" }, index.h("span", { class: "s-order-edit-modal-row-label" }, salla.lang.getWithDefault('pages.orders.modified_products_total', 'مجموع المنتجات المعدلة')), index.h("span", { class: "s-order-edit-modal-row-value", innerHTML: salla.money(preview.totals.updated_products_total.amount) }))), taxAmount > 0 && (index.h("div", { class: "s-order-edit-modal-row" }, index.h("span", { class: "s-order-edit-modal-tax-label" }, index.h("i", { class: "sicon-info-circle s-order-edit-modal-tax-icon" }), salla.lang.getWithDefault('pages.orders.vat', 'ضريبة القيمة المضافة')), index.h("span", { class: "s-order-edit-modal-row-value", innerHTML: salla.money(taxAmount) }))), preview?.totals?.total && (index.h("div", { class: "s-order-edit-modal-total" }, index.h("span", { class: "s-order-edit-modal-total-label" }, salla.lang.getWithDefault('pages.orders.order_total', 'اجمالي الطلب')), index.h("span", { class: "s-order-edit-modal-total-value", innerHTML: salla.money(preview.totals.total.amount) }))), hasRefundAmount && (index.h("div", { class: "s-order-edit-modal-refund" }, index.h("i", { class: "sicon-info-circle s-order-edit-modal-refund-icon" }), index.h("p", { class: "s-order-edit-modal-refund-text" }, salla.lang.getWithDefault('pages.orders.refund_message', 'سيتم تحويل فارق المبلغ على نفس وسيلة الدفع')))), index.h("div", { class: "s-order-edit-modal-btn-wrapper" }, index.h("salla-button", { onClick: () => this.handleConfirm() }, hasRemainingAmount
? salla.lang.getWithDefault('pages.orders.pay_difference', 'دفع فارق المبلغ')
: hasRefundAmount
? salla.lang.getWithDefault('pages.orders.confirm_and_receive_difference', 'تأكيد واستلام فارق المبلغ')
: salla.lang.getWithDefault('pages.orders.confirm_changes', 'تأكيد التعديلات'), index.h("i", { class: `${this.getConfirmButtonIconClass()} s-order-edit-modal-btn-icon` })), index.h("salla-button", { color: 'gray', fill: "outline", onClick: () => this.returnToOrderDetails() }, salla.lang.getWithDefault('pages.orders.back_to_order_details', 'العودة إلى تفاصيل الطلب'))))));
}
render() {
if (this.loading) {
return (index.h(index.Host, null, index.h("salla-loading", null)));
}
if (this.expired) {
return (index.h(index.Host, null, index.h("div", { class: "s-order-edit-expired" }, index.h("p", null, salla.lang.getWithDefault('pages.orders.edit_session_expired', 'انتهت مدة التعديل المتاحة')), index.h("salla-button", { onClick: () => this.navigateToOrder() }, salla.lang.getWithDefault('pages.orders.back_to_order', 'العودة إلى تفاصيل الطلب')))));
}
if (this.error || !this.order) {
return (index.h(index.Host, null, index.h("div", { class: "s-order-edit-no-content-placeholder" }, index.h("i", { class: "sicon-shopping-bag icon" }), index.h("p", null, this.error))));
}
const hasItems = this.order.items && this.order.items.length > 0;
const endsAt = this.order.customer_editing_session?.ends_at;
return (index.h(index.Host, null, endsAt && (index.h("div", { class: "s-order-edit-timer-wrapper" }, index.h("salla-count-down", { prefixText: salla.lang.getWithDefault('pages.orders.edit_within', 'يمكنك التعديل خلال'), date: endsAt, horizontal: true, withButton: true, autoSegments: true, labeled: false, size: "sm", color: "primary" }))), index.h("div", { class: "s-order-edit-layout" }, !this.isMobileViewport ? this.renderProductsPanel() : null, index.h("section", { class: "s-order-edit-order-panel" }, index.h("div", { class: "s-order-edit-items-wrapper" }, index.h("h2", { class: "s-order-edit-items-title" }, salla.lang.getWithDefault('pages.orders.order_products', 'منتجات الطلب')), hasItems ? (this.order.items.map((item, index$1) => [
index.h("salla-order-edit-item", { key: item.id, item: item, orderId: this.orderId }),
index$1 < this.order.items.length - 1 ? (index.h("div", { class: "s-order-edit-items-divider" })) : null,
])) : (index.h("div", { class: "s-order-edit-no-content-placeholder" }, index.h("i", { class: "sicon-shopping-bag icon" }), index.h("p", null, salla.lang.getWithDefault('common.elements.no_items', 'لا توجد عناصر'))))), index.h("div", { class: "s-order-edit-actions" }, index.h("salla-button", { class: "s-order-edit-mobile-products-trigger", color: "gray", size: "small", fill: "outline", onClick: () => this.openMobileProductsModal() }, index.h("i", { class: "sicon-add s-order-edit-mobile-products-trigger-icon" }), salla.lang.getWithDefault('pages.orders.add_product', 'إضافة منتج')), index.h("salla-button", { onClick: () => this.saveOrder(), loading: this.saveLoading, size: "small", disabled: !this.hasChanges }, salla.lang.getWithDefault('pages.orders.save_changes', 'حفظ التعديلات')), index.h("salla-button", { size: "small", color: "gray", fill: "outline", onClick: () => this.cancelEditSession() }, salla.lang.getWithDefault('common.elements.cancel', 'الغاء'))))), this.renderMobileProductsModal(), this.renderAddProductDrawer(), this.renderSaveModal()));
}
};
SallaOrderEdit.style = sallaOrderEditCss;
exports.salla_order_edit = SallaOrderEdit;