using System.Collections.Generic;
using System.Linq;
namespace Sozsoft.Platform.Editors;
///
/// ListForm alanlarinin DevExtreme editor options JSON'unu uretir.
///
/// Buradaki metotlar hazir bir baslangic dondurur; uzerine
/// metotlariyla ekleme yapilabilir ve sonuc
/// string'e ortuk donustugu icin dogrudan atanabilir:
///
///
/// EditorOptions = EditorOptions.ShowClearButton(),
/// EditorOptions = EditorOptions.Number(4).ShowClearButton(),
/// EditorOptions = EditorOptions.Multiline(60).Placeholder("Aciklama"),
/// EditorOptions = EditorOptions.New().Flag("acceptCustomValue", true),
///
///
public static class EditorOptions
{
/// Bos baslangic; secenekler elle eklenir.
public static EditorOptionsBuilder New() => new EditorOptionsBuilder();
/// Alan pasif: kullanici degistiremez.
public static EditorOptionsBuilder Disabled() => New().Disabled();
/// Alan salt okunur: deger gorunur ve gonderilir, degistirilemez.
public static EditorOptionsBuilder ReadOnly() => New().ReadOnly();
/// Temizleme (x) dugmesi.
public static EditorOptionsBuilder ShowClearButton() => New().ShowClearButton();
/// Cok satirli metin alani icin yukseklik.
public static EditorOptionsBuilder Multiline(int height) => New().Height(height);
/// Sabit ondalikli sayi: bicim, maske davranisi ve artir/azalt dugmeleri.
public static EditorOptionsBuilder Number(int precision = 2)
=> New().FixedPointFormat(precision).UseMaskBehavior().ShowSpinButtons();
/// Yuzde alani.
public static EditorOptionsBuilder Percent()
=> New().Format("#0.##'%'").UseMaskBehavior().ShowSpinButtons();
/// Tarih alani (gun/ay/yil).
public static EditorOptionsBuilder Date()
=> New().Format("dd/MM/yyyy").DisplayFormat("dd/MM/yyyy");
/// Tarih + saat alani.
public static EditorOptionsBuilder DateTime()
=> New().Format("dd/MM/yyyy HH:mm").DisplayFormat("dd/MM/yyyy HH:mm");
/// Listeden secilen saat alani.
public static EditorOptionsBuilder Time(int intervalMinutes = 5)
=> New()
.Text("type", "time")
.Text("pickerType", "list")
.DisplayFormat("HH:mm")
.DateSerializationFormat("yyyy-MM-ddTHH:mm:ss")
.Number("interval", intervalMinutes)
.Width("100%");
/// Telefon alani: global bicim, maske ve ornek deger.
public static EditorOptionsBuilder Phone(string invalidMessage = "Lütfen geçerli bir telefon numarası girin")
=> New()
.Format("phoneGlobal")
.Mask("(000) 000-0000", invalidMessage)
.Raw("maskRules", "{\"X\":\"[0-9]\"}")
.Placeholder("(555) 123-4567");
/// Kaydirma cubugu; degeri ipucu olarak gosterir.
public static EditorOptionsBuilder Slider()
=> New().Raw("tooltip", "{\"enabled\":true}");
/// Gorsel yukleme alani.
public static EditorOptionsBuilder ImageUpload(bool multiple = true, int width = 80, int height = 80)
=> New().Width(width).Height(height).Flag("multiple", multiple);
/// Zengin metin (HTML) editoru; tam arac cubugu ile.
///
/// height verilirse editor sabitlenir ve icerik kaydirilir; min-height ise
/// en az yuksekligi korurken yeni satirlarla buyumesine izin verir.
///
public static EditorOptionsBuilder Html(int minHeight = 200)
=> New()
.Raw("mediaResizing", "{\"enabled\":true}")
.Raw("imageUpload", "{\"tabs\":[\"file\",\"url\"],\"fileUploadMode\":\"base64\"}")
.Raw("toolbar", "{\"multiline\":true,\"items\":[" + string.Join(",", HtmlToolbarItems()) + "]}")
.Flag("encodeHtml", true)
.Raw("elementAttr", "{\"style\":\"min-height:" + EditorJson.Number(minHeight) + "px\"}");
private static IEnumerable HtmlToolbarItems()
{
var fontSizes = new[] { "8pt", "10pt", "12pt", "14pt", "18pt", "24pt", "36pt" };
var fontFamilies = new[]
{
"Arial", "Courier New", "Georgia", "Impact",
"Lucida Console", "Tahoma", "Times New Roman", "Verdana"
};
yield return Item("undo");
yield return Item("redo");
yield return Item("separator");
yield return Picker("size", fontSizes, "Font size");
yield return Picker("font", fontFamilies, "Font family");
yield return Item("separator");
yield return Item("bold");
yield return Item("italic");
yield return Item("strike");
yield return Item("underline");
yield return Item("separator");
yield return Item("alignLeft");
yield return Item("alignCenter");
yield return Item("alignRight");
yield return Item("alignJustify");
yield return Item("separator");
yield return Item("orderedList");
yield return Item("bulletList");
yield return Item("separator");
yield return "{\"name\":\"header\",\"acceptedValues\":[false,1,2,3,4,5]}";
yield return Item("separator");
yield return Item("color");
yield return Item("background");
yield return Item("separator");
yield return Item("link");
yield return Item("image");
yield return Item("separator");
yield return Item("clear");
yield return Item("codeBlock");
yield return Item("blockquote");
yield return Item("separator");
yield return Item("insertTable");
yield return Item("deleteTable");
yield return Item("insertRowAbove");
yield return Item("insertRowBelow");
yield return Item("deleteRow");
yield return Item("insertColumnLeft");
yield return Item("insertColumnRight");
yield return Item("deleteColumn");
yield return Item("cellProperties");
yield return Item("tableProperties");
}
private static string Item(string name) => "{\"name\":" + EditorJson.Quote(name) + "}";
private static string Picker(string name, IEnumerable values, string ariaLabel)
=> "{\"name\":" + EditorJson.Quote(name) +
",\"acceptedValues\":[" + string.Join(",", values.Select(EditorJson.Quote)) + "]" +
",\"options\":{\"inputAttr\":{\"aria-label\":" + EditorJson.Quote(ariaLabel) + "}}}";
}