
struct ContentButtons {

    struct Item {

        let icon: PageIcon

        let filePath: String?

        let text: String

        let downloadFileName: String?

        let onClickText: String?

        init(icon: PageIcon, filePath: String?, text: String, downloadFileName: String? = nil, onClickText: String? = nil) {
            self.icon = icon
            self.filePath = filePath
            self.text = text
            self.downloadFileName = downloadFileName
            self.onClickText = onClickText
        }
    }

    let items: [Item]

    init(items: [Item]) {
        self.items = items
    }

    var content: String {
        var result = "<p class='tags tag-buttons'>"
        for item in items {
            addButton(of: item, to: &result)
        }
        result += "</p>"
        return result
    }

    private func addButton(of item: Item, to result: inout String) {
        let downloadText = item.downloadFileName.map { " download='\($0)'" } ?? ""
        let linkText = item.filePath.map { " href='\($0)'" } ?? ""
        let onClickText = item.onClickText.map { " onClick='\($0)'" } ?? ""
        result += "<a class='tag'\(linkText)\(downloadText)\(onClickText)>"
        result += "\(item.icon.usageString)\(item.text)"
        result += "</a>"
    }
}
