var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import state from '../state';
import product from '../services/product';
import * as analytics from '../services/analytics';
function isActive(sku) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!state.init)
            return Promise.reject(new Error('R2U - Not initialized'));
        if (!sku)
            return Promise.reject(new Error('R2U - Missing SKU'));
        analytics.setSku(sku);
        try {
            const { isActive, manufacturerId } = yield product(sku);
            if (manufacturerId)
                analytics.setManufacturerId(manufacturerId);
            analytics.isActive3D(isActive);
            return isActive;
        }
        catch (err) {
            // `product` throws error if SKU not found
            return false;
        }
    });
}
function getData(sku) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!state.init)
            return Promise.reject(new Error('R2U - Not initialized'));
        if (!sku)
            return Promise.reject(new Error('R2U - Missing SKU'));
        const productData = yield product(sku);
        return productData;
    });
}
export default {
    isActive,
    getData,
};
//# sourceMappingURL=sku.js.map