// src/framework/shadowlisp/primitives/SlGt.ts
//
// Vision 49: Greater-than element - IS a Matrix component
//
// <sl-gt><a><b></sl-gt> => a > b

import type { SExpr } from '../../../lisp/SExpr';
import { SlMatrixElement } from '../SlMatrixElement';
import { SlBootstrap } from '../SlBootstrap';

/**
 * SlGt - Greater-than comparison element that IS a Matrix component.
 *
 * @example
 * <sl-gt><sl-num>5</sl-num><sl-num>3</sl-num></sl-gt>  => true
 */
export class SlGt extends SlMatrixElement {
  async evalSelf(env: SExpr[]): Promise<SExpr> {
    const children = Array.from(this.children);
    if (children.length < 2) {
      throw new Error('sl-gt requires 2 children');
    }

    const a = await this.evalChild(children[0], env) as number;
    const b = await this.evalChild(children[1], env) as number;

    return SlBootstrap.gt(a, b);
  }

  toSExpr(): SExpr {
    const args = Array.from(this.children).map(c =>
      (c instanceof SlMatrixElement) ? c.toSExpr() : null
    );
    return ['>', ...args];
  }
}

if (!customElements.get('sl-gt')) {
  customElements.define('sl-gt', SlGt);
}
