import { z } from 'zod'

// ── Constants ──────────────────────────────────────────────────────────
export const perPage = 10

export const metaTitleMinLength = 50
export const metaTitleMaxLength = 60
export const metaDescriptionMinLength = 120
export const metaDescriptionMaxLength = 160

export const FRONTEND_URL =
  (import.meta.env.VITE_FRONTEND_URL as string | undefined)?.replace(
    /\/$/,
    ''
  ) || 'http://localhost:3000'

// ── SEO helpers ────────────────────────────────────────────────────────
export type SeoCounterTone = 'good' | 'warning' | 'danger'

export function getSeoCounter(length: number, min: number, max: number) {
  if (length === 0) {
    return {
      tone: 'warning' as SeoCounterTone,
      text: `Önerilen aralık ${min}-${max} karakter.`,
    }
  }
  if (length < min) {
    return {
      tone: 'warning' as SeoCounterTone,
      text: `${length} karakter. En az ${min} hedefleyin.`,
    }
  }
  if (length > max) {
    return {
      tone: 'danger' as SeoCounterTone,
      text: `${length} karakter. ${max} üstüne çıkınca sonuçlar kesilebilir.`,
    }
  }
  return {
    tone: 'good' as SeoCounterTone,
    text: `${length} karakter. SEO için ideal aralıkta.`,
  }
}

// ── Form schema ────────────────────────────────────────────────────────
export const courseFormSchema = z.object({
  categoryId: z.coerce.number().min(1, 'Kategori seciniz'),
  title: z.string().min(2, 'Baslik en az 2 karakter olmalidir'),
  slug: z.string().min(2, 'Slug en az 2 karakter olmalidir'),
  sub: z.string().optional(),
  duration: z.string().min(1, 'Sure zorunludur'),
  price: z.string().optional(),
  badge: z.string().optional(),
  standard: z.string().optional(),
  image: z.string().optional(),
  description: z.string().min(10, 'Kısa açıklama en az 10 karakter olmalıdır'),
  longDescription: z.string().optional(),
  includes: z.array(z.string()).default([]),
  requirements: z.array(z.string()).default([]),
  scope: z.array(z.string()).default([]),
  metaTitle: z.string().optional(),
  metaDescription: z.string().optional(),
})

export type CourseFormInput = z.input<typeof courseFormSchema>
export type CourseFormValues = z.output<typeof courseFormSchema>
