//
//  KBFunctionTagCell.m
//  CustomKeyboard
//
//  Created by Codex on 2025/10/28.
//

#import "KBFunctionTagCell.h"
#import "Masonry.h"

@interface KBFunctionTagCell ()
@property (nonatomic, strong) UILabel *titleLabelInternal;
@property (nonatomic, strong) UIImageView *iconViewInternal;
@end

@implementation KBFunctionTagCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
        self.contentView.layer.cornerRadius = 12;
        self.contentView.layer.masksToBounds = YES;

        [self.contentView addSubview:self.iconViewInternal];
        [self.contentView addSubview:self.titleLabelInternal];

        [self.iconViewInternal mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(10);
            make.centerY.equalTo(self.contentView.mas_centerY);
            make.width.height.mas_equalTo(24);
        }];
        [self.titleLabelInternal mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconViewInternal.mas_right).offset(6);
            make.right.equalTo(self.contentView.mas_right).offset(-10);
            make.centerY.equalTo(self.contentView.mas_centerY);
        }];
    }
    return self;
}

#pragma mark - Lazy

- (UIImageView *)iconViewInternal {
    if (!_iconViewInternal) {
        _iconViewInternal = [[UIImageView alloc] init];
        UILabel *emoji = [[UILabel alloc] init];
        emoji.text = @"🙂"; // 占位图标
        emoji.textAlignment = NSTextAlignmentCenter;
        emoji.font = [UIFont systemFontOfSize:20];
        [_iconViewInternal addSubview:emoji];
        [emoji mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(_iconViewInternal);
        }];
    }
    return _iconViewInternal;
}

- (UILabel *)titleLabelInternal {
    if (!_titleLabelInternal) {
        _titleLabelInternal = [[UILabel alloc] init];
        _titleLabelInternal.font = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold];
        _titleLabelInternal.textColor = [UIColor blackColor];
    }
    return _titleLabelInternal;
}

#pragma mark - Expose

- (UILabel *)titleLabel { return self.titleLabelInternal; }
- (UIImageView *)iconView { return self.iconViewInternal; }

@end

