// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/settings/ui_bundled/cells/inline_promo_item.h"

#import "ios/chrome/browser/settings/ui_bundled/cells/inline_promo_cell.h"
#import "ios/chrome/browser/shared/public/features/features.h"

@implementation InlinePromoItem

- (instancetype)initWithType:(NSInteger)type {
  self = [super initWithType:type];
  if (self) {
    self.cellClass = [InlinePromoCell class];
    _shouldShowCloseButton = YES;
    _shouldDisplayBadge = YES;
    _enabled = YES;
  }
  return self;
}

#pragma mark - TableViewItem

- (void)configureCell:(InlinePromoCell*)cell {
  [super configureCell:cell];
  cell.closeButton.hidden = !self.shouldShowCloseButton;
  cell.badgeView.hidden = !self.shouldDisplayBadge;
  cell.promoImageView.image = self.promoImage;
  cell.promoTextLabel.text = self.promoText;
  cell.enabled = self.enabled;
  cell.shouldHaveWideLayout = self.shouldHaveWideLayout;

  UIButtonConfiguration* buttonConfiguration =
      cell.moreInfoButton.configuration;
  UIFont* font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  NSDictionary* attributes = @{NSFontAttributeName : font};
  NSMutableAttributedString* attributedString =
      [[NSMutableAttributedString alloc] initWithString:self.moreInfoButtonTitle
                                             attributes:attributes];
  buttonConfiguration.attributedTitle = attributedString;
  cell.moreInfoButton.configuration = buttonConfiguration;

  cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

@end
