import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { MainProductNameWrapper, MainProductPriceWrapper, MainProductQuantityWrapper, MainProductWrapper, } from './style';
import ProductSubItems from '../ProductSubItems';
import Loader from 'react-loaders';
import { PROCESSED, PROCESSING } from '../utils/constants';
import Price from '../Price';
import TickIcon from '../assets/TickIcon';
const OrderProduct = (props) => {
    const { line, fullMode = false, showItems = false, kdsFilter = '', kdsLayout = '', currency = '', kdsDeviceConfigs = {}, } = props;
    const { product, quantity, price } = line;
    const isStageDone = (line.extra &&
        kdsDeviceConfigs &&
        kdsDeviceConfigs.KDS_STAGE_DONE &&
        line.extra[`X-${kdsDeviceConfigs.KDS_STAGE_DONE}`]) ||
        line.status === PROCESSED;
    const isProcessing = (line.extra &&
        kdsDeviceConfigs &&
        kdsDeviceConfigs.KDS_STAGE_DONE &&
        line?.extra[`X-${kdsDeviceConfigs.KDS_STAGE_DONE}`] !== 'DONE') ||
        (!line.extra && line.status === PROCESSING);
    const productLineItems = 'items' in product &&
        Array.isArray(product.items) &&
        product.items.length > 0 &&
        product.items.map((item) => {
            showItems &&
                'items' in item &&
                Array.isArray(item.items) &&
                item.items.map((element) => {
                    const filteredGroup = element;
                    if ('items' in element && Array.isArray(element.items)) {
                        const filteredItems = element.items.filter((el) => el.extra && el.extra.KDS_FILTER === kdsFilter);
                        filteredGroup.items = filteredItems;
                        return filteredGroup;
                    }
                    return element;
                });
            return (_jsxs("div", { children: [item.literals && item.literals.name && (_jsx("div", { children: item.literals.name })), Array.isArray(item.items) &&
                        item.items.map((item) => (_jsx(ProductSubItems, { item: item, fullMode: fullMode, kdsLayout: kdsLayout, currency: currency }, item.id)))] }, `${item.id}-item-line`));
        });
    return (_jsxs("div", { children: [_jsxs(MainProductWrapper, { children: [_jsxs(MainProductQuantityWrapper, { children: [quantity, " x"] }), _jsxs(MainProductNameWrapper, { children: [product.literals.name, ":"] }), _jsx(MainProductPriceWrapper, { children: _jsx(Price, { amount: price, currency: currency, hideCurrency: true }) }), isProcessing && (_jsx(Loader, { type: "ball-pulse", active: true, innerClassName: "loader-active" })), isStageDone && (_jsx("div", { style: { marginLeft: '10px' }, children: _jsx(TickIcon, {}) }))] }), _jsx("div", { style: { marginLeft: '30px' }, children: productLineItems })] }));
};
export default OrderProduct;
//# sourceMappingURL=index.js.map