const DESIGN_SYSTEM_PREFIX = 'vds';
// TODO: once token studio tokens are transformed into style dictionary tokens object - use the later to generate this helper object
const transformDesignTokenCTI = (tokens, valueResolver) => {
  const category = Object.keys(tokens)[0];
  const types = Object.entries(tokens[category]).map(([type, items]) => {
    const transformedItems = Object.entries(items).flatMap(([item, tokenData]) => {
      var _a, _b;
      // if there are no subItems, return the item
      if (tokenData.value) {
        const resolvedValue = (_a = valueResolver === null || valueResolver === void 0 ? void 0 : valueResolver(category, type, item)) !== null && _a !== void 0 ? _a : tokenData.value;
        const description = (_b = tokenData) === null || _b === void 0 ? void 0 : _b.description;
        const name = item;
        const fullName = `${DESIGN_SYSTEM_PREFIX}-${category}-${type}-${item}`;
        return [{ name, value: resolvedValue, fullName, description }];
      }
      else {
        // if there are subItems, return transformed subItems
        return Object.entries(tokenData).map(([subItem, subItemValue]) => {
          var _a;
          const tokenValue = subItemValue.value;
          const resolvedValue = (_a = valueResolver === null || valueResolver === void 0 ? void 0 : valueResolver(category, type, item, subItem)) !== null && _a !== void 0 ? _a : tokenValue;
          const description = subItemValue === null || subItemValue === void 0 ? void 0 : subItemValue.description;
          const name = `${item}-${subItem}`;
          const fullName = `${DESIGN_SYSTEM_PREFIX}-${category}-${type}-${item}-${subItem}`;
          return { name, value: resolvedValue, fullName, description };
        });
      }
    });
    return { name: type, items: transformedItems };
  });
  return { name: category, types };
};
// TODO: create universal transformer to properly support Category-Type-Item-SubItem(-State?) design tokens structure
const transformDesignTokenCT = (token, valueResolver) => {
  const category = Object.keys(token)[0];
  const types = Object.entries(token[category]).map(([type, value]) => {
    const tokenValue = value.value;
    const resolvedValue = valueResolver || typeof tokenValue !== 'string'
      ? valueResolver(category, type)
      : tokenValue;
    const description = value.description;
    const name = type;
    const fullName = `${DESIGN_SYSTEM_PREFIX}-${category}-${type}`;
    return Object.assign({ name, value: resolvedValue, fullName }, (description && { description }));
  });
  return { name: category, types };
};
export { transformDesignTokenCTI, transformDesignTokenCT };
