//
//  LNCreateOrderFailedPanel.swift
//  Lanu
//
//  Created by OneeChan on 2025/12/22.
//

import Foundation
import UIKit
import SnapKit


class LNCreateOrderFailedPanel: LNPopupView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension LNCreateOrderFailedPanel {
    private func setupViews() {
        let bg = UIImageView()
        bg.image = .icOrderBg
        container.addSubview(bg)
        bg.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview()
            make.top.equalToSuperview()
        }
        
        let ic = UIImageView()
        ic.image = .icOrderFailed
        container.addSubview(ic)
        ic.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(59)
        }
        
        let descLabel = UILabel()
        descLabel.text = .init(key: "A00119")
        descLabel.font = .heading_h2
        descLabel.textColor = .text_4
        descLabel.numberOfLines = 0
        descLabel.textAlignment = .center
        container.addSubview(descLabel)
        descLabel.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview().inset(16)
            make.top.equalTo(ic.snp.bottom).offset(16)
        }
        
        let confirmButton = UIButton()
        confirmButton.setTitle(.init(key: "A00002"), for: .normal)
        confirmButton.setTitleColor(.text_1, for: .normal)
        confirmButton.titleLabel?.font = .heading_h3
        confirmButton.setBackgroundImage(.primary_8, for: .normal)
        confirmButton.layer.cornerRadius = 23.5
        confirmButton.clipsToBounds = true
        confirmButton.addAction(UIAction(handler: { [weak self] _ in
            guard let self else { return }
            dismiss()
        }), for: .touchUpInside)
        container.addSubview(confirmButton)
        confirmButton.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview().inset(12)
            make.top.equalTo(descLabel.snp.bottom).offset(46)
            make.bottom.equalToSuperview().offset(commonBottomInset)
            make.height.equalTo(47)
        }
    }
}
