/* Custex editor — shared labels, logo URL, appearance options. */
const { useState: uS, useRef: uR, useEffect: uE, useMemo: uM } = React;
const { NODE_W, PORT_FIRST, PORT_STRIDE } = window.CxGeom;

/** Studio topbar — `logo.svg` next to `Custex Node Editor.html` (stable with `<base>` or nested paths). */
const CX_STUDIO_LOGO_SRC = (() => {
  if (typeof document === 'undefined') return 'logo.svg';
  try {
    return new URL('logo.svg', document.baseURI || window.location.href).href;
  } catch {
    return 'logo.svg';
  }
})();

/** Theme + Atelier canvas pattern (single control). Values: pigment | atelier:weave | atelier:dots | atelier:stripes | atelier:solid */
const CX_APPEARANCE_OPTIONS = [
  ['atelier:weave', 'Atelier · Grid weave'],
  ['atelier:dots', 'Atelier · Dots'],
  ['atelier:stripes', 'Atelier · Stripes'],
  ['atelier:solid', 'Atelier · Solid'],
  ['pigment', 'Pigment'],
];
function nodeNumFor(role) {
  return ({ product:'01', craft:'02', fabric:'03', yarn:'03', motif:'04', matte:'04b', colorSplit:'04c', layout:'05', airender:'06', output:'07' })[role] || '—';
}
function nodeTitleFor(role) {
  return ({ product:'Product', craft:'Craft', fabric:'Material', yarn:'Yarn', motif:'Motif', matte:'Matte strip', colorSplit:'Color split', layout:'Layout', airender:'AI render', output:'Output' })[role];
}

function cxCollapseTruncate(s, max) {
  const t = String(s ?? '').trim();
  if (!t) return '';
  if (t.length <= max) return t;
  return `${t.slice(0, Math.max(0, max - 1))}…`;
}
window.CxEditorShared = { nodeNumFor, nodeTitleFor, cxCollapseTruncate, CX_STUDIO_LOGO_SRC, CX_APPEARANCE_OPTIONS };
