import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/extends";
var _excluded = ["onClick", "title", "image", "imagePlacement", "description", "type", "textLines", "itemColumns", "itemPadding", "iconList", "text3", "text4", "imgWidth", "imgHeight", "itemBgColor", "style", "textAlign", "isShoppingCart", "isWishList", "itemType", "textImgGap", "imgBorderRadius", "imgObjectFit", "titleColor", "titleFontSize", "titleFontWeight", "titleLineClamp", "descriptionColor", "descriptionFontSize", "descriptionFontWeight", "descriptionLineClamp", "itemBorderRadius", "itemBorderColor", "itemBorderWidth"];
import React, { createElement } from 'react';
import "./teletext-list-item.scss";
import { Icon } from '@alilc/lowcode-materials';
// ─── 图标位置计算（纯函数，无副作用） ────────────────────────────────────────────
function getIconStyle(icon) {
  var base = {
    position: 'absolute',
    zIndex: 10
  };
  switch (icon.position) {
    case 'leftTop':
      return _extends({}, base, {
        top: '0px',
        left: '10px'
      });
    case 'leftBottom':
      return _extends({}, base, {
        bottom: '0px',
        left: '10px'
      });
    case 'rightTop':
      return _extends({}, base, {
        top: '0px',
        right: '10px'
      });
    case 'rightBottom':
      return _extends({}, base, {
        bottom: '0px',
        right: '10px'
      });
    case 'customize':
      return _extends({}, base, {
        right: (icon.rightOffset || 0) + "px",
        top: (icon.topOffset || 0) + "px"
      });
    default:
      return base;
  }
}

// ─── 文本行内容映射（纯函数） ─────────────────────────────────────────────────────
function getTextContent(index, title, description, text3, text4) {
  switch (index) {
    case 0:
      return title || '';
    case 1:
      return description || '';
    case 2:
      return text3 || '';
    case 3:
      return text4 || '';
    default:
      return '';
  }
}
var TeletextListItem = function TeletextListItem(_ref) {
  var _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
    title = _ref.title,
    image = _ref.image,
    imagePlacement = _ref.imagePlacement,
    description = _ref.description,
    type = _ref.type,
    _ref$textLines = _ref.textLines,
    textLines = _ref$textLines === void 0 ? 2 : _ref$textLines,
    itemColumns = _ref.itemColumns,
    itemPadding = _ref.itemPadding,
    iconList = _ref.iconList,
    text3 = _ref.text3,
    text4 = _ref.text4,
    _ref$imgWidth = _ref.imgWidth,
    imgWidth = _ref$imgWidth === void 0 ? 100 : _ref$imgWidth,
    _ref$imgHeight = _ref.imgHeight,
    imgHeight = _ref$imgHeight === void 0 ? 100 : _ref$imgHeight,
    itemBgColor = _ref.itemBgColor,
    style = _ref.style,
    textAlign = _ref.textAlign,
    isShoppingCart = _ref.isShoppingCart,
    isWishList = _ref.isWishList,
    itemType = _ref.itemType,
    _ref$textImgGap = _ref.textImgGap,
    textImgGap = _ref$textImgGap === void 0 ? 16 : _ref$textImgGap,
    imgBorderRadius = _ref.imgBorderRadius,
    imgObjectFit = _ref.imgObjectFit,
    titleColor = _ref.titleColor,
    titleFontSize = _ref.titleFontSize,
    titleFontWeight = _ref.titleFontWeight,
    titleLineClamp = _ref.titleLineClamp,
    descriptionColor = _ref.descriptionColor,
    descriptionFontSize = _ref.descriptionFontSize,
    descriptionFontWeight = _ref.descriptionFontWeight,
    descriptionLineClamp = _ref.descriptionLineClamp,
    itemBorderRadius = _ref.itemBorderRadius,
    itemBorderColor = _ref.itemBorderColor,
    itemBorderWidth = _ref.itemBorderWidth,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var IconComp = Icon;
  var _otherProps = otherProps || {};

  // 图片地址：唯一来源是 dataList[i].image prop，不依赖任何子节点 schema
  var resultImage = Array.isArray(image) ? image[0] || '' : image || '';

  // 图片尺寸：唯一来源是 imgWidth / imgHeight prop（由父组件 TeletextList 统一下发）
  // 不读取、不写入任何子节点 style，彻底消除与低代码引擎节点级重渲染的冲突
  var imageStyle = {
    width: imgWidth + "px",
    height: imgHeight + "px",
    borderRadius: imgBorderRadius != null ? imgBorderRadius + "px" : undefined,
    objectFit: imgObjectFit
  };
  var containerClass = "teletext-list__panel__item image-" + imagePlacement + " itemColumns-" + itemColumns;
  var containerStyle = _extends({
    padding: itemPadding != null ? itemPadding + "px" : undefined,
    backgroundColor: itemBgColor,
    alignItems: textAlign,
    gap: textImgGap + "px",
    borderRadius: itemBorderRadius != null ? itemBorderRadius + "px" : undefined,
    border: itemBorderWidth != null || itemBorderColor ? (itemBorderWidth !== null && itemBorderWidth !== void 0 ? itemBorderWidth : 1) + "px solid " + (itemBorderColor !== null && itemBorderColor !== void 0 ? itemBorderColor : 'transparent') : undefined
  }, style);

  // ── 图片元素（原生 img，不依赖低代码 Image 组件 / convertChildren / cloneElement）
  var imageEl = resultImage && type !== 'textOnly' ? /*#__PURE__*/React.createElement("img", {
    src: resultImage,
    alt: title || '',
    className: "teletext-list__panel__item_image",
    style: imageStyle
  }) : null;

  // ── 开关行（原生 CSS toggle switch；点击不冒泡到 item，状态由页面级事件控制）
  var switchRow = type !== 'imgOnly' && itemType === '开关' ? /*#__PURE__*/React.createElement("div", {
    className: "teletext-list__panel__item__switch",
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between'
    }
  }, /*#__PURE__*/React.createElement("span", {
    className: "teletext-list__panel__item__switch__title",
    style: {
      color: titleColor,
      fontSize: titleFontSize != null ? titleFontSize + "px" : undefined,
      fontWeight: titleFontWeight,
      WebkitLineClamp: titleLineClamp
    }
  }, title), /*#__PURE__*/React.createElement("label", {
    className: "teletext-list__panel__item__switch__toggle",
    onClick: function onClick(e) {
      return e.stopPropagation();
    }
  }, /*#__PURE__*/React.createElement("input", {
    type: "checkbox"
  }), /*#__PURE__*/React.createElement("span", {
    className: "teletext-list__panel__item__switch__slider"
  }))) : null;

  // ── 文本区
  var textArea = type !== 'imgOnly' && itemType !== '开关' ? /*#__PURE__*/React.createElement("div", {
    className: "teletext-list__panel__item__text"
  }, Array.from({
    length: textLines
  }).map(function (_, index) {
    return /*#__PURE__*/React.createElement("span", {
      key: index,
      className: "teletext-list__panel__item__text__" + (index === 0 ? 'title' : 'description'),
      style: index === 0 ? {
        color: titleColor,
        fontSize: titleFontSize != null ? titleFontSize + "px" : undefined,
        fontWeight: titleFontWeight,
        WebkitLineClamp: titleLineClamp
      } : {
        color: descriptionColor,
        fontSize: descriptionFontSize != null ? descriptionFontSize + "px" : undefined,
        fontWeight: descriptionFontWeight,
        WebkitLineClamp: descriptionLineClamp
      }
    }, getTextContent(index, title, description, text3, text4));
  }), isShoppingCart && /*#__PURE__*/React.createElement("div", {
    className: "shopping-cart-select"
  }, /*#__PURE__*/React.createElement("div", {
    className: "select-box"
  }, /*#__PURE__*/React.createElement("select", {
    className: "teletext-list__panel__item__select"
  }, [1, 2, 3, 4, 5].map(function (n) {
    return /*#__PURE__*/React.createElement("option", {
      key: n,
      value: n
    }, "\u6570\u91CF: ", n);
  })), /*#__PURE__*/React.createElement("select", {
    className: "teletext-list__panel__item__select"
  }, ['M', 'X', 'XL'].map(function (s) {
    return /*#__PURE__*/React.createElement("option", {
      key: s,
      value: s
    }, "\u5C3A\u7801: ", s);
  }))), /*#__PURE__*/React.createElement("div", {
    className: "shopping-cart-select__btn"
  }, /*#__PURE__*/React.createElement("div", {
    className: "shopping-cart-select__btn__item"
  }, /*#__PURE__*/React.createElement("img", {
    className: "shopping-cart-select-img",
    src: "https://51ymb.com/source/api/upload/1075055372064133120/2025/202501/20250110/1075084331397025792.png",
    alt: ""
  }), "Move to wishlist"), /*#__PURE__*/React.createElement("div", {
    className: "remove-box"
  }, /*#__PURE__*/React.createElement("img", {
    className: "shopping-cart-select-img",
    src: "https://51ymb.com/source/api/upload/1075055372064133120/2025/202502/20250207/1085235703970926592.png",
    alt: ""
  }), "Remove"))), isWishList && /*#__PURE__*/React.createElement("div", {
    className: "shopping-cart-select__btn"
  }, /*#__PURE__*/React.createElement("div", {
    className: "shopping-cart-select__btn__item"
  }, /*#__PURE__*/React.createElement("img", {
    className: "shopping-cart-select-img",
    src: "https://51ymb.com/source/api/upload/1075055372064133120/2025/202501/20250110/1075084331397025792.png",
    alt: ""
  }), "Move to Cart"), /*#__PURE__*/React.createElement("div", {
    className: "remove-box"
  }, /*#__PURE__*/React.createElement("img", {
    className: "shopping-cart-select-img",
    src: "https://51ymb.com/source/api/upload/1075055372064133120/2025/202502/20250207/1085235703970926592.png",
    alt: ""
  }), "Remove"))) : null;
  return /*#__PURE__*/React.createElement("div", _extends({
    className: containerClass,
    onClick: onClick,
    style: containerStyle
  }, _otherProps), (imagePlacement === 'left' || imagePlacement === 'top') && imageEl, switchRow, textArea, (imagePlacement === 'right' || imagePlacement === 'bottom') && imageEl, iconList === null || iconList === void 0 ? void 0 : iconList.map(function (icon, index) {
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: "teletext-list__panel__item__icon size-" + icon.size,
      style: getIconStyle(icon)
    }, /*#__PURE__*/createElement(IconComp, {
      type: icon.icon,
      size: icon.size
    }));
  }));
};
TeletextListItem.displayName = 'TeletextListItem';
export default TeletextListItem;