/**
 * LogoElement Component
 *
 * Logo element with icon or text fallback.
 * Renders with unified wrapper styling + content.
 */

import React from 'react';
import type { CSSProperties } from 'react';
import type { CanvasElement } from '../../../types/constructor';
import { resolveAssetPlaybackUrl } from '../../../lib/assetUrl';

interface LogoElementProps {
  element: CanvasElement;
  resolveUrl?: (url: string | undefined) => string;
  className: string;
  style: CSSProperties;
}

const LogoElement: React.FC<LogoElementProps> = ({
  element,
  resolveUrl,
  className,
  style,
}) => {
  const resolve = resolveUrl ?? resolveAssetPlaybackUrl;

  // With icon: render image
  if (element.iconUrl) {
    const imgStyle: CSSProperties = {
      width: element.width ? '100%' : 'auto',
      height: element.height ? '100%' : 'auto',
      objectFit: 'contain',
    };

    return (
      <div className={className} style={style}>
        {/* eslint-disable-next-line @next/next/no-img-element */}
        <img
          src={resolve(element.iconUrl)}
          alt='Logo'
          style={imgStyle}
          draggable={false}
        />
      </div>
    );
  }

  // Without icon: render text logo
  return (
    <div className={className} style={style}>
      <span className='px-4 py-2 font-bold'>{element.label || 'LOGO'}</span>
    </div>
  );
};

export default LogoElement;
