package io.xpipe.app.browser;

import io.xpipe.app.comp.BaseRegionBuilder;
import io.xpipe.app.ext.DataStore;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreColor;
import io.xpipe.app.storage.DataStoreEntryRef;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;

import lombok.Getter;

@Getter
public abstract class BrowserStoreSessionTab<T extends DataStore> extends BrowserSessionTab {

    protected final DataStoreEntryRef<? extends T> entry;
    private final String name;

    public BrowserStoreSessionTab(BrowserAbstractSessionModel<?> browserModel, DataStoreEntryRef<? extends T> entry) {
        super(browserModel);
        this.entry = entry;
        this.name = DataStorage.get().getStoreEntryDisplayName(entry.get());
    }

    public abstract BaseRegionBuilder<?, ?> comp();

    public abstract boolean canImmediatelyClose();

    public abstract void init() throws Exception;

    public abstract void close();

    @Override
    public ObservableValue<String> getName() {
        return new SimpleStringProperty(name);
    }

    @Override
    public String getIcon() {
        return entry.get().getEffectiveIconFile();
    }

    @Override
    public DataStoreColor getColor() {
        return DataStorage.get().getEffectiveColor(entry.get());
    }
}
