import { FormSection } from '@/components/admin/form-section';

/** What App\Content\MediaLibrary found for the page (only the parts shown here). */
export type PageMedia = {
    kind: 'image' | 'video';
    /** The picture, or the poster of a video; null for a video without one. */
    src: string | null;
};

type Props = {
    /** What the page shows today; null while no file has been added. */
    media: PageMedia | null;
    /** Folder of the media library. */
    collection: 'categories' | 'treatments' | 'blog';
    /** The record's key — the file name without its extension. */
    name: string;
};

const code = 'rounded bg-muted px-1 py-0.5 font-mono text-xs break-all';

/**
 * Read-only note about the photo or video of a page. Media is not uploaded
 * in the panel: the public site picks files up by their name
 * (App\Content\MediaLibrary, docs/PLACEHOLDERS.md → Medya), and this note
 * tells which name that is and whether a file is in place.
 */
export function MediaNote({ media, collection, name }: Props) {
    const base = `storage/app/public/media/${collection}/${name}`;

    return (
        <FormSection
            title="Sayfa görseli"
            description="Sayfanın üst bölümündeki fotoğraf ya da video. Panelden yüklenmez: dosya sunucuya aşağıdaki adla konduğunda site kendiliğinden gösterir, kaydetmek gerekmez."
        >
            <div className="flex flex-col gap-5 sm:flex-row sm:items-start">
                {media?.src ? (
                    <img
                        src={media.src}
                        alt=""
                        className="h-32 w-28 shrink-0 rounded-md border object-cover"
                    />
                ) : (
                    <div className="flex h-32 w-28 shrink-0 items-center justify-center rounded-md border border-dashed px-2 text-center text-xs text-muted-foreground">
                        {media ? 'Afişsiz video' : 'Dosya yok'}
                    </div>
                )}

                <div className="grid gap-2 text-sm">
                    <p className="font-medium">
                        {media === null
                            ? 'Henüz dosya eklenmedi; sayfada üretken çizim gösteriliyor.'
                            : media.kind === 'video'
                              ? 'Bu sayfada şu an bir video gösteriliyor.'
                              : 'Bu sayfada şu an bu fotoğraf gösteriliyor.'}
                    </p>
                    <p className="text-muted-foreground">
                        Fotoğraf: <code className={code}>{base}.jpg</code>{' '}
                        (avif, webp, jpg ya da png; öneri: dikey 4:5, en çok 200
                        KB).
                    </p>
                    <p className="text-muted-foreground">
                        Video: <code className={code}>{base}.mp4</code> ve/veya{' '}
                        <code className={code}>.webm</code>; yanına aynı adla
                        bir fotoğraf konursa afiş olur.
                    </p>
                    <p className="text-muted-foreground">
                        Değiştirmek için dosyayı aynı adla yeniden koyun,
                        kaldırmak için silin. Fotoğraf aynı zamanda sayfanın
                        paylaşım görseli olur.
                    </p>
                    {collection === 'blog' && (
                        <p className="text-muted-foreground">
                            Aynı görsel blog listesindeki yazı kartında yatay
                            kırpılarak gösterilir; konuyu görselin ortasında
                            tutun.
                        </p>
                    )}
                </div>
            </div>
        </FormSection>
    );
}
