// find the input based on the unique name.
export const findInput = (el, name) => {
  var _a, _b;
  const slot = (_b = (_a = el.querySelector('sc-form')) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('slot');
  if (!slot)
    return;
  return slot
    .assignedElements({ flatten: true })
    .reduce((all, el) => all.concat(el, [...el.querySelectorAll('*')]), [])
    .find((el) => el.name === name);
};
export const handleInputs = (el, order) => {
  // handle our own built-in inputs.
  const names = ['name', 'email'];
  // handle our our inputs.
  names.forEach(name => {
    const input = findInput(el, name);
    if (!input)
      return;
    input.value = order[name];
  });
  // update metadata.
  Object.keys((order === null || order === void 0 ? void 0 : order.metadata) || {}).forEach(key => {
    const input = findInput(el, key);
    input.value = order.metadata[key];
  });
};
