package com.lemenzo.gallery.ui;

import android.view.View;
import android.view.ViewGroup;

public final class GalleryTabs {
    private GalleryTabs() {}

    public static void positionIndicator(View tabs, View indicator, int tabIndex, int tabCount) {
        if (tabs == null || indicator == null || tabCount <= 0) return;
        tabs.post(() -> {
            int usableWidth = tabs.getWidth() - tabs.getPaddingLeft() - tabs.getPaddingRight();
            if (usableWidth <= 0) return;
            int width = usableWidth / tabCount;
            ViewGroup.LayoutParams params = indicator.getLayoutParams();
            params.width = width;
            indicator.setLayoutParams(params);
            indicator.setTranslationX(tabs.getPaddingLeft() + (width * tabIndex));
        });
    }
}
