//
//  PreviewPanel.swift
//  Kordophone
//
//  Created by James Magahern on 9/12/25.
//

import AppKit
import QuickLook
import QuickLookUI

internal class PreviewPanel
{
    static let shared = PreviewPanel()

    private var displayedURL: URL? = nil
    private var impl: QLPreviewPanel { QLPreviewPanel.shared() }

    private init() {
        impl.dataSource = self
    }

    public func show(url: URL) {
        self.displayedURL = url
        impl.makeKeyAndOrderFront(self)
    }
}


extension PreviewPanel: QLPreviewPanelDataSource
{
    func numberOfPreviewItems(in panel: QLPreviewPanel!) -> Int {
        1
    }

    func previewPanel(_ panel: QLPreviewPanel!, previewItemAt index: Int) -> (any QLPreviewItem)! {
        return displayedURL! as NSURL
    }
}
